@webiny/app-headless-cms 6.5.0-beta.4 → 6.5.0-beta.5

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.
Files changed (101) hide show
  1. package/admin/components/ContentEntries/BulkActions/ActionDelete.d.ts +2 -2
  2. package/admin/components/ContentEntries/BulkActions/ActionDelete.js.map +1 -1
  3. package/admin/components/ContentEntries/BulkActions/ActionMove.d.ts +2 -2
  4. package/admin/components/ContentEntries/BulkActions/ActionMove.js.map +1 -1
  5. package/admin/components/ContentEntries/BulkActions/ActionPublish.d.ts +2 -2
  6. package/admin/components/ContentEntries/BulkActions/ActionPublish.js.map +1 -1
  7. package/admin/components/ContentEntries/BulkActions/ActionUnpublish.d.ts +2 -2
  8. package/admin/components/ContentEntries/BulkActions/ActionUnpublish.js.map +1 -1
  9. package/admin/components/ContentModelEditor/ContentModelEditor.js +1 -1
  10. package/admin/components/ContentModelEditor/ContentModelEditor.js.map +1 -1
  11. package/admin/components/FieldEditor/EditFieldDialog.d.ts +2 -2
  12. package/admin/components/FieldEditor/Field.js +4 -4
  13. package/admin/components/FieldEditor/Field.js.map +1 -1
  14. package/features/contentEntry/createEntry/CreateEntryGateway.d.ts +0 -1
  15. package/features/contentEntry/createEntry/CreateEntryGateway.js +1 -9
  16. package/features/contentEntry/createEntry/CreateEntryGateway.js.map +1 -1
  17. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.d.ts +3 -1
  18. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js +6 -2
  19. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js.map +1 -1
  20. package/features/contentEntry/entryValueGateways.test.d.ts +1 -0
  21. package/features/contentEntry/entryValueGateways.test.js +106 -0
  22. package/features/contentEntry/entryValueGateways.test.js.map +1 -0
  23. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.d.ts +0 -1
  24. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js +1 -9
  25. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js.map +1 -1
  26. package/features/contentEntry/updateEntry/UpdateEntryGateway.d.ts +0 -1
  27. package/features/contentEntry/updateEntry/UpdateEntryGateway.js +1 -9
  28. package/features/contentEntry/updateEntry/UpdateEntryGateway.js.map +1 -1
  29. package/features/contentEntry/valueTransformers/EntryDataPreparer.d.ts +9 -0
  30. package/features/contentEntry/valueTransformers/EntryDataPreparer.js +8 -0
  31. package/features/contentEntry/valueTransformers/EntryDataPreparer.js.map +1 -1
  32. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.d.ts +1 -0
  33. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js +113 -0
  34. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js.map +1 -0
  35. package/features/contentEntry/valueTransformers/entryValueFixtures.d.ts +146 -0
  36. package/features/contentEntry/valueTransformers/entryValueFixtures.js +171 -0
  37. package/features/contentEntry/valueTransformers/entryValueFixtures.js.map +1 -0
  38. package/features/formModel/mappers/DynamicZoneFieldMapper.js +1 -0
  39. package/features/formModel/mappers/DynamicZoneFieldMapper.js.map +1 -1
  40. package/features/model/exportModels/ExportModelsGateway.d.ts +1 -1
  41. package/features/model/exportModels/ExportModelsGateway.js.map +1 -1
  42. package/features/model/exportModels/ExportModelsUseCase.js +7 -1
  43. package/features/model/exportModels/ExportModelsUseCase.js.map +1 -1
  44. package/features/model/exportModels/abstractions.d.ts +8 -2
  45. package/features/model/exportModels/abstractions.js.map +1 -1
  46. package/package.json +26 -26
  47. package/presentation/contentEntries/trashBin/CmsTrashBin.d.ts +2 -2
  48. package/presentation/contentEntries/views/CmsAdvancedSearch.d.ts +2 -2
  49. package/presentation/contentEntries/views/ContentEntriesListLayout.d.ts +2 -2
  50. package/presentation/contentEntries/views/ContentEntryFormView.d.ts +2 -2
  51. package/presentation/contentEntries/views/OlderRevisionAlert.d.ts +2 -2
  52. package/presentation/contentEntries/views/RevisionDrawer.d.ts +2 -2
  53. package/presentation/contentEntries/views/RevisionsList.d.ts +2 -2
  54. package/presentation/contentEntries/views/SingleEntryLayout.d.ts +2 -2
  55. package/presentation/contentEntries/views/Table/Table.d.ts +2 -2
  56. package/presentation/contentEntries/views/actions/CreateNewRevisionButton.d.ts +2 -2
  57. package/presentation/contentEntries/views/actions/DeleteEntryMenuItem.d.ts +2 -2
  58. package/presentation/contentEntries/views/actions/PublishOnlyButton.d.ts +2 -2
  59. package/presentation/contentEntries/views/actions/RevisionSelector.d.ts +2 -2
  60. package/presentation/contentEntries/views/actions/SaveAndPublishButton.d.ts +2 -2
  61. package/presentation/contentEntries/views/actions/SaveContentButton.d.ts +2 -2
  62. package/presentation/contentEntries/views/actions/ShowRevisionListMenuItem.d.ts +2 -2
  63. package/presentation/contentEntries/views/layout/ContentEntryForm.d.ts +12 -12
  64. package/presentation/contentModels/ContentModelsPresenter.d.ts +5 -5
  65. package/presentation/contentModels/ContentModelsPresenter.js +1 -1
  66. package/presentation/contentModels/ContentModelsPresenter.js.map +1 -1
  67. package/presentation/contentModels/abstractions.d.ts +7 -2
  68. package/presentation/contentModels/abstractions.js.map +1 -1
  69. package/presentation/contentModels/components/CloneContentModelDialog.d.ts +2 -2
  70. package/presentation/contentModels/components/ContentModels.d.ts +2 -2
  71. package/presentation/contentModels/components/ContentModelsDataList.d.ts +2 -2
  72. package/presentation/contentModels/components/ContentModelsDataList.js +6 -5
  73. package/presentation/contentModels/components/ContentModelsDataList.js.map +1 -1
  74. package/presentation/contentModels/components/NewContentModelDialog.d.ts +2 -2
  75. package/presentation/contentModels/components/fullDelete/dialog/Content.js +2 -2
  76. package/presentation/contentModels/components/fullDelete/dialog/Content.js.map +1 -1
  77. package/presentation/contentModels/components/fullDelete/types.js.map +1 -1
  78. package/presentation/fieldRenderers/ref/components/RefFieldOptions.d.ts +2 -2
  79. package/presentation/fieldRenderers/ref/components/RefFieldOptions.js +3 -2
  80. package/presentation/fieldRenderers/ref/components/RefFieldOptions.js.map +1 -1
  81. package/presentation/importContentModels/ImportContentModelsDialog.d.ts +2 -2
  82. package/presentation/importContentModels/ImportContentModelsPresenter.js +1 -1
  83. package/presentation/importContentModels/ImportContentModelsPresenter.js.map +1 -1
  84. package/presentation/importContentModels/components/DataList.d.ts +2 -2
  85. package/presentation/importContentModels/components/FileUpload.d.ts +2 -2
  86. package/presentation/importContentModels/components/FileUpload.js +1 -1
  87. package/presentation/importContentModels/components/FileUpload.js.map +1 -1
  88. package/presentation/importContentModels/components/Model/DataListModelItem.js +3 -3
  89. package/presentation/importContentModels/components/Model/DataListModelItem.js.map +1 -1
  90. package/presentation/importContentModels/components/Model/DataListModelItemInfo.js +2 -2
  91. package/presentation/importContentModels/components/Model/DataListModelItemInfo.js.map +1 -1
  92. package/presentation/importContentModels/components/Model/DataListModels.d.ts +2 -2
  93. package/presentation/menus/ContentGroupsMenuItems.d.ts +2 -2
  94. package/presentation/modelGroup/ModelGroupPresenter.js +1 -2
  95. package/presentation/modelGroup/ModelGroupPresenter.js.map +1 -1
  96. package/presentation/modelGroup/components/ContentModelGroups.d.ts +2 -2
  97. package/presentation/modelGroup/components/ContentModelGroupsDataList.d.ts +6 -2
  98. package/presentation/modelGroup/components/ContentModelGroupsForm.d.ts +8 -2
  99. package/utils/normalizeIcon.d.ts +4 -0
  100. package/utils/normalizeIcon.js +9 -6
  101. 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,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,uBAAuB,GAAvBA;aACAC,KAAK,GAALA;aAdJ,aAAa,GAAyB;aACtC,OAAO,GAAG;aACV,MAAM,GAAG;aACT,QAAQ,GAAG;QAaf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO;QAClCC,mBASE,IAAI,EAAE;YACJ,kB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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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AC;QACAC;QACAC;KACH;AACL"}
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- declare const ContentModelGroups: (() => React.JSX.Element) & {
3
- displayName: string;
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
- displayName: string;
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
- displayName: string;
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
  };
@@ -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;
@@ -1,10 +1,13 @@
1
1
  const normalizeIcon = (icon)=>{
2
- let iconName;
3
- if (icon) {
4
- const name = "string" == typeof icon ? icon : icon.name;
5
- iconName = name.split("/");
6
- }
7
- return iconName;
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) => {\n let iconName: IconProp | undefined = undefined;\n if (icon) {\n const name = typeof icon === \"string\" ? icon : icon.name;\n iconName = name.split(\"/\") as IconProp;\n }\n return iconName;\n};\n"],"names":["normalizeIcon","icon","iconName","name"],"mappings":"AAGO,MAAMA,gBAAgB,CAACC;IAC1B,IAAIC;IACJ,IAAID,MAAM;QACN,MAAME,OAAO,AAAgB,YAAhB,OAAOF,OAAoBA,OAAOA,KAAK,IAAI;QACxDC,WAAWC,KAAK,KAAK,CAAC;IAC1B;IACA,OAAOD;AACX"}
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"}