@leav/ui 1.9.0-63f51574 → 1.9.0-8

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 (53) hide show
  1. package/dist/_gqlTypes/index.d.ts +104 -213
  2. package/dist/_gqlTypes/index.js +72 -122
  3. package/dist/_gqlTypes/index.js.map +1 -1
  4. package/dist/_queries/records/createRecordMutation.js +2 -2
  5. package/dist/_queries/records/createRecordMutation.js.map +1 -1
  6. package/dist/_queries/trees/getTreeContentQuery.d.ts +6 -0
  7. package/dist/_queries/trees/getTreeContentQuery.js +70 -0
  8. package/dist/_queries/trees/getTreeContentQuery.js.map +1 -0
  9. package/dist/components/Explorer/Explorer.js +11 -21
  10. package/dist/components/Explorer/Explorer.js.map +1 -1
  11. package/dist/components/Explorer/ExplorerToolbar.js +1 -2
  12. package/dist/components/Explorer/ExplorerToolbar.js.map +1 -1
  13. package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.d.ts +2 -9
  14. package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.js +4 -18
  15. package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.js.map +1 -1
  16. package/dist/components/Explorer/actions-mass/useMassActions.d.ts +3 -5
  17. package/dist/components/Explorer/actions-mass/useMassActions.js +13 -19
  18. package/dist/components/Explorer/actions-mass/useMassActions.js.map +1 -1
  19. package/dist/components/Explorer/actions-primary/useCreatePrimaryAction.d.ts +1 -3
  20. package/dist/components/Explorer/actions-primary/useCreatePrimaryAction.js +1 -5
  21. package/dist/components/Explorer/actions-primary/useCreatePrimaryAction.js.map +1 -1
  22. package/dist/components/Filters/context/useGetTreeFilters.js +22 -38
  23. package/dist/components/Filters/context/useGetTreeFilters.js.map +1 -1
  24. package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js +22 -41
  25. package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js.map +1 -1
  26. package/dist/components/RecordEdition/EditRecordContent/_types.d.ts +0 -4
  27. package/dist/components/RecordEdition/EditRecordContent/_types.js.map +1 -1
  28. package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js +17 -28
  29. package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js.map +1 -1
  30. package/dist/components/RecordEdition/EditRecordPage/EditRecordPage.js +17 -29
  31. package/dist/components/RecordEdition/EditRecordPage/EditRecordPage.js.map +1 -1
  32. package/dist/components/RecordEdition/_types.d.ts +1 -1
  33. package/dist/components/RecordEdition/_types.js.map +1 -1
  34. package/dist/components/RecordEdition/hooks/useGetSubmitButtons.d.ts +1 -1
  35. package/dist/components/RecordEdition/hooks/useGetSubmitButtons.js +2 -6
  36. package/dist/components/RecordEdition/hooks/useGetSubmitButtons.js.map +1 -1
  37. package/dist/hooks/useIFrameMessenger/types.d.ts +0 -5
  38. package/dist/hooks/useIFrameMessenger/types.js.map +1 -1
  39. package/dist/locales/en/shared.json +2 -2
  40. package/dist/locales/fr/shared.json +2 -2
  41. package/package.json +4 -4
  42. package/dist/components/Explorer/_queries/useExplorerCountData.d.ts +0 -16
  43. package/dist/components/Explorer/_queries/useExplorerCountData.js +0 -26
  44. package/dist/components/Explorer/_queries/useExplorerCountData.js.map +0 -1
  45. package/dist/components/Explorer/actions-mass/ResultsCount.d.ts +0 -10
  46. package/dist/components/Explorer/actions-mass/ResultsCount.js +0 -8
  47. package/dist/components/Explorer/actions-mass/ResultsCount.js.map +0 -1
  48. package/dist/components/RecordEdition/EditRecordPage/ErrorComponent.d.ts +0 -2
  49. package/dist/components/RecordEdition/EditRecordPage/ErrorComponent.js +0 -11
  50. package/dist/components/RecordEdition/EditRecordPage/ErrorComponent.js.map +0 -1
  51. package/dist/components/RecordEdition/EditRecordPage/getInitialRecordValues.d.ts +0 -2
  52. package/dist/components/RecordEdition/EditRecordPage/getInitialRecordValues.js +0 -35
  53. package/dist/components/RecordEdition/EditRecordPage/getInitialRecordValues.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useMassActions.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useMassActions.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAiB,eAAe,EAAC,MAAM,YAAY,CAAC;AAChH,OAAO,EAAgB,WAAW,EAAE,SAAS,EAAU,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAC,qBAAqB,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAC,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC3B,SAAS,EACT,KAAK,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,EACvB,YAAY,EAAE,EAAC,OAAO,EAAE,eAAe,EAAC,EACxC,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,UAAU,GAab,EAAE,EAAE;IACD,MAAM,EAAC,CAAC,EAAC,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEpD,SAAS,CAAC,GAAG,EAAE;QACX,aAAa,CAA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C,OAAO,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAC9F,aAAa,EAAE,oBAAoB,EACnC,OAAO,EAAE,4BAA4B,YAErC,MAAC,QAAQ,IAAC,IAAI,EAAC,KAAK,aAChB,KAAC,YAAY,IACT,CAAC,EAAE,CAAC,EACJ,UAAU,EAAE,UAAU,EACtB,kBAAkB,EAAE,kBAAkB,EACtC,iBAAiB,EAAE,iBAAiB,GACtC,EACF,KAAC,eAAe,IAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAC,KAAK,GAAG,IAC1C,GACD,GACJ,CACjB,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAChC,CAAC,IAAmB,EAAE,EAAE,CACpB,QAAQ,CAAC;QACL,IAAI,EAAE,uBAAuB,CAAC,iBAAiB;QAC/C,OAAO,EAAE,IAAI;KAChB,CAAC,EACN,CAAC,QAAQ,CAAC,CACb,CAAC;IAEF,OAAO;QACH,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;QACpD,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;KACvD,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {closeKitSnackBar, KitCheckbox, KitDropDown, KitSpace, KitTypography, openKitSnackBar} from 'aristid-ds';\nimport {type Dispatch, useCallback, useEffect, useRef, useState} from 'react';\nimport {RecordFilterCondition, RecordFilterOperator} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {interleaveElement} from '_ui/_utils/interleaveElement';\nimport {type IMassActions, type MassSelection} from '../_types';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {prepareFiltersForRequest} from '_ui/components/Filters';\nimport {type IUIFiltersState} from '_ui/components/Filters/context/filtersReducer';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faCaretDown} from '@fortawesome/free-solid-svg-icons';\nimport {ResultsCount} from './ResultsCount';\n\n/**\n * Hook used to manage mass selection as the snackbar and all kind of selection (manual, all in page, all in filters)\n *\n * @param isEnabled - whether the selection is present\n * @param view - represent the current view\n * @param dispatch - method to change the current view\n * @param totalCountFiltered - number of results with the current filters\n * @param totalCountLibrary - number of total items in the library (without filters)\n * @param allVisibleKeys - list of all ids currently selected\n * @param massActions - array of all actions available on mass selection\n * @param snackbarId - id of the snackbar displayed\n */\nexport const useMassActions = ({\n isEnabled,\n store: {dispatch, view},\n filtersStore: {filters, filtersOperator},\n totalCountFiltered,\n totalCountLibrary,\n allVisibleKeys,\n massActions,\n snackbarId,\n}: {\n isEnabled: boolean;\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n filtersStore: IUIFiltersState;\n totalCountFiltered: number;\n totalCountLibrary: number;\n allVisibleKeys: string[];\n massActions: IMassActions[];\n snackbarId: string;\n}) => {\n const {t} = useSharedTranslation();\n const [isInactive, setIsInactive] = useState(false);\n\n useEffect(() => {\n setIsInactive(filters.filter(f => f.field === 'active')?.[0]?.value === 'false');\n }, [filters]);\n\n useEffect(() => {\n if (view.massSelection === MASS_SELECTION_ALL || view.massSelection.length !== 0) {\n openKitSnackBar({\n duration: 0,\n closable: true,\n snackbarId,\n toasterId: snackbarId,\n onClose: () => _setSelectedKeys([]),\n message: t('explorer.massAction.selectedItems', {\n count: view.massSelection === MASS_SELECTION_ALL ? totalCountFiltered : view.massSelection.length,\n }),\n actions: massActions.map(({label, icon, deselectAll, callback}, index) => ({\n key: index,\n label,\n icon,\n onClick: async () => {\n await callback(\n view.massSelection === MASS_SELECTION_ALL\n ? prepareFiltersForRequest(filters, filtersOperator)\n : interleaveElement(\n {operator: RecordFilterOperator.OR},\n view.massSelection.map(key => [\n {\n field: 'id',\n condition: RecordFilterCondition.EQUAL,\n value: String(key),\n },\n ]),\n ),\n view.massSelection,\n );\n if (deselectAll) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: [],\n });\n }\n },\n })),\n });\n } else {\n closeKitSnackBar(snackbarId);\n }\n }, [view.massSelection, filters, totalCountFiltered]);\n\n useEffect(() => () => closeKitSnackBar(snackbarId), []);\n\n const isOnePage = view.pageSize > totalCountFiltered;\n const hasSelectedAllAvailableItems =\n view.massSelection === MASS_SELECTION_ALL || view.massSelection.length === totalCountFiltered;\n const hasSelectedSomeItems =\n view.massSelection !== MASS_SELECTION_ALL &&\n view.massSelection.length > 0 &&\n view.massSelection.length < totalCountFiltered;\n\n const _selectAllButton = isOnePage ? (\n <KitCheckbox\n aria-checked={hasSelectedSomeItems ? 'mixed' : hasSelectedAllAvailableItems ? 'true' : 'false'}\n indeterminate={hasSelectedSomeItems}\n checked={hasSelectedAllAvailableItems}\n onChange={_ => {\n if (hasSelectedAllAvailableItems) {\n _setSelectedKeys([]);\n } else {\n _setSelectedKeys(allVisibleKeys);\n }\n }}\n >\n <ResultsCount\n t={t}\n isInactive={isInactive}\n totalCountFiltered={totalCountFiltered}\n totalCountLibrary={totalCountLibrary}\n />\n </KitCheckbox>\n ) : (\n <KitDropDown\n trigger={['click']}\n menu={{\n items: [\n hasSelectedAllAvailableItems\n ? null\n : {\n key: 'toggle_page_selection',\n label: t('explorer.massAction.toggle_selection.select_page', {count: view.pageSize}),\n onClick: () => {\n _setSelectedKeys([...new Set([...view.massSelection, ...allVisibleKeys])]);\n },\n },\n {\n key: 'toggle_all_selection',\n label: hasSelectedAllAvailableItems\n ? t('explorer.massAction.toggle_selection.deselect_all', {count: totalCountFiltered})\n : t('explorer.massAction.toggle_selection.select_all', {count: totalCountFiltered}),\n onClick: async () => {\n if (hasSelectedAllAvailableItems) {\n _setSelectedKeys([]);\n } else {\n _setSelectedKeys(MASS_SELECTION_ALL);\n }\n },\n },\n ],\n }}\n >\n <KitCheckbox\n aria-checked={hasSelectedSomeItems ? 'mixed' : hasSelectedAllAvailableItems ? 'true' : 'false'}\n indeterminate={hasSelectedSomeItems}\n checked={hasSelectedAllAvailableItems}\n >\n <KitSpace size=\"xxs\">\n <ResultsCount\n t={t}\n isInactive={isInactive}\n totalCountFiltered={totalCountFiltered}\n totalCountLibrary={totalCountLibrary}\n />\n <FontAwesomeIcon icon={faCaretDown} size=\"2xs\" />\n </KitSpace>\n </KitCheckbox>\n </KitDropDown>\n );\n\n const _setSelectedKeys = useCallback(\n (keys: MassSelection) =>\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: keys,\n }),\n [dispatch],\n );\n\n return {\n selectAllButton: isEnabled ? _selectAllButton : null,\n setSelectedKeys: isEnabled ? _setSelectedKeys : null,\n };\n};\n"]}
