@webiny/app-headless-cms 6.5.0-beta.0 → 6.5.0-beta.10
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/ContentEntriesModule.js +14 -2
- package/ContentEntriesModule.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionDelete.d.ts +2 -2
- package/admin/components/ContentEntries/BulkActions/ActionDelete.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionMove.d.ts +2 -2
- package/admin/components/ContentEntries/BulkActions/ActionMove.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionPublish.d.ts +2 -2
- package/admin/components/ContentEntries/BulkActions/ActionPublish.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionUnpublish.d.ts +2 -2
- package/admin/components/ContentEntries/BulkActions/ActionUnpublish.js.map +1 -1
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.d.ts +2 -0
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.js +84 -0
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.js.map +1 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.d.ts +2 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js +34 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js.map +1 -0
- package/admin/components/ContentEntries/Table/Actions/index.d.ts +1 -0
- package/admin/components/ContentEntries/Table/Actions/index.js +1 -0
- package/admin/components/ContentModelEditor/ContentModelEditor.js +1 -1
- package/admin/components/ContentModelEditor/ContentModelEditor.js.map +1 -1
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.d.ts +2 -0
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js +22 -0
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js.map +1 -0
- package/admin/components/FieldEditor/EditFieldDialog.d.ts +2 -2
- package/admin/components/FieldEditor/Field.js +4 -4
- package/admin/components/FieldEditor/Field.js.map +1 -1
- package/features/contentEntry/CmsEntryError.d.ts +10 -0
- package/features/contentEntry/CmsEntryError.js +11 -0
- package/features/contentEntry/CmsEntryError.js.map +1 -0
- package/features/contentEntry/createEntry/CreateEntryGateway.d.ts +0 -1
- package/features/contentEntry/createEntry/CreateEntryGateway.js +3 -10
- package/features/contentEntry/createEntry/CreateEntryGateway.js.map +1 -1
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.d.ts +3 -1
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js +8 -3
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js.map +1 -1
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.d.ts +14 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js +43 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js.map +1 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.d.ts +15 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js +34 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js.map +1 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.d.ts +11 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js +18 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js.map +1 -0
- package/features/contentEntry/duplicateEntry/abstractions.d.ts +26 -0
- package/features/contentEntry/duplicateEntry/abstractions.js +7 -0
- package/features/contentEntry/duplicateEntry/abstractions.js.map +1 -0
- package/features/contentEntry/duplicateEntry/feature.d.ts +3 -0
- package/features/contentEntry/duplicateEntry/feature.js +21 -0
- package/features/contentEntry/duplicateEntry/feature.js.map +1 -0
- package/features/contentEntry/entryValueGateways.test.d.ts +1 -0
- package/features/contentEntry/entryValueGateways.test.js +106 -0
- package/features/contentEntry/entryValueGateways.test.js.map +1 -0
- package/features/contentEntry/feature.js +2 -0
- package/features/contentEntry/feature.js.map +1 -1
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.d.ts +0 -1
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js +3 -10
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js.map +1 -1
- package/features/contentEntry/updateEntry/UpdateEntryGateway.d.ts +0 -1
- package/features/contentEntry/updateEntry/UpdateEntryGateway.js +3 -10
- package/features/contentEntry/updateEntry/UpdateEntryGateway.js.map +1 -1
- package/features/contentEntry/valueTransformers/EntryDataPreparer.d.ts +9 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.js +8 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.js.map +1 -1
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.d.ts +1 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js +113 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js.map +1 -0
- package/features/contentEntry/valueTransformers/entryValueFixtures.d.ts +146 -0
- package/features/contentEntry/valueTransformers/entryValueFixtures.js +171 -0
- package/features/contentEntry/valueTransformers/entryValueFixtures.js.map +1 -0
- package/features/formModel/CmsFormModelBuilder.d.ts +9 -1
- package/features/formModel/CmsFormModelBuilder.js +26 -15
- package/features/formModel/CmsFormModelBuilder.js.map +1 -1
- package/features/formModel/CmsFormModelBuilder.test.d.ts +1 -0
- package/features/formModel/CmsFormModelBuilder.test.js +252 -0
- package/features/formModel/CmsFormModelBuilder.test.js.map +1 -0
- package/features/formModel/CmsLayoutMapper.d.ts +8 -1
- package/features/formModel/CmsLayoutMapper.js +23 -1
- package/features/formModel/CmsLayoutMapper.js.map +1 -1
- package/features/formModel/mappers/DynamicZoneFieldMapper.js +4 -0
- package/features/formModel/mappers/DynamicZoneFieldMapper.js.map +1 -1
- package/features/formModel/mappers/ObjectFieldMapper.js +11 -6
- package/features/formModel/mappers/ObjectFieldMapper.js.map +1 -1
- package/features/model/exportModels/ExportModelsGateway.d.ts +1 -1
- package/features/model/exportModels/ExportModelsGateway.js.map +1 -1
- package/features/model/exportModels/ExportModelsUseCase.js +7 -1
- package/features/model/exportModels/ExportModelsUseCase.js.map +1 -1
- package/features/model/exportModels/abstractions.d.ts +8 -2
- package/features/model/exportModels/abstractions.js.map +1 -1
- package/package.json +26 -26
- package/presentation/cloneContentModel/CloneContentModelPresenter.d.ts +1 -0
- package/presentation/cloneContentModel/CloneContentModelPresenter.js +8 -6
- package/presentation/cloneContentModel/CloneContentModelPresenter.js.map +1 -1
- package/presentation/contentEntries/form/ContentEntryFormPresenter.js +34 -29
- package/presentation/contentEntries/form/ContentEntryFormPresenter.js.map +1 -1
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js +210 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js.map +1 -0
- package/presentation/contentEntries/form/toFormErrors.d.ts +7 -0
- package/presentation/contentEntries/form/toFormErrors.js +49 -0
- package/presentation/contentEntries/form/toFormErrors.js.map +1 -0
- package/presentation/contentEntries/form/toFormErrors.test.d.ts +1 -0
- package/presentation/contentEntries/form/toFormErrors.test.js +175 -0
- package/presentation/contentEntries/form/toFormErrors.test.js.map +1 -0
- package/presentation/contentEntries/list/ContentEntriesDataSource.d.ts +5 -0
- package/presentation/contentEntries/list/ContentEntriesDataSource.js +11 -2
- package/presentation/contentEntries/list/ContentEntriesDataSource.js.map +1 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.d.ts +6 -2
- package/presentation/contentEntries/list/ContentEntriesPresenter.js +27 -2
- package/presentation/contentEntries/list/ContentEntriesPresenter.js.map +1 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js +130 -5
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js.map +1 -1
- package/presentation/contentEntries/list/abstractions.d.ts +12 -0
- package/presentation/contentEntries/list/abstractions.js.map +1 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.d.ts +12 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.js +48 -5
- package/presentation/contentEntries/preview/LivePreviewPresenter.js.map +1 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.js +81 -0
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.js.map +1 -0
- package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js +1 -1
- package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js.map +1 -1
- package/presentation/contentEntries/preview/PreviewDecorator.js +25 -6
- package/presentation/contentEntries/preview/PreviewDecorator.js.map +1 -1
- package/presentation/contentEntries/preview/PreviewDomainStatus.d.ts +10 -0
- package/presentation/contentEntries/preview/PreviewDomainStatus.js +19 -0
- package/presentation/contentEntries/preview/PreviewDomainStatus.js.map +1 -0
- package/presentation/contentEntries/preview/PreviewPane.d.ts +10 -1
- package/presentation/contentEntries/preview/PreviewPane.js +81 -45
- package/presentation/contentEntries/preview/PreviewPane.js.map +1 -1
- package/presentation/contentEntries/preview/abstractions.d.ts +8 -0
- package/presentation/contentEntries/preview/abstractions.js.map +1 -1
- package/presentation/contentEntries/preview/resolvePreviewUrl.d.ts +21 -0
- package/presentation/contentEntries/preview/resolvePreviewUrl.js +50 -1
- package/presentation/contentEntries/preview/resolvePreviewUrl.js.map +1 -1
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.d.ts +1 -0
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.js +127 -0
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.js.map +1 -0
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js +9 -4
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js.map +1 -1
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js +122 -0
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js.map +1 -0
- package/presentation/contentEntries/trashBin/CmsTrashBin.d.ts +2 -2
- package/presentation/contentEntries/views/CmsAdvancedSearch.d.ts +2 -2
- package/presentation/contentEntries/views/ContentEntriesListLayout.d.ts +2 -2
- package/presentation/contentEntries/views/ContentEntryFormView.d.ts +2 -2
- package/presentation/contentEntries/views/OlderRevisionAlert.d.ts +2 -2
- package/presentation/contentEntries/views/RevisionDrawer.d.ts +2 -2
- package/presentation/contentEntries/views/RevisionsList.d.ts +2 -2
- package/presentation/contentEntries/views/SingleEntryLayout.d.ts +2 -2
- package/presentation/contentEntries/views/Table/Table.d.ts +2 -2
- package/presentation/contentEntries/views/actions/CreateNewRevisionButton.d.ts +2 -2
- package/presentation/contentEntries/views/actions/DeleteEntryMenuItem.d.ts +2 -2
- package/presentation/contentEntries/views/actions/PublishOnlyButton.d.ts +2 -2
- package/presentation/contentEntries/views/actions/RevisionSelector.d.ts +2 -2
- package/presentation/contentEntries/views/actions/SaveAndPublishButton.d.ts +2 -2
- package/presentation/contentEntries/views/actions/SaveContentButton.d.ts +2 -2
- package/presentation/contentEntries/views/actions/ShowRevisionListMenuItem.d.ts +2 -2
- package/presentation/contentEntries/views/layout/ContentEntryForm.d.ts +12 -12
- package/presentation/contentModels/ContentModelsPresenter.d.ts +5 -5
- package/presentation/contentModels/ContentModelsPresenter.js +1 -1
- package/presentation/contentModels/ContentModelsPresenter.js.map +1 -1
- package/presentation/contentModels/abstractions.d.ts +7 -2
- package/presentation/contentModels/abstractions.js.map +1 -1
- package/presentation/contentModels/components/CloneContentModelDialog.d.ts +2 -2
- package/presentation/contentModels/components/ContentModels.d.ts +2 -2
- package/presentation/contentModels/components/ContentModelsDataList.d.ts +2 -2
- package/presentation/contentModels/components/ContentModelsDataList.js +6 -5
- package/presentation/contentModels/components/ContentModelsDataList.js.map +1 -1
- package/presentation/contentModels/components/NewContentModelDialog.d.ts +2 -2
- package/presentation/contentModels/components/fullDelete/dialog/Content.js +2 -2
- package/presentation/contentModels/components/fullDelete/dialog/Content.js.map +1 -1
- package/presentation/contentModels/components/fullDelete/types.js.map +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.d.ts +1 -0
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js +133 -0
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js.map +1 -0
- package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js.map +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js.map +1 -1
- package/presentation/fieldRenderers/ref/components/RefFieldOptions.d.ts +2 -2
- package/presentation/fieldRenderers/ref/components/RefFieldOptions.js +3 -2
- package/presentation/fieldRenderers/ref/components/RefFieldOptions.js.map +1 -1
- package/presentation/importContentModels/ImportContentModelsDialog.d.ts +2 -2
- package/presentation/importContentModels/ImportContentModelsPresenter.js +1 -1
- package/presentation/importContentModels/ImportContentModelsPresenter.js.map +1 -1
- package/presentation/importContentModels/components/DataList.d.ts +2 -2
- package/presentation/importContentModels/components/FileUpload.d.ts +2 -2
- package/presentation/importContentModels/components/FileUpload.js +1 -1
- package/presentation/importContentModels/components/FileUpload.js.map +1 -1
- package/presentation/importContentModels/components/Model/DataListModelItem.js +3 -3
- package/presentation/importContentModels/components/Model/DataListModelItem.js.map +1 -1
- package/presentation/importContentModels/components/Model/DataListModelItemInfo.js +2 -2
- package/presentation/importContentModels/components/Model/DataListModelItemInfo.js.map +1 -1
- package/presentation/importContentModels/components/Model/DataListModels.d.ts +2 -2
- package/presentation/menus/ContentGroupsMenuItems.d.ts +2 -2
- package/presentation/modelGroup/ModelGroupPresenter.js +1 -2
- package/presentation/modelGroup/ModelGroupPresenter.js.map +1 -1
- package/presentation/modelGroup/components/ContentModelGroups.d.ts +2 -2
- package/presentation/modelGroup/components/ContentModelGroupsDataList.d.ts +6 -2
- package/presentation/modelGroup/components/ContentModelGroupsForm.d.ts +8 -2
- package/presentation/newContentModel/NewContentModelPresenter.d.ts +1 -0
- package/presentation/newContentModel/NewContentModelPresenter.js +8 -6
- package/presentation/newContentModel/NewContentModelPresenter.js.map +1 -1
- package/utils/normalizeIcon.d.ts +4 -0
- package/utils/normalizeIcon.js +9 -6
- package/utils/normalizeIcon.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/modelGroup/ModelGroupPresenter.js","sources":["../../../src/presentation/modelGroup/ModelGroupPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction, computed } from \"mobx\";\nimport slugify from \"slugify\";\nimport { ListPresenter } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\nimport { FormModelFactory } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { IFormModel } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { ModelGroupDto } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { ListModelGroupsUseCase } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { GetModelGroupUseCase } from \"~/features/modelGroup/getModelGroup/abstractions.js\";\nimport { CreateModelGroupUseCase } from \"~/features/modelGroup/createModelGroup/abstractions.js\";\nimport { UpdateModelGroupUseCase } from \"~/features/modelGroup/updateModelGroup/abstractions.js\";\nimport { DeleteModelGroupUseCase } from \"~/features/modelGroup/deleteModelGroup/abstractions.js\";\nimport { ModelGroupsCache } from \"~/features/modelGroup/abstractions.js\";\nimport {\n ModelGroupPresenter as Abstraction,\n type IModelGroupPresenter,\n type IModelGroupPresenterViewModel\n} from \"./abstractions.js\";\nimport { ModelGroupDataSource } from \"./ModelGroupDataSource.js\";\n\nfunction extractIconName(icon: unknown): string {\n if (icon !== null && typeof icon === \"object\" && \"name\" in icon) {\n return (icon as { name: string }).name;\n }\n if (typeof icon === \"string\") {\n return icon;\n }\n return \"\";\n}\n\nfunction toIconValue(name: string): { type: string; name: string } {\n return { type: \"icon\", name };\n}\n\nclass ModelGroupPresenterImpl implements IModelGroupPresenter {\n private selectedGroup: ModelGroupDto | null = null;\n private loading = false;\n private saving = false;\n private showForm = false;\n private form: IFormModel;\n\n constructor(\n private listPresenter: ListPresenter.Interface<ModelGroupDto>,\n private formModelFactory: FormModelFactory.Interface,\n private listModelGroupsUseCase: ListModelGroupsUseCase.Interface,\n private getRoleUseCase: GetModelGroupUseCase.Interface,\n private createModelGroupUseCase: CreateModelGroupUseCase.Interface,\n private updateModelGroupUseCase: UpdateModelGroupUseCase.Interface,\n private deleteModelGroupUseCase: DeleteModelGroupUseCase.Interface,\n private cache: ModelGroupsCache.Interface\n ) {\n this.form = this.buildForm(false, false);\n makeAutoObservable<\n ModelGroupPresenterImpl,\n | \"formModelFactory\"\n | \"listModelGroupsUseCase\"\n | \"getRoleUseCase\"\n | \"createModelGroupUseCase\"\n | \"updateModelGroupUseCase\"\n | \"deleteModelGroupUseCase\"\n | \"cache\"\n >(this, {\n formModelFactory: false,\n listModelGroupsUseCase: false,\n getRoleUseCase: false,\n createModelGroupUseCase: false,\n updateModelGroupUseCase: false,\n deleteModelGroupUseCase: false,\n cache: false,\n vm: computed\n });\n }\n\n get vm(): IModelGroupPresenterViewModel {\n const group = this.selectedGroup;\n const isPluginGroup = group !== null && (group.plugin ?? false);\n\n return {\n selectedGroup: this.selectedGroup,\n loading: this.loading,\n saving: this.saving,\n showForm: this.showForm,\n canModify: !isPluginGroup,\n isPluginGroup,\n form: this.form.vm\n };\n }\n\n get list(): ListPresenter.Interface<ModelGroupDto> {\n return this.listPresenter;\n }\n\n init(): void {\n const dataSource = new ModelGroupDataSource(this.listModelGroupsUseCase, this.cache);\n\n this.listPresenter.init({\n dataSource,\n initialSort: { field: \"createdOn\", direction: \"DESC\" },\n limit: 1000\n });\n }\n\n async selectGroup(id: string): Promise<void> {\n runInAction(() => {\n this.loading = true;\n this.showForm = true;\n });\n\n try {\n const group = await this.getRoleUseCase.execute(id);\n const isPluginGroup = group.plugin ?? false;\n const canModify = !isPluginGroup;\n\n runInAction(() => {\n this.selectedGroup = group;\n this.form = this.buildForm(false, canModify);\n this.form.setData({\n name: group.name,\n slug: group.slug,\n description: group.description,\n icon: extractIconName(group.icon)\n });\n });\n } finally {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n createNew(): void {\n this.selectedGroup = null;\n this.form = this.buildForm(true, true);\n this.form.setData({ icon: \"fas/star\", description: \"\" });\n this.showForm = true;\n }\n\n deselect(): void {\n this.selectedGroup = null;\n this.showForm = false;\n }\n\n async save(): Promise<ModelGroupDto | null> {\n const data = await this.form.submit<ModelGroupDto>();\n if (!data) {\n return null;\n }\n\n runInAction(() => {\n this.saving = true;\n });\n\n try {\n const isUpdate = this.selectedGroup !== null && this.selectedGroup.createdOn;\n\n const iconValue = toIconValue(data.icon as unknown as string);\n\n if (isUpdate) {\n const group = await this.updateModelGroupUseCase.execute({\n id: this.selectedGroup!.id,\n name: data.name as unknown as string,\n slug: this.selectedGroup!.slug,\n description: data.description as unknown as string,\n icon: iconValue as unknown as string\n });\n runInAction(() => {\n this.selectedGroup = group;\n });\n return group;\n } else {\n const group = await this.createModelGroupUseCase.execute({\n name: data.name as unknown as string,\n slug: data.slug as unknown as string,\n description: data.description as unknown as string,\n icon: iconValue as unknown as string\n });\n runInAction(() => {\n this.selectedGroup = group;\n this.form = this.buildForm(false, true);\n this.form.setData({\n name: group.name,\n slug: group.slug,\n description: group.description,\n icon: extractIconName(group.icon)\n });\n });\n return group;\n }\n } catch {\n return null;\n } finally {\n runInAction(() => {\n this.saving = false;\n });\n }\n }\n\n async deleteGroup(id: string): Promise<void> {\n await this.deleteModelGroupUseCase.execute(id);\n\n runInAction(() => {\n if (this.selectedGroup !== null && this.selectedGroup.id === id) {\n this.selectedGroup = null;\n this.showForm = false;\n }\n });\n }\n\n private buildForm(isNew: boolean, canModify: boolean): IFormModel {\n return this.formModelFactory.create({\n fields: fields => ({\n name: fields\n .text()\n .label(\"Name\")\n .required(\"Name is required.\")\n .disabled(!canModify)\n .onBlur((value, { form }) => {\n const slugValue = form.field(\"slug\").getValue();\n if (slugValue || !value) {\n return;\n }\n form.field(\"slug\").setValue(\n slugify(String(value), {\n replacement: \"-\",\n lower: true,\n remove: /[*#?<>_{}[\\]+~.()'\"!:;@]/g,\n trim: false\n })\n );\n }),\n slug: fields\n .text()\n .label(\"Slug\")\n .required(\"Slug is required.\")\n .disabled(!isNew || !canModify),\n icon: fields\n .text()\n .label(\"Group icon\")\n .required(\"Icon is required.\")\n .disabled(!canModify)\n .renderer(\"cmsIconPicker\"),\n description: fields\n .text()\n .label(\"Description\")\n .defaultValue(\"\")\n .renderer(\"textarea\")\n .disabled(!canModify)\n }),\n layout: layout => [\n layout.row(\"name\"),\n layout.row(\"slug\"),\n layout.row(\"icon\"),\n layout.row(\"description\")\n ]\n });\n }\n}\n\nexport const ModelGroupPresenter = Abstraction.createImplementation({\n implementation: ModelGroupPresenterImpl,\n dependencies: [\n ListPresenter,\n FormModelFactory,\n ListModelGroupsUseCase,\n GetModelGroupUseCase,\n CreateModelGroupUseCase,\n UpdateModelGroupUseCase,\n DeleteModelGroupUseCase,\n ModelGroupsCache\n ]\n});\n"],"names":["extractIconName","icon","toIconValue","name","ModelGroupPresenterImpl","listPresenter","formModelFactory","listModelGroupsUseCase","getRoleUseCase","createModelGroupUseCase","updateModelGroupUseCase","deleteModelGroupUseCase","cache","makeAutoObservable","computed","group","isPluginGroup","dataSource","ModelGroupDataSource","id","runInAction","canModify","data","isUpdate","iconValue","isNew","fields","value","form","slugValue","slugify","String","layout","ModelGroupPresenter","Abstraction","ListPresenter","FormModelFactory","ListModelGroupsUseCase","GetModelGroupUseCase","CreateModelGroupUseCase","UpdateModelGroupUseCase","DeleteModelGroupUseCase","ModelGroupsCache"],"mappings":";;;;;;;;;;;;AAmBA,SAASA,gBAAgBC,IAAa;IAClC,IAAIA,AAAS,SAATA,QAAiB,AAAgB,YAAhB,OAAOA,QAAqB,UAAUA,MACvD,OAAQA,KAA0B,IAAI;IAE1C,IAAI,AAA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AAEJ,SAAkB,EAAc;QAC9D,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAChC,QAAQK,CAAAA,SAAW;oBACf,MAAMA,OACD,IAAI,GACJ,KAAK,CAAC,QACN,QAAQ,CAAC,qBACT,QAAQ,CAAC,CAACL,WACV,MAAM,CAAC,CAACM,OAAO,EAAEC,IAAI,EAAE;wBACpB,MAAMC,YAAYD,KAAK,KAAK,CAAC,QAAQ,QAAQ;wBAC7C,IAAIC,aAAa,CAACF,OACd;wBAEJC,KAAK,KAAK,CAAC,QAAQ,QAAQ,CACvBE,QAAQC,OAAOJ,QAAQ;4BACnB,aAAa;4BACb,OAAO;4BACP,QAAQ;4BACR,MAAM;wBACV;oBAER;oBACJ,MAAMD,OACD,IAAI,GACJ,KAAK,CAAC,QACN,QAAQ,CAAC,qBACT,QAAQ,CAAC,CAACD,SAAS,CAACJ;oBACzB,MAAMK,OACD,IAAI,GACJ,KAAK,CAAC,cACN,QAAQ,CAAC,qBACT,QAAQ,CAAC,CAACL,WACV,QAAQ,CAAC;oBACd,aAAaK,OACR,IAAI,GACJ,KAAK,CAAC,eACN,YAAY,CAAC,IACb,QAAQ,CAAC,YACT,QAAQ,CAAC,CAACL;gBACnB;YACA,QAAQW,CAAAA,SAAU;oBACdA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;iBACd;QACL;IACJ;AACJ;AAEO,MAAMC,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"presentation/modelGroup/ModelGroupPresenter.js","sources":["../../../src/presentation/modelGroup/ModelGroupPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction, computed } from \"mobx\";\nimport slugify from \"slugify\";\nimport { ListPresenter } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\nimport { FormModelFactory } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { IFormModel } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { ModelGroupDto } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { ListModelGroupsUseCase } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { GetModelGroupUseCase } from \"~/features/modelGroup/getModelGroup/abstractions.js\";\nimport { CreateModelGroupUseCase } from \"~/features/modelGroup/createModelGroup/abstractions.js\";\nimport { UpdateModelGroupUseCase } from \"~/features/modelGroup/updateModelGroup/abstractions.js\";\nimport { DeleteModelGroupUseCase } from \"~/features/modelGroup/deleteModelGroup/abstractions.js\";\nimport { ModelGroupsCache } from \"~/features/modelGroup/abstractions.js\";\nimport {\n ModelGroupPresenter as Abstraction,\n type IModelGroupPresenter,\n type IModelGroupPresenterViewModel\n} from \"./abstractions.js\";\nimport { ModelGroupDataSource } from \"./ModelGroupDataSource.js\";\n\nfunction extractIconName(icon: unknown): string {\n if (icon !== null && typeof icon === \"object\" && \"name\" in icon) {\n return (icon as { name: string }).name;\n }\n if (typeof icon === \"string\") {\n return icon;\n }\n return \"\";\n}\n\nfunction toIconValue(name: string): { type: string; name: string } {\n return { type: \"icon\", name };\n}\n\nclass ModelGroupPresenterImpl implements IModelGroupPresenter {\n private selectedGroup: ModelGroupDto | null = null;\n private loading = false;\n private saving = false;\n private showForm = false;\n private form: IFormModel;\n\n constructor(\n private listPresenter: ListPresenter.Interface<ModelGroupDto>,\n private formModelFactory: FormModelFactory.Interface,\n private listModelGroupsUseCase: ListModelGroupsUseCase.Interface,\n private getRoleUseCase: GetModelGroupUseCase.Interface,\n private createModelGroupUseCase: CreateModelGroupUseCase.Interface,\n private updateModelGroupUseCase: UpdateModelGroupUseCase.Interface,\n private deleteModelGroupUseCase: DeleteModelGroupUseCase.Interface,\n private cache: ModelGroupsCache.Interface\n ) {\n this.form = this.buildForm(false, false);\n makeAutoObservable<\n ModelGroupPresenterImpl,\n | \"formModelFactory\"\n | \"listModelGroupsUseCase\"\n | \"getRoleUseCase\"\n | \"createModelGroupUseCase\"\n | \"updateModelGroupUseCase\"\n | \"deleteModelGroupUseCase\"\n | \"cache\"\n >(this, {\n formModelFactory: false,\n listModelGroupsUseCase: false,\n getRoleUseCase: false,\n createModelGroupUseCase: false,\n updateModelGroupUseCase: false,\n deleteModelGroupUseCase: false,\n cache: false,\n vm: computed\n });\n }\n\n get vm(): IModelGroupPresenterViewModel {\n const group = this.selectedGroup;\n const isPluginGroup = group !== null && (group.plugin ?? false);\n\n return {\n selectedGroup: this.selectedGroup,\n loading: this.loading,\n saving: this.saving,\n showForm: this.showForm,\n canModify: !isPluginGroup,\n isPluginGroup,\n form: this.form.vm\n };\n }\n\n get list(): ListPresenter.Interface<ModelGroupDto> {\n return this.listPresenter;\n }\n\n init(): void {\n const dataSource = new ModelGroupDataSource(this.listModelGroupsUseCase, this.cache);\n\n this.listPresenter.init({\n dataSource,\n initialSort: { field: \"createdOn\", direction: \"DESC\" },\n limit: 1000\n });\n }\n\n async selectGroup(id: string): Promise<void> {\n runInAction(() => {\n this.loading = true;\n this.showForm = true;\n });\n\n try {\n const group = await this.getRoleUseCase.execute(id);\n const isPluginGroup = group.plugin ?? false;\n const canModify = !isPluginGroup;\n\n runInAction(() => {\n this.selectedGroup = group;\n this.form = this.buildForm(false, canModify);\n this.form.setData({\n name: group.name,\n slug: group.slug,\n description: group.description,\n icon: extractIconName(group.icon)\n });\n });\n } finally {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n createNew(): void {\n this.selectedGroup = null;\n this.form = this.buildForm(true, true);\n this.form.setData({ icon: \"fas/star\", description: \"\" });\n this.showForm = true;\n }\n\n deselect(): void {\n this.selectedGroup = null;\n this.showForm = false;\n }\n\n async save(): Promise<ModelGroupDto | null> {\n const data = await this.form.submit<ModelGroupDto>();\n if (!data) {\n return null;\n }\n\n runInAction(() => {\n this.saving = true;\n });\n\n try {\n const isUpdate = this.selectedGroup !== null && this.selectedGroup.createdOn;\n\n const iconValue = toIconValue(data.icon as unknown as string);\n\n if (isUpdate) {\n const group = await this.updateModelGroupUseCase.execute({\n id: this.selectedGroup!.id,\n name: data.name as unknown as string,\n slug: this.selectedGroup!.slug,\n description: data.description as unknown as string,\n icon: iconValue as unknown as string\n });\n runInAction(() => {\n this.selectedGroup = group;\n });\n return group;\n } else {\n const group = await this.createModelGroupUseCase.execute({\n name: data.name as unknown as string,\n slug: data.slug as unknown as string,\n description: data.description as unknown as string,\n icon: iconValue as unknown as string\n });\n runInAction(() => {\n this.selectedGroup = group;\n this.form = this.buildForm(false, true);\n this.form.setData({\n name: group.name,\n slug: group.slug,\n description: group.description,\n icon: extractIconName(group.icon)\n });\n });\n return group;\n }\n } catch {\n return null;\n } finally {\n runInAction(() => {\n this.saving = false;\n });\n }\n }\n\n async deleteGroup(id: string): Promise<void> {\n await this.deleteModelGroupUseCase.execute(id);\n\n runInAction(() => {\n if (this.selectedGroup !== null && this.selectedGroup.id === id) {\n this.selectedGroup = null;\n this.showForm = false;\n }\n });\n }\n\n private buildForm(isNew: boolean, canModify: boolean): IFormModel {\n return this.formModelFactory.create({\n fields: fields => ({\n name: fields\n .text()\n .label(\"Name\")\n .required(\"Name is required.\")\n .disabled(!canModify)\n .onBlur((value, { form }) => {\n const slugValue = form.field(\"slug\").getValue();\n if (slugValue || !value) {\n return;\n }\n form.field(\"slug\").setValue(\n slugify(String(value), {\n replacement: \"-\",\n lower: true,\n remove: /[*#?<>_{}[\\]+~.()'\"!:;@]/g,\n trim: false\n })\n );\n }),\n slug: fields\n .text()\n .label(\"Slug\")\n .required(\"Slug is required.\")\n .disabled(!isNew || !canModify),\n icon: fields\n .text()\n .label(\"Group icon\")\n .required(\"Icon is required.\")\n .disabled(!canModify)\n .renderer(\"cmsIconPicker\"),\n description: fields\n .text()\n .label(\"Description\")\n .defaultValue(\"\")\n .renderer(\"textarea\")\n .disabled(!canModify)\n }),\n layout: layout => [\n layout.row(\"name\"),\n layout.row(\"slug\"),\n layout.row(\"icon\"),\n layout.row(\"description\")\n ]\n });\n }\n}\n\nexport const ModelGroupPresenter = Abstraction.createImplementation({\n implementation: ModelGroupPresenterImpl,\n dependencies: [\n ListPresenter,\n FormModelFactory,\n ListModelGroupsUseCase,\n GetModelGroupUseCase,\n CreateModelGroupUseCase,\n UpdateModelGroupUseCase,\n DeleteModelGroupUseCase,\n ModelGroupsCache\n ]\n});\n"],"names":["extractIconName","icon","toIconValue","name","ModelGroupPresenterImpl","listPresenter","formModelFactory","listModelGroupsUseCase","getRoleUseCase","createModelGroupUseCase","updateModelGroupUseCase","deleteModelGroupUseCase","cache","makeAutoObservable","computed","group","isPluginGroup","dataSource","ModelGroupDataSource","id","runInAction","canModify","data","isUpdate","iconValue","isNew","fields","value","form","slugValue","slugify","String","layout","ModelGroupPresenter","Abstraction","ListPresenter","FormModelFactory","ListModelGroupsUseCase","GetModelGroupUseCase","CreateModelGroupUseCase","UpdateModelGroupUseCase","DeleteModelGroupUseCase","ModelGroupsCache"],"mappings":";;;;;;;;;;;;AAmBA,SAASA,gBAAgBC,IAAa;IAClC,IAAIA,AAAS,SAATA,QAAiB,AAAgB,YAAhB,OAAOA,QAAqB,UAAUA,MACvD,OAAQA,KAA0B,IAAI;IAE1C,IAAI,AAAgB,YAAhB,OAAOA,MACP,OAAOA;IAEX,OAAO;AACX;AAEA,SAASC,YAAYC,IAAY;IAC7B,OAAO;QAAE,MAAM;QAAQA;IAAK;AAChC;AAEA,MAAMC;IAOF,YACYC,aAAqD,EACrDC,gBAA4C,EAC5CC,sBAAwD,EACxDC,cAA8C,EAC9CC,uBAA0D,EAC1DC,uBAA0D,EAC1DC,uBAA0D,EAC1DC,KAAiC,CAC3C;aARUP,aAAa,GAAbA;aACAC,gBAAgB,GAAhBA;aACAC,sBAAsB,GAAtBA;aACAC,cAAc,GAAdA;aACAC,uBAAuB,GAAvBA;aACAC,uBAAuB,GAAvBA;aACAC,uB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,OAAO;4BACP,QAAQ;4BACR,MAAM;wBACV;oBAER;oBACJ,MAAMD,OACD,IAAI,GACJ,KAAK,CAAC,QACN,QAAQ,CAAC,qBACT,QAAQ,CAAC,CAACD,SAAS,CAACJ;oBACzB,MAAMK,OACD,IAAI,GACJ,KAAK,CAAC,cACN,QAAQ,CAAC,qBACT,QAAQ,CAAC,CAACL,WACV,QAAQ,CAAC;oBACd,aAAaK,OACR,IAAI,GACJ,KAAK,CAAC,eACN,YAAY,CAAC,IACb,QAAQ,CAAC,YACT,QAAQ,CAAC,CAACL;gBACnB;YACA,QAAQW,CAAAA,SAAU;oBACdA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;iBACd;QACL;IACJ;AACJ;AAEO,MAAMC,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
declare const ContentModelGroups: (() => React.JSX.Element) & {
|
|
3
|
-
|
|
2
|
+
declare const ContentModelGroups: (() => React.JSX.Element) & React.NamedExoticComponent<unknown> & {
|
|
3
|
+
readonly type: () => React.JSX.Element;
|
|
4
4
|
};
|
|
5
5
|
export default ContentModelGroups;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export declare const ContentModelGroupsDataList: (({ activeId }: {
|
|
3
3
|
activeId: string | undefined;
|
|
4
|
-
}) => React.JSX.Element) & {
|
|
5
|
-
|
|
4
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
5
|
+
activeId: string | undefined;
|
|
6
|
+
}> & {
|
|
7
|
+
readonly type: ({ activeId }: {
|
|
8
|
+
activeId: string | undefined;
|
|
9
|
+
}) => React.JSX.Element;
|
|
6
10
|
};
|
|
@@ -2,6 +2,12 @@ import React from "react";
|
|
|
2
2
|
export declare const ContentModelGroupsForm: (({ newEntry, id }: {
|
|
3
3
|
newEntry: boolean;
|
|
4
4
|
id: string | undefined;
|
|
5
|
-
}) => React.JSX.Element) & {
|
|
6
|
-
|
|
5
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
6
|
+
newEntry: boolean;
|
|
7
|
+
id: string | undefined;
|
|
8
|
+
}> & {
|
|
9
|
+
readonly type: ({ newEntry, id }: {
|
|
10
|
+
newEntry: boolean;
|
|
11
|
+
id: string | undefined;
|
|
12
|
+
}) => React.JSX.Element;
|
|
7
13
|
};
|
|
@@ -16,6 +16,7 @@ declare class NewContentModelPresenterImpl implements INewContentModelPresenter
|
|
|
16
16
|
private form;
|
|
17
17
|
constructor(formModelFactory: FormModelFactory.Interface, listModelGroupsUseCase: ListModelGroupsUseCase.Interface, createModelUseCase: CreateModelUseCase.Interface, groupsCache: ModelGroupsCache.Interface, modelsCache: ModelsCache.Interface);
|
|
18
18
|
get vm(): INewContentModelPresenterViewModel;
|
|
19
|
+
private get groupOptions();
|
|
19
20
|
init(): Promise<void>;
|
|
20
21
|
save(): Promise<CmsModel | null>;
|
|
21
22
|
reset(): void;
|
|
@@ -26,18 +26,20 @@ class NewContentModelPresenterImpl {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
get vm() {
|
|
29
|
-
const groups = this.groupsCache.getItems().map((g)=>({
|
|
30
|
-
value: g.slug,
|
|
31
|
-
label: g.name
|
|
32
|
-
}));
|
|
33
29
|
return {
|
|
34
30
|
loading: this.loading,
|
|
35
31
|
saving: this.saving,
|
|
36
|
-
groups,
|
|
32
|
+
groups: this.groupOptions,
|
|
37
33
|
models: this.modelsCache.getItems(),
|
|
38
34
|
form: this.form.vm
|
|
39
35
|
};
|
|
40
36
|
}
|
|
37
|
+
get groupOptions() {
|
|
38
|
+
return this.groupsCache.getItems().map((group)=>({
|
|
39
|
+
value: group.slug,
|
|
40
|
+
label: group.name
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
41
43
|
async init() {
|
|
42
44
|
try {
|
|
43
45
|
await this.listModelGroupsUseCase.execute();
|
|
@@ -97,7 +99,7 @@ class NewContentModelPresenterImpl {
|
|
|
97
99
|
singularApiName: fields.text().label("Singular API Name").required("Singular API Name is required."),
|
|
98
100
|
singleEntry: fields.boolean().label("Single entry model").defaultValue(false),
|
|
99
101
|
pluralApiName: fields.text().label("Plural API Name"),
|
|
100
|
-
group: fields.text().label("Content model group").required("Group is required."),
|
|
102
|
+
group: fields.text().label("Content model group").required("Group is required.").options(()=>this.groupOptions),
|
|
101
103
|
icon: fields.text().label("Icon").renderer("cmsIconPicker"),
|
|
102
104
|
description: fields.text().label("Description").renderer("textarea"),
|
|
103
105
|
defaultFields: fields.boolean().label("Create model with default fields").defaultValue(true)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/newContentModel/NewContentModelPresenter.js","sources":["../../../src/presentation/newContentModel/NewContentModelPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction, computed } from \"mobx\";\nimport { FormModelFactory } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { IFormModel } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModel } from \"~/types.js\";\nimport { ListModelGroupsUseCase } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { CreateModelUseCase } from \"~/features/model/createModel/abstractions.js\";\nimport { ModelGroupsCache } from \"~/features/modelGroup/abstractions.js\";\nimport { ModelsCache } from \"~/features/model/abstractions.js\";\nconst CMS_MODEL_SINGLETON_TAG = \"singleEntry\";\nimport {\n NewContentModelPresenter as Abstraction,\n type INewContentModelPresenter,\n type INewContentModelPresenterViewModel\n} from \"./abstractions.js\";\n\nclass NewContentModelPresenterImpl implements INewContentModelPresenter {\n private loading = true;\n private saving = false;\n private form: IFormModel;\n\n constructor(\n private formModelFactory: FormModelFactory.Interface,\n private listModelGroupsUseCase: ListModelGroupsUseCase.Interface,\n private createModelUseCase: CreateModelUseCase.Interface,\n private groupsCache: ModelGroupsCache.Interface,\n private modelsCache: ModelsCache.Interface\n ) {\n this.form = this.buildForm();\n makeAutoObservable<\n NewContentModelPresenterImpl,\n | \"formModelFactory\"\n | \"listModelGroupsUseCase\"\n | \"createModelUseCase\"\n | \"groupsCache\"\n | \"modelsCache\"\n >(this, {\n formModelFactory: false,\n listModelGroupsUseCase: false,\n createModelUseCase: false,\n groupsCache: false,\n modelsCache: false,\n vm: computed\n });\n }\n\n get vm(): INewContentModelPresenterViewModel {\n
|
|
1
|
+
{"version":3,"file":"presentation/newContentModel/NewContentModelPresenter.js","sources":["../../../src/presentation/newContentModel/NewContentModelPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction, computed } from \"mobx\";\nimport { FormModelFactory } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { IFormModel } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModel } from \"~/types.js\";\nimport { ListModelGroupsUseCase } from \"~/features/modelGroup/listModelGroups/abstractions.js\";\nimport { CreateModelUseCase } from \"~/features/model/createModel/abstractions.js\";\nimport { ModelGroupsCache } from \"~/features/modelGroup/abstractions.js\";\nimport { ModelsCache } from \"~/features/model/abstractions.js\";\nconst CMS_MODEL_SINGLETON_TAG = \"singleEntry\";\nimport {\n NewContentModelPresenter as Abstraction,\n type INewContentModelPresenter,\n type INewContentModelPresenterViewModel\n} from \"./abstractions.js\";\n\nclass NewContentModelPresenterImpl implements INewContentModelPresenter {\n private loading = true;\n private saving = false;\n private form: IFormModel;\n\n constructor(\n private formModelFactory: FormModelFactory.Interface,\n private listModelGroupsUseCase: ListModelGroupsUseCase.Interface,\n private createModelUseCase: CreateModelUseCase.Interface,\n private groupsCache: ModelGroupsCache.Interface,\n private modelsCache: ModelsCache.Interface\n ) {\n this.form = this.buildForm();\n makeAutoObservable<\n NewContentModelPresenterImpl,\n | \"formModelFactory\"\n | \"listModelGroupsUseCase\"\n | \"createModelUseCase\"\n | \"groupsCache\"\n | \"modelsCache\"\n >(this, {\n formModelFactory: false,\n listModelGroupsUseCase: false,\n createModelUseCase: false,\n groupsCache: false,\n modelsCache: false,\n vm: computed\n });\n }\n\n get vm(): INewContentModelPresenterViewModel {\n return {\n loading: this.loading,\n saving: this.saving,\n groups: this.groupOptions,\n models: this.modelsCache.getItems(),\n form: this.form.vm\n };\n }\n\n private get groupOptions() {\n return this.groupsCache.getItems().map(group => ({\n value: group.slug,\n label: group.name\n }));\n }\n\n async init(): Promise<void> {\n try {\n await this.listModelGroupsUseCase.execute();\n } finally {\n runInAction(() => {\n this.loading = false;\n const groups = this.groupsCache.getItems();\n if (groups.length > 0) {\n this.form.setData({ group: groups[0].slug });\n }\n });\n }\n }\n\n async save(): Promise<CmsModel | null> {\n const data = await this.form.submit<Record<string, any>>();\n if (!data) {\n return null;\n }\n\n runInAction(() => {\n this.saving = true;\n });\n\n try {\n const tags: string[] = Array.isArray(data.tags) ? data.tags : [];\n let pluralApiName = data.pluralApiName as string;\n\n if (data.singleEntry) {\n tags.push(CMS_MODEL_SINGLETON_TAG);\n pluralApiName = `${data.singularApiName}Unused`;\n }\n\n const model = await this.createModelUseCase.execute({\n name: data.name as string,\n singularApiName: data.singularApiName as string,\n pluralApiName,\n group: data.group as string,\n icon: data.icon as string | undefined,\n description: data.description as string | undefined,\n defaultFields: data.defaultFields as boolean | undefined,\n tags\n });\n\n return model;\n } catch {\n return null;\n } finally {\n runInAction(() => {\n this.saving = false;\n });\n }\n }\n\n reset(): void {\n this.form = this.buildForm();\n const groups = this.groupsCache.getItems();\n if (groups.length > 0) {\n this.form.setData({ group: groups[0].slug });\n }\n }\n\n private buildForm(): IFormModel {\n return this.formModelFactory.create({\n fields: fields => ({\n name: fields.text().label(\"Name\").required(\"Name is required.\"),\n singularApiName: fields\n .text()\n .label(\"Singular API Name\")\n .required(\"Singular API Name is required.\"),\n singleEntry: fields.boolean().label(\"Single entry model\").defaultValue(false),\n pluralApiName: fields.text().label(\"Plural API Name\"),\n group: fields\n .text()\n .label(\"Content model group\")\n .required(\"Group is required.\")\n /*\n * Options turn the text field into a select. The groups arrive after the form\n * is built, so they have to be read through a callback.\n */\n .options(() => this.groupOptions),\n icon: fields.text().label(\"Icon\").renderer(\"cmsIconPicker\"),\n description: fields.text().label(\"Description\").renderer(\"textarea\"),\n defaultFields: fields\n .boolean()\n .label(\"Create model with default fields\")\n .defaultValue(true)\n }),\n layout: layout => [\n layout.row(\"name\"),\n layout.row(\"singularApiName\"),\n layout.row(\"singleEntry\"),\n layout.row(\"pluralApiName\"),\n layout.row(\"group\"),\n layout.row(\"icon\"),\n layout.row(\"description\"),\n layout.row(\"defaultFields\")\n ]\n });\n }\n}\n\nexport const NewContentModelPresenter = Abstraction.createImplementation({\n implementation: NewContentModelPresenterImpl,\n dependencies: [\n FormModelFactory,\n ListModelGroupsUseCase,\n CreateModelUseCase,\n ModelGroupsCache,\n ModelsCache\n ]\n});\n"],"names":["CMS_MODEL_SINGLETON_TAG","NewContentModelPresenterImpl","formModelFactory","listModelGroupsUseCase","createModelUseCase","groupsCache","modelsCache","makeAutoObservable","computed","group","runInAction","groups","data","tags","Array","pluralApiName","model","fields","layout","NewContentModelPresenter","Abstraction","FormModelFactory","ListModelGroupsUseCase","CreateModelUseCase","ModelGroupsCache","ModelsCache"],"mappings":";;;;;;;AAQA,MAAMA,0BAA0B;AAOhC,MAAMC;IAKF,YACYC,gBAA4C,EAC5CC,sBAAwD,EACxDC,kBAAgD,EAChDC,WAAuC,EACvCC,WAAkC,CAC5C;aALUJ,gBAAgB,GAAhBA;aACAC,sBAAsB,GAAtBA;aACAC,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;aACAC,WAAW,GAAXA;aATJ,OAAO,GAAG;aACV,MAAM,GAAG;QAUb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS;QAC1BC,mBAOE,IAAI,EAAE;YACJ,kBAAkB;YAClB,wBAAwB;YACx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,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;oBACXA,OAAO,GAAG,CAAC;iBACd;QACL;IACJ;AACJ;AAEO,MAAMC,oDAA2BC,yBAAAA,oBAAgC,CAAC;IACrE,gBAAgBnB;IAChB,cAAc;QACVoB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
package/utils/normalizeIcon.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { IconProp } from "@fortawesome/fontawesome-svg-core";
|
|
2
2
|
import type { CmsIcon } from "@webiny/app-headless-cms-common/types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a stored icon ("prefix/name") into a FontAwesome icon tuple.
|
|
5
|
+
* Returns undefined when the value is missing or not in the "prefix/name" format.
|
|
6
|
+
*/
|
|
3
7
|
export declare const normalizeIcon: (icon: string | CmsIcon | undefined) => IconProp | undefined;
|
package/utils/normalizeIcon.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
const normalizeIcon = (icon)=>{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
2
|
+
if (!icon) return;
|
|
3
|
+
const name = "string" == typeof icon ? icon : icon.name;
|
|
4
|
+
if (!name) return;
|
|
5
|
+
const [prefix, iconName, ...rest] = name.split("/");
|
|
6
|
+
if (!prefix || !iconName || rest.length > 0) return;
|
|
7
|
+
return [
|
|
8
|
+
prefix,
|
|
9
|
+
iconName
|
|
10
|
+
];
|
|
8
11
|
};
|
|
9
12
|
export { normalizeIcon };
|
|
10
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/normalizeIcon.js","sources":["../../src/utils/normalizeIcon.ts"],"sourcesContent":["import type { IconProp } from \"@fortawesome/fontawesome-svg-core\";\nimport type { CmsIcon } from \"@webiny/app-headless-cms-common/types/index.js\";\n\nexport const normalizeIcon = (icon: string | CmsIcon | undefined)
|
|
1
|
+
{"version":3,"file":"utils/normalizeIcon.js","sources":["../../src/utils/normalizeIcon.ts"],"sourcesContent":["import type { IconProp } from \"@fortawesome/fontawesome-svg-core\";\nimport type { CmsIcon } from \"@webiny/app-headless-cms-common/types/index.js\";\n\n/**\n * Converts a stored icon (\"prefix/name\") into a FontAwesome icon tuple.\n * Returns undefined when the value is missing or not in the \"prefix/name\" format.\n */\nexport const normalizeIcon = (icon: string | CmsIcon | undefined): IconProp | undefined => {\n if (!icon) {\n return undefined;\n }\n const name = typeof icon === \"string\" ? icon : icon.name;\n if (!name) {\n return undefined;\n }\n const [prefix, iconName, ...rest] = name.split(\"/\");\n if (!prefix || !iconName || rest.length > 0) {\n return undefined;\n }\n return [prefix, iconName] as IconProp;\n};\n"],"names":["normalizeIcon","icon","name","prefix","iconName","rest"],"mappings":"AAOO,MAAMA,gBAAgB,CAACC;IAC1B,IAAI,CAACA,MACD;IAEJ,MAAMC,OAAO,AAAgB,YAAhB,OAAOD,OAAoBA,OAAOA,KAAK,IAAI;IACxD,IAAI,CAACC,MACD;IAEJ,MAAM,CAACC,QAAQC,UAAU,GAAGC,KAAK,GAAGH,KAAK,KAAK,CAAC;IAC/C,IAAI,CAACC,UAAU,CAACC,YAAYC,KAAK,MAAM,GAAG,GACtC;IAEJ,OAAO;QAACF;QAAQC;KAAS;AAC7B"}
|