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

clean up indexes store and pass values directly #4821

Merged
merged 3 commits into from
Sep 8, 2023

Conversation

mabaasit
Copy link
Contributor

@mabaasit mabaasit commented Sep 7, 2023

Description

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

Comment on lines -42 to -56
const rootReducer = (state: RootState, action: AnyAction): RootState => {
if (action.type === RESET_FORM) {
return {
...state,
isWritable: WRITABLE_INITIAL_STATE,
isReadonlyView: READONLY_VIEW_INITIAL_STATE,
description: DESCRIPTION_INITIAL_STATE,
serverVersion: SV_INITIAL_STATE,
namespace: NAMESPACE_INITIAL_STATE,
regularIndexes: REGULAR_INDEXES_INITIAL_STATE,
searchIndexes: SEARCH_INDEXES_INITIAL_STATE,
};
}
return reducer(state, action);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this as we do not have any form fields in view-indexes. This clean up is only applicable to create/drop indexes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome, those RESET actions are the biggest mess in old reducers in Compass, nice that we can remove it so easily

}
}

void store.dispatch(fetchIndexes());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably should be triggered from the UI, but keeping it here as was.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, when you are doing similar for search indexes, would probably be good to move this to UI too

@mabaasit mabaasit changed the title set up support for search indexes clean up indexes store and pass values directly Sep 7, 2023
@mabaasit mabaasit requested a review from gribnoysup September 7, 2023 16:48
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

Solid clean-up!

Comment on lines +61 to +62
const localAppRegistry = options.localAppRegistry;
store.dispatch(localAppRegistryActivated(localAppRegistry));
Copy link
Collaborator

Choose a reason for hiding this comment

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

If those are not in the store, we don't need to dispatch this, same for global one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we probably need it because we trigger delete/create modals using localAppRegistry. And by removing this, it not able to find the registry and throws.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, drop index and create index stores both have app registry slice, but this is a completely different store, you literally don't have a slice here that would react to those actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait i missed adding the registry. We have a default slice from the redux-common which is used in this store and then used on the UI to trigger actions.

I added this commit to the parent branch 91195c6

}
}

void store.dispatch(fetchIndexes());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, when you are doing similar for search indexes, would probably be good to move this to UI too

@@ -247,7 +250,8 @@ export const fetchIndexes = (): ThunkAction<
} = getState();

if (isReadonlyView) {
return _handleIndexesChanged(dispatch, []);
dispatch(_handleIndexesChanged([]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

store.dispatch(setIndexes(defaultSortedDesc as any));

{
await store.dispatch(sortIndexes('Name and Definition', 'asc'));
store.dispatch(sortIndexes('Name and Definition', 'asc') as any);
Copy link
Collaborator

@gribnoysup gribnoysup Sep 8, 2023

Choose a reason for hiding this comment

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

You need to assert here because Store<RootState> above is not a correct type for the store (it doesn't take thunk into account), if you change it to ReturnType<typeof setupStore> the need for this should go away (and this actually validates that the thunk type is matching what we are passing as extra args, so a good thing to have)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh that's awesome :) i spent time figuring this out and ended up with any.

Copy link
Collaborator

Choose a reason for hiding this comment

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

One cool (but totally not obvious thing) about redux middleware (not only thunk one) types is that it can actually change the type of store and dispatch methods, very handy technique

@mabaasit mabaasit merged commit 2c2a12b into setup-search-support Sep 8, 2023
@mabaasit mabaasit deleted the setup-store-with-defaults branch September 8, 2023 08:31
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