Issue #3502887 by mglaman, hooroomoo, jessebaker, bnjmnm, f.mazeikis: Prepare for avoiding full page reloads: move entity type and ID from base path and into routing parameters
Closes #3502887
The main change here is that previously Drupal's route was /xb/entityType/entityId and the presence of those slugs would add specific settings for the edited entity to drupalSettings.xb. Now the entityType and entityId is available from the React Route (via useParams()).
One outstanding issue that is a result of this change is that xbSettings.entityTypeKeys.label
is now not set but also I can't see a way of getting this info via an API or anything. Not sure what the solution to this is so open for suggestions. I think it can be a follow up because it only solves an edge case, not a core piece of functionality.
Another wrinkle that I've not solved and instead decided to kick down the road is that the current UX relies (in a number of different places) on users being able to enter the /code-editor
and then come back out of it again back to editing the same entity they came from. To facilitate this the code editor is now available via two different routes
/code-editor/code/:componentName
but also /editor/:entityType/:entityId/code-editor/code/:componentName
I don't really like this as a long term solution because a) I think there should be a canonical url for editing code components and b) it introduces complexity when sharing URLs between users. I think a better solution is something close to "We store a ‘history’ in memory or sessionStorage that we can then reference when we want to direct the user back to where they came from"
The vast majority of changes in this MR are to change /canvas/:entityType/:entityId/editor
to /canvas/editor/:entityId/:entityType
across many files and tests.
What this MR doesn't do
- Moving between editing different entities still has a full page reload. There were just too many different moving parts to try and do that as part of this (not to mention open questions like "what do we do with undo states when a user leaves one entity and starts editing a different one".
- I made changes to Drupal's route but it's broken PHP unit tests that I am not qualified to fix!