Skip to content

Recognise that view isn't in the hierarchy with flow.has #210

@dariocravero

Description

@dariocravero

In this app flowhasissue.zip, when /App/Content is No, then the button on /App/EditOneAction shouldn't have isSelected set to true because /App/Content/Content/Edit/One isn't set.

What happens now is that because One is the default view in /App/Content/Content/Edit, it wins because of this https://github.com/viewstools/morph/blob/master/views/ViewsFlow.js#L104.

The expected behaviour would be that the flow.has method goes all the way up trying to find whether a parent of the view being checked is in fact in the flow, be it that it is a default view of an active path or not.

A workaround for now is to add a new view called No in /App/Content/Content/Edit.

Side note:
Since that'll be a recursive operation, it might be slow. Since these checks happen on every render I suggest that whenever we implement this we also consider adding a local cache to flow.has, something like this:

export function useFlow() {
  let state = useFlowState()

  return useMemo(() => {
    let _has = {}

    return {
      has: key => {
        if (!key) return false

        if (!(key in _has)) {
          _has[key] = calculate()
        }
        return _has[key]

        function calculate() {
          // ...the actual logic we have in there now plus the changes
        }
      },
      flow: state.flow,
    }
  }, [state.flow])
}

This will need to be tested for side effects with flow items with arguments (eg, a list gets a new item or the item gets removed) but in principle it should work as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions