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:
Charles Bochet
2026-03-16 00:38:11 +01:00
committed by GitHub
parent 06efee1eef
commit ba9aa41bba
161 changed files with 3106 additions and 4350 deletions
@@ -13,7 +13,6 @@ import {
import {
combineFilters,
isDefined,
isMetadataGqlOperationSignature,
isNonEmptyArray,
isRecordGqlOperationSignature,
} from 'twenty-shared/utils';
@@ -51,10 +50,7 @@ import { buildRowLevelPermissionRecordFilter } from 'src/engine/twenty-orm/utils
import { isRecordMatchingRLSRowLevelPermissionPredicate } from 'src/engine/twenty-orm/utils/is-record-matching-rls-row-level-permission-predicate.util';
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
import { isMetadataRecordMatchingFilter } from 'src/engine/workspace-event-emitter/utils/is-metadata-record-matching-filter.util';
import { parseEventNameOrThrow } from 'src/engine/workspace-event-emitter/utils/parse-event-name';
import { type MetadataEvent } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-runner/types/metadata-event';
@Injectable()
export class WorkspaceEventEmitterService {
constructor(
@@ -183,36 +179,22 @@ export class WorkspaceEventEmitterService {
private async processMetadataStreamEvents(
streamChannelId: string,
streamData: EventStreamData,
_streamData: EventStreamData,
metadataEventBatch: MetadataEventBatch,
): Promise<void> {
const metadataEventsWithQueryIds: {
queryIds: string[];
metadataEvent: MetadataEvent & { updatedCollectionHash?: string };
}[] = [];
if (!isNonEmptyArray(metadataEventBatch.events)) {
return;
}
for (const metadataEvent of metadataEventBatch.events) {
const matchedQueryIds = this.getMatchingMetadataQueryIds(
streamData.queries,
metadataEvent,
);
if (!isNonEmptyArray(matchedQueryIds)) {
continue;
}
metadataEventsWithQueryIds.push({
queryIds: matchedQueryIds,
const metadataEventsWithQueryIds = metadataEventBatch.events.map(
(metadataEvent) => ({
queryIds: [] as string[],
metadataEvent: {
...metadataEvent,
updatedCollectionHash: metadataEventBatch.updatedCollectionHash,
},
});
}
if (!isNonEmptyArray(metadataEventsWithQueryIds)) {
return;
}
}),
);
const payload: EventStreamPayload = {
objectRecordEventsWithQueryIds: [],
@@ -226,49 +208,6 @@ export class WorkspaceEventEmitterService {
});
}
private getMatchingMetadataQueryIds(
queries: Record<string, RecordOrMetadataGqlOperationSignature>,
metadataEvent: MetadataEvent,
): string[] {
const properties = metadataEvent.properties as {
after?: Record<string, unknown>;
before?: Record<string, unknown>;
};
const record = properties?.after ?? properties?.before;
return Object.entries(queries)
.filter(([, operationSignature]) => {
if (!isMetadataGqlOperationSignature(operationSignature)) {
return false;
}
if (operationSignature.metadataName !== metadataEvent.metadataName) {
return false;
}
const queryFilter = (
operationSignature.variables as {
filter?: Record<string, unknown>;
}
)?.filter;
if (!isDefined(queryFilter) || Object.keys(queryFilter).length === 0) {
return true;
}
if (!isDefined(record)) {
return false;
}
return isMetadataRecordMatchingFilter({
record,
filter: queryFilter,
});
})
.map(([queryId]) => queryId);
}
private async processObjectRecordStreamEvents(
streamChannelId: string,
streamData: EventStreamData,