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

Persist open state for list items during session #90

Open
pinussilvestrus opened this issue Aug 6, 2021 · 3 comments
Open

Persist open state for list items during session #90

pinussilvestrus opened this issue Aug 6, 2021 · 3 comments
Labels
backlog Queued in backlog enhancement New feature or request spring cleaning Could be cleaned up one day

Comments

@pinussilvestrus
Copy link
Contributor

pinussilvestrus commented Aug 6, 2021

Is your feature request related to a problem? Please describe

This is a follow up of: #86

Introducing #86, list items are completely unique per id. Therefore they have their own state depending on what element is selected. Since the items are unique per id, they got rerendered when a new element got selected.+

That causes that the state got lost when switching from one element to another and switch back again (the item is closed, no matter it was opened after the switch).

Kapture 2021-08-06 at 10 55 19

Describe the solution you'd like

For a smoother editing experience and to avoid opening list items multiple times during element switches, it should be possible to persist the opened state per item during a session (or multiple sessions).

We have the LayoutContext which was meant for exactly this purpose, but we are currently not using it.

Describe alternatives you've considered

Additional context

Cf. #86

@pinussilvestrus pinussilvestrus added the enhancement New feature or request label Aug 6, 2021
@pinussilvestrus pinussilvestrus added the backlog Queued in backlog label Aug 6, 2021 — with bpmn-io-tasks
@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed backlog Queued in backlog labels Aug 6, 2021
@pinussilvestrus pinussilvestrus added backlog Queued in backlog and removed in progress Currently worked on labels Aug 6, 2021
@pinussilvestrus pinussilvestrus removed their assignment Aug 6, 2021
@pinussilvestrus
Copy link
Contributor Author

pinussilvestrus commented Aug 6, 2021

A sketch of how to use the LayoutContext to persist the open state (cf. this branch)

import {
  useContext,
  useMemo,
  useState
} from 'preact/hooks';

import {
  LayoutContext
} from '../../context';

export default function CollapsibleEntry(props) {

  const {
    // ...
    open: shouldOpen
  } = props;

  const {
    layout,
    setLayoutForKey
  } = useContext(LayoutContext);

  const layoutKey = useMemo(() => {
    return `collapsible-${id}`;
  }, [ id ]);

  const collapsibleLayout = layout[layoutKey] || {};

  const [ open, setOpen ] = useState(shouldOpen || collapsibleLayout.open);

  const toggleOpen = () => {
    setOpen(!open);
    setLayoutForKey(layoutKey, {
      ...collapsibleLayout,
      open: !open
    });
  };

  // ...
}
{
  "collapsible-StartEvent_1-output-0": {
    "open": true
  },
  "collapsible-StartEvent_1-output-1": {
    "open": false
  },
  "collapsible-StartEvent_1-output-2": {
    "open": true
  },
  "collapsible-Task_1-output-0": {
    "open": false
  },
  "collapsible-StartEvent_1-output-3": {
    "open": false
  }
}

Kapture 2021-08-06 at 10 45 47

@pinussilvestrus
Copy link
Contributor Author

pinussilvestrus commented Aug 6, 2021

Open for discussion:

  • How should the layout API look like?
  • How to properly store the data inside the context?
  • For which components does it make sense?
  • Should we promote this? Event listeners (propertiesPanel.layoutChanged)?

@pinussilvestrus
Copy link
Contributor Author

With #99 we've built a fundamental to use the layout context for individual components. Let's use that for list items (and nested list items) as well 👍

@pinussilvestrus pinussilvestrus added ready Ready to be worked on spring cleaning Could be cleaned up one day and removed backlog Queued in backlog labels Oct 7, 2021
@MaxTru MaxTru added the backlog Queued in backlog label Dec 2, 2021 — with bpmn-io-tasks
@MaxTru MaxTru removed the ready Ready to be worked on label Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Queued in backlog enhancement New feature or request spring cleaning Could be cleaned up one day
Development

No branches or pull requests

2 participants