Refactor flat entity maps to be universal oriented (#17665)
# Introduction
In preparation of the workspace agnostic builder, we're migrating
`FlatEntityMaps` to be universal identifier oriented and based
As in the builder context there're won't be any ids at all
Please also note that the FlatEntity is a UniversalFlatEntity superset
From
```ts
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';
export type FlatEntityMaps<T extends SyncableFlatEntity> = {
byId: Partial<Record<string, T>>;
idByUniversalIdentifier: Partial<Record<string, string>>;
universalIdentifiersByApplicationId: Partial<Record<string, string[]>>;
};
```
To
```ts
export type FlatEntityMaps<
T extends SyncableFlatEntity | UniversalSyncableFlatEntity,
> = {
byUniversalIdentifier: Partial<Record<string, T>>;
universalIdentifierById: Partial<Record<string, string>>;
universalIdentifiersByApplicationId: Partial<Record<string, string[]>>; // this might make more sense to be migrated to universalIdentifiersByApplicationUniversalIdentifier but it's the main topic of this PR
};
```
## Low level maps tools
Had to refactor find | create | delete | replace | find-many | get-sub
tools ( through mutations and or throw equivalent )
This commit is contained in:
+5
-1
@@ -5,6 +5,7 @@ import {
|
||||
} from 'twenty-shared/utils';
|
||||
|
||||
import { type FlatPageLayoutMaps } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout-maps.type';
|
||||
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
|
||||
import { type FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';
|
||||
import {
|
||||
PageLayoutException,
|
||||
@@ -27,7 +28,10 @@ export const fromDestroyPageLayoutInputToFlatPageLayoutOrThrow = ({
|
||||
['id'],
|
||||
);
|
||||
|
||||
const existingFlatPageLayoutToDestroy = flatPageLayoutMaps.byId[pageLayoutId];
|
||||
const existingFlatPageLayoutToDestroy = findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: pageLayoutId,
|
||||
flatEntityMaps: flatPageLayoutMaps,
|
||||
});
|
||||
|
||||
if (!isDefined(existingFlatPageLayoutToDestroy)) {
|
||||
throw new PageLayoutException(
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@ import {
|
||||
} from 'twenty-shared/utils';
|
||||
|
||||
import { FLAT_PAGE_LAYOUT_EDITABLE_PROPERTIES } from 'src/engine/metadata-modules/flat-page-layout/constants/flat-page-layout-editable-properties.constant';
|
||||
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
|
||||
import { type FlatPageLayoutMaps } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout-maps.type';
|
||||
import { type FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';
|
||||
import { type UpdatePageLayoutInput } from 'src/engine/metadata-modules/page-layout/dtos/inputs/update-page-layout.input';
|
||||
@@ -31,8 +32,10 @@ export const fromUpdatePageLayoutInputToFlatPageLayoutToUpdateOrThrow = ({
|
||||
['id'],
|
||||
);
|
||||
|
||||
const existingFlatPageLayoutToUpdate =
|
||||
flatPageLayoutMaps.byId[pageLayoutToUpdateId];
|
||||
const existingFlatPageLayoutToUpdate = findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: pageLayoutToUpdateId,
|
||||
flatEntityMaps: flatPageLayoutMaps,
|
||||
});
|
||||
|
||||
if (!isDefined(existingFlatPageLayoutToUpdate)) {
|
||||
throw new PageLayoutException(
|
||||
|
||||
+4
-2
@@ -23,7 +23,7 @@ export const reconstructFlatPageLayoutWithTabsAndWidgets = ({
|
||||
flatPageLayoutTabMaps: FlatPageLayoutTabMaps;
|
||||
flatPageLayoutWidgetMaps: FlatPageLayoutWidgetMaps;
|
||||
}): FlatPageLayoutWithTabsAndWidgets => {
|
||||
const tabs = Object.values(flatPageLayoutTabMaps.byId)
|
||||
const tabs = Object.values(flatPageLayoutTabMaps.byUniversalIdentifier)
|
||||
.filter(isDefined)
|
||||
.filter(
|
||||
(tab) => tab.pageLayoutId === layout.id && !isDefined(tab.deletedAt),
|
||||
@@ -31,7 +31,9 @@ export const reconstructFlatPageLayoutWithTabsAndWidgets = ({
|
||||
.sort((a, b) => (a.position ?? 0) - (b.position ?? 0));
|
||||
|
||||
const tabsWithWidgets: FlatPageLayoutTabWithWidgets[] = tabs.map((tab) => {
|
||||
const widgets = Object.values(flatPageLayoutWidgetMaps.byId)
|
||||
const widgets = Object.values(
|
||||
flatPageLayoutWidgetMaps.byUniversalIdentifier,
|
||||
)
|
||||
.filter(isDefined)
|
||||
.filter(
|
||||
(widget) =>
|
||||
|
||||
Reference in New Issue
Block a user