1
+ {"version":3,"file":"useMassActions.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useMassActions.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAC,MAAM,YAAY,CAAC;AACjG,OAAO,EAAgB,WAAW,EAAE,SAAS,EAAS,MAAM,OAAO,CAAC;AACpE,OAAO,EAAC,qBAAqB,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAC,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AAEhE,OAA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gB,CAAC,kBAAkB,CAAC,CAAC;wBACzC,CAAC;oBACL,CAAC;iBACJ;aACJ;SACJ,YAED,KAAC,WAAW,oBACM,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAC9F,aAAa,EAAE,oBAAoB,EACnC,OAAO,EAAE,4BAA4B,YAErC,MAAC,QAAQ,IAAC,IAAI,EAAC,GAAG,aACb,CAAC,CAAC,gCAAgC,EAAE,EAAC,KAAK,EAAE,UAAU,EAAC,CAAC,EACzD,KAAC,eAAe,IAAC,IAAI,EAAE,aAAa,GAAI,IACjC,GACD,GACJ,CACjB,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAChC,CAAC,IAAmB,EAAE,EAAE,CACpB,QAAQ,CAAC;QACL,IAAI,EAAE,uBAAuB,CAAC,iBAAiB;QAC/C,OAAO,EAAE,IAAI;KAChB,CAAC,EACN,CAAC,QAAQ,CAAC,CACb,CAAC;IAEF,OAAO;QACH,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;QACpD,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;KACvD,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {closeKitSnackBar, KitCheckbox, KitDropDown, KitSpace, openKitSnackBar} from 'aristid-ds';\nimport {type Dispatch, useCallback, useEffect, useRef} from 'react';\nimport {RecordFilterCondition, RecordFilterOperator} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {interleaveElement} from '_ui/_utils/interleaveElement';\nimport {type IMassActions, type MassSelection} from '../_types';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {prepareFiltersForRequest} from '_ui/components/Filters';\nimport {type IUIFiltersState} from '_ui/components/Filters/context/filtersReducer';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faChevronDown} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to manage mass selection as the snackbar and all kind of selection (manual, all in page, all in filters)\n *\n * @param isEnabled - whether the selection is present\n * @param view - represent the current view\n * @param dispatch - method to change the current view\n * @param totalCount - used for display only\n * @param allVisibleKeys - list of all ids currently selected\n * @param massActions - array of all actions available on mass selection\n * @param snackbarId - id of the snackbar displayed\n */\nexport const useMassActions = ({\n isEnabled,\n store: {dispatch, view},\n filtersStore: {filters, filtersOperator},\n totalCount,\n allVisibleKeys,\n massActions,\n snackbarId,\n}: {\n isEnabled: boolean;\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n filtersStore: IUIFiltersState;\n totalCount: number;\n allVisibleKeys: string[];\n massActions: IMassActions[];\n snackbarId: string;\n}) => {\n const {t} = useSharedTranslation();\n\n useEffect(() => {\n if (view.massSelection === MASS_SELECTION_ALL || view.massSelection.length !== 0) {\n openKitSnackBar({\n duration: 0,\n closable: true,\n snackbarId,\n toasterId: snackbarId,\n onClose: () => _setSelectedKeys([]),\n message: t('explorer.massAction.selectedItems', {\n count: view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length,\n }),\n actions: massActions.map(({label, icon, deselectAll, callback}, index) => ({\n key: index,\n label,\n icon,\n onClick: async () => {\n await callback(\n view.massSelection === MASS_SELECTION_ALL\n ? prepareFiltersForRequest(filters, filtersOperator)\n : interleaveElement(\n {operator: RecordFilterOperator.OR},\n view.massSelection.map(key => [\n {\n field: 'id',\n condition: RecordFilterCondition.EQUAL,\n value: String(key),\n },\n ]),\n ),\n view.massSelection,\n );\n if (deselectAll) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: [],\n });\n }\n },\n })),\n });\n } else {\n closeKitSnackBar(snackbarId);\n }\n }, [view.massSelection, filters, totalCount]);\n\n useEffect(() => () => closeKitSnackBar(snackbarId), []);\n\n const isOnePage = view.pageSize > totalCount;\n const hasSelectedAllAvailableItems =\n view.massSelection === MASS_SELECTION_ALL || view.massSelection.length === totalCount;\n const hasSelectedSomeItems =\n view.massSelection !== MASS_SELECTION_ALL &&\n view.massSelection.length > 0 &&\n view.massSelection.length < totalCount;\n\n const _selectAllButton = isOnePage ? (\n <KitCheckbox\n aria-checked={hasSelectedSomeItems ? 'mixed' : hasSelectedAllAvailableItems ? 'true' : 'false'}\n indeterminate={hasSelectedSomeItems}\n checked={hasSelectedAllAvailableItems}\n onChange={_ => {\n if (hasSelectedAllAvailableItems) {\n _setSelectedKeys([]);\n } else {\n _setSelectedKeys(allVisibleKeys);\n }\n }}\n >\n {t('explorer.massAction.itemsTotal', {count: totalCount})}\n </KitCheckbox>\n ) : (\n <KitDropDown\n trigger={['click']}\n menu={{\n items: [\n hasSelectedAllAvailableItems\n ? null\n : {\n key: 'toggle_page_selection',\n label: t('explorer.massAction.toggle_selection.select_page', {count: view.pageSize}),\n onClick: () => {\n _setSelectedKeys([...new Set([...view.massSelection, ...allVisibleKeys])]);\n },\n },\n {\n key: 'toggle_all_selection',\n label: hasSelectedAllAvailableItems\n ? t('explorer.massAction.toggle_selection.deselect_all', {count: totalCount})\n : t('explorer.massAction.toggle_selection.select_all', {count: totalCount}),\n onClick: async () => {\n if (hasSelectedAllAvailableItems) {\n _setSelectedKeys([]);\n } else {\n _setSelectedKeys(MASS_SELECTION_ALL);\n }\n },\n },\n ],\n }}\n >\n <KitCheckbox\n aria-checked={hasSelectedSomeItems ? 'mixed' : hasSelectedAllAvailableItems ? 'true' : 'false'}\n indeterminate={hasSelectedSomeItems}\n checked={hasSelectedAllAvailableItems}\n >\n <KitSpace size=\"s\">\n {t('explorer.massAction.itemsTotal', {count: totalCount})}\n <FontAwesomeIcon icon={faChevronDown} />\n </KitSpace>\n </KitCheckbox>\n </KitDropDown>\n );\n\n const _setSelectedKeys = useCallback(\n (keys: MassSelection) =>\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: keys,\n }),\n [dispatch],\n );\n\n return {\n selectAllButton: isEnabled ? _selectAllButton : null,\n setSelectedKeys: isEnabled ? _setSelectedKeys : null,\n };\n};\n"]}
@@ -16,9 +16,8 @@ import { type FeatureHook, type Entrypoint, type IPrimaryAction } from '../_type
16
16
  * @param totalCount - used for display purpose only
17
17
  * @param onCreate - callback to let outside world known about creating item (and linking)
18
18
  * @param refetch - method to call to refresh the list. A new item will be visible if it matches filters and sorts
19
- * @param refetchCount - method to call to refresh the count of the library. A new item will be visible if it matches filters and sorts
20
19
  */
21
- export declare const useCreatePrimaryAction: ({ isEnabled, isVisible, libraryId, entrypoint, totalCount, canCreateAndLinkValue, isMultivalue, onCreate, formId, joinLibraryContext, refetch, refetchCount, }: FeatureHook<{
20
+ export declare const useCreatePrimaryAction: ({ isEnabled, isVisible, libraryId, entrypoint, totalCount, canCreateAndLinkValue, isMultivalue, onCreate, formId, joinLibraryContext, refetch, }: FeatureHook<{
22
21
  libraryId: string;
23
22
  entrypoint: Entrypoint;
24
23
  totalCount: number;
@@ -31,7 +30,6 @@ export declare const useCreatePrimaryAction: ({ isEnabled, isVisible, libraryId,
31
30
  joinLibraryContext?: JoinLibraryContextFragment;
32
31
  formId?: string;
33
32
  refetch: () => void;
34
- refetchCount: () => void;
35
33
  }>) => {
36
34
  createPrimaryAction: IPrimaryAction;
37
35
  createModal: ReactElement<any, string | import("react").JSXElementConstructor<any>>;
@@ -28,9 +28,8 @@ import { faPlus } from '@fortawesome/free-solid-svg-icons';
28
28
  * @param totalCount - used for display purpose only
29
29
  * @param onCreate - callback to let outside world known about creating item (and linking)
30
30
  * @param refetch - method to call to refresh the list. A new item will be visible if it matches filters and sorts
31
- * @param refetchCount - method to call to refresh the count of the library. A new item will be visible if it matches filters and sorts
32
31
  */
33
- export const useCreatePrimaryAction = ({ isEnabled, isVisible, libraryId, entrypoint, totalCount, canCreateAndLinkValue, isMultivalue, onCreate, formId, joinLibraryContext, refetch, refetchCount, }) => {
32
+ export const useCreatePrimaryAction = ({ isEnabled, isVisible, libraryId, entrypoint, totalCount, canCreateAndLinkValue, isMultivalue, onCreate, formId, joinLibraryContext, refetch, }) => {
34
33
  const { t } = useSharedTranslation();
35
34
  const { lang } = useLang();
36
35
  const [isModalCreationVisible, setIsModalCreationVisible] = useState(false);
@@ -86,7 +85,6 @@ export const useCreatePrimaryAction = ({ isEnabled, isVisible, libraryId, entryp
86
85
  case LibraryBehavior.files:
87
86
  _createModal = (_jsx(UploadFiles, { libraryId: _getLibraryId(), multiple: true, onClose: () => setIsModalCreationVisible(false), onCompleted: () => {
88
87
  refetch();
89
- refetchCount();
90
88
  _notifyNewCreation(t('upload.file'));
91
89
  setIsModalCreationVisible(false);
92
90
  } }));
@@ -94,7 +92,6 @@ export const useCreatePrimaryAction = ({ isEnabled, isVisible, libraryId, entryp
94
92
  case LibraryBehavior.directories:
95
93
  _createModal = (_jsx(CreateDirectory, { libraryId: _getLibraryId(), onClose: () => setIsModalCreationVisible(false), onCompleted: () => {
96
94
  refetch();
97
- refetchCount();
98
95
  _notifyNewCreation(t('upload.folder'));
99
96
  setIsModalCreationVisible(false);
100
97
  } }));
@@ -127,7 +124,6 @@ export const useCreatePrimaryAction = ({ isEnabled, isVisible, libraryId, entryp
127
124
  await Promise.resolve(onCreate?.({ recordIdCreated: newRecord.id }));
128
125
  }
129
126
  refetch();
130
- refetchCount();
131
127
  }, submitButtons: ['create'] }));
132
128
  break;
133
129
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useCreatePrimaryAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-primary/useCreatePrimaryAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EA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E,CAAC,EAAC,eAAe,EAAE,SAAS,CAAC,EAAE,EAAC,CAAC,CAAC,CAAC;oBACvE,CAAC;oBACD,OAAO,EAAE,CAAC;oBACV,YAAY,EAAE,CAAC;gBACnB,CAAC,EACD,aAAa,EAAE,CAAC,QAAQ,CAAC,GAC3B,CACL,CAAC;YACF,MAAM;IACd,CAAC;IAED,OAAO;QACH,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI;QAC5D,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI;KAC5D,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ReactElement, useState} from 'react';\nimport {KitAlert} from 'aristid-ds';\nimport {CreateDirectory, EditRecordModal, UploadFiles} from '_ui/components';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport useSaveValueBatchMutation from '_ui/components/RecordEdition/EditRecordContent/hooks/useExecuteSaveValueBatchMutation';\nimport {type ISubmitMultipleResult} from '_ui/components/RecordEdition/EditRecordContent/_types';\nimport {\n AttributeType,\n type JoinLibraryContextFragment,\n LibraryBehavior,\n useExplorerLibraryDetailsQuery,\n} from '_ui/_gqlTypes';\nimport {type FeatureHook, type Entrypoint, type IPrimaryAction} from '../_types';\nimport {CREATE_RECORD_MODAL_CLASSNAME} from '../_constants';\nimport {SUCCESS_ALERT_DURATION} from '_ui/constants';\nimport {localizedTranslation} from '@leav/utils';\nimport {useLang} from '_ui/hooks';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faPlus} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to get the action for the `<DataView />` component.\n *\n * When the creation is done, we refresh all data even if the new record is not visible due to some filters.\n *\n * It returns also two parts: one for the call action button - one for displaying the modal required by the action.\n *\n * @param isEnabled - whether the action is present\n * @param isVisible - whether the button should be visible or not\n * @param libraryId - the library's id to add new item\n * @param entrypoint - represent the current entrypoint\n * @param totalCount - used for display purpose only\n * @param onCreate - callback to let outside world known about creating item (and linking)\n * @param refetch - method to call to refresh the list. A new item will be visible if it matches filters and sorts\n * @param refetchCount - method to call to refresh the count of the library. A new item will be visible if it matches filters and sorts\n */\nexport const useCreatePrimaryAction = ({\n isEnabled,\n isVisible,\n libraryId,\n entrypoint,\n totalCount,\n canCreateAndLinkValue,\n isMultivalue,\n onCreate,\n formId,\n joinLibraryContext,\n refetch,\n refetchCount,\n}: FeatureHook<{\n libraryId: string;\n entrypoint: Entrypoint;\n totalCount: number;\n canCreateAndLinkValue: boolean;\n isMultivalue: boolean;\n onCreate?: ({\n recordIdCreated,\n saveValuesResultOnLink,\n }: {\n recordIdCreated: string;\n saveValuesResultOnLink?: ISubmitMultipleResult;\n }) => void;\n joinLibraryContext?: JoinLibraryContextFragment;\n formId?: string;\n refetch: () => void;\n refetchCount: () => void;\n}>) => {\n const {t} = useSharedTranslation();\n const {lang} = useLang();\n\n const [isModalCreationVisible, setIsModalCreationVisible] = useState(false);\n const {saveValues} = useSaveValueBatchMutation();\n\n const _getLibraryId = () =>\n (joinLibraryContext?.mandatoryAttribute &&\n 'linked_library' in joinLibraryContext.mandatoryAttribute &&\n joinLibraryContext.mandatoryAttribute.linked_library?.id) ||\n libraryId;\n\n const {data, loading, error} = useExplorerLibraryDetailsQuery({\n variables: {libraryId: _getLibraryId()},\n skip: !isEnabled,\n });\n\n const hasCreateRecordPermission = data?.libraries?.list[0]?.permissions?.create_record ?? false;\n\n if (error || loading || !isVisible || !hasCreateRecordPermission) {\n return {createPrimaryAction: null, createModal: null};\n }\n\n let canCreateRecord;\n if (joinLibraryContext?.mandatoryAttribute?.type === AttributeType.tree) {\n canCreateRecord = false;\n } else if (entrypoint.type === 'library') {\n canCreateRecord = true;\n } else {\n canCreateRecord = canCreateAndLinkValue && (isMultivalue || totalCount === 0);\n }\n\n const _createPrimaryAction: IPrimaryAction = {\n callback: () => {\n setIsModalCreationVisible(true);\n },\n icon: <FontAwesomeIcon icon={faPlus} />,\n disabled: !canCreateRecord,\n label: t('explorer.create-one'),\n };\n\n const _notifyNewCreation = (label?: string | null) => {\n KitAlert.success({\n showIcon: true,\n duration: SUCCESS_ALERT_DURATION,\n message: t('items_list.created_in_success.message', {\n libName:\n localizedTranslation(data?.libraries?.list[0]?.label, lang) ||\n t('items_list.created_in_success.item'),\n }),\n description: t('items_list.created_in_success.description', {\n libName:\n localizedTranslation(data?.libraries?.list[0]?.label, lang) ||\n t('items_list.created_in_success.item'),\n itemName: label || t('items_list.created_in_success.item'),\n }),\n closable: true,\n });\n };\n\n let _createModal: ReactElement | null = null;\n switch (data?.libraries?.list[0]?.behavior) {\n case LibraryBehavior.files:\n _createModal = (\n <UploadFiles\n libraryId={_getLibraryId()}\n multiple\n onClose={() => setIsModalCreationVisible(false)}\n onCompleted={() => {\n refetch();\n refetchCount();\n _notifyNewCreation(t('upload.file'));\n setIsModalCreationVisible(false);\n }}\n />\n );\n break;\n case LibraryBehavior.directories:\n _createModal = (\n <CreateDirectory\n libraryId={_getLibraryId()}\n onClose={() => setIsModalCreationVisible(false)}\n onCompleted={() => {\n refetch();\n refetchCount();\n _notifyNewCreation(t('upload.folder'));\n setIsModalCreationVisible(false);\n }}\n />\n );\n break;\n case LibraryBehavior.standard:\n case LibraryBehavior.join:\n _createModal = (\n <EditRecordModal\n className={CREATE_RECORD_MODAL_CLASSNAME}\n open\n record={null}\n library={_getLibraryId()}\n creationFormId={formId}\n onClose={() => {\n setIsModalCreationVisible(false);\n }}\n onCreate={async newRecord => {\n _notifyNewCreation(newRecord.label);\n setIsModalCreationVisible(false);\n if (entrypoint.type === 'link') {\n await saveValues(\n {\n id: entrypoint.parentRecordId,\n library: {\n id: entrypoint.parentLibraryId,\n },\n },\n [\n {\n attribute: entrypoint.linkAttributeId,\n idValue: null,\n value: newRecord.id,\n },\n ],\n ).then(async saveValuesResult =>\n onCreate?.({\n recordIdCreated: newRecord.id,\n saveValuesResultOnLink: saveValuesResult,\n }),\n );\n } else {\n await Promise.resolve(onCreate?.({recordIdCreated: newRecord.id}));\n }\n refetch();\n refetchCount();\n }}\n submitButtons={['create']}\n />\n );\n break;\n }\n\n return {\n createPrimaryAction: isEnabled ? _createPrimaryAction : null,\n createModal: isModalCreationVisible ? _createModal : null,\n };\n};\n"]}
1
+ {"version":3,"file":"useCreatePrimaryAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-primary/useCreatePrimaryAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAoB,QAAQ,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,yBAAyB,MAAM,uFAAuF,CAAC;AAE9H,OAAO,EACH,aAAa,EAEb,eAAe,EACf,8BAA8B,GACjC,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,6BAA6B,EAAC,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAEzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EACnC,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,qBAAqB,EAC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AC,eAAe;6BACjC;yBACJ,EACD;4BACI;gCACI,SAAS,EAAE,UAAU,CAAC,eAAe;gCACrC,OAAO,EAAE,IAAI;gCACb,KAAK,EAAE,SAAS,CAAC,EAAE;6BACtB;yBACJ,CACJ,CAAC,IAAI,CAAC,KAAK,EAAC,gBAAgB,EAAC,EAAE,CAC5B,QAAQ,EAAE,CAAC;4BACP,eAAe,EAAE,SAAS,CAAC,EAAE;4BAC7B,sBAAsB,EAAE,gBAAgB;yBAC3C,CAAC,CACL,CAAC;oBACN,CAAC;yBAAM,CAAC;wBACJ,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAC,eAAe,EAAE,SAAS,CAAC,EAAE,EAAC,CAAC,CAAC,CAAC;oBACvE,CAAC;oBACD,OAAO,EAAE,CAAC;gBACd,CAAC,EACD,aAAa,EAAE,CAAC,QAAQ,CAAC,GAC3B,CACL,CAAC;YACF,MAAM;IACd,CAAC;IAED,OAAO;QACH,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI;QAC5D,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI;KAC5D,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ReactElement, useState} from 'react';\nimport {KitAlert} from 'aristid-ds';\nimport {CreateDirectory, EditRecordModal, UploadFiles} from '_ui/components';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport useSaveValueBatchMutation from '_ui/components/RecordEdition/EditRecordContent/hooks/useExecuteSaveValueBatchMutation';\nimport {type ISubmitMultipleResult} from '_ui/components/RecordEdition/EditRecordContent/_types';\nimport {\n AttributeType,\n type JoinLibraryContextFragment,\n LibraryBehavior,\n useExplorerLibraryDetailsQuery,\n} from '_ui/_gqlTypes';\nimport {type FeatureHook, type Entrypoint, type IPrimaryAction} from '../_types';\nimport {CREATE_RECORD_MODAL_CLASSNAME} from '../_constants';\nimport {SUCCESS_ALERT_DURATION} from '_ui/constants';\nimport {localizedTranslation} from '@leav/utils';\nimport {useLang} from '_ui/hooks';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faPlus} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to get the action for the `<DataView />` component.\n *\n * When the creation is done, we refresh all data even if the new record is not visible due to some filters.\n *\n * It returns also two parts: one for the call action button - one for displaying the modal required by the action.\n *\n * @param isEnabled - whether the action is present\n * @param isVisible - whether the button should be visible or not\n * @param libraryId - the library's id to add new item\n * @param entrypoint - represent the current entrypoint\n * @param totalCount - used for display purpose only\n * @param onCreate - callback to let outside world known about creating item (and linking)\n * @param refetch - method to call to refresh the list. A new item will be visible if it matches filters and sorts\n */\nexport const useCreatePrimaryAction = ({\n isEnabled,\n isVisible,\n libraryId,\n entrypoint,\n totalCount,\n canCreateAndLinkValue,\n isMultivalue,\n onCreate,\n formId,\n joinLibraryContext,\n refetch,\n}: FeatureHook<{\n libraryId: string;\n entrypoint: Entrypoint;\n totalCount: number;\n canCreateAndLinkValue: boolean;\n isMultivalue: boolean;\n onCreate?: ({\n recordIdCreated,\n saveValuesResultOnLink,\n }: {\n recordIdCreated: string;\n saveValuesResultOnLink?: ISubmitMultipleResult;\n }) => void;\n joinLibraryContext?: JoinLibraryContextFragment;\n formId?: string;\n refetch: () => void;\n}>) => {\n const {t} = useSharedTranslation();\n const {lang} = useLang();\n\n const [isModalCreationVisible, setIsModalCreationVisible] = useState(false);\n const {saveValues} = useSaveValueBatchMutation();\n\n const _getLibraryId = () =>\n (joinLibraryContext?.mandatoryAttribute &&\n 'linked_library' in joinLibraryContext.mandatoryAttribute &&\n joinLibraryContext.mandatoryAttribute.linked_library?.id) ||\n libraryId;\n\n const {data, loading, error} = useExplorerLibraryDetailsQuery({\n variables: {libraryId: _getLibraryId()},\n skip: !isEnabled,\n });\n\n const hasCreateRecordPermission = data?.libraries?.list[0]?.permissions?.create_record ?? false;\n\n if (error || loading || !isVisible || !hasCreateRecordPermission) {\n return {createPrimaryAction: null, createModal: null};\n }\n\n let canCreateRecord;\n if (joinLibraryContext?.mandatoryAttribute?.type === AttributeType.tree) {\n canCreateRecord = false;\n } else if (entrypoint.type === 'library') {\n canCreateRecord = true;\n } else {\n canCreateRecord = canCreateAndLinkValue && (isMultivalue || totalCount === 0);\n }\n\n const _createPrimaryAction: IPrimaryAction = {\n callback: () => {\n setIsModalCreationVisible(true);\n },\n icon: <FontAwesomeIcon icon={faPlus} />,\n disabled: !canCreateRecord,\n label: t('explorer.create-one'),\n };\n\n const _notifyNewCreation = (label?: string | null) => {\n KitAlert.success({\n showIcon: true,\n duration: SUCCESS_ALERT_DURATION,\n message: t('items_list.created_in_success.message', {\n libName:\n localizedTranslation(data?.libraries?.list[0]?.label, lang) ||\n t('items_list.created_in_success.item'),\n }),\n description: t('items_list.created_in_success.description', {\n libName:\n localizedTranslation(data?.libraries?.list[0]?.label, lang) ||\n t('items_list.created_in_success.item'),\n itemName: label || t('items_list.created_in_success.item'),\n }),\n closable: true,\n });\n };\n\n let _createModal: ReactElement | null = null;\n switch (data?.libraries?.list[0]?.behavior) {\n case LibraryBehavior.files:\n _createModal = (\n <UploadFiles\n libraryId={_getLibraryId()}\n multiple\n onClose={() => setIsModalCreationVisible(false)}\n onCompleted={() => {\n refetch();\n _notifyNewCreation(t('upload.file'));\n setIsModalCreationVisible(false);\n }}\n />\n );\n break;\n case LibraryBehavior.directories:\n _createModal = (\n <CreateDirectory\n libraryId={_getLibraryId()}\n onClose={() => setIsModalCreationVisible(false)}\n onCompleted={() => {\n refetch();\n _notifyNewCreation(t('upload.folder'));\n setIsModalCreationVisible(false);\n }}\n />\n );\n break;\n case LibraryBehavior.standard:\n case LibraryBehavior.join:\n _createModal = (\n <EditRecordModal\n className={CREATE_RECORD_MODAL_CLASSNAME}\n open\n record={null}\n library={_getLibraryId()}\n creationFormId={formId}\n onClose={() => {\n setIsModalCreationVisible(false);\n }}\n onCreate={async newRecord => {\n _notifyNewCreation(newRecord.label);\n setIsModalCreationVisible(false);\n if (entrypoint.type === 'link') {\n await saveValues(\n {\n id: entrypoint.parentRecordId,\n library: {\n id: entrypoint.parentLibraryId,\n },\n },\n [\n {\n attribute: entrypoint.linkAttributeId,\n idValue: null,\n value: newRecord.id,\n },\n ],\n ).then(async saveValuesResult =>\n onCreate?.({\n recordIdCreated: newRecord.id,\n saveValuesResultOnLink: saveValuesResult,\n }),\n );\n } else {\n await Promise.resolve(onCreate?.({recordIdCreated: newRecord.id}));\n }\n refetch();\n }}\n submitButtons={['create']}\n />\n );\n break;\n }\n\n return {\n createPrimaryAction: isEnabled ? _createPrimaryAction : null,\n createModal: isModalCreationVisible ? _createModal : null,\n };\n};\n"]}
@@ -1,13 +1,27 @@
1
1
  // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
2
  // This file is released under LGPL V3
3
3
  // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
- import { useGetLibraryByIdQuery, useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery, } from '../../../_gqlTypes';
4
+ import { useLazyQuery } from '@apollo/client';
5
+ import { useGetLibraryByIdQuery, } from '../../../_gqlTypes';
6
+ import { getTreeContentQuery } from '../../../_queries/trees/getTreeContentQuery';
5
7
  import { useEffect, useState } from 'react';
6
- import { defaultPaginationPageSize } from '../../../constants';
8
+ const _flattenNodes = (nodes) => nodes.flatMap(node => [
9
+ ...(node.accessRecordByDefaultPermission
10
+ ? [
11
+ {
12
+ nodeId: node.id,
13
+ libraryId: node.record.whoAmI.library.id,
14
+ value: node.record.id,
15
+ label: node.record.whoAmI.label,
16
+ },
17
+ ]
18
+ : []),
19
+ ..._flattenNodes(node.children ?? []),
20
+ ]);
7
21
  export const useGetTreeFilters = ({ libraryId, skip }) => {
8
22
  const [treeFilters, setTreeFilters] = useState({});
9
23
  const [treeFiltersLoading, setTreeFiltersLoading] = useState(true);
10
- const [loadTreeContent] = useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery();
24
+ const [loadTreeContent] = useLazyQuery(getTreeContentQuery());
11
25
  const { data: libraryData, loading: libraryLoading } = useGetLibraryByIdQuery({
12
26
  variables: {
13
27
  id: libraryId,
@@ -23,50 +37,20 @@ export const useGetTreeFilters = ({ libraryId, skip }) => {
23
37
  attributeId: attribute.id,
24
38
  treeId: libraryData?.libraries.list[0]?.attributes.find(tree => tree.id === attribute.id)?.linked_tree?.id,
25
39
  })) || [];
26
- const _fetchChildrenPage = async (treeId, attributeId, parentNodeKey, offset) => {
40
+ const treeResponse = await Promise.all(treeAttributesWithExtendedPermissions.map(async (attribute) => {
27
41
  const { data } = await loadTreeContent({
28
42
  variables: {
29
- treeId,
30
- node: parentNodeKey,
31
- pagination: { offset, limit: defaultPaginationPageSize },
43
+ treeId: attribute.treeId,
32
44
  accessRecordByDefaultPermission: {
33
- attributeId,
45
+ attributeId: attribute.attributeId,
34
46
  libraryId,
35
47
  },
36
48
  },
37
49
  });
38
- const { list, totalCount } = data?.treeNodeChildren ?? { list: [], totalCount: 0 };
39
- const records = [];
40
- for (const node of list) {
41
- if (node.accessRecordByDefaultPermission) {
42
- records.push({
43
- nodeId: node.id,
44
- libraryId: node.record.whoAmI.library.id,
45
- value: node.record.id,
46
- label: node.record.whoAmI.label,
47
- });
48
- }
49
- if (node.childrenCount > 0) {
50
- const childrenRecords = await _fetchAllChildren(treeId, attributeId, node.id);
51
- records.push(...childrenRecords);
52
- }
53
- }
54
- return { records, totalCount };
55
- };
56
- const _fetchAllChildren = async (treeId, attributeId, parentNodeKey, offset = 0, accumulated = []) => {
57
- const { records, totalCount } = await _fetchChildrenPage(treeId, attributeId, parentNodeKey, offset);
58
- const allRecords = [...accumulated, ...records];
59
- const nextOffset = offset + defaultPaginationPageSize;
60
- if (nextOffset < totalCount) {
61
- return _fetchAllChildren(treeId, attributeId, parentNodeKey, nextOffset, allRecords);
62
- }
63
- return allRecords;
64
- };
65
- const treeResponse = await Promise.all(treeAttributesWithExtendedPermissions.map(async (attribute) => {
66
- const recordIds = await _fetchAllChildren(attribute.treeId, attribute.attributeId, null);
50
+ const flatNodes = _flattenNodes(data?.treeContent ?? []);
67
51
  return {
68
52
  attributeId: attribute.attributeId,
69
- recordIds,
53
+ recordIds: flatNodes,
70
54
  };
71
55
  }));
72
56
  const attributeRecords = treeResponse.reduce((acc, item) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useGetTreeFilters.js","sourceRoot":"","sources":["../../../../src/components/Filters/context/useGetTreeFilters.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAEH,sBAAsB,EACtB,iEAAiE,GACpE,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,yBAAyB,EAAC,MAAM,eAAe,CAAC;AAaxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAC,SAAS,EAAE,IAAI,EAAqC,EAAE,EAAE;IACvF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAe,EAAE,CAAC,CAAC;IACjE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnE,MAAM,CAAC,eAAe,CAAC,GAAG,iEAAiE,EAAE,CAAC;IAE9F,MAAM,EAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAC,GAAG,sBAAsB,CAAC;QACxE,SAAS,EAAE;YACP,EAAE,EAAE,SAAS;SAChB;QACD,IAAI,EAAE,IAAI,IAAI,CAAC,SAAS;KAC3B,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,IAAI,IAAI,CA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CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBAEzF,OAAO;oBACH,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,SAAS;iBACZ,CAAC;YACN,CAAC,CAAC,CACL,CAAC;YAEF,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC5B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;gBAC3C,CAAC;gBACD,OAAO,GAAG,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,cAAc,CAAC,gBAAgB,CAAC,CAAC;YACjC,qBAAqB,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC;QAEF,gBAAgB,EAAE,CAAC;IACvB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;IAEpE,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,kBAAkB;KAC9B,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {\n type TreeAttributeDetailsFragment,\n useGetLibraryByIdQuery,\n useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery,\n} from '_ui/_gqlTypes';\nimport {useEffect, useState} from 'react';\nimport {defaultPaginationPageSize} from '_ui/constants';\n\ninterface ITreeNode {\n nodeId: string;\n libraryId: string;\n value: string;\n label: string;\n}\n\nexport interface ITreeFilters {\n [x: string]: ITreeNode[];\n}\n\nexport const useGetTreeFilters = ({libraryId, skip}: {libraryId: string; skip: boolean}) => {\n const [treeFilters, setTreeFilters] = useState<ITreeFilters>({});\n const [treeFiltersLoading, setTreeFiltersLoading] = useState(true);\n const [loadTreeContent] = useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery();\n\n const {data: libraryData, loading: libraryLoading} = useGetLibraryByIdQuery({\n variables: {\n id: libraryId,\n },\n skip: skip || !libraryId,\n });\n\n useEffect(() => {\n if (skip || !libraryId || libraryLoading || !libraryData) {\n return;\n }\n\n const fetchTreeFilters = async () => {\n const treeAttributesWithExtendedPermissions: Array<{attributeId: string; treeId: string}> =\n libraryData?.libraries.list[0]?.permissions_conf?.permissionTreeAttributes.map(attribute => ({\n attributeId: attribute.id,\n treeId: (\n libraryData?.libraries.list[0]?.attributes.find(\n tree => tree.id === attribute.id,\n ) as TreeAttributeDetailsFragment\n )?.linked_tree?.id,\n })) || [];\n\n const _fetchChildrenPage = async (\n treeId: string,\n attributeId: string,\n parentNodeKey: string | null,\n offset: number,\n ) => {\n const {data} = await loadTreeContent({\n variables: {\n treeId,\n node: parentNodeKey,\n pagination: {offset, limit: defaultPaginationPageSize},\n accessRecordByDefaultPermission: {\n attributeId,\n libraryId,\n },\n },\n });\n\n const {list, totalCount} = data?.treeNodeChildren ?? {list: [], totalCount: 0};\n\n const records: ITreeNode[] = [];\n\n for (const node of list) {\n if (node.accessRecordByDefaultPermission) {\n records.push({\n nodeId: node.id,\n libraryId: node.record.whoAmI.library.id,\n value: node.record.id,\n label: node.record.whoAmI.label,\n });\n }\n\n if (node.childrenCount > 0) {\n const childrenRecords = await _fetchAllChildren(treeId, attributeId, node.id);\n records.push(...childrenRecords);\n }\n }\n\n return {records, totalCount};\n };\n\n const _fetchAllChildren = async (\n treeId: string,\n attributeId: string,\n parentNodeKey: string | null,\n offset = 0,\n accumulated: ITreeNode[] = [],\n ): Promise<ITreeNode[]> => {\n const {records, totalCount} = await _fetchChildrenPage(treeId, attributeId, parentNodeKey, offset);\n const allRecords = [...accumulated, ...records];\n\n const nextOffset = offset + defaultPaginationPageSize;\n if (nextOffset < totalCount) {\n return _fetchAllChildren(treeId, attributeId, parentNodeKey, nextOffset, allRecords);\n }\n\n return allRecords;\n };\n\n const treeResponse = await Promise.all(\n treeAttributesWithExtendedPermissions.map(async attribute => {\n const recordIds = await _fetchAllChildren(attribute.treeId, attribute.attributeId, null);\n\n return {\n attributeId: attribute.attributeId,\n recordIds,\n };\n }),\n );\n\n const attributeRecords = treeResponse.reduce((acc, item) => {\n if (item.recordIds.length > 0) {\n acc[item.attributeId] = item.recordIds;\n }\n return acc;\n }, {});\n\n setTreeFilters(attributeRecords);\n setTreeFiltersLoading(false);\n };\n\n fetchTreeFilters();\n }, [skip, libraryId, libraryLoading, libraryData, loadTreeContent]);\n\n return {\n data: treeFilters,\n loading: treeFiltersLoading,\n };\n};\n"]}
1
+ {"version":3,"file":"useGetTreeFilters.js","sourceRoot":"","sources":["../../../../src/components/Filters/context/useGetTreeFilters.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAIH,sBAAsB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,mBAAmB,EAAC,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAa1C,MAAM,aAAa,GAAG,CAClB,KAIC,EACU,EAAE,CACb,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,GAAG,CAAC,IAAI,CAAC,+BAA+B;QACpC,CAAC,CAAC;YACI;gBACI,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;gBACxC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;gBACrB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;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YAEd,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,qCAAqC,CAAC,GAAG,CAAC,KAAK,EAAC,SAAS,EAAC,EAAE;gBACxD,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,eAAe,CAAC;oBACjC,SAAS,EAAE;wBACP,MAAM,EAAE,SAAS,CAAC,MAAM;wBACxB,+BAA+B,EAAE;4BAC7B,WAAW,EAAE,SAAS,CAAC,WAAW;4BAClC,SAAS;yBACZ;qBACJ;iBACJ,CAAC,CAAC;gBAEH,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;gBAEzD,OAAO;oBACH,WAAW,EAAE,SAAS,CAAC,WAAW;oBAClC,SAAS,EAAE,SAAS;iBACvB,CAAC;YACN,CAAC,CAAC,CACL,CAAC;YAEF,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC5B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;gBAC3C,CAAC;gBACD,OAAO,GAAG,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,cAAc,CAAC,gBAAgB,CAAC,CAAC;YACjC,qBAAqB,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC;QAEF,gBAAgB,EAAE,CAAC;IACvB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;IAEpE,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,kBAAkB;KAC9B,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useLazyQuery} from '@apollo/client';\nimport {\n type GetTreeContentQueryQuery,\n type GetTreeContentQueryQueryVariables,\n type TreeAttributeDetailsFragment,\n useGetLibraryByIdQuery,\n} from '_ui/_gqlTypes';\nimport {getTreeContentQuery} from '_ui/_queries/trees/getTreeContentQuery';\nimport {useEffect, useState} from 'react';\n\ninterface ITreeNode {\n nodeId: string;\n libraryId: string;\n value: string;\n label: string;\n}\n\nexport interface ITreeFilters {\n [x: string]: ITreeNode[];\n}\n\nconst _flattenNodes = (\n nodes: Array<\n GetTreeContentQueryQuery['treeContent'][number] & {\n children?: Array<GetTreeContentQueryQuery['treeContent'][number]>;\n }\n >,\n): ITreeNode[] =>\n nodes.flatMap(node => [\n ...(node.accessRecordByDefaultPermission\n ? [\n {\n nodeId: node.id,\n libraryId: node.record.whoAmI.library.id,\n value: node.record.id,\n label: node.record.whoAmI.label,\n },\n ]\n : []),\n ..._flattenNodes(node.children ?? []),\n ]);\n\nexport const useGetTreeFilters = ({libraryId, skip}: {libraryId: string; skip: boolean}) => {\n const [treeFilters, setTreeFilters] = useState<ITreeFilters>({});\n const [treeFiltersLoading, setTreeFiltersLoading] = useState(true);\n const [loadTreeContent] = useLazyQuery<GetTreeContentQueryQuery, GetTreeContentQueryQueryVariables>(\n getTreeContentQuery(),\n );\n\n const {data: libraryData, loading: libraryLoading} = useGetLibraryByIdQuery({\n variables: {\n id: libraryId,\n },\n skip: skip || !libraryId,\n });\n\n useEffect(() => {\n if (skip || !libraryId || libraryLoading || !libraryData) {\n return;\n }\n\n const fetchTreeFilters = async () => {\n const treeAttributesWithExtendedPermissions: Array<{attributeId: string; treeId: string}> =\n libraryData?.libraries.list[0]?.permissions_conf?.permissionTreeAttributes.map(attribute => ({\n attributeId: attribute.id,\n treeId: (\n libraryData?.libraries.list[0]?.attributes.find(\n tree => tree.id === attribute.id,\n ) as TreeAttributeDetailsFragment\n )?.linked_tree?.id,\n })) || [];\n\n const treeResponse = await Promise.all(\n treeAttributesWithExtendedPermissions.map(async attribute => {\n const {data} = await loadTreeContent({\n variables: {\n treeId: attribute.treeId,\n accessRecordByDefaultPermission: {\n attributeId: attribute.attributeId,\n libraryId,\n },\n },\n });\n\n const flatNodes = _flattenNodes(data?.treeContent ?? []);\n\n return {\n attributeId: attribute.attributeId,\n recordIds: flatNodes,\n };\n }),\n );\n\n const attributeRecords = treeResponse.reduce((acc, item) => {\n if (item.recordIds.length > 0) {\n acc[item.attributeId] = item.recordIds;\n }\n return acc;\n }, {});\n\n setTreeFilters(attributeRecords);\n setTreeFiltersLoading(false);\n };\n\n fetchTreeFilters();\n }, [skip, libraryId, libraryLoading, libraryData, loadTreeContent]);\n\n return {\n data: treeFilters,\n loading: treeFiltersLoading,\n };\n};\n"]}
@@ -1,50 +1,23 @@
1
1
  // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
2
  // This file is released under LGPL V3
3
3
  // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
+ import { useLazyQuery } from '@apollo/client';
4
5
  import { useEffect, useState } from 'react';
5
- import { useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery } from '../../../../../_gqlTypes';
6
- import { defaultPaginationPageSize } from '../../../../../constants';
6
+ import { getTreeContentQuery } from '../../../../../_queries/trees/getTreeContentQuery';
7
+ const _toTreeNode = (node) => ({
8
+ title: node.record.whoAmI.label ?? node.record.whoAmI.id,
9
+ id: node.id,
10
+ key: node.id,
11
+ children: (node.children ?? []).map(_toTreeNode),
12
+ accessRecordByDefaultPermission: node.accessRecordByDefaultPermission ?? undefined,
13
+ libraryId: node.record.whoAmI.library.id,
14
+ recordId: node.record.id,
15
+ });
7
16
  export const useGetTreeData = ({ treeId, attributeId, libraryId }) => {
8
- const [loadTreeContent] = useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery();
17
+ const [loadTreeContent] = useLazyQuery(getTreeContentQuery());
9
18
  const [treeData, setTreeData] = useState([]);
10
19
  const [isLoading, setIsLoading] = useState(true);
11
20
  const [error, setError] = useState(null);
12
- const _fetchChildrenPage = async (parentNodeKey, offset) => {
13
- const { data } = await loadTreeContent({
14
- variables: {
15
- treeId,
16
- node: parentNodeKey,
17
- pagination: { offset, limit: defaultPaginationPageSize },
18
- accessRecordByDefaultPermission: {
19
- attributeId,
20
- libraryId,
21
- },
22
- },
23
- });
24
- const { list, totalCount } = data?.treeNodeChildren ?? { list: [], totalCount: 0 };
25
- const nodes = await Promise.all(list.map(async (node) => {
26
- const children = node.childrenCount ? await _fetchAllChildren(node.id) : [];
27
- return {
28
- title: node.record.whoAmI.label || node.record.whoAmI.id,
29
- id: node.id,
30
- key: node.id,
31
- children,
32
- accessRecordByDefaultPermission: node.accessRecordByDefaultPermission,
33
- libraryId: node.record.whoAmI.library.id,
34
- recordId: node.record.id,
35
- };
36
- }));
37
- return { nodes, totalCount };
38
- };
39
- const _fetchAllChildren = async (parentNodeKey, offset = 0, accumulated = []) => {
40
- const { nodes, totalCount } = await _fetchChildrenPage(parentNodeKey, offset);
41
- const allNodes = [...accumulated, ...nodes];
42
- const nextOffset = offset + defaultPaginationPageSize;
43
- if (nextOffset < totalCount) {
44
- return _fetchAllChildren(parentNodeKey, nextOffset, allNodes);
45
- }
46
- return allNodes;
47
- };
48
21
  useEffect(() => {
49
22
  if (!treeId) {
50
23
  setTreeData([]);
@@ -55,8 +28,16 @@ export const useGetTreeData = ({ treeId, attributeId, libraryId }) => {
55
28
  setIsLoading(true);
56
29
  setError(null);
57
30
  try {
58
- const children = await _fetchAllChildren(null);
59
- setTreeData(children);
31
+ const { data } = await loadTreeContent({
32
+ variables: {
33
+ treeId,
34
+ accessRecordByDefaultPermission: {
35
+ attributeId,
36
+ libraryId,
37
+ },
38
+ },
39
+ });
40
+ setTreeData((data?.treeContent ?? []).map(node => _toTreeNode(node)));
60
41
  }
61
42
  catch (err) {
62
43
  setError(err instanceof Error ? err : new Error('Failed to load tree'));
@@ -1 +1 @@
1
- {"version":3,"file":"useGetTreeData.js","sourceRoot":"","sources":["../../../../../../src/components/Filters/filter-items/filter-type/tree/useGetTreeData.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,iEAAiE,EAAC,MAAM,eAAe,CAAC;AAChG,OAAO,EAAC,yBAAyB,EAAC,MAAM,eAAe,CAAC;AAkBxD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAuB,EAAE,EAAE;IACrF,MAAM,CAAC,eAAe,CAAC,GAAG,iEAAiE,EAAE,CAAC;IAC9F,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAc,EAAE,CAAC,CAAC;IAC1D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,kBAAkB,GAAG,KAAK,EAAE,aAA4B,EAAE,MAAc,EAAE,EAAE;QAC9E,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,eAAe,CAAC;YACjC,SAAS,EAAE;gBACP,MAAM;gBACN,IAAI,EAAE,aAAa;gBACnB,UAAU,EAAE,EAAC,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAC;gBACtD,+BAA+B,EAAE;oBAC7B,WAAW;oBACX,SAAS;iBACZ;aACJ;SACJ,CAAC,CAAC;QAEH,MAAM,EAAC,IAAI,EAAE,UAAU,EAAC,GAAG,IAAI,EAAE,gBAAgB,IAAI,EAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAC,CAAC;QAE/E,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3B,IAAI,CAA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CAAC,EAAE,CAAC,CAAC;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,CAAC;YACf,IAAI,CAAC;gBACD,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBAC/C,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC;YAC5E,CAAC;oBAAS,CAAC;gBACP,YAAY,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACL,CAAC,CAAC;QAEF,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAErC,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useEffect, useState} from 'react';\nimport {useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery} from '_ui/_gqlTypes';\nimport {defaultPaginationPageSize} from '_ui/constants';\n\nexport interface ITreeNode {\n title: string;\n id: string;\n key: string;\n children: ITreeNode[];\n accessRecordByDefaultPermission?: boolean;\n libraryId: string;\n recordId: string;\n}\n\ninterface IUseGetTreeDataProps {\n treeId: string;\n attributeId: string;\n libraryId: string;\n}\n\nexport const useGetTreeData = ({treeId, attributeId, libraryId}: IUseGetTreeDataProps) => {\n const [loadTreeContent] = useGetTreeNodeChildrenWithAccessByDefaultPermissionQueryLazyQuery();\n const [treeData, setTreeData] = useState<ITreeNode[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const _fetchChildrenPage = async (parentNodeKey: string | null, offset: number) => {\n const {data} = await loadTreeContent({\n variables: {\n treeId,\n node: parentNodeKey,\n pagination: {offset, limit: defaultPaginationPageSize},\n accessRecordByDefaultPermission: {\n attributeId,\n libraryId,\n },\n },\n });\n\n const {list, totalCount} = data?.treeNodeChildren ?? {list: [], totalCount: 0};\n\n const nodes = await Promise.all(\n list.map(async node => {\n const children = node.childrenCount ? await _fetchAllChildren(node.id) : [];\n\n return {\n title: node.record.whoAmI.label || node.record.whoAmI.id,\n id: node.id,\n key: node.id,\n children,\n accessRecordByDefaultPermission: node.accessRecordByDefaultPermission,\n libraryId: node.record.whoAmI.library.id,\n recordId: node.record.id,\n };\n }),\n );\n\n return {nodes, totalCount};\n };\n\n const _fetchAllChildren = async (\n parentNodeKey: string | null,\n offset = 0,\n accumulated: ITreeNode[] = [],\n ): Promise<ITreeNode[]> => {\n const {nodes, totalCount} = await _fetchChildrenPage(parentNodeKey, offset);\n const allNodes = [...accumulated, ...nodes];\n\n const nextOffset = offset + defaultPaginationPageSize;\n if (nextOffset < totalCount) {\n return _fetchAllChildren(parentNodeKey, nextOffset, allNodes);\n }\n\n return allNodes;\n };\n\n useEffect(() => {\n if (!treeId) {\n setTreeData([]);\n setIsLoading(false);\n return;\n }\n\n const loadTree = async () => {\n setIsLoading(true);\n setError(null);\n try {\n const children = await _fetchAllChildren(null);\n setTreeData(children);\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to load tree'));\n } finally {\n setIsLoading(false);\n }\n };\n\n loadTree();\n }, [treeId, attributeId, libraryId]);\n\n return {treeData, isLoading, error};\n};\n"]}
1
+ {"version":3,"file":"useGetTreeData.js","sourceRoot":"","sources":["../../../../../../src/components/Filters/filter-items/filter-type/tree/useGetTreeData.ts"],"names":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WAAW,CAAC,EAAE,CAAC,CAAC;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YACxB,YAAY,CAAC,IAAI,CAAC,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,CAAC;YACf,IAAI,CAAC;gBACD,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,eAAe,CAAC;oBACjC,SAAS,EAAE;wBACP,MAAM;wBACN,+BAA+B,EAAE;4BAC7B,WAAW;4BACX,SAAS;yBACZ;qBACJ;iBACJ,CAAC,CAAC;gBAEH,WAAW,CAAC,CAAC,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1E,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC;YAC5E,CAAC;oBAAS,CAAC;gBACP,YAAY,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACL,CAAC,CAAC;QAEF,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAErC,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useLazyQuery} from '@apollo/client';\nimport {useEffect, useState} from 'react';\nimport {type GetTreeContentQueryQuery, type GetTreeContentQueryQueryVariables} from '_ui/_gqlTypes';\nimport {getTreeContentQuery} from '_ui/_queries/trees/getTreeContentQuery';\n\nexport interface ITreeNode {\n title: string;\n id: string;\n key: string;\n children: ITreeNode[];\n accessRecordByDefaultPermission?: boolean;\n libraryId: string;\n recordId: string;\n}\n\ninterface IUseGetTreeDataProps {\n treeId: string;\n attributeId: string;\n libraryId: string;\n}\n\nconst _toTreeNode = (\n node: GetTreeContentQueryQuery['treeContent'][number] & {\n children?: Array<GetTreeContentQueryQuery['treeContent'][number]>;\n },\n): ITreeNode => ({\n title: node.record.whoAmI.label ?? node.record.whoAmI.id,\n id: node.id,\n key: node.id,\n children: (node.children ?? []).map(_toTreeNode),\n accessRecordByDefaultPermission: node.accessRecordByDefaultPermission ?? undefined,\n libraryId: node.record.whoAmI.library.id,\n recordId: node.record.id,\n});\n\nexport const useGetTreeData = ({treeId, attributeId, libraryId}: IUseGetTreeDataProps) => {\n const [loadTreeContent] = useLazyQuery<GetTreeContentQueryQuery, GetTreeContentQueryQueryVariables>(\n getTreeContentQuery(),\n );\n\n const [treeData, setTreeData] = useState<ITreeNode[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n if (!treeId) {\n setTreeData([]);\n setIsLoading(false);\n return;\n }\n\n const loadTree = async () => {\n setIsLoading(true);\n setError(null);\n try {\n const {data} = await loadTreeContent({\n variables: {\n treeId,\n accessRecordByDefaultPermission: {\n attributeId,\n libraryId,\n },\n },\n });\n\n setTreeData((data?.treeContent ?? []).map(node => _toTreeNode(node)));\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to load tree'));\n } finally {\n setIsLoading(false);\n }\n };\n\n loadTree();\n }, [treeId, attributeId, libraryId]);\n\n return {treeData, isLoading, error};\n};\n"]}
@@ -56,10 +56,6 @@ export type SubmittedValue = ISubmittedValueStandard | ISubmittedValueLink | ISu
56
56
  export type SubmitValueFunc = (values: SubmittedValue[], version: IValueVersion) => Promise<ISubmitMultipleResult>;
57
57
  export type DeleteValueFunc = (value: ValueInput | null, attribute: string) => Promise<IDeleteValueResult>;
58
58
  export type CreateEmptyRecordFunc = (library: string) => Promise<ICreateRecordResult>;
59
- export type CreateRecordFunc = (library: string, skipActivate?: boolean, data?: {
60
- values: Array<Omit<IValueToSubmit, 'idValue'>>;
61
- version: IValueVersion;
62
- }) => Promise<ICreateRecordResult>;
63
59
  export type DeleteMultipleValuesFunc = (attribute: string, values: RecordProperty[], version: IValueVersion) => Promise<ISubmitMultipleResult>;
64
60
  export type MetadataSubmitValueFunc = (value: RecordProperty, attribute: RecordFormAttributeFragment, metadata: IKeyValue<AnyPrimitive>) => Promise<ISubmitMultipleResult>;
65
61
  export interface ISubmittedValueBase {
@@ -1 +1 @@
1
- {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../../src/components/RecordEdition/EditRecordContent/_types.ts"],"names":[],"mappings":"AAoCA,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACrB,oCAAmB,CAAA;IACnB,gCAAe,CAAA;IACf,oCAAmB,CAAA;AACvB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AA4GD,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IACzB,4CAAuB,CAAA;IACvB,wCAAmB,CAAA;AACvB,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type FunctionComponent} from 'react';\nimport {\n type AnyPrimitive,\n type FormFieldTypes,\n type FormUIElementTypes,\n type IRequiredFieldsSettings,\n type IKeyValue,\n type Override,\n} from '@leav/utils';\nimport {type RecordFormElementsValue} from '_ui/hooks/useGetRecordForm';\nimport {type IRecordIdentity, type IRecordIdentityWhoAmI} from '_ui/types/records';\nimport {type ITreeNodeWithRecord} from '_ui/types/trees';\nimport {type IValueVersion} from '_ui/types/values';\nimport {\n type RecordFormAttributeFragment,\n type SaveValueBatchMutation,\n type CreateRecordMutation,\n type RecordFormElementFragment,\n type RecordIdentityFragment,\n type ValueDetailsFragment,\n type ValueInput,\n} from '_ui/_gqlTypes';\nimport {type RecordProperty} from '_ui/_queries/records/getRecordPropertiesQuery';\nimport {type FormInstance} from 'antd/lib/form/Form';\nimport {type GetRecordColumnsValuesRecord} from '_ui/_queries/records/getRecordColumnsValues';\n\nexport interface IValueToSubmit {\n attribute: string;\n value: AnyPrimitive | null;\n idValue: string | null;\n metadata?: IKeyValue<AnyPrimitive>;\n}\n\nexport enum APICallStatus {\n SUCCESS = 'SUCCESS',\n ERROR = 'ERROR',\n PARTIAL = 'PARTIAL',\n}\n\nexport type FieldSubmitMultipleFunc = (\n record: IRecordIdentityWhoAmI,\n values: IValueToSubmit[],\n version?: IValueVersion,\n deleteEmpty?: boolean,\n) => Promise<ISubmitMultipleResult>;\n\nexport interface ISubmitMultipleResult {\n status: APICallStatus;\n error?: string;\n values?: ValueDetailsFragment[];\n errors?: SaveValueBatchMutation['saveValueBatch']['errors'];\n}\n\nexport interface IDeleteValueResult {\n status: APICallStatus;\n error?: string;\n}\n\nexport interface ICreateRecordResult {\n status: APICallStatus;\n record?: RecordIdentityFragment['whoAmI'];\n errors?: CreateRecordMutation['createRecord']['valuesErrors'];\n}\n\nexport interface IRecordEditionContext {\n elements: IFormElementsByContainer;\n readOnly: boolean;\n record: IRecordIdentityWhoAmI;\n}\n\nexport interface IFormElementsByContainer {\n [containerId: string]: Array<FormElement<unknown>>;\n}\n\nexport interface ISubmittedValueStandard extends ISubmittedValueBase {\n value: AnyPrimitive;\n}\n\nexport interface ISubmittedValueLink extends ISubmittedValueBase {\n value: IRecordIdentity;\n}\n\nexport interface ISubmittedValueTree extends ISubmittedValueBase {\n value: ITreeNodeWithRecord;\n}\n\nexport type SubmittedValue = ISubmittedValueStandard | ISubmittedValueLink | ISubmittedValueTree;\n\nexport type SubmitValueFunc = (values: SubmittedValue[], version: IValueVersion) => Promise<ISubmitMultipleResult>;\nexport type DeleteValueFunc = (value: ValueInput | null, attribute: string) => Promise<IDeleteValueResult>;\nexport type CreateEmptyRecordFunc = (library: string) => Promise<ICreateRecordResult>;\nexport type CreateRecordFunc = (\n library: string,\n skipActivate?: boolean,\n data?: {\n values: Array<Omit<IValueToSubmit, 'idValue'>>;\n version: IValueVersion;\n },\n) => Promise<ICreateRecordResult>;\nexport type DeleteMultipleValuesFunc = (\n attribute: string,\n values: RecordProperty[],\n version: IValueVersion,\n) => Promise<ISubmitMultipleResult>;\n\nexport type MetadataSubmitValueFunc = (\n value: RecordProperty,\n attribute: RecordFormAttributeFragment,\n metadata: IKeyValue<AnyPrimitive>,\n) => Promise<ISubmitMultipleResult>;\n\nexport interface ISubmittedValueBase {\n attribute: RecordFormAttributeFragment;\n idValue: string;\n metadata?: IKeyValue<AnyPrimitive>;\n}\n\nexport interface IFormElementProps<SettingsType, RecordFormElements = RecordFormElementsValue> {\n element: FormElement<SettingsType, RecordFormElements>;\n readonly?: boolean;\n onValueSubmit?: SubmitValueFunc;\n onValueDelete?: DeleteValueFunc;\n onDeleteMultipleValues?: DeleteMultipleValuesFunc;\n metadataEdit?: boolean;\n isFormCreationMode?: boolean;\n}\n\nexport type FormElement<SettingsType, RecordFormElements = RecordFormElementsValue> = Override<\n RecordFormElementFragment,\n {\n settings: SettingsType;\n uiElementType: FormUIElementTypes | FormFieldTypes;\n values: RecordFormElements[];\n }\n> & {\n uiElement: FunctionComponent<\n IFormElementProps<unknown> & {\n antdForm?: FormInstance;\n computedValues?: GetRecordColumnsValuesRecord;\n }\n >;\n};\n\nexport type StandardValueTypes = AnyPrimitive;\n\nexport enum VersionFieldScope {\n INHERITED = 'INHERITED', // inherited values\n CURRENT = 'CURRENT', // values of \"current\" version, eg. the version selected in the form\n}\n\nexport interface ICommonFieldsReducerState<ValuesType, RecordFormAttributeFragmentType = RecordFormAttributeFragment> {\n record: IRecordIdentityWhoAmI;\n formElement: FormElement<IRequiredFieldsSettings>;\n attribute: RecordFormAttributeFragmentType;\n isReadOnly: boolean;\n activeScope: VersionFieldScope;\n values: {\n [scope in VersionFieldScope]: {\n version: IValueVersion;\n values: ValuesType;\n } | null;\n };\n}\n\nexport interface IProvidedByAntFormItem<\n InputFieldProps extends {value?: unknown; onChange?: unknown},\n AntNotifier extends {onChange?: unknown} = InputFieldProps,\n> {\n value?: InputFieldProps['value'];\n onChange?: AntNotifier['onChange'];\n}\n"]}
1
+ {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../../src/components/RecordEdition/EditRecordContent/_types.ts"],"names":[],"mappings":"AAoCA,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACrB,oCAAmB,CAAA;IACnB,gCAAe,CAAA;IACf,oCAAmB,CAAA;AACvB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAoGD,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IACzB,4CAAuB,CAAA;IACvB,wCAAmB,CAAA;AACvB,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type FunctionComponent} from 'react';\nimport {\n type AnyPrimitive,\n type FormFieldTypes,\n type FormUIElementTypes,\n type IRequiredFieldsSettings,\n type IKeyValue,\n type Override,\n} from '@leav/utils';\nimport {type RecordFormElementsValue} from '_ui/hooks/useGetRecordForm';\nimport {type IRecordIdentity, type IRecordIdentityWhoAmI} from '_ui/types/records';\nimport {type ITreeNodeWithRecord} from '_ui/types/trees';\nimport {type IValueVersion} from '_ui/types/values';\nimport {\n type RecordFormAttributeFragment,\n type SaveValueBatchMutation,\n type CreateRecordMutation,\n type RecordFormElementFragment,\n type RecordIdentityFragment,\n type ValueDetailsFragment,\n type ValueInput,\n} from '_ui/_gqlTypes';\nimport {type RecordProperty} from '_ui/_queries/records/getRecordPropertiesQuery';\nimport {type FormInstance} from 'antd/lib/form/Form';\nimport {type GetRecordColumnsValuesRecord} from '_ui/_queries/records/getRecordColumnsValues';\n\nexport interface IValueToSubmit {\n attribute: string;\n value: AnyPrimitive | null;\n idValue: string | null;\n metadata?: IKeyValue<AnyPrimitive>;\n}\n\nexport enum APICallStatus {\n SUCCESS = 'SUCCESS',\n ERROR = 'ERROR',\n PARTIAL = 'PARTIAL',\n}\n\nexport type FieldSubmitMultipleFunc = (\n record: IRecordIdentityWhoAmI,\n values: IValueToSubmit[],\n version?: IValueVersion,\n deleteEmpty?: boolean,\n) => Promise<ISubmitMultipleResult>;\n\nexport interface ISubmitMultipleResult {\n status: APICallStatus;\n error?: string;\n values?: ValueDetailsFragment[];\n errors?: SaveValueBatchMutation['saveValueBatch']['errors'];\n}\n\nexport interface IDeleteValueResult {\n status: APICallStatus;\n error?: string;\n}\n\nexport interface ICreateRecordResult {\n status: APICallStatus;\n record?: RecordIdentityFragment['whoAmI'];\n errors?: CreateRecordMutation['createRecord']['valuesErrors'];\n}\n\nexport interface IRecordEditionContext {\n elements: IFormElementsByContainer;\n readOnly: boolean;\n record: IRecordIdentityWhoAmI;\n}\n\nexport interface IFormElementsByContainer {\n [containerId: string]: Array<FormElement<unknown>>;\n}\n\nexport interface ISubmittedValueStandard extends ISubmittedValueBase {\n value: AnyPrimitive;\n}\n\nexport interface ISubmittedValueLink extends ISubmittedValueBase {\n value: IRecordIdentity;\n}\n\nexport interface ISubmittedValueTree extends ISubmittedValueBase {\n value: ITreeNodeWithRecord;\n}\n\nexport type SubmittedValue = ISubmittedValueStandard | ISubmittedValueLink | ISubmittedValueTree;\n\nexport type SubmitValueFunc = (values: SubmittedValue[], version: IValueVersion) => Promise<ISubmitMultipleResult>;\nexport type DeleteValueFunc = (value: ValueInput | null, attribute: string) => Promise<IDeleteValueResult>;\nexport type CreateEmptyRecordFunc = (library: string) => Promise<ICreateRecordResult>;\nexport type DeleteMultipleValuesFunc = (\n attribute: string,\n values: RecordProperty[],\n version: IValueVersion,\n) => Promise<ISubmitMultipleResult>;\n\nexport type MetadataSubmitValueFunc = (\n value: RecordProperty,\n attribute: RecordFormAttributeFragment,\n metadata: IKeyValue<AnyPrimitive>,\n) => Promise<ISubmitMultipleResult>;\n\nexport interface ISubmittedValueBase {\n attribute: RecordFormAttributeFragment;\n idValue: string;\n metadata?: IKeyValue<AnyPrimitive>;\n}\n\nexport interface IFormElementProps<SettingsType, RecordFormElements = RecordFormElementsValue> {\n element: FormElement<SettingsType, RecordFormElements>;\n readonly?: boolean;\n onValueSubmit?: SubmitValueFunc;\n onValueDelete?: DeleteValueFunc;\n onDeleteMultipleValues?: DeleteMultipleValuesFunc;\n metadataEdit?: boolean;\n isFormCreationMode?: boolean;\n}\n\nexport type FormElement<SettingsType, RecordFormElements = RecordFormElementsValue> = Override<\n RecordFormElementFragment,\n {\n settings: SettingsType;\n uiElementType: FormUIElementTypes | FormFieldTypes;\n values: RecordFormElements[];\n }\n> & {\n uiElement: FunctionComponent<\n IFormElementProps<unknown> & {\n antdForm?: FormInstance;\n computedValues?: GetRecordColumnsValuesRecord;\n }\n >;\n};\n\nexport type StandardValueTypes = AnyPrimitive;\n\nexport enum VersionFieldScope {\n INHERITED = 'INHERITED', // inherited values\n CURRENT = 'CURRENT', // values of \"current\" version, eg. the version selected in the form\n}\n\nexport interface ICommonFieldsReducerState<ValuesType, RecordFormAttributeFragmentType = RecordFormAttributeFragment> {\n record: IRecordIdentityWhoAmI;\n formElement: FormElement<IRequiredFieldsSettings>;\n attribute: RecordFormAttributeFragmentType;\n isReadOnly: boolean;\n activeScope: VersionFieldScope;\n values: {\n [scope in VersionFieldScope]: {\n version: IValueVersion;\n values: ValuesType;\n } | null;\n };\n}\n\nexport interface IProvidedByAntFormItem<\n InputFieldProps extends {value?: unknown; onChange?: unknown},\n AntNotifier extends {onChange?: unknown} = InputFieldProps,\n> {\n value?: InputFieldProps['value'];\n onChange?: AntNotifier['onChange'];\n}\n"]}
@@ -3,10 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // This file is released under LGPL V3
4
4
  // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
5
5
  import { useEffect, useRef, useState } from 'react';
6
- import { KitButton, KitLoader, KitModal, KitSpace, KitTypography } from 'aristid-ds';
6
+ import { KitButton, KitModal, KitSpace, KitTypography } from 'aristid-ds';
7
7
  import styled from 'styled-components';
8
8
  import { useSharedTranslation } from '../../../hooks/useSharedTranslation';
9
- import { useCreateRecordMutation, usePurgeRecordMutation } from '../../../_gqlTypes';
9
+ import { usePurgeRecordMutation } from '../../../_gqlTypes';
10
10
  import { EditRecord } from '../EditRecord';
11
11
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
12
12
  import { faXmark } from '@fortawesome/free-solid-svg-icons';
@@ -14,8 +14,8 @@ import { useGetSubmitButtons } from '../hooks/useGetSubmitButtons';
14
14
  import { useForm } from 'antd/lib/form/Form';
15
15
  import { useCreateCancelConfirm } from '../hooks/useCreateCancelConfirm';
16
16
  import { EDIT_RECORD_MODAL_HEADER_CONTAINER_BUTTONS } from '../constants';
17
- import { useGetInitialRecordValues } from '../EditRecordPage/getInitialRecordValues';
18
- import { ErrorComponent } from '../EditRecordPage/ErrorComponent';
17
+ import useExecuteCreateEmptyRecordMutation from '../EditRecordContent/hooks/useCreateEmptyRecordMutation';
18
+ import { APICallStatus } from '../EditRecordContent/_types';
19
19
  const MODAL_HEIGHT = '80vh';
20
20
  const MODAL_WIDTH = '90vw';
21
21
  const MODAL_MAX_WIDTH = '656px';
@@ -60,40 +60,29 @@ export const EditRecordModal = ({ className, open, record, creationFormId, editi
60
60
  const { t } = useSharedTranslation();
61
61
  const [antdForm] = useForm();
62
62
  const [currentRecord, setCurrentRecord] = useState(record);
63
- const clickedSubmitButton = useRef(null);
64
- const [createRecord] = useCreateRecordMutation();
63
+ const [clickedSubmitButton, setClickedSubmitButton] = useState(null);
64
+ const { createEmptyRecord } = useExecuteCreateEmptyRecordMutation();
65
65
  const [purgeRecordMutation] = usePurgeRecordMutation();
66
66
  const formElementId = useRef(window.crypto.randomUUID());
67
67
  const [isCreation, setIsCreation] = useState(!record);
68
- const [isReady, setIsReady] = useState(!!record);
69
- const [isError, setIsError] = useState(false);
70
68
  const [formId, setFormId] = useState(isCreation ? (creationFormId ?? 'creation') : (editionFormId ?? 'edition'));
71
69
  const closeButtonLabel = isCreation ? t('global.cancel') : t('global.close');
72
70
  const modalTitle = currentRecord?.label && currentRecord.label.trim() ? currentRecord.label : t('record_edition.new_record');
73
71
  useEffect(() => {
74
72
  const createEmptyRecordFunction = async () => {
75
- const values = useGetInitialRecordValues();
76
- const { data } = await createRecord({
77
- variables: {
78
- library,
79
- skipActivate: true,
80
- data: { values },
81
- },
82
- });
83
- const recordId = data?.createRecord.record?.id;
84
- setCurrentRecord(data?.createRecord.record.whoAmI ?? null);
85
- if (!recordId) {
86
- setIsError(true);
87
- return;
73
+ const res = await createEmptyRecord(library);
74
+ if (res?.status === APICallStatus.ERROR) {
75
+ // TODO : call KitNotification error
76
+ return null;
88
77
  }
89
- setIsReady(true);
78
+ setCurrentRecord(res?.record ?? null);
90
79
  };
91
80
  if (open && isCreation && !currentRecord) {
92
81
  createEmptyRecordFunction();
93
82
  }
94
83
  }, [open, currentRecord]);
95
84
  const _handleClickSubmit = (button) => {
96
- clickedSubmitButton.current = button;
85
+ setClickedSubmitButton(button);
97
86
  };
98
87
  const _purgeRecordOnCreationCancel = () => purgeRecordMutation({
99
88
  errorPolicy: 'ignore',
@@ -109,15 +98,16 @@ export const EditRecordModal = ({ className, open, record, creationFormId, editi
109
98
  return onClose();
110
99
  };
111
100
  const showCancelConfirm = useCreateCancelConfirm(_closeAfterConfirm);
101
+ const displayedSubmitButtons = useGetSubmitButtons(submitButtons, formElementId.current, isCreation, _handleClickSubmit);
112
102
  const _handleCreate = (newRecord) => {
113
103
  setCurrentRecord(newRecord);
114
- if (onCreateAndEdit && clickedSubmitButton.current === 'createAndEdit') {
104
+ if (onCreateAndEdit && clickedSubmitButton === 'createAndEdit') {
115
105
  setFormId(editionFormId ?? 'edition');
116
106
  setIsCreation(false);
117
107
  onCreateAndEdit(newRecord);
118
108
  return;
119
109
  }
120
- if (onCreate && clickedSubmitButton.current === 'create') {
110
+ if (onCreate && clickedSubmitButton === 'create') {
121
111
  onCreate(newRecord);
122
112
  return;
123
113
  }
@@ -133,10 +123,9 @@ export const EditRecordModal = ({ className, open, record, creationFormId, editi
133
123
  }
134
124
  return onClose();
135
125
  };
136
- const displayedSubmitButtons = useGetSubmitButtons(submitButtons, formElementId.current, isCreation, _handleClickSubmit, _handleClose);
137
- return (_jsxs(KitModalStyled, { appElement: document.getElementById('root'), className: className, height: autoHeight ? 'auto' : MODAL_HEIGHT, maxHeight: autoHeight ? MODAL_HEIGHT : undefined, width: MODAL_WIDTH, isOpen: open, close: _handleClose, title: _jsxs(KitSpace, { children: [_jsx(KitTypography.Title, { level: "h2", style: { margin: 0 }, children: modalTitle }), _jsx("div", { id: EDIT_RECORD_MODAL_HEADER_CONTAINER_BUTTONS })] }), footer: _jsx(KitSpace, { children: [
126
+ return (_jsx(KitModalStyled, { appElement: document.getElementById('root'), className: className, height: autoHeight ? 'auto' : MODAL_HEIGHT, maxHeight: autoHeight ? MODAL_HEIGHT : undefined, width: MODAL_WIDTH, isOpen: open, close: _handleClose, title: _jsxs(KitSpace, { children: [_jsx(KitTypography.Title, { level: "h2", style: { margin: 0 }, children: modalTitle }), _jsx("div", { id: EDIT_RECORD_MODAL_HEADER_CONTAINER_BUTTONS })] }), footer: _jsx(KitSpace, { children: [
138
127
  _jsx(KitButton, { "aria-label": closeButtonLabel, icon: _jsx(FontAwesomeIcon, { icon: faXmark }), onClick: _handleClose, children: closeButtonLabel }, "close"),
139
128
  ...displayedSubmitButtons,
140
- ] }), closeIcon: _jsx(FontAwesomeIcon, { icon: faXmark }), showCloseIcon: true, destroyOnClose: true, children: [isError && _jsx(ErrorComponent, {}), !isReady && _jsx(KitLoader, {}), isReady && (_jsx(EditRecord, { antdForm: antdForm, isFormCreationMode: isCreation, formId: formId, formElementId: formElementId.current, record: currentRecord, library: library, onCreate: _handleCreate, valuesVersion: valuesVersion, showSidebar: showSidebar, enableSidebar: enableSidebar, withInfoButton: withInfoButton }))] }));
129
+ ] }), closeIcon: _jsx(FontAwesomeIcon, { icon: faXmark }), showCloseIcon: true, destroyOnClose: true, children: _jsx(EditRecord, { antdForm: antdForm, isFormCreationMode: isCreation, formId: formId, formElementId: formElementId.current, record: currentRecord, library: library, onCreate: _handleCreate, valuesVersion: valuesVersion, showSidebar: showSidebar, enableSidebar: enableSidebar, withInfoButton: withInfoButton }) }));
141
130
  };
142
131
  //# sourceMappingURL=EditRecordModal.js.map