Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Implement selections per windowType and viewId #1264

Merged
merged 11 commits into from
Oct 17, 2017
Merged

Implement selections per windowType and viewId #1264

merged 11 commits into from
Oct 17, 2017

Conversation

ottosichert
Copy link
Contributor

(See #1248)

There was a lot of refactoring needed to reduce the complexity of the gist of this PR: a49cbf8

Now there is one global state.windowHandler.selected and selectedWindowType attribute shared across all windows. DocumentList caches the selection to avoid losing selection:
https://github.com/metasfresh/metasfresh-webui-frontend/blob/25ecf1f3c0716c7312c47e63ee6c16d51157c021/src/components/app/DocumentList.js#L158-L185

With this PR, this part will be removed. Instead selections for each windowType and viewId are stored, meaning selections can be re-used after changing view (and not being re-created in future).

Also the components DocumentList, Modal and SubHeader will retrieve selected items based on their viewId and windowType props.

@teosarca
Copy link
Member

@pablosichert hi Pablo, can u pls review this one?

Copy link
Contributor

@pablosichert pablosichert left a comment

Choose a reason for hiding this comment

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

The changes are a good move towards reducing complexity of the codebase. 👍

(There is still a lot to be done, especially restructuring the store so components can subscribe to changes properly.)

modalSaveStatus={
modal.saveStatus &&
modal.saveStatus.saved !== undefined ?
modal.saveStatus.saved : true
Copy link
Contributor

Choose a reason for hiding this comment

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

I would reverse this condition for readability:

modal.saveStatus &&
(modal.saveStatus.saved === undefined ?
    true : modal.saveStatus.saved)

However, I can't imagine why it should return true when saved is undefined.

Copy link
Member

Choose a reason for hiding this comment

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

not sure if is related, but the "saveStatus" (same as validStatus) are provided only when it's changed.
So it might be that saveStatus is missing from API response, just because nothing changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's most likely the correct explanation, thanks

};

export const NO_SELECTION = [];
export const getSelection = ({ state, windowType, viewId }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, windowType and viewId should be managed and taken from the store directly. Currently viewId is managed in DocumentList's internal state which is hard to share between all components reliably. When it's only passed down as a prop, we can't share it with sibling or parent components and lose the overview quick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is if we keep windowType and viewId in store, there still are different windowTypes and viewIds per DocumentList. And there can be 4 different DocumentLists active at the same time: modal and non-modal, and additionally as includedView each.

But you are right, viewId can not be shared with components other than its children. Actually this line (48) https://github.com/metasfresh/metasfresh-webui-frontend/blob/a49cbf8d11878b885d74a1e833c5e4865b51d6b8/src/components/app/DocumentList.js#L44-L50 uses defaultViewId from props instead of state, because there is no way to access state or context in connect()...


This is confusing, but not because of this connect() but because of the existence of defaultViewId. The viewId from state is only changed here:

@teosarca teosarca merged commit 4529802 into master Oct 17, 2017
@teosarca teosarca deleted the dev-1248 branch October 17, 2017 10:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants