Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist layout state in localStorage #891

Merged
merged 1 commit into from
Apr 13, 2023
Merged

Conversation

marstamm
Copy link
Contributor

Recording 2023-03-16 at 11 43 35

@bpmn-io-tasks bpmn-io-tasks bot added the in progress Currently worked on label Mar 16, 2023
@@ -314,7 +401,7 @@ describe('<BpmnPropertiesPanel>', function() {
createBpmnPropertiesPanel({ container, eventBus });

// then
expect(loadedSpy).to.have.been.calledOnce;
expect(loadedSpy).to.have.been.called;
Copy link
Contributor Author

@marstamm marstamm Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically tested internal API of the properties-panel before. I moved the assumption of calledOnce to the properties-panel repo, cf. bpmn-io/properties-panel#228

@marstamm marstamm marked this pull request as ready for review March 16, 2023 11:06
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Mar 16, 2023
@marstamm marstamm requested review from a team, philippfromme and barmac and removed request for a team March 16, 2023 11:06

// helpers //////
function getSavedLayout() {
const savedLayout = window.localStorage.getItem('bpmn-properties-panel-layout') || '{}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to hard code this inside the properties panel.

I'd rather

  • Provide a clear api / contract to listen for properties panel layout changes
  • Instantiate the properties panel or update it with a shared layout

➡️ Be API first, and not bury this inside the properties panel. How saving happens (if remotely or locally) is an application concern I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propertiesPanel.on('layoutChanged', ({ layout }) => {

  // persist layout somewhere
});

propertiesPanel.setLayout(layout);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we provide such a hook then could we make saving and getting configurable to accomplish https://github.com/bpmn-io/bpmn-js-properties-panel/pull/891/files#r1140288946?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the API should be explicit. I added a172bd0 to make the API more explicit and also expose it as propertiesPanel.setLayout().

I disagree that the implementation should always be on the integration side. In my opinion, it makes sense to have sensible defaults in the core which can be overwritten by the application. This is the case here: you can implement your own persistence/update logic by subscribing to propertiesPanel.layoutChanged and using the API (either eventBus or propertiesPanel.setLayout).
If you don't implement your own handler, you still get basic persistence across tabs in localStorage as the default implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say that this would be the first time that we move persistent state inside our libraries :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Removed with c82d5b3

@marstamm marstamm force-pushed the persist-group-state branch 3 times, most recently from c82d5b3 to e712f6e Compare March 20, 2023 15:35
@marstamm
Copy link
Contributor Author

My last commit on Friday broke the tests, it is fixed now :)

Ready for review again

@@ -207,7 +221,7 @@ export default function BpmnPropertiesPanel(props) {
headerProvider={ PanelHeaderProvider }
placeholderProvider={ PanelPlaceholderProvider(translate) }
groups={ groups }
layoutConfig={ layoutConfig }
layoutConfig={ layout }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make sense to change this key to layout, too?

Otherwise let's stay consistent and keep layout named layoutConfig.

Copy link
Member

@nikku nikku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me.

@marstamm
Copy link
Contributor Author

actually, let's move this to WIP until bpmn-io/properties-panel#228 is merged and released. We intermittently removed the feature this PR relies on with @bpmn-io/properties-panel@1.5.1

@marstamm marstamm marked this pull request as draft March 22, 2023 13:19
@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Mar 22, 2023
- exposes `setLayout` on `propertiesPanel` module

related to camunda/camunda-modeler#2638
@marstamm marstamm marked this pull request as ready for review April 13, 2023 06:34
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Apr 13, 2023
@marstamm marstamm merged commit 01ed48f into master Apr 13, 2023
@marstamm marstamm deleted the persist-group-state branch April 13, 2023 06:56
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants