Skip to content

Conversation

@JamieB-gu
Copy link
Contributor

@JamieB-gu JamieB-gu commented Nov 10, 2025

Experimental nav tool, nowhere near ready. This draft PR exists just to get a Chromatic build for testing.

Note: The lint failure is expected.

Creates a type to represent the apps nav as it currently appears in
`guardian/cross-platform-navigation`. Also adds a fixture taken from
that repo, for testing.
Add a component to display the apps nav, and corresponding stories.
Adds three buttons to each section:

- Delete: deletes the section
- Insert Into: inserts a new section as a subsection of the current one
- Insert After: inserts a new section adjacent to the current one

Also introduces a way to keep track of changes, and two buttons to work
with this history:

- Undo: undoes the last change
- Reset: undoes all changes, reverting to the initial state
Switched to an icon-only version of the inline section buttons, and
aligned them to appear before the section titles, making the UI more
regular.

The 'Insert After' button moves to the top menu, is renamed
"Add Section", and now reuses the `insertInto` action. The `insertAfter`
action is removed. The top menu now uses a `menu` element.

Swapped the icons used for "Undo" and "Reset".
@JamieB-gu JamieB-gu added the run_chromatic Runs chromatic when label is applied label Nov 10, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Nov 10, 2025
@github-actions
Copy link

github-actions bot commented Nov 13, 2025

Fixes a bug where the state for the form fields wasn't being populated
by the initial values coming from props.

As the form was always rendered, regardless of whether anything was
currently being edited, the initial values coming from the props and
passed to the `useState` calls were empty. Then when a particular
section was selected, these props changed to reflect the data from that
section. However, `useState` only uses the initial values from the
*first render*, so it was ignoring these updated props, and retaining
the empty values.

The solution is not to render the form while nothing is being edited,
and then render it when a section is selected for editing. That way each
time a section is selected for editing, the form is considered a new
addition to the tree, and therefore the initial data coming from props
on the "first render" is the section data.
Fixes a bug where the state for the form fields was being populated by
the data from the previous section added.

As the form is always rendered, regardless of whether anything is
currently being inserted, the state shown in the form fields and managed
by `useState` persists for the lifetime of the application. The first
time someone adds a section, the fields are empty. But if they're filled
out, the section inserted, and then the form is opened again to insert
another section, it still retains the values from the previous section
added.

The solution is not to render the form while nothing is being inserted,
and then render it when the "Add Section" button is clicked. That way
each time the form appears it is considered a new addition to the tree,
and therefore the initial, empty data coming from props on the "first
render" is used to populate the state.
@JamieB-gu JamieB-gu added the run_chromatic Runs chromatic when label is applied label Nov 13, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants