refactor: metadata store cleanup, SSE unification, mock metadata loading & login redirect fix (#18651)
## Summary - **SSE unification**: Replaced 11 individual SSE effect components with a single generic `MetadataStoreSSEEffect` - **Metadata store cleanup**: Merged `metadataCollectionHashesState` into `metadataStoreState` (currentCollectionHash / draftCollectionHash per entity), moved `objectMetadataItemsSelector` to `object-metadata` domain, converted `navigationMenuItemsState` to a derived selector - **Naming clarity**: Renamed `isAppMetadataReadyState` → `isMinimalMetadataReadyState`, `MetadataGater` → `MinimalMetadataGater`, `useIsLogged` → `useHasAccessTokenPair`, `patchMetadataStoreFromSSEEvent` now takes named object params - **Mock metadata loading**: Added `generate-navigation-menu-items.ts` script, rewrote `useLoadMockedMinimalMetadata` to load full objects/fields/indexes/views/navItems from generated mock data, enabling proper sign-in background rendering (table columns, view picker, navigation) - **Login/logout transitions**: `MinimalMetadataLoadEffect` manages mocked↔real metadata transitions based on auth state, `MainContextStoreProvider` computes context on auth pages for view picker support - **Login redirect fix**: `handleLoadWorkspaceAfterAuthentication` now re-enables `isAppEffectRedirectEnabled` after `loadCurrentUser()` completes, fixing the blocked post-login navigation - **Dead code removal**: Deleted `useRefreshPageLayouts`, `useApplyPageLayouts`, `useStaleMetadataEntities`, `metadataCollectionHashesState`, and all individual SSE effects ## Test plan - [x] Login from welcome page redirects to companies page - [x] Logout transitions cleanly to mocked metadata on welcome page - [x] Sign-in background shows table columns, view picker, and navigation items - [x] SSE events still update metadata store entries correctly - [x] Navigation menu items persist across page refreshes - [ ] CI: lint, typecheck, tests pass
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import { useMetadataStore } from '@/metadata-store/hooks/useMetadataStore';
|
||||
import { splitPageLayoutWithRelated } from '@/metadata-store/utils/splitPageLayoutWithRelated';
|
||||
import { pageLayoutCurrentLayoutsComponentState } from '@/page-layout/states/pageLayoutCurrentLayoutsComponentState';
|
||||
import { pageLayoutPersistedComponentState } from '@/page-layout/states/pageLayoutPersistedComponentState';
|
||||
import { recordPageLayoutsState } from '@/page-layout/states/recordPageLayoutsState';
|
||||
import { convertPageLayoutToTabLayouts } from '@/page-layout/utils/convertPageLayoutToTabLayouts';
|
||||
import { transformPageLayout } from '@/page-layout/utils/transformPageLayout';
|
||||
import { useStore } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
import { type PageLayout as PageLayoutGenerated } from '~/generated-metadata/graphql';
|
||||
|
||||
export const useApplyPageLayouts = () => {
|
||||
const store = useStore();
|
||||
const { updateDraft, applyChanges } = useMetadataStore();
|
||||
|
||||
const applyPageLayouts = useCallback(
|
||||
(pageLayouts: PageLayoutGenerated[]) => {
|
||||
const transformedPageLayouts = pageLayouts.map(transformPageLayout);
|
||||
|
||||
for (const pageLayout of transformedPageLayouts) {
|
||||
store.set(
|
||||
pageLayoutPersistedComponentState.atomFamily({
|
||||
instanceId: pageLayout.id,
|
||||
}),
|
||||
pageLayout,
|
||||
);
|
||||
store.set(
|
||||
pageLayoutCurrentLayoutsComponentState.atomFamily({
|
||||
instanceId: pageLayout.id,
|
||||
}),
|
||||
convertPageLayoutToTabLayouts(pageLayout),
|
||||
);
|
||||
}
|
||||
|
||||
store.set(recordPageLayoutsState.atom, transformedPageLayouts);
|
||||
|
||||
const { flatPageLayouts, flatPageLayoutTabs, flatPageLayoutWidgets } =
|
||||
splitPageLayoutWithRelated(transformedPageLayouts);
|
||||
|
||||
updateDraft('pageLayouts', flatPageLayouts);
|
||||
updateDraft('pageLayoutTabs', flatPageLayoutTabs);
|
||||
updateDraft('pageLayoutWidgets', flatPageLayoutWidgets);
|
||||
applyChanges();
|
||||
},
|
||||
[store, updateDraft, applyChanges],
|
||||
);
|
||||
|
||||
return {
|
||||
applyPageLayouts,
|
||||
};
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
import { useApplyPageLayouts } from '@/page-layout/hooks/useApplyPageLayouts';
|
||||
import { useCallback } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { useApolloClient } from '@apollo/client/react';
|
||||
import { FindAllPageLayoutsDocument } from '~/generated-metadata/graphql';
|
||||
|
||||
export const useRefreshPageLayouts = () => {
|
||||
const client = useApolloClient();
|
||||
|
||||
const { applyPageLayouts } = useApplyPageLayouts();
|
||||
|
||||
const refreshPageLayouts = useCallback(async () => {
|
||||
const result = await client.query({
|
||||
query: FindAllPageLayoutsDocument,
|
||||
fetchPolicy: 'network-only',
|
||||
});
|
||||
|
||||
if (!isDefined(result.data?.getPageLayouts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
applyPageLayouts(result.data.getPageLayouts);
|
||||
}, [client, applyPageLayouts]);
|
||||
|
||||
return {
|
||||
refreshPageLayouts,
|
||||
};
|
||||
};
|
||||
@@ -6,7 +6,6 @@ import { fieldsWidgetGroupsPersistedComponentState } from '@/page-layout/states/
|
||||
import { fieldsWidgetUngroupedFieldsDraftComponentState } from '@/page-layout/states/fieldsWidgetUngroupedFieldsDraftComponentState';
|
||||
import { fieldsWidgetUngroupedFieldsPersistedComponentState } from '@/page-layout/states/fieldsWidgetUngroupedFieldsPersistedComponentState';
|
||||
import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';
|
||||
import { useRefreshAllCoreViews } from '@/views/hooks/useRefreshAllCoreViews';
|
||||
import { useMutation } from '@apollo/client/react';
|
||||
import { useStore } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
@@ -82,8 +81,6 @@ export const useSaveFieldsWidgetGroups = ({
|
||||
{ input: UpsertFieldsWidgetInput }
|
||||
>(UPSERT_FIELDS_WIDGET);
|
||||
|
||||
const { refreshAllCoreViews } = useRefreshAllCoreViews();
|
||||
|
||||
const store = useStore();
|
||||
|
||||
const saveFieldsWidgetGroups = useCallback(async () => {
|
||||
@@ -165,8 +162,6 @@ export const useSaveFieldsWidgetGroups = ({
|
||||
);
|
||||
store.set(fieldsWidgetEditorModePersistedState, allEditorModes);
|
||||
|
||||
await refreshAllCoreViews();
|
||||
|
||||
return { status: 'successful' as const };
|
||||
}, [
|
||||
fieldsWidgetGroupsDraftState,
|
||||
@@ -176,7 +171,6 @@ export const useSaveFieldsWidgetGroups = ({
|
||||
fieldsWidgetEditorModeDraftState,
|
||||
fieldsWidgetEditorModePersistedState,
|
||||
upsertFieldsWidgetMutation,
|
||||
refreshAllCoreViews,
|
||||
store,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user