@webiny/app-headless-cms 6.6.0-alpha.10 → 6.6.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HeadlessCMS.js +3 -0
- package/HeadlessCMS.js.map +1 -1
- package/features/contentEntry/entryEvents/ApplyEntryChangeToCache.d.ts +21 -0
- package/features/contentEntry/entryEvents/ApplyEntryChangeToCache.js +39 -0
- package/features/contentEntry/entryEvents/ApplyEntryChangeToCache.js.map +1 -0
- package/features/contentEntry/entryEvents/EntryEvents.test.d.ts +1 -0
- package/features/contentEntry/entryEvents/EntryEvents.test.js +124 -0
- package/features/contentEntry/entryEvents/EntryEvents.test.js.map +1 -0
- package/features/contentEntry/entryEvents/feature.d.ts +6 -0
- package/features/contentEntry/entryEvents/feature.js +11 -0
- package/features/contentEntry/entryEvents/feature.js.map +1 -0
- package/features/contentEntry/entryEvents/index.d.ts +1 -0
- package/features/contentEntry/entryEvents/index.js +1 -0
- package/package.json +20 -20
- package/presentation/contentEntries/list/ContentEntriesPresenter.d.ts +8 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.js +35 -2
- package/presentation/contentEntries/list/ContentEntriesPresenter.js.map +1 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js +69 -0
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js.map +1 -1
- package/presentation/contentEntries/trashBin/CmsTrashBin.js +12 -2
- package/presentation/contentEntries/trashBin/CmsTrashBin.js.map +1 -1
- package/presentation/contentEntries/views/SingleEntryLayout.js +1 -1
- package/presentation/contentEntries/views/SingleEntryLayout.js.map +1 -1
- package/presentation/contentModels/ContentModelsDataSource.d.ts +5 -6
- package/presentation/contentModels/ContentModelsDataSource.js +12 -14
- package/presentation/contentModels/ContentModelsDataSource.js.map +1 -1
- package/presentation/contentModels/ContentModelsDataSource.test.d.ts +1 -0
- package/presentation/contentModels/ContentModelsDataSource.test.js +70 -0
- package/presentation/contentModels/ContentModelsDataSource.test.js.map +1 -0
- package/presentation/contentModels/ContentModelsPresenter.d.ts +1 -2
- package/presentation/contentModels/ContentModelsPresenter.js +13 -24
- package/presentation/contentModels/ContentModelsPresenter.js.map +1 -1
- package/presentation/contentModels/abstractions.d.ts +2 -6
- package/presentation/contentModels/abstractions.js.map +1 -1
- package/presentation/contentModels/components/ContentModels.js +1 -0
- package/presentation/contentModels/components/ContentModels.js.map +1 -1
- package/presentation/contentModels/components/ContentModelsDataList.js +12 -37
- package/presentation/contentModels/components/ContentModelsDataList.js.map +1 -1
- package/presentation/contentModels/isListedModel.d.ts +2 -0
- package/presentation/contentModels/isListedModel.js +4 -0
- package/presentation/contentModels/isListedModel.js.map +1 -0
- package/presentation/modelGroup/ModelGroupDataSource.d.ts +5 -6
- package/presentation/modelGroup/ModelGroupDataSource.js +10 -13
- package/presentation/modelGroup/ModelGroupDataSource.js.map +1 -1
- package/presentation/modelGroup/ModelGroupDataSource.test.d.ts +1 -0
- package/presentation/modelGroup/ModelGroupDataSource.test.js +63 -0
- package/presentation/modelGroup/ModelGroupDataSource.test.js.map +1 -0
- package/presentation/modelGroup/ModelGroupPresenter.d.ts +4 -0
- package/presentation/modelGroup/ModelGroupPresenter.js +32 -2
- package/presentation/modelGroup/ModelGroupPresenter.js.map +1 -1
- package/presentation/modelGroup/ModelGroupPresenter.test.d.ts +1 -0
- package/presentation/modelGroup/ModelGroupPresenter.test.js +88 -0
- package/presentation/modelGroup/ModelGroupPresenter.test.js.map +1 -0
- package/presentation/modelGroup/abstractions.d.ts +2 -0
- package/presentation/modelGroup/abstractions.js.map +1 -1
- package/presentation/modelGroup/components/ContentModelGroups.js +1 -0
- package/presentation/modelGroup/components/ContentModelGroups.js.map +1 -1
- package/presentation/modelGroup/components/ContentModelGroupsDataList.js +12 -37
- package/presentation/modelGroup/components/ContentModelGroupsDataList.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/contentModels/ContentModelsPresenter.js","sources":["../../../src/presentation/contentModels/ContentModelsPresenter.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"presentation/contentModels/ContentModelsPresenter.js","sources":["../../../src/presentation/contentModels/ContentModelsPresenter.ts"],"sourcesContent":["import { ListPresenter } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\nimport type { CmsModel } from \"~/types.js\";\nimport { ListModelsUseCase } from \"~/features/model/listModels/abstractions.js\";\nimport { DeleteModelUseCase } from \"~/features/model/deleteModel/abstractions.js\";\nimport { CancelDeleteModelUseCase } from \"~/features/model/cancelDeleteModel/abstractions.js\";\nimport { ExportModelsUseCase } from \"~/features/model/exportModels/abstractions.js\";\nimport { ModelsCache } from \"~/features/model/abstractions.js\";\nimport { ContentModelsPresenter as Abstraction } from \"./abstractions.js\";\nimport { ContentModelsDataSource } from \"./ContentModelsDataSource.js\";\n\nclass ContentModelsPresenterImpl implements Abstraction.Interface {\n constructor(\n private listPresenter: ListPresenter.Interface<CmsModel>,\n private listModelsUseCase: ListModelsUseCase.Interface,\n private deleteModelUseCase: DeleteModelUseCase.Interface,\n private cancelDeleteModelUseCase: CancelDeleteModelUseCase.Interface,\n private exportModelsUseCase: ExportModelsUseCase.Interface,\n private cache: ModelsCache.Interface\n ) {}\n\n get list(): ListPresenter.Interface<CmsModel> {\n return this.listPresenter;\n }\n\n init(): void {\n const dataSource = new ContentModelsDataSource(this.listModelsUseCase, this.cache);\n\n this.listPresenter.init({\n dataSource,\n initialSort: { field: \"savedOn\", direction: \"DESC\" },\n limit: 1000,\n itemLabel: { singular: \"model\", plural: \"models\" },\n assistant: {\n view: () => \"Content models in Headless CMS\",\n rowTitle: model => model.name,\n rowId: model => model.modelId\n }\n });\n }\n\n dispose(): void {\n this.listPresenter.dispose();\n }\n\n async deleteModel(modelId: string, confirmation: string) {\n return this.deleteModelUseCase.execute(modelId, confirmation);\n }\n\n async cancelDelete(modelId: string) {\n return this.cancelDeleteModelUseCase.execute(modelId);\n }\n\n async exportModels(modelIds?: string[]): Promise<Abstraction.ExportModelResponse | null> {\n return await this.exportModelsUseCase.execute(modelIds);\n }\n}\n\nexport const ContentModelsPresenter = Abstraction.createImplementation({\n implementation: ContentModelsPresenterImpl,\n dependencies: [\n ListPresenter,\n ListModelsUseCase,\n DeleteModelUseCase,\n CancelDeleteModelUseCase,\n ExportModelsUseCase,\n ModelsCache\n ]\n});\n"],"names":["ContentModelsPresenterImpl","listPresenter","listModelsUseCase","deleteModelUseCase","cancelDeleteModelUseCase","exportModelsUseCase","cache","dataSource","ContentModelsDataSource","model","modelId","confirmation","modelIds","ContentModelsPresenter","Abstraction","ListPresenter","ListModelsUseCase","DeleteModelUseCase","CancelDeleteModelUseCase","ExportModelsUseCase","ModelsCache"],"mappings":";;;;;;;;AAUA,MAAMA;IACF,YACYC,aAAgD,EAChDC,iBAA8C,EAC9CC,kBAAgD,EAChDC,wBAA4D,EAC5DC,mBAAkD,EAClDC,KAA4B,CACtC;aANUL,aAAa,GAAbA;aACAC,iBAAiB,GAAjBA;aACAC,kBAAkB,GAAlBA;aACAC,wBAAwB,GAAxBA;aACAC,mBAAmB,GAAnBA;aACAC,KAAK,GAALA;IACT;IAEH,IAAI,OAA0C;QAC1C,OAAO,IAAI,CAAC,aAAa;IAC7B;IAEA,OAAa;QACT,MAAMC,aAAa,IAAIC,wBAAwB,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK;QAEjF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACpBD;YACA,aAAa;gBAAE,OAAO;gBAAW,WAAW;YAAO;YACnD,OAAO;YACP,WAAW;gBAAE,UAAU;gBAAS,QAAQ;YAAS;YACjD,WAAW;gBACP,MAAM,IAAM;gBACZ,UAAUE,CAAAA,QAASA,MAAM,IAAI;gBAC7B,OAAOA,CAAAA,QAASA,MAAM,OAAO;YACjC;QACJ;IACJ;IAEA,UAAgB;QACZ,IAAI,CAAC,aAAa,CAAC,OAAO;IAC9B;IAEA,MAAM,YAAYC,OAAe,EAAEC,YAAoB,EAAE;QACrD,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACD,SAASC;IACpD;IAEA,MAAM,aAAaD,OAAe,EAAE;QAChC,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACA;IACjD;IAEA,MAAM,aAAaE,QAAmB,EAAmD;QACrF,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACA;IAClD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAAgC,CAAC;IACnE,gBAAgBd;IAChB,cAAc;QACVe;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { IListPresenter } from "@webiny/app-admin/presentation/listPresenter/abstractions.js";
|
|
2
2
|
import type { CmsGroup, CmsModel } from "../../types.js";
|
|
3
3
|
import type { DeleteModelResult } from "../../features/model/deleteModel/abstractions.js";
|
|
4
|
-
export interface IContentModelsPresenterViewModel {
|
|
5
|
-
loading: boolean;
|
|
6
|
-
models: CmsModel[];
|
|
7
|
-
}
|
|
8
4
|
export interface IContentModelsPresenterExportModelsResponse {
|
|
9
5
|
groups: CmsGroup[];
|
|
10
6
|
models: CmsModel[];
|
|
11
7
|
}
|
|
12
8
|
export interface IContentModelsPresenter {
|
|
13
|
-
readonly vm: IContentModelsPresenterViewModel;
|
|
14
9
|
readonly list: IListPresenter<CmsModel>;
|
|
15
10
|
init(): void;
|
|
11
|
+
/** Stops telling the assistant about the models list. */
|
|
12
|
+
dispose(): void;
|
|
16
13
|
deleteModel(modelId: string, confirmation: string): Promise<DeleteModelResult>;
|
|
17
14
|
cancelDelete(modelId: string): Promise<void>;
|
|
18
15
|
exportModels(modelIds?: string[]): Promise<IContentModelsPresenterExportModelsResponse | null>;
|
|
@@ -20,6 +17,5 @@ export interface IContentModelsPresenter {
|
|
|
20
17
|
export declare const ContentModelsPresenter: import("@webiny/di").Abstraction<IContentModelsPresenter>;
|
|
21
18
|
export declare namespace ContentModelsPresenter {
|
|
22
19
|
type Interface = IContentModelsPresenter;
|
|
23
|
-
type ViewModel = IContentModelsPresenterViewModel;
|
|
24
20
|
type ExportModelResponse = IContentModelsPresenterExportModelsResponse;
|
|
25
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/contentModels/abstractions.js","sources":["../../../src/presentation/contentModels/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IListPresenter } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\nimport type { CmsGroup, CmsModel } from \"~/types.js\";\nimport type { DeleteModelResult } from \"~/features/model/deleteModel/abstractions.js\";\n\nexport interface
|
|
1
|
+
{"version":3,"file":"presentation/contentModels/abstractions.js","sources":["../../../src/presentation/contentModels/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IListPresenter } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\nimport type { CmsGroup, CmsModel } from \"~/types.js\";\nimport type { DeleteModelResult } from \"~/features/model/deleteModel/abstractions.js\";\n\nexport interface IContentModelsPresenterExportModelsResponse {\n groups: CmsGroup[];\n models: CmsModel[];\n}\n\nexport interface IContentModelsPresenter {\n readonly list: IListPresenter<CmsModel>;\n init(): void;\n /** Stops telling the assistant about the models list. */\n dispose(): void;\n deleteModel(modelId: string, confirmation: string): Promise<DeleteModelResult>;\n cancelDelete(modelId: string): Promise<void>;\n exportModels(modelIds?: string[]): Promise<IContentModelsPresenterExportModelsResponse | null>;\n}\n\nexport const ContentModelsPresenter = createAbstraction<IContentModelsPresenter>(\n \"CmsContentModels/Presenter\"\n);\n\nexport namespace ContentModelsPresenter {\n export type Interface = IContentModelsPresenter;\n export type ExportModelResponse = IContentModelsPresenterExportModelsResponse;\n}\n"],"names":["ContentModelsPresenter","createAbstraction"],"mappings":";AAoBO,MAAMA,yBAAyBC,kBAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/contentModels/components/ContentModels.js","sources":["../../../../src/presentation/contentModels/components/ContentModels.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useSecurity } from \"@webiny/app-admin\";\nimport type { CmsModel, CmsSecurityPermission } from \"~/types.js\";\nimport { Grid } from \"@webiny/admin-ui\";\nimport { useContentModelsPresenter } from \"../useContentModelsPresenter.js\";\nimport ContentModelsDataList from \"./ContentModelsDataList.js\";\nimport NewContentModelDialog from \"./NewContentModelDialog.js\";\nimport { CloneContentModelDialog } from \"./CloneContentModelDialog.js\";\nimport { ImportContentModelsDialog } from \"~/presentation/importContentModels/ImportContentModelsDialog.js\";\n\nconst ContentModels = observer(() => {\n const presenter = useContentModelsPresenter();\n\n const [newContentModelDialogOpened, openNewContentModelDialog] = useState(false);\n const [cloneContentModel, setCloneContentModel] = useState<CmsModel | null>(null);\n const [importModels, setImportModels] = useState(false);\n\n const { identity, getPermission } = useSecurity();\n\n const canCreate = React.useMemo((): boolean => {\n const permission = getPermission<CmsSecurityPermission>(\"cms.contentModel\");\n if (!permission) {\n return false;\n }\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n return permission.rwd.includes(\"w\");\n }, [identity]);\n\n useEffect(() => {\n presenter.init();\n }, [presenter]);\n\n const onCreate = useCallback((): void => openNewContentModelDialog(true), []);\n const onClose = useCallback((): void => openNewContentModelDialog(false), []);\n const onClone = useCallback(\n (contentModel: CmsModel): void => setCloneContentModel(contentModel),\n []\n );\n const onCloneClose = useCallback((): void => setCloneContentModel(null), []);\n const showImportModelModal = useCallback(() => setImportModels(true), []);\n const closeImportModelModal = useCallback(() => setImportModels(false), []);\n\n return (\n <div className={\"container h-main-content\"}>\n <Grid className=\"h-full pt-lg\">\n <Grid.Column span={10} offset={1}>\n <div className=\"h-full border-sm border-b-none border-neutral-dimmed-darker rounded-t-3xl\">\n <ContentModelsDataList\n showImportModelModal={showImportModelModal}\n canCreate={canCreate}\n onCreate={onCreate}\n onClone={onClone}\n />\n </div>\n </Grid.Column>\n </Grid>\n <NewContentModelDialog open={newContentModelDialogOpened} onClose={onClose} />\n {cloneContentModel ? (\n <CloneContentModelDialog\n contentModel={cloneContentModel}\n onClose={onCloneClose}\n closeModal={() => setCloneContentModel(null)}\n />\n ) : null}\n {importModels ? <ImportContentModelsDialog onClose={closeImportModelModal} /> : null}\n </div>\n );\n});\n\nexport default ContentModels;\n"],"names":["ContentModels","observer","presenter","useContentModelsPresenter","newContentModelDialogOpened","openNewContentModelDialog","useState","cloneContentModel","setCloneContentModel","importModels","setImportModels","identity","getPermission","useSecurity","canCreate","React","permission","useEffect","onCreate","useCallback","onClose","onClone","contentModel","onCloneClose","showImportModelModal","closeImportModelModal","Grid","ContentModelsDataList","NewContentModelDialog","CloneContentModelDialog","ImportContentModelsDialog"],"mappings":";;;;;;;;;AAWA,MAAMA,gBAAgBC,SAAS;IAC3B,MAAMC,YAAYC;IAElB,MAAM,CAACC,6BAA6BC,0BAA0B,GAAGC,SAAS;IAC1E,MAAM,CAACC,mBAAmBC,qBAAqB,GAAGF,SAA0B;IAC5E,MAAM,CAACG,cAAcC,gBAAgB,GAAGJ,SAAS;IAEjD,MAAM,EAAEK,QAAQ,EAAEC,aAAa,EAAE,GAAGC;IAEpC,MAAMC,YAAYC,MAAAA,OAAa,CAAC;QAC5B,MAAMC,aAAaJ,cAAqC;QACxD,IAAI,CAACI,YACD,OAAO;QAEX,IAAI,AAA0B,YAA1B,OAAOA,WAAW,GAAG,EACrB,OAAO;QAEX,OAAOA,WAAW,GAAG,CAAC,QAAQ,CAAC;IACnC,GAAG;QAACL;KAAS;IAEbM,UAAU;QACNf,UAAU,IAAI;
|
|
1
|
+
{"version":3,"file":"presentation/contentModels/components/ContentModels.js","sources":["../../../../src/presentation/contentModels/components/ContentModels.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useSecurity } from \"@webiny/app-admin\";\nimport type { CmsModel, CmsSecurityPermission } from \"~/types.js\";\nimport { Grid } from \"@webiny/admin-ui\";\nimport { useContentModelsPresenter } from \"../useContentModelsPresenter.js\";\nimport ContentModelsDataList from \"./ContentModelsDataList.js\";\nimport NewContentModelDialog from \"./NewContentModelDialog.js\";\nimport { CloneContentModelDialog } from \"./CloneContentModelDialog.js\";\nimport { ImportContentModelsDialog } from \"~/presentation/importContentModels/ImportContentModelsDialog.js\";\n\nconst ContentModels = observer(() => {\n const presenter = useContentModelsPresenter();\n\n const [newContentModelDialogOpened, openNewContentModelDialog] = useState(false);\n const [cloneContentModel, setCloneContentModel] = useState<CmsModel | null>(null);\n const [importModels, setImportModels] = useState(false);\n\n const { identity, getPermission } = useSecurity();\n\n const canCreate = React.useMemo((): boolean => {\n const permission = getPermission<CmsSecurityPermission>(\"cms.contentModel\");\n if (!permission) {\n return false;\n }\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n return permission.rwd.includes(\"w\");\n }, [identity]);\n\n useEffect(() => {\n presenter.init();\n return () => presenter.dispose();\n }, [presenter]);\n\n const onCreate = useCallback((): void => openNewContentModelDialog(true), []);\n const onClose = useCallback((): void => openNewContentModelDialog(false), []);\n const onClone = useCallback(\n (contentModel: CmsModel): void => setCloneContentModel(contentModel),\n []\n );\n const onCloneClose = useCallback((): void => setCloneContentModel(null), []);\n const showImportModelModal = useCallback(() => setImportModels(true), []);\n const closeImportModelModal = useCallback(() => setImportModels(false), []);\n\n return (\n <div className={\"container h-main-content\"}>\n <Grid className=\"h-full pt-lg\">\n <Grid.Column span={10} offset={1}>\n <div className=\"h-full border-sm border-b-none border-neutral-dimmed-darker rounded-t-3xl\">\n <ContentModelsDataList\n showImportModelModal={showImportModelModal}\n canCreate={canCreate}\n onCreate={onCreate}\n onClone={onClone}\n />\n </div>\n </Grid.Column>\n </Grid>\n <NewContentModelDialog open={newContentModelDialogOpened} onClose={onClose} />\n {cloneContentModel ? (\n <CloneContentModelDialog\n contentModel={cloneContentModel}\n onClose={onCloneClose}\n closeModal={() => setCloneContentModel(null)}\n />\n ) : null}\n {importModels ? <ImportContentModelsDialog onClose={closeImportModelModal} /> : null}\n </div>\n );\n});\n\nexport default ContentModels;\n"],"names":["ContentModels","observer","presenter","useContentModelsPresenter","newContentModelDialogOpened","openNewContentModelDialog","useState","cloneContentModel","setCloneContentModel","importModels","setImportModels","identity","getPermission","useSecurity","canCreate","React","permission","useEffect","onCreate","useCallback","onClose","onClone","contentModel","onCloneClose","showImportModelModal","closeImportModelModal","Grid","ContentModelsDataList","NewContentModelDialog","CloneContentModelDialog","ImportContentModelsDialog"],"mappings":";;;;;;;;;AAWA,MAAMA,gBAAgBC,SAAS;IAC3B,MAAMC,YAAYC;IAElB,MAAM,CAACC,6BAA6BC,0BAA0B,GAAGC,SAAS;IAC1E,MAAM,CAACC,mBAAmBC,qBAAqB,GAAGF,SAA0B;IAC5E,MAAM,CAACG,cAAcC,gBAAgB,GAAGJ,SAAS;IAEjD,MAAM,EAAEK,QAAQ,EAAEC,aAAa,EAAE,GAAGC;IAEpC,MAAMC,YAAYC,MAAAA,OAAa,CAAC;QAC5B,MAAMC,aAAaJ,cAAqC;QACxD,IAAI,CAACI,YACD,OAAO;QAEX,IAAI,AAA0B,YAA1B,OAAOA,WAAW,GAAG,EACrB,OAAO;QAEX,OAAOA,WAAW,GAAG,CAAC,QAAQ,CAAC;IACnC,GAAG;QAACL;KAAS;IAEbM,UAAU;QACNf,UAAU,IAAI;QACd,OAAO,IAAMA,UAAU,OAAO;IAClC,GAAG;QAACA;KAAU;IAEd,MAAMgB,WAAWC,YAAY,IAAYd,0BAA0B,OAAO,EAAE;IAC5E,MAAMe,UAAUD,YAAY,IAAYd,0BAA0B,QAAQ,EAAE;IAC5E,MAAMgB,UAAUF,YACZ,CAACG,eAAiCd,qBAAqBc,eACvD,EAAE;IAEN,MAAMC,eAAeJ,YAAY,IAAYX,qBAAqB,OAAO,EAAE;IAC3E,MAAMgB,uBAAuBL,YAAY,IAAMT,gBAAgB,OAAO,EAAE;IACxE,MAAMe,wBAAwBN,YAAY,IAAMT,gBAAgB,QAAQ,EAAE;IAE1E,OAAO,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAACgB,MAAIA;QAAC,WAAU;qBACZ,oBAACA,KAAK,MAAM;QAAC,MAAM;QAAI,QAAQ;qBAC3B,oBAAC;QAAI,WAAU;qBACX,oBAACC,uBAAqBA;QAClB,sBAAsBH;QACtB,WAAWV;QACX,UAAUI;QACV,SAASG;yBAKzB,oBAACO,uBAAqBA;QAAC,MAAMxB;QAA6B,SAASgB;QAClEb,oBAAoB,WAApBA,GACG,oBAACsB,yBAAuBA;QACpB,cAActB;QACd,SAASgB;QACT,YAAY,IAAMf,qBAAqB;SAE3C,MACHC,eAAe,WAAfA,GAAe,oBAACqB,2BAAyBA;QAAC,SAASL;SAA4B;AAG5F;AAEA,iCAAezB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import react, { useCallback,
|
|
1
|
+
import react, { useCallback, useState } from "react";
|
|
2
2
|
import { observer } from "mobx-react-lite";
|
|
3
|
-
import orderBy from "lodash/orderBy.js";
|
|
4
3
|
import { Button, DataList, DataListModal, DropdownMenu, Icon, IconButton, List, Select, TimeAgo, Tooltip } from "@webiny/admin-ui";
|
|
5
4
|
import { SearchUI, useRouter, useSnackbar } from "@webiny/app-admin";
|
|
6
5
|
import { ReactComponent } from "@webiny/icons/add.svg";
|
|
@@ -21,6 +20,7 @@ import { Routes } from "../../../routes.js";
|
|
|
21
20
|
import { normalizeIcon } from "../../../utils/normalizeIcon.js";
|
|
22
21
|
import { useContentModelsPresenter } from "../useContentModelsPresenter.js";
|
|
23
22
|
import { download } from "../utils/download.js";
|
|
23
|
+
import { fromSortOption, toSortOption } from "@webiny/app-admin/presentation/listPresenter/sortOption.js";
|
|
24
24
|
const t = i18n.namespace("FormsApp.ContentModelsDataList");
|
|
25
25
|
const SORTERS = [
|
|
26
26
|
{
|
|
@@ -40,13 +40,6 @@ const SORTERS = [
|
|
|
40
40
|
sorter: "name_DESC"
|
|
41
41
|
}
|
|
42
42
|
];
|
|
43
|
-
const deserializeSorters = (data)=>{
|
|
44
|
-
const [field, order] = data.split("_");
|
|
45
|
-
return [
|
|
46
|
-
field,
|
|
47
|
-
"asc" === order.toLowerCase() ? "asc" : "desc"
|
|
48
|
-
];
|
|
49
|
-
};
|
|
50
43
|
const DisplayIcon = ({ model })=>{
|
|
51
44
|
const icon = normalizeIcon(model.icon);
|
|
52
45
|
if (!icon) return null;
|
|
@@ -66,31 +59,13 @@ const ContentModelsDataList = observer(({ canCreate, onCreate, onClone, showImpo
|
|
|
66
59
|
const { goToRoute } = useRouter();
|
|
67
60
|
const { showSnackbar } = useSnackbar();
|
|
68
61
|
const { canDelete, canEdit } = usePermission();
|
|
69
|
-
const [filter, setFilter] = useState("");
|
|
70
|
-
const [sort, setSort] = useState(SORTERS[0].sorter);
|
|
71
62
|
const [modelToBeDeleted, setModelToBeDeleted] = useState(null);
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}, [
|
|
79
|
-
models,
|
|
80
|
-
filter
|
|
81
|
-
]);
|
|
82
|
-
const sortedData = useMemo(()=>{
|
|
83
|
-
if (!sort) return filteredData;
|
|
84
|
-
const [key, order] = deserializeSorters(sort);
|
|
85
|
-
return orderBy(filteredData, [
|
|
86
|
-
key
|
|
87
|
-
], [
|
|
88
|
-
order
|
|
89
|
-
]);
|
|
90
|
-
}, [
|
|
91
|
-
filteredData,
|
|
92
|
-
sort
|
|
93
|
-
]);
|
|
63
|
+
const { list } = presenter;
|
|
64
|
+
const sort = toSortOption(list.vm.sort);
|
|
65
|
+
const setSort = (value)=>{
|
|
66
|
+
const option = fromSortOption(value);
|
|
67
|
+
list.actions.sort.set(option.field, option.direction);
|
|
68
|
+
};
|
|
94
69
|
const editRecord = (contentModel)=>{
|
|
95
70
|
goToRoute(Routes.ContentModels.Editor, {
|
|
96
71
|
modelId: contentModel.modelId
|
|
@@ -122,8 +97,8 @@ const ContentModelsDataList = observer(({ canCreate, onCreate, onClone, showImpo
|
|
|
122
97
|
handleModelsExport
|
|
123
98
|
]);
|
|
124
99
|
return /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement(DataList, {
|
|
125
|
-
loading: loading,
|
|
126
|
-
data:
|
|
100
|
+
loading: list.vm.pagination.loading,
|
|
101
|
+
data: list.vm.rows,
|
|
127
102
|
title: t`Content Models`,
|
|
128
103
|
actions: /*#__PURE__*/ react.createElement("div", {
|
|
129
104
|
className: "flex items-center justify-end gap-xs"
|
|
@@ -152,8 +127,8 @@ const ContentModelsDataList = observer(({ canCreate, onCreate, onClone, showImpo
|
|
|
152
127
|
className: "ml-xs"
|
|
153
128
|
}) : null),
|
|
154
129
|
search: /*#__PURE__*/ react.createElement(SearchUI, {
|
|
155
|
-
value:
|
|
156
|
-
onChange:
|
|
130
|
+
value: list.vm.search,
|
|
131
|
+
onChange: list.actions.search.set,
|
|
157
132
|
inputPlaceholder: t`Search content model...`
|
|
158
133
|
}),
|
|
159
134
|
modalOverlay: /*#__PURE__*/ react.createElement(DataListModal.Content, null, /*#__PURE__*/ react.createElement(Select, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/contentModels/components/ContentModelsDataList.js","sources":["../../../../src/presentation/contentModels/components/ContentModelsDataList.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport orderBy from \"lodash/orderBy.js\";\nimport { TimeAgo } from \"@webiny/admin-ui\";\nimport { SearchUI, useRouter, useSnackbar } from \"@webiny/app-admin\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport {\n ReactComponent as DownloadFileIcon,\n ReactComponent as ExportIcon\n} from \"@webiny/icons/file_download.svg\";\nimport { ReactComponent as UploadFileIcon } from \"@webiny/icons/file_upload.svg\";\nimport { ReactComponent as ListIcon } from \"@webiny/icons/list.svg\";\nimport { ReactComponent as EditIcon } from \"@webiny/icons/edit.svg\";\nimport { ReactComponent as MoreVertIcon } from \"@webiny/icons/more_vert.svg\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete.svg\";\nimport { ReactComponent as CloneIcon } from \"@webiny/icons/flip_to_front.svg\";\nimport { DataList, DataListModal, List } from \"@webiny/admin-ui\";\nimport { i18n } from \"@webiny/app/i18n/index.js\";\nimport type { CmsModel } from \"~/types.js\";\nimport { usePermission } from \"~/admin/hooks/usePermission.js\";\nimport { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\";\nimport { ModelIsBeingDeleted } from \"./fullDelete/ModelIsBeingDeleted.js\";\nimport { FullyDeleteModelDialog } from \"./fullDelete/FullyDeleteModelDialog.js\";\nimport { Button, DropdownMenu, Icon, IconButton, Select, Tooltip } from \"@webiny/admin-ui\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/app-headless-cms-common\";\nimport { Routes } from \"~/routes.js\";\nimport { normalizeIcon } from \"~/utils/normalizeIcon.js\";\nimport { useContentModelsPresenter } from \"../useContentModelsPresenter.js\";\nimport { download } from \"../utils/download.js\";\n\nconst t = i18n.namespace(\"FormsApp.ContentModelsDataList\");\n\nconst SORTERS = [\n { label: \"Newest to oldest\", sorter: \"savedOn_DESC\" },\n { label: \"Oldest to newest\", sorter: \"savedOn_ASC\" },\n { label: \"Name A-Z\", sorter: \"name_ASC\" },\n { label: \"Name Z-A\", sorter: \"name_DESC\" }\n];\n\nconst deserializeSorters = (data: string): [string, \"asc\" | \"desc\"] => {\n const [field, order] = data.split(\"_\");\n return [field, order.toLowerCase() === \"asc\" ? \"asc\" : \"desc\"];\n};\n\ninterface ContentModelsDataListProps {\n canCreate: boolean;\n onCreate: () => void;\n onClone: (contentModel: CmsModel) => void;\n showImportModelModal: () => void;\n}\n\ninterface IconProps {\n model: Pick<CmsModel, \"icon\">;\n}\n\nconst DisplayIcon = ({ model }: IconProps) => {\n const icon = normalizeIcon(model.icon);\n if (!icon) {\n return null;\n }\n return (\n <div className={\"text-neutral-muted\"}>\n <Icon\n size={\"lg\"}\n color={\"inherit\"}\n label={\"Content model icon\"}\n icon={<FontAwesomeIcon icon={icon} />}\n />\n </div>\n );\n};\n\nconst ContentModelsDataList = observer(\n ({ canCreate, onCreate, onClone, showImportModelModal }: ContentModelsDataListProps) => {\n const presenter = useContentModelsPresenter();\n const { goToRoute } = useRouter();\n const { showSnackbar } = useSnackbar();\n const { canDelete, canEdit } = usePermission();\n\n const [filter, setFilter] = useState(\"\");\n const [sort, setSort] = useState(SORTERS[0].sorter);\n const [modelToBeDeleted, setModelToBeDeleted] = useState<CmsModel | null>(null);\n\n const models = presenter.vm.models;\n const loading = presenter.vm.loading;\n\n const filteredData = useMemo(() => {\n if (filter === \"\") {\n return models;\n }\n const lc = filter.toLowerCase();\n return models.filter((m: CmsModel) => m.name.toLowerCase().includes(lc));\n }, [models, filter]);\n\n const sortedData = useMemo(() => {\n if (!sort) {\n return filteredData;\n }\n const [key, order] = deserializeSorters(sort);\n return orderBy(filteredData, [key], [order]);\n }, [filteredData, sort]);\n\n const editRecord = (contentModel: CmsModel): void => {\n goToRoute(Routes.ContentModels.Editor, { modelId: contentModel.modelId });\n };\n\n const viewContentEntries = useCallback((contentModel: Pick<CmsModel, \"modelId\">) => {\n return () => {\n goToRoute(Routes.ContentEntries.List, { modelId: contentModel.modelId });\n };\n }, []);\n\n const handleModelsExport = useCallback(\n (modelIds?: string[]) => {\n (async () => {\n try {\n const data = await presenter.exportModels(modelIds);\n if (!data?.models?.length) {\n showSnackbar(\"No data returned from the export query.\");\n return;\n }\n download(data);\n } catch (ex: any) {\n showSnackbar(ex.message);\n }\n })();\n },\n [presenter]\n );\n\n const handleModelExport = useCallback(\n (model: CmsModel) => {\n return () => {\n handleModelsExport([model.modelId]);\n };\n },\n [handleModelsExport]\n );\n\n return (\n <>\n <DataList\n loading={loading}\n data={sortedData}\n title={t`Content Models`}\n actions={\n <div className={\"flex items-center justify-end gap-xs\"}>\n <Tooltip\n content={\"Export all models\"}\n trigger={\n <IconButton\n icon={<DownloadFileIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n onClick={() => handleModelsExport()}\n />\n }\n />\n <Tooltip\n content={\"Import models\"}\n trigger={\n <IconButton\n icon={<UploadFileIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n onClick={() => showImportModelModal()}\n />\n }\n />\n {canCreate ? (\n <Button\n data-testid=\"new-record-button\"\n onClick={onCreate}\n text={t`New`}\n icon={<AddIcon />}\n size={\"sm\"}\n className={\"ml-xs\"}\n />\n ) : null}\n </div>\n }\n search={\n <SearchUI\n value={filter}\n onChange={setFilter}\n inputPlaceholder={t`Search content model...`}\n />\n }\n modalOverlay={\n <DataListModal.Content>\n <Select\n value={sort}\n onChange={setSort}\n label={t`Sort by`}\n options={SORTERS.map(({ label, sorter: value }) => ({\n label,\n value\n }))}\n />\n </DataListModal.Content>\n }\n modalOverlayAction={\n <DataListModal.Trigger data-testid={\"default-data-list.filter\"} />\n }\n refresh={null}\n >\n {({ data = [] }: { data: CmsModel[] }) => {\n return (\n <List data-testid=\"default-data-list\">\n {data.map(contentModel => {\n const disableViewContent = contentModel.fields.length === 0;\n const getMessage = () => {\n if (disableViewContent) {\n return \"To view the entries, you first need to add a field and save the model\";\n }\n if (contentModel.tags.includes(CMS_MODEL_SINGLETON_TAG)) {\n return \"View\";\n }\n return \"View entries\";\n };\n\n const canDeleteModel = canDelete(\n contentModel,\n \"cms.contentModel\"\n );\n const canEditModel = canEdit(contentModel, \"cms.contentModel\");\n\n return (\n <List.Item\n key={contentModel.modelId}\n className={\"group/item\"}\n icon={<DisplayIcon model={contentModel} />}\n title={contentModel.name}\n description={t`Last modified: {time}.`({\n time: contentModel.savedOn ? (\n <TimeAgo datetime={contentModel.savedOn} />\n ) : (\n \"N/A\"\n )\n })}\n actions={\n <>\n <ModelIsBeingDeleted model={contentModel}>\n <span\n className={\n \"invisible group-hover/item:visible\"\n }\n >\n <Tooltip\n side={\"top\"}\n content={getMessage()}\n trigger={\n <Button\n text={\"View entries\"}\n icon={<ListIcon />}\n variant={\"secondary\"}\n size={\"sm\"}\n data-testid={\n \"cms-view-content-model-button\"\n }\n onClick={viewContentEntries(\n contentModel\n )}\n disabled={\n disableViewContent\n }\n />\n }\n />\n </span>\n\n {canEditModel && (\n <span\n className={\n \"invisible group-hover/item:visible\"\n }\n >\n <Tooltip\n side={\"top\"}\n content={\n contentModel.plugin\n ? t`Content model is registered via a plugin.`\n : t`Edit content model`\n }\n trigger={\n <Button\n text={\"Edit\"}\n icon={<EditIcon />}\n variant={\"secondary\"}\n size={\"sm\"}\n disabled={\n contentModel.plugin\n }\n onClick={() =>\n editRecord(\n contentModel\n )\n }\n data-testid={\n \"cms-edit-content-model-button\"\n }\n />\n }\n />\n </span>\n )}\n\n <DropdownMenu\n trigger={\n <IconButton\n icon={<MoreVertIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n />\n }\n >\n {canEditModel && (\n <DropdownMenu.Item\n text={\"Clone\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Clone\"}\n element={<CloneIcon />}\n />\n }\n data-testid={\n \"cms-clone-content-model-button\"\n }\n onClick={() =>\n onClone(contentModel)\n }\n />\n )}\n\n <DropdownMenu.Item\n text={\"Export\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Export\"}\n element={<ExportIcon />}\n />\n }\n data-testid={\n \"cms-export-content-model-button\"\n }\n onClick={handleModelExport(\n contentModel\n )}\n />\n\n {canDeleteModel && (\n <DropdownMenu.Item\n text={\"Delete\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Delete\"}\n element={<DeleteIcon />}\n />\n }\n onClick={() => {\n setModelToBeDeleted(\n contentModel\n );\n }}\n data-testid={\n \"cms-delete-content-model-button\"\n }\n className={\n \"text-destructive-primary! [&_svg]:fill-destructive\"\n }\n />\n )}\n </DropdownMenu>\n </ModelIsBeingDeleted>\n </>\n }\n />\n );\n })}\n </List>\n );\n }}\n </DataList>\n {modelToBeDeleted ? (\n <FullyDeleteModelDialog\n model={modelToBeDeleted}\n onClose={() => {\n setModelToBeDeleted(null);\n }}\n />\n ) : null}\n </>\n );\n }\n);\n\nexport default ContentModelsDataList;\n"],"names":["t","i18n","SORTERS","deserializeSorters","data","field","order","DisplayIcon","model","icon","normalizeIcon","Icon","FontAwesomeIcon","ContentModelsDataList","observer","canCreate","onCreate","onClone","showImportModelModal","presenter","useContentModelsPresenter","goToRoute","useRouter","showSnackbar","useSnackbar","canDelete","canEdit","usePermission","filter","setFilter","useState","sort","setSort","modelToBeDeleted","setModelToBeDeleted","models","loading","filteredData","useMemo","lc","m","sortedData","key","orderBy","editRecord","contentModel","Routes","viewContentEntries","useCallback","handleModelsExport","modelIds","download","ex","handleModelExport","DataList","Tooltip","IconButton","DownloadFileIcon","UploadFileIcon","Button","AddIcon","SearchUI","DataListModal","Select","label","value","List","disableViewContent","getMessage","CMS_MODEL_SINGLETON_TAG","canDeleteModel","canEditModel","TimeAgo","ModelIsBeingDeleted","ListIcon","EditIcon","DropdownMenu","MoreVertIcon","CloneIcon","ExportIcon","DeleteIcon","FullyDeleteModelDialog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,IAAIC,KAAK,SAAS,CAAC;AAEzB,MAAMC,UAAU;IACZ;QAAE,OAAO;QAAoB,QAAQ;IAAe;IACpD;QAAE,OAAO;QAAoB,QAAQ;IAAc;IACnD;QAAE,OAAO;QAAY,QAAQ;IAAW;IACxC;QAAE,OAAO;QAAY,QAAQ;IAAY;CAC5C;AAED,MAAMC,qBAAqB,CAACC;IACxB,MAAM,CAACC,OAAOC,MAAM,GAAGF,KAAK,KAAK,CAAC;IAClC,OAAO;QAACC;QAA+B,UAAxBC,MAAM,WAAW,KAAe,QAAQ;KAAO;AAClE;AAaA,MAAMC,cAAc,CAAC,EAAEC,KAAK,EAAa;IACrC,MAAMC,OAAOC,cAA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B,WAAhBA,GACG,oBAAC;oBACG,WACI;iCAGJ,oBAAChB,SAAOA;oBACJ,MAAM;oBACN,SACIV,aAAa,MAAM,GACb7C,CAAC,CAAC,yCAAyC,CAAC,GAC5CA,CAAC,CAAC,kBAAkB,CAAC;oBAE/B,uBACI,oBAAC2D,QAAMA;wBACH,MAAM;wBACN,oBAAM,oBAACgB,yBAAQA;wBACf,SAAS;wBACT,MAAM;wBACN,UACI9B,aAAa,MAAM;wBAEvB,SAAS,IACLD,WACIC;wBAGR,eACI;;mCAQxB,oBAAC+B,cAAYA;oBACT,uBACI,oBAACpB,YAAUA;wBACP,oBAAM,oBAACqB,8BAAYA;wBACnB,MAAM;wBACN,SAAS;;mBAIhBN,gBAAgB,WAAhBA,GACG,oBAACK,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACE,kCAASA;;oBAG3B,eACI;oBAEJ,SAAS,IACL7D,QAAQ4B;kCAKpB,oBAAC+B,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACG,kCAAUA;;oBAG5B,eACI;oBAEJ,SAAS1B,kBACLR;oBAIPyB,kBAAkB,WAAlBA,GACG,oBAACM,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACI,2BAAUA;;oBAG5B,SAAS;wBACL9C,oBACIW;oBAER;oBACA,eACI;oBAEJ,WACI;;;QAUxC,MAKfZ,mBAAmB,WAAnBA,GACG,oBAACgD,wBAAsBA;QACnB,OAAOhD;QACP,SAAS;YACLC,oBAAoB;QACxB;SAEJ;AAGhB;AAGJ,yCAAerB"}
|
|
1
|
+
{"version":3,"file":"presentation/contentModels/components/ContentModelsDataList.js","sources":["../../../../src/presentation/contentModels/components/ContentModelsDataList.tsx"],"sourcesContent":["import React from \"react\";\nimport { useCallback } from \"react\";\nimport { useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { TimeAgo } from \"@webiny/admin-ui\";\nimport { SearchUI, useRouter, useSnackbar } from \"@webiny/app-admin\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport {\n ReactComponent as DownloadFileIcon,\n ReactComponent as ExportIcon\n} from \"@webiny/icons/file_download.svg\";\nimport { ReactComponent as UploadFileIcon } from \"@webiny/icons/file_upload.svg\";\nimport { ReactComponent as ListIcon } from \"@webiny/icons/list.svg\";\nimport { ReactComponent as EditIcon } from \"@webiny/icons/edit.svg\";\nimport { ReactComponent as MoreVertIcon } from \"@webiny/icons/more_vert.svg\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete.svg\";\nimport { ReactComponent as CloneIcon } from \"@webiny/icons/flip_to_front.svg\";\nimport { DataList, DataListModal, List } from \"@webiny/admin-ui\";\nimport { i18n } from \"@webiny/app/i18n/index.js\";\nimport type { CmsModel } from \"~/types.js\";\nimport { usePermission } from \"~/admin/hooks/usePermission.js\";\nimport { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\";\nimport { ModelIsBeingDeleted } from \"./fullDelete/ModelIsBeingDeleted.js\";\nimport { FullyDeleteModelDialog } from \"./fullDelete/FullyDeleteModelDialog.js\";\nimport { Button, DropdownMenu, Icon, IconButton, Select, Tooltip } from \"@webiny/admin-ui\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/app-headless-cms-common\";\nimport { Routes } from \"~/routes.js\";\nimport { normalizeIcon } from \"~/utils/normalizeIcon.js\";\nimport { useContentModelsPresenter } from \"../useContentModelsPresenter.js\";\nimport { download } from \"../utils/download.js\";\nimport { toSortOption } from \"@webiny/app-admin/presentation/listPresenter/sortOption.js\";\nimport { fromSortOption } from \"@webiny/app-admin/presentation/listPresenter/sortOption.js\";\n\nconst t = i18n.namespace(\"FormsApp.ContentModelsDataList\");\n\nconst SORTERS = [\n { label: \"Newest to oldest\", sorter: \"savedOn_DESC\" },\n { label: \"Oldest to newest\", sorter: \"savedOn_ASC\" },\n { label: \"Name A-Z\", sorter: \"name_ASC\" },\n { label: \"Name Z-A\", sorter: \"name_DESC\" }\n];\n\ninterface ContentModelsDataListProps {\n canCreate: boolean;\n onCreate: () => void;\n onClone: (contentModel: CmsModel) => void;\n showImportModelModal: () => void;\n}\n\ninterface IconProps {\n model: Pick<CmsModel, \"icon\">;\n}\n\nconst DisplayIcon = ({ model }: IconProps) => {\n const icon = normalizeIcon(model.icon);\n if (!icon) {\n return null;\n }\n return (\n <div className={\"text-neutral-muted\"}>\n <Icon\n size={\"lg\"}\n color={\"inherit\"}\n label={\"Content model icon\"}\n icon={<FontAwesomeIcon icon={icon} />}\n />\n </div>\n );\n};\n\nconst ContentModelsDataList = observer(\n ({ canCreate, onCreate, onClone, showImportModelModal }: ContentModelsDataListProps) => {\n const presenter = useContentModelsPresenter();\n const { goToRoute } = useRouter();\n const { showSnackbar } = useSnackbar();\n const { canDelete, canEdit } = usePermission();\n\n const [modelToBeDeleted, setModelToBeDeleted] = useState<CmsModel | null>(null);\n\n const { list } = presenter;\n const sort = toSortOption(list.vm.sort);\n const setSort = (value: string) => {\n const option = fromSortOption(value);\n list.actions.sort.set(option.field, option.direction);\n };\n\n const editRecord = (contentModel: CmsModel): void => {\n goToRoute(Routes.ContentModels.Editor, { modelId: contentModel.modelId });\n };\n\n const viewContentEntries = useCallback((contentModel: Pick<CmsModel, \"modelId\">) => {\n return () => {\n goToRoute(Routes.ContentEntries.List, { modelId: contentModel.modelId });\n };\n }, []);\n\n const handleModelsExport = useCallback(\n (modelIds?: string[]) => {\n (async () => {\n try {\n const data = await presenter.exportModels(modelIds);\n if (!data?.models?.length) {\n showSnackbar(\"No data returned from the export query.\");\n return;\n }\n download(data);\n } catch (ex: any) {\n showSnackbar(ex.message);\n }\n })();\n },\n [presenter]\n );\n\n const handleModelExport = useCallback(\n (model: CmsModel) => {\n return () => {\n handleModelsExport([model.modelId]);\n };\n },\n [handleModelsExport]\n );\n\n return (\n <>\n <DataList\n loading={list.vm.pagination.loading}\n data={list.vm.rows}\n title={t`Content Models`}\n actions={\n <div className={\"flex items-center justify-end gap-xs\"}>\n <Tooltip\n content={\"Export all models\"}\n trigger={\n <IconButton\n icon={<DownloadFileIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n onClick={() => handleModelsExport()}\n />\n }\n />\n <Tooltip\n content={\"Import models\"}\n trigger={\n <IconButton\n icon={<UploadFileIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n onClick={() => showImportModelModal()}\n />\n }\n />\n {canCreate ? (\n <Button\n data-testid=\"new-record-button\"\n onClick={onCreate}\n text={t`New`}\n icon={<AddIcon />}\n size={\"sm\"}\n className={\"ml-xs\"}\n />\n ) : null}\n </div>\n }\n search={\n <SearchUI\n value={list.vm.search}\n onChange={list.actions.search.set}\n inputPlaceholder={t`Search content model...`}\n />\n }\n modalOverlay={\n <DataListModal.Content>\n <Select\n value={sort}\n onChange={setSort}\n label={t`Sort by`}\n options={SORTERS.map(({ label, sorter: value }) => ({\n label,\n value\n }))}\n />\n </DataListModal.Content>\n }\n modalOverlayAction={\n <DataListModal.Trigger data-testid={\"default-data-list.filter\"} />\n }\n refresh={null}\n >\n {({ data = [] }: { data: CmsModel[] }) => {\n return (\n <List data-testid=\"default-data-list\">\n {data.map(contentModel => {\n const disableViewContent = contentModel.fields.length === 0;\n const getMessage = () => {\n if (disableViewContent) {\n return \"To view the entries, you first need to add a field and save the model\";\n }\n if (contentModel.tags.includes(CMS_MODEL_SINGLETON_TAG)) {\n return \"View\";\n }\n return \"View entries\";\n };\n\n const canDeleteModel = canDelete(\n contentModel,\n \"cms.contentModel\"\n );\n const canEditModel = canEdit(contentModel, \"cms.contentModel\");\n\n return (\n <List.Item\n key={contentModel.modelId}\n className={\"group/item\"}\n icon={<DisplayIcon model={contentModel} />}\n title={contentModel.name}\n description={t`Last modified: {time}.`({\n time: contentModel.savedOn ? (\n <TimeAgo datetime={contentModel.savedOn} />\n ) : (\n \"N/A\"\n )\n })}\n actions={\n <>\n <ModelIsBeingDeleted model={contentModel}>\n <span\n className={\n \"invisible group-hover/item:visible\"\n }\n >\n <Tooltip\n side={\"top\"}\n content={getMessage()}\n trigger={\n <Button\n text={\"View entries\"}\n icon={<ListIcon />}\n variant={\"secondary\"}\n size={\"sm\"}\n data-testid={\n \"cms-view-content-model-button\"\n }\n onClick={viewContentEntries(\n contentModel\n )}\n disabled={\n disableViewContent\n }\n />\n }\n />\n </span>\n\n {canEditModel && (\n <span\n className={\n \"invisible group-hover/item:visible\"\n }\n >\n <Tooltip\n side={\"top\"}\n content={\n contentModel.plugin\n ? t`Content model is registered via a plugin.`\n : t`Edit content model`\n }\n trigger={\n <Button\n text={\"Edit\"}\n icon={<EditIcon />}\n variant={\"secondary\"}\n size={\"sm\"}\n disabled={\n contentModel.plugin\n }\n onClick={() =>\n editRecord(\n contentModel\n )\n }\n data-testid={\n \"cms-edit-content-model-button\"\n }\n />\n }\n />\n </span>\n )}\n\n <DropdownMenu\n trigger={\n <IconButton\n icon={<MoreVertIcon />}\n size={\"sm\"}\n variant={\"ghost\"}\n />\n }\n >\n {canEditModel && (\n <DropdownMenu.Item\n text={\"Clone\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Clone\"}\n element={<CloneIcon />}\n />\n }\n data-testid={\n \"cms-clone-content-model-button\"\n }\n onClick={() =>\n onClone(contentModel)\n }\n />\n )}\n\n <DropdownMenu.Item\n text={\"Export\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Export\"}\n element={<ExportIcon />}\n />\n }\n data-testid={\n \"cms-export-content-model-button\"\n }\n onClick={handleModelExport(\n contentModel\n )}\n />\n\n {canDeleteModel && (\n <DropdownMenu.Item\n text={\"Delete\"}\n icon={\n <DropdownMenu.Item.Icon\n label={\"Delete\"}\n element={<DeleteIcon />}\n />\n }\n onClick={() => {\n setModelToBeDeleted(\n contentModel\n );\n }}\n data-testid={\n \"cms-delete-content-model-button\"\n }\n className={\n \"text-destructive-primary! [&_svg]:fill-destructive\"\n }\n />\n )}\n </DropdownMenu>\n </ModelIsBeingDeleted>\n </>\n }\n />\n );\n })}\n </List>\n );\n }}\n </DataList>\n {modelToBeDeleted ? (\n <FullyDeleteModelDialog\n model={modelToBeDeleted}\n onClose={() => {\n setModelToBeDeleted(null);\n }}\n />\n ) : null}\n </>\n );\n }\n);\n\nexport default ContentModelsDataList;\n"],"names":["t","i18n","SORTERS","DisplayIcon","model","icon","normalizeIcon","Icon","FontAwesomeIcon","ContentModelsDataList","observer","canCreate","onCreate","onClone","showImportModelModal","presenter","useContentModelsPresenter","goToRoute","useRouter","showSnackbar","useSnackbar","canDelete","canEdit","usePermission","modelToBeDeleted","setModelToBeDeleted","useState","list","sort","toSortOption","setSort","value","option","fromSortOption","editRecord","contentModel","Routes","viewContentEntries","useCallback","handleModelsExport","modelIds","data","download","ex","handleModelExport","DataList","Tooltip","IconButton","DownloadFileIcon","UploadFileIcon","Button","AddIcon","SearchUI","DataListModal","Select","label","List","disableViewContent","getMessage","CMS_MODEL_SINGLETON_TAG","canDeleteModel","canEditModel","TimeAgo","ModelIsBeingDeleted","ListIcon","EditIcon","DropdownMenu","MoreVertIcon","CloneIcon","ExportIcon","DeleteIcon","FullyDeleteModelDialog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMA,IAAIC,KAAK,SAAS,CAAC;AAEzB,MAAMC,UAAU;IACZ;QAAE,OAAO;QAAoB,QAAQ;IAAe;IACpD;QAAE,OAAO;QAAoB,QAAQ;IAAc;IACnD;QAAE,OAAO;QAAY,QAAQ;IAAW;IACxC;QAAE,OAAO;QAAY,QAAQ;IAAY;CAC5C;AAaD,MAAMC,cAAc,CAAC,EAAEC,KAAK,EAAa;IACrC,MAAMC,OAAOC,cAAcF,MAAM,IAAI;IACrC,IAAI,CAACC,MACD,OAAO;IAEX,OAAO,WAAP,GACI,oBAAC;QAA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AAM,oBAACoB,8BAAYA;wBACnB,MAAM;wBACN,SAAS;;mBAIhBN,gBAAgB,WAAhBA,GACG,oBAACK,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACE,kCAASA;;oBAG3B,eACI;oBAEJ,SAAS,IACLvD,QAAQsB;kCAKpB,oBAAC+B,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACG,kCAAUA;;oBAG5B,eACI;oBAEJ,SAASzB,kBACLT;oBAIPyB,kBAAkB,WAAlBA,GACG,oBAACM,aAAa,IAAI;oBACd,MAAM;oBACN,oBACI,oBAACA,aAAa,IAAI,CAAC,IAAI;wBACnB,OAAO;wBACP,uBAAS,oBAACI,2BAAUA;;oBAG5B,SAAS;wBACL7C,oBACIU;oBAER;oBACA,eACI;oBAEJ,WACI;;;QAUxC,MAKfX,mBAAmB,WAAnBA,GACG,oBAAC+C,wBAAsBA;QACnB,OAAO/C;QACP,SAAS;YACLC,oBAAoB;QACxB;SAEJ;AAGhB;AAGJ,yCAAehB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/contentModels/isListedModel.js","sources":["../../../src/presentation/contentModels/isListedModel.ts"],"sourcesContent":["import type { CmsModel } from \"~/types.js\";\n\n// Models tagged `$hidden:true` are internal and never listed.\nexport const isListedModel = (model: CmsModel): boolean => {\n return !model.tags?.includes(\"$hidden:true\");\n};\n"],"names":["isListedModel","model"],"mappings":"AAGO,MAAMA,gBAAgB,CAACC,QACnB,CAACA,MAAM,IAAI,EAAE,SAAS"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { IDataSourceQuery } from "@webiny/app-admin/presentation/listPresenter/abstractions.js";
|
|
3
|
-
import type { FetchResult } from "@webiny/app-admin/presentation/listPresenter/FolderAwareDataSource.js";
|
|
1
|
+
import { LocalDataSource } from "@webiny/app-admin/presentation/listPresenter/LocalDataSource.js";
|
|
4
2
|
import type { ModelGroupDto } from "../../features/modelGroup/listModelGroups/abstractions.js";
|
|
5
3
|
import type { IListModelGroupsUseCase } from "../../features/modelGroup/listModelGroups/abstractions.js";
|
|
6
4
|
import type { IListCache } from "@webiny/app-admin/features/listCache/index.js";
|
|
7
|
-
export declare class ModelGroupDataSource extends
|
|
5
|
+
export declare class ModelGroupDataSource extends LocalDataSource<ModelGroupDto> {
|
|
8
6
|
private listModelGroupsUseCase;
|
|
9
7
|
private cache;
|
|
10
8
|
constructor(listModelGroupsUseCase: IListModelGroupsUseCase, cache: IListCache<ModelGroupDto>);
|
|
11
|
-
get
|
|
12
|
-
|
|
9
|
+
protected get items(): ModelGroupDto[];
|
|
10
|
+
protected load(): Promise<void>;
|
|
11
|
+
protected searchIn(group: ModelGroupDto): Array<string | null | undefined>;
|
|
13
12
|
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class ModelGroupDataSource extends
|
|
1
|
+
import { LocalDataSource } from "@webiny/app-admin/presentation/listPresenter/LocalDataSource.js";
|
|
2
|
+
class ModelGroupDataSource extends LocalDataSource {
|
|
3
3
|
constructor(listModelGroupsUseCase, cache){
|
|
4
4
|
super(), this.listModelGroupsUseCase = listModelGroupsUseCase, this.cache = cache;
|
|
5
5
|
}
|
|
6
|
-
get
|
|
6
|
+
get items() {
|
|
7
7
|
return this.cache.getItems();
|
|
8
8
|
}
|
|
9
|
-
async
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
totalCount: result.length
|
|
17
|
-
}
|
|
18
|
-
};
|
|
9
|
+
async load() {
|
|
10
|
+
await this.listModelGroupsUseCase.execute();
|
|
11
|
+
}
|
|
12
|
+
searchIn(group) {
|
|
13
|
+
return [
|
|
14
|
+
group.name
|
|
15
|
+
];
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
export { ModelGroupDataSource };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/modelGroup/ModelGroupDataSource.js","sources":["../../../src/presentation/modelGroup/ModelGroupDataSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"presentation/modelGroup/ModelGroupDataSource.js","sources":["../../../src/presentation/modelGroup/ModelGroupDataSource.ts"],"sourcesContent":["import { LocalDataSource } from \"@webiny/app-admin/presentation/listPresenter/LocalDataSource.js\";\nimport type { ModelGroupDto } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport type { IListModelGroupsUseCase } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport type { IListCache } from \"@webiny/app-admin/features/listCache/index.js\";\n\nexport class ModelGroupDataSource extends LocalDataSource<ModelGroupDto> {\n constructor(\n private listModelGroupsUseCase: IListModelGroupsUseCase,\n private cache: IListCache<ModelGroupDto>\n ) {\n super();\n }\n\n protected get items(): ModelGroupDto[] {\n return this.cache.getItems();\n }\n\n protected async load(): Promise<void> {\n await this.listModelGroupsUseCase.execute();\n }\n\n protected searchIn(group: ModelGroupDto): Array<string | null | undefined> {\n return [group.name];\n }\n}\n"],"names":["ModelGroupDataSource","LocalDataSource","listModelGroupsUseCase","cache","group"],"mappings":";AAKO,MAAMA,6BAA6BC;IACtC,YACYC,sBAA+C,EAC/CC,KAAgC,CAC1C;QACE,KAAK,SAHGD,sBAAsB,GAAtBA,wBAAAA,IAAAA,CACAC,KAAK,GAALA;IAGZ;IAEA,IAAc,QAAyB;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ;IAC9B;IAEA,MAAgB,OAAsB;QAClC,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO;IAC7C;IAEU,SAASC,KAAoB,EAAoC;QACvE,OAAO;YAACA,MAAM,IAAI;SAAC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ListCache } from "@webiny/app-admin/features/listCache/index.js";
|
|
3
|
+
import { ModelGroupDataSource } from "./ModelGroupDataSource.js";
|
|
4
|
+
const group = (id, name, createdOn)=>({
|
|
5
|
+
id,
|
|
6
|
+
name,
|
|
7
|
+
slug: id,
|
|
8
|
+
createdOn
|
|
9
|
+
});
|
|
10
|
+
const GROUPS = [
|
|
11
|
+
group("blog", "Blog", "2026-01-01T00:00:00.000Z"),
|
|
12
|
+
group("shop", "Shop", "2026-03-01T00:00:00.000Z"),
|
|
13
|
+
group("ungrouped", "Ungrouped", "2026-02-01T00:00:00.000Z")
|
|
14
|
+
];
|
|
15
|
+
describe("ModelGroupDataSource", ()=>{
|
|
16
|
+
it("searches and sorts the loaded groups without loading again", async ()=>{
|
|
17
|
+
const cache = new ListCache();
|
|
18
|
+
const execute = vi.fn(async ()=>{
|
|
19
|
+
cache.setItems(GROUPS);
|
|
20
|
+
return GROUPS;
|
|
21
|
+
});
|
|
22
|
+
const dataSource = new ModelGroupDataSource({
|
|
23
|
+
execute
|
|
24
|
+
}, cache);
|
|
25
|
+
await dataSource.query({
|
|
26
|
+
sort: {
|
|
27
|
+
field: "createdOn",
|
|
28
|
+
direction: "DESC"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
expect(dataSource.rows.map((row)=>row.id)).toEqual([
|
|
32
|
+
"shop",
|
|
33
|
+
"ungrouped",
|
|
34
|
+
"blog"
|
|
35
|
+
]);
|
|
36
|
+
await dataSource.query({
|
|
37
|
+
search: "o",
|
|
38
|
+
sort: {
|
|
39
|
+
field: "name",
|
|
40
|
+
direction: "DESC"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
expect(dataSource.rows.map((row)=>row.id)).toEqual([
|
|
44
|
+
"ungrouped",
|
|
45
|
+
"shop",
|
|
46
|
+
"blog"
|
|
47
|
+
]);
|
|
48
|
+
await dataSource.query({
|
|
49
|
+
search: "SHOP",
|
|
50
|
+
sort: {
|
|
51
|
+
field: "name",
|
|
52
|
+
direction: "DESC"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
expect(dataSource.rows.map((row)=>row.id)).toEqual([
|
|
56
|
+
"shop"
|
|
57
|
+
]);
|
|
58
|
+
expect(dataSource.meta.totalCount).toBe(1);
|
|
59
|
+
expect(execute).toHaveBeenCalledTimes(1);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=ModelGroupDataSource.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation/modelGroup/ModelGroupDataSource.test.js","sources":["../../../src/presentation/modelGroup/ModelGroupDataSource.test.ts"],"sourcesContent":["import { describe } from \"vitest\";\nimport { it } from \"vitest\";\nimport { expect } from \"vitest\";\nimport { vi } from \"vitest\";\nimport { ListCache } from \"@webiny/app-admin/features/listCache/index.js\";\nimport type { ModelGroupDto } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { ModelGroupDataSource } from \"./ModelGroupDataSource.js\";\n\nconst group = (id: string, name: string, createdOn: string): ModelGroupDto =>\n ({ id, name, slug: id, createdOn }) as unknown as ModelGroupDto;\n\nconst GROUPS = [\n group(\"blog\", \"Blog\", \"2026-01-01T00:00:00.000Z\"),\n group(\"shop\", \"Shop\", \"2026-03-01T00:00:00.000Z\"),\n group(\"ungrouped\", \"Ungrouped\", \"2026-02-01T00:00:00.000Z\")\n];\n\ndescribe(\"ModelGroupDataSource\", () => {\n it(\"searches and sorts the loaded groups without loading again\", async () => {\n const cache = new ListCache<ModelGroupDto>();\n const execute = vi.fn(async () => {\n cache.setItems(GROUPS);\n return GROUPS;\n });\n const dataSource = new ModelGroupDataSource({ execute }, cache);\n\n await dataSource.query({ sort: { field: \"createdOn\", direction: \"DESC\" } });\n expect(dataSource.rows.map(row => row.id)).toEqual([\"shop\", \"ungrouped\", \"blog\"]);\n\n await dataSource.query({ search: \"o\", sort: { field: \"name\", direction: \"DESC\" } });\n expect(dataSource.rows.map(row => row.id)).toEqual([\"ungrouped\", \"shop\", \"blog\"]);\n\n await dataSource.query({ search: \"SHOP\", sort: { field: \"name\", direction: \"DESC\" } });\n expect(dataSource.rows.map(row => row.id)).toEqual([\"shop\"]);\n expect(dataSource.meta.totalCount).toBe(1);\n\n expect(execute).toHaveBeenCalledTimes(1);\n });\n});\n"],"names":["group","id","name","createdOn","GROUPS","describe","it","cache","ListCache","execute","vi","dataSource","ModelGroupDataSource","expect","row"],"mappings":";;;AAQA,MAAMA,QAAQ,CAACC,IAAYC,MAAcC,YACpC;QAAEF;QAAIC;QAAM,MAAMD;QAAIE;IAAU;AAErC,MAAMC,SAAS;IACXJ,MAAM,QAAQ,QAAQ;IACtBA,MAAM,QAAQ,QAAQ;IACtBA,MAAM,aAAa,aAAa;CACnC;AAEDK,SAAS,wBAAwB;IAC7BC,GAAG,8DAA8D;QAC7D,MAAMC,QAAQ,IAAIC;QAClB,MAAMC,UAAUC,GAAG,EAAE,CAAC;YAClBH,MAAM,QAAQ,CAACH;YACf,OAAOA;QACX;QACA,MAAMO,aAAa,IAAIC,qBAAqB;YAAEH;QAAQ,GAAGF;QAEzD,MAAMI,WAAW,KAAK,CAAC;YAAE,MAAM;gBAAE,OAAO;gBAAa,WAAW;YAAO;QAAE;QACzEE,OAAOF,WAAW,IAAI,CAAC,GAAG,CAACG,CAAAA,MAAOA,IAAI,EAAE,GAAG,OAAO,CAAC;YAAC;YAAQ;YAAa;SAAO;QAEhF,MAAMH,WAAW,KAAK,CAAC;YAAE,QAAQ;YAAK,MAAM;gBAAE,OAAO;gBAAQ,WAAW;YAAO;QAAE;QACjFE,OAAOF,WAAW,IAAI,CAAC,GAAG,CAACG,CAAAA,MAAOA,IAAI,EAAE,GAAG,OAAO,CAAC;YAAC;YAAa;YAAQ;SAAO;QAEhF,MAAMH,WAAW,KAAK,CAAC;YAAE,QAAQ;YAAQ,MAAM;gBAAE,OAAO;gBAAQ,WAAW;YAAO;QAAE;QACpFE,OAAOF,WAAW,IAAI,CAAC,GAAG,CAACG,CAAAA,MAAOA,IAAI,EAAE,GAAG,OAAO,CAAC;YAAC;SAAO;QAC3DD,OAAOF,WAAW,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;QAExCE,OAAOJ,SAAS,qBAAqB,CAAC;IAC1C;AACJ"}
|
|
@@ -24,10 +24,14 @@ declare class ModelGroupPresenterImpl implements IModelGroupPresenter {
|
|
|
24
24
|
private saving;
|
|
25
25
|
private showForm;
|
|
26
26
|
private form;
|
|
27
|
+
/** Bumped by every select, createNew and deselect, so a lookup that resolves after any of them stops there. */
|
|
28
|
+
private selectRun;
|
|
27
29
|
constructor(listPresenter: ListPresenter.Interface<ModelGroupDto>, formModelFactory: FormModelFactory.Interface, listModelGroupsUseCase: ListModelGroupsUseCase.Interface, getRoleUseCase: GetModelGroupUseCase.Interface, createModelGroupUseCase: CreateModelGroupUseCase.Interface, updateModelGroupUseCase: UpdateModelGroupUseCase.Interface, deleteModelGroupUseCase: DeleteModelGroupUseCase.Interface, cache: ModelGroupsCache.Interface, stringFormatter: StringFormatter.Interface);
|
|
28
30
|
get vm(): IModelGroupPresenterViewModel;
|
|
29
31
|
get list(): ListPresenter.Interface<ModelGroupDto>;
|
|
30
32
|
init(): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
private describeForAssistant;
|
|
31
35
|
selectGroup(id: string): Promise<void>;
|
|
32
36
|
createNew(): void;
|
|
33
37
|
deselect(): void;
|
|
@@ -36,6 +36,7 @@ class ModelGroupPresenterImpl {
|
|
|
36
36
|
this.loading = false;
|
|
37
37
|
this.saving = false;
|
|
38
38
|
this.showForm = false;
|
|
39
|
+
this.selectRun = 0;
|
|
39
40
|
this.form = this.buildForm(false, false);
|
|
40
41
|
makeAutoObservable(this, {
|
|
41
42
|
formModelFactory: false,
|
|
@@ -46,6 +47,7 @@ class ModelGroupPresenterImpl {
|
|
|
46
47
|
deleteModelGroupUseCase: false,
|
|
47
48
|
cache: false,
|
|
48
49
|
stringFormatter: false,
|
|
50
|
+
selectRun: false,
|
|
49
51
|
vm: computed
|
|
50
52
|
});
|
|
51
53
|
}
|
|
@@ -73,16 +75,40 @@ class ModelGroupPresenterImpl {
|
|
|
73
75
|
field: "createdOn",
|
|
74
76
|
direction: "DESC"
|
|
75
77
|
},
|
|
76
|
-
limit: 1000
|
|
78
|
+
limit: 1000,
|
|
79
|
+
itemLabel: {
|
|
80
|
+
singular: "group",
|
|
81
|
+
plural: "groups"
|
|
82
|
+
},
|
|
83
|
+
assistant: {
|
|
84
|
+
view: ()=>"Content model groups in Headless CMS",
|
|
85
|
+
rowTitle: (group)=>group.name,
|
|
86
|
+
details: ()=>this.describeForAssistant()
|
|
87
|
+
}
|
|
77
88
|
});
|
|
78
89
|
}
|
|
90
|
+
dispose() {
|
|
91
|
+
this.deselect();
|
|
92
|
+
this.listPresenter.dispose();
|
|
93
|
+
}
|
|
94
|
+
describeForAssistant() {
|
|
95
|
+
if (this.selectedGroup) return {
|
|
96
|
+
openGroupId: this.selectedGroup.id
|
|
97
|
+
};
|
|
98
|
+
if (this.showForm) return {
|
|
99
|
+
editing: "a new group, not saved yet"
|
|
100
|
+
};
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
79
103
|
async selectGroup(id) {
|
|
104
|
+
const run = ++this.selectRun;
|
|
80
105
|
runInAction(()=>{
|
|
81
106
|
this.loading = true;
|
|
82
107
|
this.showForm = true;
|
|
83
108
|
});
|
|
84
109
|
try {
|
|
85
110
|
const group = await this.getRoleUseCase.execute(id);
|
|
111
|
+
if (run !== this.selectRun) return;
|
|
86
112
|
const isPluginGroup = group.plugin ?? false;
|
|
87
113
|
const canModify = !isPluginGroup;
|
|
88
114
|
runInAction(()=>{
|
|
@@ -96,12 +122,14 @@ class ModelGroupPresenterImpl {
|
|
|
96
122
|
});
|
|
97
123
|
});
|
|
98
124
|
} finally{
|
|
99
|
-
runInAction(()=>{
|
|
125
|
+
if (run === this.selectRun) runInAction(()=>{
|
|
100
126
|
this.loading = false;
|
|
101
127
|
});
|
|
102
128
|
}
|
|
103
129
|
}
|
|
104
130
|
createNew() {
|
|
131
|
+
this.selectRun++;
|
|
132
|
+
this.loading = false;
|
|
105
133
|
this.selectedGroup = null;
|
|
106
134
|
this.form = this.buildForm(true, true);
|
|
107
135
|
this.form.setData({
|
|
@@ -111,6 +139,8 @@ class ModelGroupPresenterImpl {
|
|
|
111
139
|
this.showForm = true;
|
|
112
140
|
}
|
|
113
141
|
deselect() {
|
|
142
|
+
this.selectRun++;
|
|
143
|
+
this.loading = false;
|
|
114
144
|
this.selectedGroup = null;
|
|
115
145
|
this.showForm = false;
|
|
116
146
|
}
|