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:
@@ -10,7 +10,6 @@ import { useLastAuthenticatedWorkspaceDomain } from '@/domain-manager/hooks/useL
|
||||
import { useInitializeFormatPreferences } from '@/localization/hooks/useInitializeFormatPreferences';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
|
||||
import { coreViewsState } from '@/views/states/coreViewState';
|
||||
import { workspaceAuthBypassProvidersState } from '@/workspace/states/workspaceAuthBypassProvidersState';
|
||||
import { useCallback } from 'react';
|
||||
import { SOURCE_LOCALE, type APP_LOCALES } from 'twenty-shared/translations';
|
||||
@@ -18,10 +17,7 @@ import { type ObjectPermissions } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { type ColorScheme } from 'twenty-ui/input';
|
||||
import { useApolloClient } from '@apollo/client/react';
|
||||
import {
|
||||
FindAllCoreViewsDocument,
|
||||
GetCurrentUserDocument,
|
||||
} from '~/generated-metadata/graphql';
|
||||
import { GetCurrentUserDocument } from '~/generated-metadata/graphql';
|
||||
import { getWorkspaceUrl } from '~/utils/getWorkspaceUrl';
|
||||
import { dynamicActivate } from '~/utils/i18n/dynamicActivate';
|
||||
|
||||
@@ -39,7 +35,6 @@ export const useLoadCurrentUser = () => {
|
||||
);
|
||||
const setCurrentWorkspace = useSetAtomState(currentWorkspaceState);
|
||||
const { initializeFormatPreferences } = useInitializeFormatPreferences();
|
||||
const setCoreViews = useSetAtomState(coreViewsState);
|
||||
const setWorkspaceAuthBypassProviders = useSetAtomState(
|
||||
workspaceAuthBypassProvidersState,
|
||||
);
|
||||
@@ -55,13 +50,6 @@ export const useLoadCurrentUser = () => {
|
||||
fetchPolicy: 'network-only',
|
||||
});
|
||||
|
||||
const coreViewsResult = isOnAWorkspace
|
||||
? await client.query({
|
||||
query: FindAllCoreViewsDocument,
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (isDefined(currentUserResult.error)) {
|
||||
throw new Error(currentUserResult.error.message);
|
||||
}
|
||||
@@ -139,10 +127,6 @@ export const useLoadCurrentUser = () => {
|
||||
});
|
||||
}
|
||||
|
||||
if (isDefined(coreViewsResult?.data?.getCoreViews)) {
|
||||
setCoreViews(coreViewsResult.data.getCoreViews);
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
workspaceMember,
|
||||
@@ -159,7 +143,6 @@ export const useLoadCurrentUser = () => {
|
||||
setCurrentWorkspaceMember,
|
||||
initializeFormatPreferences,
|
||||
setLastAuthenticateWorkspaceDomain,
|
||||
setCoreViews,
|
||||
authProviders,
|
||||
setWorkspaceAuthBypassProviders,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user