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

fix: don't double-fetch before scope is set + fetch data before click… #196

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/js/components/BentoAppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ const BentoAppRouter = () => {
const { selectedScope, isFetching: isFetchingProjects } = useAppSelector((state) => state.metadata);

useEffect(() => {
if (!selectedScope.scopeSet) return;
dispatch(makeGetConfigRequest()).then(() => dispatch(getBeaconConfig()));
dispatch(makeGetAboutRequest());
dispatch(makeGetDataRequestThunk());
dispatch(makeGetSearchFields()).then(() => dispatch(populateClickable()));
// The "Populate clickable" action needs both chart sections and search fields to be available.
// TODO: this is not a very good pattern. It would be better to have a memoized way of determining click-ability at
// render time.
Promise.all([dispatch(makeGetDataRequestThunk()), dispatch(makeGetSearchFields())]).then(() =>
dispatch(populateClickable())
);
dispatch(makeGetKatsuPublic());
dispatch(fetchKatsuData());
}, [dispatch, isAuthenticated, selectedScope]);
Expand Down
3 changes: 3 additions & 0 deletions src/js/features/metadata/metadata.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type DiscoveryScope = { project?: string; dataset?: string };

export type DiscoveryScopeSelection = {
scope: DiscoveryScope;
scopeSet: boolean;
fixedProject: boolean;
fixedDataset: boolean;
};
Expand All @@ -26,6 +27,8 @@ const initialState: MetadataState = {
isFetching: false,
selectedScope: {
scope: { project: undefined, dataset: undefined },
// Whether scope has been set from URL/action yet. If it hasn't, we need to wait before fetching scoped data.
scopeSet: false,
fixedProject: false,
fixedDataset: false,
},
Expand Down
1 change: 1 addition & 0 deletions src/js/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const validProjectDataset = (projects: Project[], unvalidatedScope: Disco

const valid: DiscoveryScopeSelection = {
scope: { project: undefined, dataset: undefined },
scopeSet: true,
fixedProject: false,
fixedDataset: false,
};
Expand Down