Skip to content

Commit

Permalink
Merge pull request #196 from bento-platform/fix/scope-fetch-and-click…
Browse files Browse the repository at this point in the history
…able

fix: don't double-fetch before scope is set + fetch data before click…
  • Loading branch information
davidlougheed authored Oct 3, 2024
2 parents edd0e14 + 52a3012 commit f482072
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit f482072

Please sign in to comment.