@leav/ui 1.12.0-69ccbdbf → 1.12.0-7392f2e8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__mocks__/utils.d.ts +3 -0
- package/dist/__mocks__/utils.js +2 -0
- package/dist/__mocks__/utils.js.map +1 -0
- package/dist/_gqlTypes/index.d.ts +129 -33
- package/dist/_gqlTypes/index.js +71 -3
- package/dist/_gqlTypes/index.js.map +1 -1
- package/dist/_queries/attributes/attributeDetailsFragment.js +3 -0
- package/dist/_queries/attributes/attributeDetailsFragment.js.map +1 -1
- package/dist/components/Explorer/DataView.js +30 -13
- package/dist/components/Explorer/DataView.js.map +1 -1
- package/dist/components/Explorer/_constants.d.ts +0 -1
- package/dist/components/Explorer/_constants.js +0 -1
- package/dist/components/Explorer/_constants.js.map +1 -1
- package/dist/components/Explorer/actions-item/useEditStatusItemAction.js +5 -9
- package/dist/components/Explorer/actions-item/useEditStatusItemAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/ResultsCount.js +2 -2
- package/dist/components/Explorer/actions-mass/ResultsCount.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useDeactivateMassAction.js +6 -10
- package/dist/components/Explorer/actions-mass/useDeactivateMassAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useDeleteLinkValues.js +5 -8
- package/dist/components/Explorer/actions-mass/useDeleteLinkValues.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js +14 -6
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useMassActions.js +30 -19
- package/dist/components/Explorer/actions-mass/useMassActions.js.map +1 -1
- package/dist/components/Explorer/conditionsHelper.d.ts +2 -1
- package/dist/components/Explorer/conditionsHelper.js.map +1 -1
- package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js +6 -4
- package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js.map +1 -1
- package/dist/components/Filters/_types.d.ts +3 -0
- package/dist/components/Filters/_types.js.map +1 -1
- package/dist/components/Filters/conditionsHelper.d.ts +2 -1
- package/dist/components/Filters/conditionsHelper.js.map +1 -1
- package/dist/components/Filters/context/filtersReducer.js +14 -1
- package/dist/components/Filters/context/filtersReducer.js.map +1 -1
- package/dist/components/Filters/filter-items/CommonFilterItem.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/useConditionOptionsByType.js.map +1 -1
- package/dist/components/Filters/useFilters.d.ts +198 -0
- package/dist/components/Filters/useTransformFilters.js +4 -2
- package/dist/components/Filters/useTransformFilters.js.map +1 -1
- package/dist/components/RecordEdition/EditRecord/EditRecord.js +8 -1
- package/dist/components/RecordEdition/EditRecord/EditRecord.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/tag/unlink-record/useUnlinkRecord.d.ts +1 -4
- package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/tag/unlink-record/useUnlinkRecord.js +5 -9
- package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/tag/unlink-record/useUnlinkRecord.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/DeleteAllValuesButton.js +4 -8
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/DeleteAllValuesButton.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js +1 -1
- package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js.map +1 -1
- package/dist/components/RecordEdition/hooks/useCreateCancelConfirm/useCreateCancelConfirm.js +4 -8
- package/dist/components/RecordEdition/hooks/useCreateCancelConfirm/useCreateCancelConfirm.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useConfirmModal/__mocks__/index.d.ts +1 -0
- package/dist/hooks/useConfirmModal/__mocks__/index.js +5 -0
- package/dist/hooks/useConfirmModal/__mocks__/index.js.map +1 -0
- package/dist/hooks/useConfirmModal/__mocks__/useConfirmModal.d.ts +3 -0
- package/dist/hooks/useConfirmModal/__mocks__/useConfirmModal.js +7 -0
- package/dist/hooks/useConfirmModal/__mocks__/useConfirmModal.js.map +1 -0
- package/dist/hooks/useConfirmModal/index.d.ts +1 -0
- package/dist/hooks/useConfirmModal/index.js +5 -0
- package/dist/hooks/useConfirmModal/index.js.map +1 -0
- package/dist/hooks/useConfirmModal/useConfirmModal.d.ts +7 -0
- package/dist/hooks/useConfirmModal/useConfirmModal.js +25 -0
- package/dist/hooks/useConfirmModal/useConfirmModal.js.map +1 -0
- package/dist/hooks/useGetRecordIdCard/index.d.ts +1 -0
- package/dist/hooks/useGetRecordIdCard/index.js +5 -0
- package/dist/hooks/useGetRecordIdCard/index.js.map +1 -0
- package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.d.ts +18 -0
- package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.js +20 -0
- package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.d.ts +6 -0
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js +8 -0
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/types.d.ts +10 -3
- package/dist/hooks/useIFrameMessenger/types.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/useIFrameMessenger.d.ts +11 -2
- package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js +31 -10
- package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.d.ts +13 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js +59 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.d.ts +13 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js +29 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js.map +1 -0
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js +3 -0
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js.map +1 -1
- package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.d.ts +1 -0
- package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.d.ts +1 -0
- package/dist/hooks/useSharedTranslation/__mocks__/useSharedTranslation.js.map +1 -1
- package/dist/locales/en/shared.json +2 -0
- package/dist/locales/fr/shared.json +3 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributeDetailsFragment.js","sourceRoot":"","sources":["../../../src/_queries/attributes/attributeDetailsFragment.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAC;AAEnC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"attributeDetailsFragment.js","sourceRoot":"","sources":["../../../src/_queries/attributes/attributeDetailsFragment.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAC;AAEnC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiE1C,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 {gql} from '@apollo/client';\n\nexport const attributeDetailsFragment = gql`\n fragment AttributeDetails on Attribute {\n id\n type\n format\n system\n readonly\n label\n description\n required\n multiple_values\n multi_link_display_option\n multi_tree_display_option\n metadata_fields {\n id\n label\n type\n format\n }\n versions_conf {\n versionable\n mode\n profile {\n id\n label\n trees {\n id\n label\n }\n }\n }\n libraries {\n id\n label\n }\n\n ... on StandardAttribute {\n unique\n }\n\n ... on LinkAttribute {\n linked_library {\n id\n label\n }\n reverse_link\n smart_filter {\n enable\n through {\n id\n }\n }\n }\n ... on TreeAttribute {\n linked_tree {\n id\n label\n }\n permissions_conf_dependent_values {\n dependenciesTreeAttributes {\n id\n }\n }\n }\n }\n`;\n"]}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
|
|
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
|
-
import { memo } from 'react';
|
|
5
|
+
import { memo, useCallback, useState } from 'react';
|
|
6
6
|
import { KitPagination, KitTable } from 'aristid-ds';
|
|
7
7
|
import styled from 'styled-components';
|
|
8
8
|
import isEqual from 'lodash/isEqual';
|
|
@@ -13,7 +13,7 @@ import { useColumnWidth } from './useColumnWidth';
|
|
|
13
13
|
import { WHO_AM_I_COLUMN } from './_constants';
|
|
14
14
|
import { TableNameCell } from './TableNameCell';
|
|
15
15
|
import cn from 'classnames';
|
|
16
|
-
import {
|
|
16
|
+
import { throttle } from 'lodash';
|
|
17
17
|
const tableRowHeight = 56;
|
|
18
18
|
const tableHeaderMinLineHeight = 22;
|
|
19
19
|
const DataViewContainerDivStyled = styled.div `
|
|
@@ -60,11 +60,9 @@ const StyledTable = styled(KitTable) `
|
|
|
60
60
|
.ant-table-cell {
|
|
61
61
|
min-height: ${tableRowHeight}px;
|
|
62
62
|
height: auto !important;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
td:has(+ td) .ant-table-cell .actions-list {
|
|
67
|
-
margin-left: auto;
|
|
63
|
+
.actions-list {
|
|
64
|
+
margin-left: auto;
|
|
65
|
+
}
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
|
|
@@ -92,19 +90,17 @@ export const DataView = memo(({ dataGroupedFilteredSorted, attributesToDisplay,
|
|
|
92
90
|
title: () => attributesProperties[attributeName].label,
|
|
93
91
|
ellipsis: useSmallHeaderSize,
|
|
94
92
|
width: getFieldColumnWidth(attributesProperties[attributeName]),
|
|
95
|
-
shouldCellUpdate: (record, prevRecord) => isMassSelectionAll ||
|
|
93
|
+
shouldCellUpdate: (record, prevRecord) => isMassSelectionAll ||
|
|
94
|
+
record.propertiesById[attributeName] !== prevRecord.propertiesById[attributeName],
|
|
96
95
|
render: (_, item) => (_jsx(TableCell, { attributeProperties: attributesProperties[attributeName], values: item.propertiesById[attributeName] })),
|
|
97
96
|
});
|
|
98
97
|
const columns = attributesToDisplay.map(getColumnProps);
|
|
99
|
-
const whoIAmColumn = {
|
|
98
|
+
const whoIAmColumn = useWhoAmIColumn({
|
|
100
99
|
...getColumnProps(WHO_AM_I_COLUMN),
|
|
101
|
-
title: () => t('explorer.name'),
|
|
102
100
|
fixed: 'left',
|
|
103
101
|
render: (_, item) => _jsx(TableNameCell, { item: item, itemActions: itemActions }),
|
|
104
102
|
shouldCellUpdate: (record, prevRecord) => isMassSelectionAll || record.whoAmI !== prevRecord.whoAmI,
|
|
105
|
-
};
|
|
106
|
-
// replace `width` by `min-width` for the whoAmI column definition to prevent selection column to expand when all column have a width defined (which is a native table behaviour).
|
|
107
|
-
whoIAmColumn[INTERNAL_COL_DEFINE] = { style: { width: 'unset', minWidth: whoIAmColumn.width } };
|
|
103
|
+
});
|
|
108
104
|
const itemActionToUseOnRowClick = itemActions.find(itemAction => itemAction.useItemActionOnRowClick);
|
|
109
105
|
const _rowSelection = onSelectionChange === null
|
|
110
106
|
? undefined
|
|
@@ -138,4 +134,25 @@ export const DataView = memo(({ dataGroupedFilteredSorted, attributesToDisplay,
|
|
|
138
134
|
onClick: () => itemActionToUseOnRowClick?.callback(item),
|
|
139
135
|
}) }), paginationProps && (_jsx("div", { className: "pagination", children: _jsx(KitPagination, { "aria-label": "pagination", showSizeChanger: true, showTotal: (total, [from, to]) => t('explorer.pagination-total-number', { from, to, count: total }), total: paginationProps.totalCount, defaultCurrent: paginationProps.currentPage, defaultPageSize: paginationProps.pageSize, pageSizeOptions: paginationProps.pageSizeOptions, onChange: paginationProps.setNewPage, onShowSizeChange: paginationProps.setNewPageSize }) }))] }));
|
|
140
136
|
}, arePropsEqual);
|
|
137
|
+
// This hook exists to change the width of the whoAmI column dynamically.
|
|
138
|
+
// The aimed result is a whoAmI column that always expand and is the only one to expand if there is horizontal space available, but never shrinks under its specifed width.
|
|
139
|
+
// This behaviour is mostly present to prevent the selection column to expand
|
|
140
|
+
function useWhoAmIColumn(props) {
|
|
141
|
+
const { t } = useSharedTranslation();
|
|
142
|
+
const [width, setWidth] = useState(props.width);
|
|
143
|
+
// initialize observer only once using the useState initializer
|
|
144
|
+
const [resizeObserver] = useState(() => new ResizeObserver(throttle(([node]) => setWidth(node.contentRect.width < props.width ? props.width : '100%'), 100)));
|
|
145
|
+
// use the `ref` prop as a callback to retrieve the div element and connect the observer on it
|
|
146
|
+
const onWhoAmIColumnRender = useCallback((node) => {
|
|
147
|
+
resizeObserver.disconnect();
|
|
148
|
+
if (node) {
|
|
149
|
+
resizeObserver.observe(node);
|
|
150
|
+
}
|
|
151
|
+
}, []);
|
|
152
|
+
return {
|
|
153
|
+
...props,
|
|
154
|
+
title: () => _jsx("div", { ref: onWhoAmIColumnRender, children: t('explorer.name') }),
|
|
155
|
+
width,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
141
158
|
//# sourceMappingURL=DataView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataView.js","sourceRoot":"","sources":["../../../src/components/Explorer/DataView.tsx"],"names":[],"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,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAC7B,CAAC,CAAC,kCAAkC,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,EAEnE,KAAK,EAAE,eAAe,CAAC,UAAU,EACjC,cAAc,EAAE,eAAe,CAAC,WAAW,EAC3C,eAAe,EAAE,eAAe,CAAC,QAAQ,EACzC,eAAe,EAAE,eAAe,CAAC,eAAe,EAChD,QAAQ,EAAE,eAAe,CAAC,UAAU,EACpC,gBAAgB,EAAE,eAAe,CAAC,cAAc,GAClD,GACA,CACT,IACwB,CAChC,CAAC;AACN,CAAC,EACD,aAAa,CAChB,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 ComponentProps, type FunctionComponent, type Key, memo} from 'react';\nimport {KitPagination, KitTable} from 'aristid-ds';\nimport {type KitTableColumnType} from 'aristid-ds/dist/Kit/DataDisplay/Table/types';\nimport styled from 'styled-components';\nimport isEqual from 'lodash/isEqual';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {type IExplorerData, type IItemAction, type IItemData} from './_types';\nimport {TableCell} from './TableCell';\nimport {defaultPaginationHeight, useTableScrollableHeight} from './useTableScrollableHeight';\nimport {useColumnWidth} from './useColumnWidth';\nimport {WHO_AM_I_COLUMN} from './_constants';\nimport {TableNameCell} from './TableNameCell';\nimport cn from 'classnames';\nimport {INTERNAL_COL_DEFINE} from 'rc-table';\n\nconst tableRowHeight = 56;\nconst tableHeaderMinLineHeight = 22;\n\nconst DataViewContainerDivStyled = styled.div`\n flex: 1 1 min-content;\n overflow: hidden;\n\n &.headless {\n overflow-y: auto;\n }\n\n .kit-table {\n padding-bottom: ${defaultPaginationHeight}px;\n position: relative;\n }\n\n .pagination {\n flex: 0 0 auto;\n justify-content: center;\n display: flex;\n padding-top: calc(var(--general-spacing-xs) * 1px);\n }\n`;\n\n// TODO: Table component should be updated fix header display\nconst StyledTable = styled(KitTable)`\n .ant-table-thead > tr > th {\n padding-top: calc(var(--general-spacing-xxs) * 1px) !important;\n padding-bottom: calc(var(--general-spacing-xxs) * 1px) !important;\n height: ${tableRowHeight}px;\n\n .ant-table-cell {\n min-height: ${tableHeaderMinLineHeight}px;\n height: auto !important;\n padding: 0 calc(var(--general-spacing-s) * 1px) 0 0;\n }\n }\n\n .ant-table-tbody > tr:hover .ant-table-cell {\n .actions-list {\n display: inline-flex;\n }\n }\n\n .ant-table-tbody > tr {\n .ant-table-cell {\n min-height: ${tableRowHeight}px;\n height: auto !important;\n }\n\n /* Align actions to the right of the cell only if another column is present after */\n td:has(+ td) .ant-table-cell .actions-list {\n margin-left: auto;\n }\n }\n\n &.row-clickable {\n .ant-table-tbody > tr {\n cursor: pointer;\n }\n }\n`;\n\ninterface IDataViewProps {\n dataGroupedFilteredSorted: IItemData[];\n itemActions: IItemAction[];\n attributesProperties: IExplorerData['attributes'];\n attributesToDisplay: string[];\n paginationProps?: {\n pageSizeOptions: number[];\n totalCount: number;\n currentPage: number;\n pageSize: number;\n setNewPage: (page: number, pageSize: number) => void;\n setNewPageSize: (page: number, pageSize: number) => void;\n };\n selection: {\n onSelectItem?: null | ((selectedItem: IItemData) => void);\n onSelectionChange: null | ((keys: Key[]) => void);\n isMassSelectionAll: boolean;\n selectedKeys: Key[];\n mode?: 'simple' | 'multiple';\n };\n hideTableHeader: boolean;\n useSmallHeaderSize?: boolean;\n tableBodyHeight?: string;\n}\n\n// TODO: tests will fail if we don't check attributeToDisplay because we have a render with no attributes but data is present. We should check why there's this behavior\nconst arePropsEqual = (prevProps: IDataViewProps, nextProps: IDataViewProps) =>\n isEqual(\n {\n attributesToDisplay: prevProps.attributesToDisplay,\n data: prevProps.dataGroupedFilteredSorted,\n selectedKeys: prevProps.selection.selectedKeys,\n },\n {\n attributesToDisplay: nextProps.attributesToDisplay,\n data: nextProps.dataGroupedFilteredSorted,\n selectedKeys: nextProps.selection.selectedKeys,\n },\n );\n\nexport const DataView: FunctionComponent<IDataViewProps> = memo(\n ({\n dataGroupedFilteredSorted,\n attributesToDisplay,\n attributesProperties,\n paginationProps,\n itemActions,\n selection: {onSelectItem, onSelectionChange, selectedKeys, isMassSelectionAll, mode},\n hideTableHeader = false,\n useSmallHeaderSize = false,\n tableBodyHeight,\n }) => {\n const {t} = useSharedTranslation();\n\n const {containerRef, scrollHeight} = useTableScrollableHeight(!!paginationProps);\n const {getFieldColumnWidth} = useColumnWidth();\n\n const getColumnProps = (attributeName: string): KitTableColumnType<IItemData> => ({\n title: () => attributesProperties[attributeName].label,\n ellipsis: useSmallHeaderSize,\n width: getFieldColumnWidth(attributesProperties[attributeName]),\n shouldCellUpdate: (record, prevRecord) =>\n isMassSelectionAll || record.propertiesById[attributeName] !== prevRecord.propertiesById[attributeName],\n render: (_, item) => (\n <TableCell\n attributeProperties={attributesProperties[attributeName]}\n values={item.propertiesById[attributeName]}\n />\n ),\n });\n\n const columns = attributesToDisplay.map(getColumnProps);\n\n const whoIAmColumn: KitTableColumnType<IItemData> = {\n ...getColumnProps(WHO_AM_I_COLUMN),\n title: () => t('explorer.name'),\n fixed: 'left',\n render: (_, item) => <TableNameCell item={item} itemActions={itemActions} />,\n shouldCellUpdate: (record, prevRecord) => isMassSelectionAll || record.whoAmI !== prevRecord.whoAmI,\n };\n\n // replace `width` by `min-width` for the whoAmI column definition to prevent selection column to expand when all column have a width defined (which is a native table behaviour).\n whoIAmColumn[INTERNAL_COL_DEFINE] = {style: {width: 'unset', minWidth: whoIAmColumn.width}};\n\n const itemActionToUseOnRowClick = itemActions.find(itemAction => itemAction.useItemActionOnRowClick);\n\n const _rowSelection: ComponentProps<typeof KitTable>['rowSelection'] =\n onSelectionChange === null\n ? undefined\n : {\n type: mode === 'simple' ? 'radio' : 'checkbox',\n columnTitle: ' ', // blank string to hide select all checkbox from <KitTable />\n selectedRowKeys: selectedKeys,\n preserveSelectedRowKeys: true,\n // TODO: review types from antd directly\n onChange: (selectedRowKeys: Key[]) => {\n const lastSelectedKey = selectedRowKeys[selectedRowKeys.length - 1];\n const lastSelectedItem = dataGroupedFilteredSorted.find(data => data.key === lastSelectedKey);\n\n onSelectionChange(selectedRowKeys);\n\n if (lastSelectedItem) {\n onSelectItem?.(lastSelectedItem);\n }\n },\n getCheckboxProps: isMassSelectionAll\n ? () => ({\n disabled: true,\n })\n : undefined,\n };\n\n // TODO: handle columns width based on attribute type/format\n return (\n <DataViewContainerDivStyled ref={containerRef} className={cn({headless: hideTableHeader})}>\n <StyledTable\n className={cn({\n 'row-clickable': itemActionToUseOnRowClick,\n })}\n showHeader={dataGroupedFilteredSorted.length > 0 && !hideTableHeader}\n headerLineSize={useSmallHeaderSize ? 's' : undefined}\n columns={[whoIAmColumn, ...columns]}\n tableLayout=\"fixed\"\n scroll={{\n y: tableBodyHeight ?? (hideTableHeader ? '100%' : scrollHeight),\n x: '100%',\n }}\n dataSource={dataGroupedFilteredSorted}\n pagination={false}\n rowSelection={_rowSelection}\n onRow={(item: IItemData) => ({\n onClick: () => itemActionToUseOnRowClick?.callback(item),\n })}\n />\n {paginationProps && (\n <div className=\"pagination\">\n <KitPagination\n aria-label=\"pagination\"\n showSizeChanger\n showTotal={(total, [from, to]) =>\n t('explorer.pagination-total-number', {from, to, count: total})\n }\n total={paginationProps.totalCount}\n defaultCurrent={paginationProps.currentPage}\n defaultPageSize={paginationProps.pageSize}\n pageSizeOptions={paginationProps.pageSizeOptions}\n onChange={paginationProps.setNewPage}\n onShowSizeChange={paginationProps.setNewPageSize}\n />\n </div>\n )}\n </DataViewContainerDivStyled>\n );\n },\n arePropsEqual,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"DataView.js","sourceRoot":"","sources":["../../../src/components/Explorer/DataView.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AAEtE,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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\n\nimport {type ComponentProps, type FunctionComponent, type Key, memo, useCallback, useState} from 'react';\nimport {KitPagination, KitTable} from 'aristid-ds';\nimport {type KitTableColumnType} from 'aristid-ds/dist/Kit/DataDisplay/Table/types';\nimport styled from 'styled-components';\nimport isEqual from 'lodash/isEqual';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {type IExplorerData, type IItemAction, type IItemData} from './_types';\nimport {TableCell} from './TableCell';\nimport {defaultPaginationHeight, useTableScrollableHeight} from './useTableScrollableHeight';\nimport {useColumnWidth} from './useColumnWidth';\nimport {WHO_AM_I_COLUMN} from './_constants';\nimport {TableNameCell} from './TableNameCell';\nimport cn from 'classnames';\nimport {throttle} from 'lodash';\n\nconst tableRowHeight = 56;\nconst tableHeaderMinLineHeight = 22;\n\nconst DataViewContainerDivStyled = styled.div`\n flex: 1 1 min-content;\n overflow: hidden;\n\n &.headless {\n overflow-y: auto;\n }\n\n .kit-table {\n padding-bottom: ${defaultPaginationHeight}px;\n position: relative;\n }\n\n .pagination {\n flex: 0 0 auto;\n justify-content: center;\n display: flex;\n padding-top: calc(var(--general-spacing-xs) * 1px);\n }\n`;\n\n// TODO: Table component should be updated fix header display\nconst StyledTable = styled(KitTable)`\n .ant-table-thead > tr > th {\n padding-top: calc(var(--general-spacing-xxs) * 1px) !important;\n padding-bottom: calc(var(--general-spacing-xxs) * 1px) !important;\n height: ${tableRowHeight}px;\n\n .ant-table-cell {\n min-height: ${tableHeaderMinLineHeight}px;\n height: auto !important;\n padding: 0 calc(var(--general-spacing-s) * 1px) 0 0;\n }\n }\n\n .ant-table-tbody > tr:hover .ant-table-cell {\n .actions-list {\n display: inline-flex;\n }\n }\n\n .ant-table-tbody > tr {\n .ant-table-cell {\n min-height: ${tableRowHeight}px;\n height: auto !important;\n .actions-list {\n margin-left: auto;\n }\n }\n }\n\n &.row-clickable {\n .ant-table-tbody > tr {\n cursor: pointer;\n }\n }\n`;\n\ninterface IDataViewProps {\n dataGroupedFilteredSorted: IItemData[];\n itemActions: IItemAction[];\n attributesProperties: IExplorerData['attributes'];\n attributesToDisplay: string[];\n paginationProps?: {\n pageSizeOptions: number[];\n totalCount: number;\n currentPage: number;\n pageSize: number;\n setNewPage: (page: number, pageSize: number) => void;\n setNewPageSize: (page: number, pageSize: number) => void;\n };\n selection: {\n onSelectItem?: null | ((selectedItem: IItemData) => void);\n onSelectionChange: null | ((keys: Key[]) => void);\n isMassSelectionAll: boolean;\n selectedKeys: Key[];\n mode?: 'simple' | 'multiple';\n };\n hideTableHeader: boolean;\n useSmallHeaderSize?: boolean;\n tableBodyHeight?: string;\n}\n\n// TODO: tests will fail if we don't check attributeToDisplay because we have a render with no attributes but data is present. We should check why there's this behavior\nconst arePropsEqual = (prevProps: IDataViewProps, nextProps: IDataViewProps) =>\n isEqual(\n {\n attributesToDisplay: prevProps.attributesToDisplay,\n data: prevProps.dataGroupedFilteredSorted,\n selectedKeys: prevProps.selection.selectedKeys,\n },\n {\n attributesToDisplay: nextProps.attributesToDisplay,\n data: nextProps.dataGroupedFilteredSorted,\n selectedKeys: nextProps.selection.selectedKeys,\n },\n );\n\nexport const DataView: FunctionComponent<IDataViewProps> = memo(\n ({\n dataGroupedFilteredSorted,\n attributesToDisplay,\n attributesProperties,\n paginationProps,\n itemActions,\n selection: {onSelectItem, onSelectionChange, selectedKeys, isMassSelectionAll, mode},\n hideTableHeader = false,\n useSmallHeaderSize = false,\n tableBodyHeight,\n }) => {\n const {t} = useSharedTranslation();\n\n const {containerRef, scrollHeight} = useTableScrollableHeight(!!paginationProps);\n const {getFieldColumnWidth} = useColumnWidth();\n\n const getColumnProps = (attributeName: string) =>\n ({\n title: () => attributesProperties[attributeName].label,\n ellipsis: useSmallHeaderSize,\n width: getFieldColumnWidth(attributesProperties[attributeName]),\n shouldCellUpdate: (record, prevRecord) =>\n isMassSelectionAll ||\n record.propertiesById[attributeName] !== prevRecord.propertiesById[attributeName],\n render: (_, item) => (\n <TableCell\n attributeProperties={attributesProperties[attributeName]}\n values={item.propertiesById[attributeName]}\n />\n ),\n }) satisfies KitTableColumnType<IItemData>;\n\n const columns = attributesToDisplay.map(getColumnProps);\n\n const whoIAmColumn = useWhoAmIColumn({\n ...getColumnProps(WHO_AM_I_COLUMN),\n fixed: 'left',\n render: (_, item) => <TableNameCell item={item} itemActions={itemActions} />,\n shouldCellUpdate: (record, prevRecord) => isMassSelectionAll || record.whoAmI !== prevRecord.whoAmI,\n });\n\n const itemActionToUseOnRowClick = itemActions.find(itemAction => itemAction.useItemActionOnRowClick);\n\n const _rowSelection: ComponentProps<typeof KitTable>['rowSelection'] =\n onSelectionChange === null\n ? undefined\n : {\n type: mode === 'simple' ? 'radio' : 'checkbox',\n columnTitle: ' ', // blank string to hide select all checkbox from <KitTable />\n selectedRowKeys: selectedKeys,\n preserveSelectedRowKeys: true,\n // TODO: review types from antd directly\n onChange: (selectedRowKeys: Key[]) => {\n const lastSelectedKey = selectedRowKeys[selectedRowKeys.length - 1];\n const lastSelectedItem = dataGroupedFilteredSorted.find(data => data.key === lastSelectedKey);\n\n onSelectionChange(selectedRowKeys);\n\n if (lastSelectedItem) {\n onSelectItem?.(lastSelectedItem);\n }\n },\n getCheckboxProps: isMassSelectionAll\n ? () => ({\n disabled: true,\n })\n : undefined,\n };\n\n // TODO: handle columns width based on attribute type/format\n return (\n <DataViewContainerDivStyled ref={containerRef} className={cn({headless: hideTableHeader})}>\n <StyledTable\n className={cn({\n 'row-clickable': itemActionToUseOnRowClick,\n })}\n showHeader={dataGroupedFilteredSorted.length > 0 && !hideTableHeader}\n headerLineSize={useSmallHeaderSize ? 's' : undefined}\n columns={[whoIAmColumn, ...columns]}\n tableLayout=\"fixed\"\n scroll={{\n y: tableBodyHeight ?? (hideTableHeader ? '100%' : scrollHeight),\n x: '100%',\n }}\n dataSource={dataGroupedFilteredSorted}\n pagination={false}\n rowSelection={_rowSelection}\n onRow={(item: IItemData) => ({\n onClick: () => itemActionToUseOnRowClick?.callback(item),\n })}\n />\n {paginationProps && (\n <div className=\"pagination\">\n <KitPagination\n aria-label=\"pagination\"\n showSizeChanger\n showTotal={(total, [from, to]) =>\n t('explorer.pagination-total-number', {from, to, count: total})\n }\n total={paginationProps.totalCount}\n defaultCurrent={paginationProps.currentPage}\n defaultPageSize={paginationProps.pageSize}\n pageSizeOptions={paginationProps.pageSizeOptions}\n onChange={paginationProps.setNewPage}\n onShowSizeChange={paginationProps.setNewPageSize}\n />\n </div>\n )}\n </DataViewContainerDivStyled>\n );\n },\n arePropsEqual,\n);\n\n// This hook exists to change the width of the whoAmI column dynamically.\n// The aimed result is a whoAmI column that always expand and is the only one to expand if there is horizontal space available, but never shrinks under its specifed width.\n// This behaviour is mostly present to prevent the selection column to expand\nfunction useWhoAmIColumn(props: KitTableColumnType<IItemData> & {width: number}) {\n const {t} = useSharedTranslation();\n\n const [width, setWidth] = useState<number | string>(props.width);\n\n // initialize observer only once using the useState initializer\n const [resizeObserver] = useState(\n () =>\n new ResizeObserver(\n throttle(\n ([node]: ResizeObserverEntry[]) =>\n setWidth(node.contentRect.width < props.width ? props.width : '100%'),\n 100,\n ),\n ),\n );\n\n // use the `ref` prop as a callback to retrieve the div element and connect the observer on it\n const onWhoAmIColumnRender = useCallback((node: HTMLDivElement) => {\n resizeObserver.disconnect();\n if (node) {\n resizeObserver.observe(node);\n }\n }, []);\n\n return {\n ...props,\n title: () => <div ref={onWhoAmIColumnRender}>{t('explorer.name')}</div>,\n width,\n };\n}\n"]}
|
|
@@ -8,4 +8,3 @@ export declare const CREATE_RECORD_MODAL_CLASSNAME = "create-record-modal";
|
|
|
8
8
|
export declare const EDIT_RECORD_MODAL_CLASSNAME = "edit-record-modal";
|
|
9
9
|
export declare const WHO_AM_I_COLUMN = "whoAmI";
|
|
10
10
|
export declare const SNACKBAR_MASS_ID = "SNACKBAR_MASS_ID";
|
|
11
|
-
export declare const BREAK_TWO_LINES = "\n\n";
|
|
@@ -20,5 +20,4 @@ export const CREATE_RECORD_MODAL_CLASSNAME = 'create-record-modal';
|
|
|
20
20
|
export const EDIT_RECORD_MODAL_CLASSNAME = 'edit-record-modal';
|
|
21
21
|
export const WHO_AM_I_COLUMN = 'whoAmI';
|
|
22
22
|
export const SNACKBAR_MASS_ID = 'SNACKBAR_MASS_ID';
|
|
23
|
-
export const BREAK_TWO_LINES = '\n\n';
|
|
24
23
|
//# sourceMappingURL=_constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_constants.js","sourceRoot":"","sources":["../../../src/components/Explorer/_constants.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAGxC,yJAAyJ;AACzJ,MAAM,CAAC,MAAM,+BAA+B,GAAgC;IACxE,KAAK,EAAE,SAAS,CAAC,IAAI;IACrB,MAAM,EAAE,SAAS,CAAC,KAAK;IACvB,QAAQ,EAAE,SAAS,CAAC,QAAQ;IAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAgC;IACxE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO;IACzB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,QAAQ;IAC3B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU;CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAExC,MAAM,CAAC,MAAM,4BAA4B,GAAG,YAAY,CAAC;AAEzD,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AAEnE,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC
|
|
1
|
+
{"version":3,"file":"_constants.js","sourceRoot":"","sources":["../../../src/components/Explorer/_constants.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAGxC,yJAAyJ;AACzJ,MAAM,CAAC,MAAM,+BAA+B,GAAgC;IACxE,KAAK,EAAE,SAAS,CAAC,IAAI;IACrB,MAAM,EAAE,SAAS,CAAC,KAAK;IACvB,QAAQ,EAAE,SAAS,CAAC,QAAQ;IAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAgC;IACxE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO;IACzB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,QAAQ;IAC3B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU;CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAExC,MAAM,CAAC,MAAM,4BAA4B,GAAG,YAAY,CAAC;AAEzD,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AAEnE,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,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 {ViewTypes} from '_ui/_gqlTypes';\nimport {type ViewType} from './manage-view-settings/store-view-settings/viewSettingsReducer';\n\n//TODO: this mapping is here for backward compatibility. When the old explorer is removed, we should updates types on the backend and remove this mapping\nexport const mapViewTypeFromExplorerToLegacy: Record<ViewType, ViewTypes> = {\n table: ViewTypes.list,\n mosaic: ViewTypes.cards,\n timeline: ViewTypes.timeline,\n list: ViewTypes.list,\n};\n\nexport const mapViewTypeFromLegacyToExplorer: Record<ViewTypes, ViewType> = {\n [ViewTypes.list]: 'table',\n [ViewTypes.cards]: 'mosaic',\n [ViewTypes.timeline]: 'timeline',\n};\n\nexport const MASS_SELECTION_ALL = 'all';\n\nexport const LINK_RECORDS_MODAL_CLASSNAME = 'link-modal';\n\nexport const CREATE_RECORD_MODAL_CLASSNAME = 'create-record-modal';\n\nexport const EDIT_RECORD_MODAL_CLASSNAME = 'edit-record-modal';\n\nexport const WHO_AM_I_COLUMN = 'whoAmI';\n\nexport const SNACKBAR_MASS_ID = 'SNACKBAR_MASS_ID';\n"]}
|
|
@@ -3,12 +3,13 @@ import { jsx as _jsx } 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 { useMemo } from 'react';
|
|
6
|
-
import {
|
|
6
|
+
import { useConfirmModal } from '../../../hooks/useConfirmModal';
|
|
7
7
|
import { useActivateRecordsMutation, useDeactivateRecordsMutation, useDeleteValueMutation, } from '../../../_gqlTypes';
|
|
8
8
|
import { useSharedTranslation } from '../../../hooks/useSharedTranslation';
|
|
9
9
|
import { useValuesCacheUpdate } from '../../../hooks/useValuesCacheUpdate';
|
|
10
10
|
import { ViewSettingsActionTypes } from '../manage-view-settings';
|
|
11
|
-
import {
|
|
11
|
+
import { MASS_SELECTION_ALL } from '../_constants';
|
|
12
|
+
import { BREAK_TWO_LINES } from '../../../constants';
|
|
12
13
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
13
14
|
import { faTrash, faTrashRestore } from '@fortawesome/free-solid-svg-icons';
|
|
14
15
|
/**
|
|
@@ -25,6 +26,7 @@ import { faTrash, faTrashRestore } from '@fortawesome/free-solid-svg-icons';
|
|
|
25
26
|
*/
|
|
26
27
|
export const useEditStatusItemAction = ({ isEnabled, canDeleteLinkValues, store: { view, dispatch }, onRemove, entrypoint, }) => {
|
|
27
28
|
const { t } = useSharedTranslation();
|
|
29
|
+
const { openConfirmModal } = useConfirmModal();
|
|
28
30
|
const updateValuesCache = useValuesCacheUpdate();
|
|
29
31
|
const [deactivateRecordsMutation] = useDeactivateRecordsMutation({
|
|
30
32
|
update(cache, deactivatedRecords) {
|
|
@@ -127,15 +129,9 @@ export const useEditStatusItemAction = ({ isEnabled, canDeleteLinkValues, store:
|
|
|
127
129
|
? t('explorer.deactivate_item_description_one')
|
|
128
130
|
: t('explorer.activate_item_description_one')
|
|
129
131
|
: t('explorer.delete_link_description_one');
|
|
130
|
-
|
|
131
|
-
width: '100%',
|
|
132
|
-
style: { content: { width: '90vw', maxWidth: '656px' } },
|
|
133
|
-
type: 'confirm',
|
|
134
|
-
icon: false,
|
|
132
|
+
openConfirmModal({
|
|
135
133
|
title,
|
|
136
134
|
content: content + BREAK_TWO_LINES + t('global.are_you_sure'),
|
|
137
|
-
okText: t('global.confirm') ?? undefined,
|
|
138
|
-
cancelText: t('global.cancel') ?? undefined,
|
|
139
135
|
onOk: async () => {
|
|
140
136
|
switch (entrypoint.type) {
|
|
141
137
|
case 'library':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditStatusItemAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-item/useEditStatusItemAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAgB,OAAO,EAAC,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAGH,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAoD,uBAAuB,EAA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AAU,CAAC,IAAI,EAAE,CAAC;wBACtB,KAAK,SAAS;4BACV,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gCACd,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;4BACjC,CAAC;4BAED,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;wBAC/B,KAAK,MAAM;4BACP,MAAM,OAAO,GAAG,MAAM,wBAAwB,CAAC;gCAC3C,SAAS,EAAE;oCACP,OAAO,EAAE,UAAU,CAAC,eAAe;oCACnC,SAAS,EAAE,UAAU,CAAC,eAAe;oCACrC,QAAQ,EAAE,UAAU,CAAC,cAAc;oCACnC,KAAK,EAAE;wCACH,OAAO,EAAE,MAAM;wCACf,QAAQ;qCACX;iCACJ;6BACJ,CAAC,CAAC;4BACH,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;4BACjB,OAAO,OAAO,CAAC;wBACnB;4BACI,OAAO;oBACf,CAAC;gBACL,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,EACF;QACI,CAAC;QACD,yBAAyB;QACzB,wBAAwB;QACxB,uBAAuB;QACvB,mBAAmB;QACnB,UAAU,CAAC,IAAI;QACf,IAAI,CAAC,aAAa;QAClB,QAAQ;KACX,CACJ,CAAC;IAEF,OAAO;QACH,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI;KACjE,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 Dispatch, useMemo} from 'react';\nimport {KitModal} from 'aristid-ds';\nimport {\n type ActivateRecordsMutation,\n type DeactivateRecordsMutation,\n useActivateRecordsMutation,\n useDeactivateRecordsMutation,\n useDeleteValueMutation,\n} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {useValuesCacheUpdate} from '_ui/hooks/useValuesCacheUpdate';\nimport {type FeatureHook, type Entrypoint, type IEntrypointLink, type IItemAction, type IItemData} from '../_types';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {BREAK_TWO_LINES, MASS_SELECTION_ALL} from '../_constants';\nimport {type FetchResult} from '@apollo/client';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faTrash, faTrashRestore} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to get the action for `<DataView />` component.\n *\n * When the mutation for removing is done, the Apollo cache will be clean (`Record` and `RecordIdentity`)\n * from removed record.\n *\n * @param isEnabled - whether the action is present\n * @param view - represent the current view\n * @param dispatch - method to change the current view\n * @param entrypoint - represent the current entrypoint\n * @param canDeleteLinkValues - check permission to delete link values\n */\nexport const useEditStatusItemAction = ({\n isEnabled,\n canDeleteLinkValues,\n store: {view, dispatch},\n onRemove,\n entrypoint,\n}: FeatureHook<{\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n canDeleteLinkValues: boolean;\n onRemove?: IItemAction['callback'];\n entrypoint: Entrypoint;\n}>) => {\n const {t} = useSharedTranslation();\n const updateValuesCache = useValuesCacheUpdate();\n\n const [deactivateRecordsMutation] = useDeactivateRecordsMutation({\n update(cache, deactivatedRecords) {\n deactivatedRecords.data?.deactivateRecords.forEach(record => {\n cache.evict({\n id: cache.identify(record),\n });\n });\n cache.modify({\n fields: {\n records: prev => ({\n ...prev,\n totalCount: prev.totalCount - 1,\n }),\n },\n broadcast: false,\n });\n cache.gc();\n },\n });\n\n const [activateRecordsMutation] = useActivateRecordsMutation({\n update(cache, activatedRecords) {\n activatedRecords.data?.activateRecords.forEach(record => {\n cache.evict({\n id: cache.identify(record),\n });\n });\n cache.modify({\n fields: {\n records: prev => ({\n ...prev,\n totalCount: prev.totalCount - 1,\n }),\n },\n broadcast: false,\n });\n cache.gc();\n },\n });\n\n const [deleteRecordLinkMutation] = useDeleteValueMutation({\n update: (_, deletedRecord) => {\n const parentRecord = {\n id: (entrypoint as IEntrypointLink).parentRecordId,\n library: {\n id: (entrypoint as IEntrypointLink).parentLibraryId,\n },\n };\n updateValuesCache(parentRecord, deletedRecord.data?.deleteValue ?? []);\n },\n });\n\n const _deactivateItem = async (item: IItemData): Promise<FetchResult<DeactivateRecordsMutation>> => {\n const libRes = await deactivateRecordsMutation({\n variables: {\n libraryId: item.libraryId,\n recordsIds: [item.itemId],\n },\n });\n\n if (view.massSelection !== MASS_SELECTION_ALL) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: view.massSelection.filter(key => key !== item.itemId),\n });\n }\n\n onRemove?.(item);\n\n return libRes;\n };\n\n const _activateItem = async (item: IItemData): Promise<FetchResult<ActivateRecordsMutation>> => {\n const libRes = await activateRecordsMutation({\n variables: {\n libraryId: item.libraryId,\n recordsIds: [item.itemId],\n },\n });\n\n if (view.massSelection !== MASS_SELECTION_ALL) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: view.massSelection.filter(key => key !== item.itemId),\n });\n }\n\n return libRes;\n };\n\n const _editStatusItemAction: IItemAction = useMemo(\n () => ({\n label: (item: IItemData) =>\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate-item')\n : t('explorer.activate-item')\n : t('explorer.delete-item'),\n icon: (item: IItemData) => (\n <FontAwesomeIcon icon={entrypoint.type === 'library' && !item.active ? faTrashRestore : faTrash} />\n ),\n isDanger: true,\n disabled: (item: IItemData) =>\n entrypoint.type === 'link' ? !canDeleteLinkValues : item.active ? !item.canDelete : !item.canActivate,\n callback: item => {\n const {itemId, id_value} = item;\n\n const title =\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate_item_one')\n : t('explorer.activate_item_one')\n : t('explorer.delete_link_one');\n\n const content =\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate_item_description_one')\n : t('explorer.activate_item_description_one')\n : t('explorer.delete_link_description_one');\n\n KitModal.confirm({\n width: '100%',\n style: {content: {width: '90vw', maxWidth: '656px'}},\n type: 'confirm',\n icon: false,\n title,\n content: content + BREAK_TWO_LINES + t('global.are_you_sure'),\n okText: t('global.confirm') ?? undefined,\n cancelText: t('global.cancel') ?? undefined,\n onOk: async () => {\n switch (entrypoint.type) {\n case 'library':\n if (item.active) {\n return _deactivateItem(item);\n }\n\n return _activateItem(item);\n case 'link':\n const linkRes = await deleteRecordLinkMutation({\n variables: {\n library: entrypoint.parentLibraryId,\n attribute: entrypoint.linkAttributeId,\n recordId: entrypoint.parentRecordId,\n value: {\n payload: itemId,\n id_value,\n },\n },\n });\n onRemove?.(item);\n return linkRes;\n default:\n return;\n }\n },\n });\n },\n }),\n [\n t,\n deactivateRecordsMutation,\n deleteRecordLinkMutation,\n activateRecordsMutation,\n canDeleteLinkValues,\n entrypoint.type,\n view.massSelection,\n dispatch,\n ],\n );\n\n return {\n editStatusItemAction: isEnabled ? _editStatusItemAction : null,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"useEditStatusItemAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-item/useEditStatusItemAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAgB,OAAO,EAAC,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAGH,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe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,SAAS,EAAE,UAAU,CAAC,eAAe;oCACrC,QAAQ,EAAE,UAAU,CAAC,cAAc;oCACnC,KAAK,EAAE;wCACH,OAAO,EAAE,MAAM;wCACf,QAAQ;qCACX;iCACJ;6BACJ,CAAC,CAAC;4BACH,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;4BACjB,OAAO,OAAO,CAAC;wBACnB;4BACI,OAAO;oBACf,CAAC;gBACL,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,EACF;QACI,CAAC;QACD,yBAAyB;QACzB,wBAAwB;QACxB,uBAAuB;QACvB,mBAAmB;QACnB,UAAU,CAAC,IAAI;QACf,IAAI,CAAC,aAAa;QAClB,QAAQ;KACX,CACJ,CAAC;IAEF,OAAO;QACH,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI;KACjE,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 Dispatch, useMemo} from 'react';\nimport {useConfirmModal} from '_ui/hooks/useConfirmModal';\nimport {\n type ActivateRecordsMutation,\n type DeactivateRecordsMutation,\n useActivateRecordsMutation,\n useDeactivateRecordsMutation,\n useDeleteValueMutation,\n} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {useValuesCacheUpdate} from '_ui/hooks/useValuesCacheUpdate';\nimport {type FeatureHook, type Entrypoint, type IEntrypointLink, type IItemAction, type IItemData} from '../_types';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {BREAK_TWO_LINES} from '_ui/constants';\nimport {type FetchResult} from '@apollo/client';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faTrash, faTrashRestore} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to get the action for `<DataView />` component.\n *\n * When the mutation for removing is done, the Apollo cache will be clean (`Record` and `RecordIdentity`)\n * from removed record.\n *\n * @param isEnabled - whether the action is present\n * @param view - represent the current view\n * @param dispatch - method to change the current view\n * @param entrypoint - represent the current entrypoint\n * @param canDeleteLinkValues - check permission to delete link values\n */\nexport const useEditStatusItemAction = ({\n isEnabled,\n canDeleteLinkValues,\n store: {view, dispatch},\n onRemove,\n entrypoint,\n}: FeatureHook<{\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n canDeleteLinkValues: boolean;\n onRemove?: IItemAction['callback'];\n entrypoint: Entrypoint;\n}>) => {\n const {t} = useSharedTranslation();\n const {openConfirmModal} = useConfirmModal();\n const updateValuesCache = useValuesCacheUpdate();\n\n const [deactivateRecordsMutation] = useDeactivateRecordsMutation({\n update(cache, deactivatedRecords) {\n deactivatedRecords.data?.deactivateRecords.forEach(record => {\n cache.evict({\n id: cache.identify(record),\n });\n });\n cache.modify({\n fields: {\n records: prev => ({\n ...prev,\n totalCount: prev.totalCount - 1,\n }),\n },\n broadcast: false,\n });\n cache.gc();\n },\n });\n\n const [activateRecordsMutation] = useActivateRecordsMutation({\n update(cache, activatedRecords) {\n activatedRecords.data?.activateRecords.forEach(record => {\n cache.evict({\n id: cache.identify(record),\n });\n });\n cache.modify({\n fields: {\n records: prev => ({\n ...prev,\n totalCount: prev.totalCount - 1,\n }),\n },\n broadcast: false,\n });\n cache.gc();\n },\n });\n\n const [deleteRecordLinkMutation] = useDeleteValueMutation({\n update: (_, deletedRecord) => {\n const parentRecord = {\n id: (entrypoint as IEntrypointLink).parentRecordId,\n library: {\n id: (entrypoint as IEntrypointLink).parentLibraryId,\n },\n };\n updateValuesCache(parentRecord, deletedRecord.data?.deleteValue ?? []);\n },\n });\n\n const _deactivateItem = async (item: IItemData): Promise<FetchResult<DeactivateRecordsMutation>> => {\n const libRes = await deactivateRecordsMutation({\n variables: {\n libraryId: item.libraryId,\n recordsIds: [item.itemId],\n },\n });\n\n if (view.massSelection !== MASS_SELECTION_ALL) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: view.massSelection.filter(key => key !== item.itemId),\n });\n }\n\n onRemove?.(item);\n\n return libRes;\n };\n\n const _activateItem = async (item: IItemData): Promise<FetchResult<ActivateRecordsMutation>> => {\n const libRes = await activateRecordsMutation({\n variables: {\n libraryId: item.libraryId,\n recordsIds: [item.itemId],\n },\n });\n\n if (view.massSelection !== MASS_SELECTION_ALL) {\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: view.massSelection.filter(key => key !== item.itemId),\n });\n }\n\n return libRes;\n };\n\n const _editStatusItemAction: IItemAction = useMemo(\n () => ({\n label: (item: IItemData) =>\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate-item')\n : t('explorer.activate-item')\n : t('explorer.delete-item'),\n icon: (item: IItemData) => (\n <FontAwesomeIcon icon={entrypoint.type === 'library' && !item.active ? faTrashRestore : faTrash} />\n ),\n isDanger: true,\n disabled: (item: IItemData) =>\n entrypoint.type === 'link' ? !canDeleteLinkValues : item.active ? !item.canDelete : !item.canActivate,\n callback: item => {\n const {itemId, id_value} = item;\n\n const title =\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate_item_one')\n : t('explorer.activate_item_one')\n : t('explorer.delete_link_one');\n\n const content =\n entrypoint.type === 'library'\n ? item.active\n ? t('explorer.deactivate_item_description_one')\n : t('explorer.activate_item_description_one')\n : t('explorer.delete_link_description_one');\n\n openConfirmModal({\n title,\n content: content + BREAK_TWO_LINES + t('global.are_you_sure'),\n onOk: async () => {\n switch (entrypoint.type) {\n case 'library':\n if (item.active) {\n return _deactivateItem(item);\n }\n\n return _activateItem(item);\n case 'link':\n const linkRes = await deleteRecordLinkMutation({\n variables: {\n library: entrypoint.parentLibraryId,\n attribute: entrypoint.linkAttributeId,\n recordId: entrypoint.parentRecordId,\n value: {\n payload: itemId,\n id_value,\n },\n },\n });\n onRemove?.(item);\n return linkRes;\n default:\n return;\n }\n },\n });\n },\n }),\n [\n t,\n deactivateRecordsMutation,\n deleteRecordLinkMutation,\n activateRecordsMutation,\n canDeleteLinkValues,\n entrypoint.type,\n view.massSelection,\n dispatch,\n ],\n );\n\n return {\n editStatusItemAction: isEnabled ? _editStatusItemAction : null,\n };\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { KitTypography } from 'aristid-ds';
|
|
3
|
-
export const ResultsCount = ({ t, isInactive, totalCountFiltered, totalCountLibrary, }) => (_jsxs(
|
|
2
|
+
import { KitSpace, KitTypography } from 'aristid-ds';
|
|
3
|
+
export const ResultsCount = ({ t, isInactive, totalCountFiltered, totalCountLibrary, }) => (_jsxs(KitSpace, { direction: "horizontal", size: "xxs", children: [_jsx(KitTypography.Text, { weight: "bold", size: "fontSize7", children: isInactive
|
|
4
4
|
? `${totalCountLibrary} `
|
|
5
5
|
: totalCountFiltered === totalCountLibrary
|
|
6
6
|
? `${totalCountLibrary} `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResultsCount.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/ResultsCount.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ResultsCount.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/ResultsCount.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAUnD,MAAM,CAAC,MAAM,YAAY,GAAyC,CAAC,EAC/D,CAAC,EACD,UAAU,EACV,kBAAkB,EAClB,iBAAiB,GACpB,EAAE,EAAE,CAAC,CACF,MAAC,QAAQ,IAAC,SAAS,EAAC,YAAY,EAAC,IAAI,EAAC,KAAK,aACvC,KAAC,aAAa,CAAC,IAAI,IAAC,MAAM,EAAC,MAAM,EAAC,IAAI,EAAC,WAAW,YAC7C,UAAU;gBACP,CAAC,CAAC,GAAG,iBAAiB,GAAG;gBACzB,CAAC,CAAC,kBAAkB,KAAK,iBAAiB;oBACxC,CAAC,CAAC,GAAG,iBAAiB,GAAG;oBACzB,CAAC,CAAC,GAAG,kBAAkB,MAAM,iBAAiB,GAAG,GACtC,EACrB,KAAC,aAAa,CAAC,IAAI,IAAC,MAAM,EAAC,QAAQ,EAAC,IAAI,EAAC,WAAW,YAC/C,CAAC,CAAC,6BAA6B,EAAE,EAAC,KAAK,EAAE,iBAAiB,EAAC,CAAC,GAC5C,IACd,CACd,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 useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {KitSpace, KitTypography} from 'aristid-ds';\nimport {type FunctionComponent} from 'react';\n\ninterface IResultCountProps {\n t: ReturnType<typeof useSharedTranslation>['t'];\n isInactive: boolean;\n totalCountFiltered: number;\n totalCountLibrary: number;\n}\n\nexport const ResultsCount: FunctionComponent<IResultCountProps> = ({\n t,\n isInactive,\n totalCountFiltered,\n totalCountLibrary,\n}) => (\n <KitSpace direction=\"horizontal\" size=\"xxs\">\n <KitTypography.Text weight=\"bold\" size=\"fontSize7\">\n {isInactive\n ? `${totalCountLibrary} `\n : totalCountFiltered === totalCountLibrary\n ? `${totalCountLibrary} `\n : `${totalCountFiltered} / ${totalCountLibrary} `}\n </KitTypography.Text>\n <KitTypography.Text weight=\"medium\" size=\"fontSize7\">\n {t('explorer.massAction.results', {count: totalCountLibrary})}\n </KitTypography.Text>\n </KitSpace>\n);\n"]}
|
|
@@ -3,12 +3,13 @@ import { jsx as _jsx } 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 { useMemo } from 'react';
|
|
6
|
-
import { KitAlert
|
|
6
|
+
import { KitAlert } from 'aristid-ds';
|
|
7
7
|
import { useDeactivateRecordsMutation } from '../../../_gqlTypes';
|
|
8
8
|
import { useSharedTranslation } from '../../../hooks/useSharedTranslation';
|
|
9
|
+
import { useConfirmModal } from '../../../hooks/useConfirmModal';
|
|
9
10
|
import { ViewSettingsActionTypes } from '../manage-view-settings';
|
|
10
|
-
import {
|
|
11
|
-
import { SUCCESS_ALERT_DURATION } from '../../../constants';
|
|
11
|
+
import { MASS_SELECTION_ALL } from '../_constants';
|
|
12
|
+
import { SUCCESS_ALERT_DURATION, BREAK_TWO_LINES } from '../../../constants';
|
|
12
13
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
13
14
|
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
|
14
15
|
/**
|
|
@@ -26,17 +27,14 @@ import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
|
|
26
27
|
*/
|
|
27
28
|
export const useDeactivateMassAction = ({ isEnabled, store: { view, dispatch }, allVisibleKeys, totalCount, onDeactivate, refetch, }) => {
|
|
28
29
|
const { t } = useSharedTranslation();
|
|
30
|
+
const { openConfirmModal } = useConfirmModal();
|
|
29
31
|
const [deactivateRecordsMutation] = useDeactivateRecordsMutation();
|
|
30
32
|
const _deactivateMassAction = useMemo(() => ({
|
|
31
33
|
label: t('explorer.massAction.deactivate'),
|
|
32
34
|
icon: _jsx(FontAwesomeIcon, { icon: faTrash }),
|
|
33
35
|
deselectAll: true,
|
|
34
36
|
callback: massSelectionFilter => {
|
|
35
|
-
|
|
36
|
-
width: '100%',
|
|
37
|
-
style: { content: { width: '90vw', maxWidth: '656px' } },
|
|
38
|
-
type: 'confirm',
|
|
39
|
-
icon: false,
|
|
37
|
+
openConfirmModal({
|
|
40
38
|
title: t('explorer.deactivate_item', {
|
|
41
39
|
count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,
|
|
42
40
|
}) ?? undefined,
|
|
@@ -45,8 +43,6 @@ export const useDeactivateMassAction = ({ isEnabled, store: { view, dispatch },
|
|
|
45
43
|
}) +
|
|
46
44
|
BREAK_TWO_LINES +
|
|
47
45
|
t('global.are_you_sure'),
|
|
48
|
-
okText: t('global.confirm') ?? undefined,
|
|
49
|
-
cancelText: t('global.cancel') ?? undefined,
|
|
50
46
|
onOk: async () => {
|
|
51
47
|
const { data } = await deactivateRecordsMutation({
|
|
52
48
|
variables: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeactivateMassAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useDeactivateMassAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAgB,OAAO,EAAC,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"useDeactivateMassAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useDeactivateMassAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAgB,OAAO,EAAC,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,4BAA4B,EAAC,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,sBAAsB,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AACtE,OAAO,EAAC,eAAe,EAAC,M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AAO,CAAC,CACxG,CAAC;IAEF,OAAO;QACH,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI;KACjE,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 Dispatch, useMemo} from 'react';\nimport {KitAlert} from 'aristid-ds';\nimport {useDeactivateRecordsMutation} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {useConfirmModal} from '_ui/hooks/useConfirmModal';\nimport {type FeatureHook, type IMassActions} from '../_types';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {type useExplorerData} from '../_queries/useExplorerData';\nimport {SUCCESS_ALERT_DURATION, BREAK_TWO_LINES} from '_ui/constants';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faTrash} from '@fortawesome/free-solid-svg-icons';\n\n/**\n * Hook used to get the action for mass actions only available on selection.\n *\n * When the mutation for deactivation is done, the Apollo cache will be clean (`Record` and `RecordIdentity`)\n * from deactivated record.\n *\n * @param isEnabled - whether the action is present\n * @param view - represent the current view\n * @param dispatch - method to change the current view\n * @param libraryId - concerned library\n * @param allVisibleKeys - list of all visible keys used to know if we need to change page\n * @param refetch - method to get fresh data when we delete last page\n */\nexport const useDeactivateMassAction = ({\n isEnabled,\n store: {view, dispatch},\n allVisibleKeys,\n totalCount,\n onDeactivate,\n refetch,\n}: FeatureHook<{\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n allVisibleKeys: string[];\n totalCount: number;\n onDeactivate?: IMassActions['callback'];\n refetch: ReturnType<typeof useExplorerData>['refetch'];\n}>) => {\n const {t} = useSharedTranslation();\n const {openConfirmModal} = useConfirmModal();\n\n const [deactivateRecordsMutation] = useDeactivateRecordsMutation();\n\n const _deactivateMassAction: IMassActions = useMemo(\n () => ({\n label: t('explorer.massAction.deactivate'),\n icon: <FontAwesomeIcon icon={faTrash} />,\n deselectAll: true,\n callback: massSelectionFilter => {\n openConfirmModal({\n title:\n t('explorer.deactivate_item', {\n count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,\n }) ?? undefined,\n content:\n t('explorer.deactivate_item_description', {\n count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,\n }) +\n BREAK_TWO_LINES +\n t('global.are_you_sure'),\n onOk: async () => {\n const {data} = await deactivateRecordsMutation({\n variables: {\n libraryId: view.libraryId,\n filters: massSelectionFilter,\n },\n });\n const total =\n view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length;\n KitAlert.success({\n showIcon: true,\n duration: SUCCESS_ALERT_DURATION,\n message: t('explorer.massAction.deactivate_message'),\n description: t('explorer.massAction.deactivate_description', {\n count: data?.deactivateRecords.length,\n total,\n }),\n closable: true,\n });\n if (\n view.massSelection === MASS_SELECTION_ALL ||\n allVisibleKeys.every(key => view.massSelection.includes(key))\n ) {\n await refetch({\n pagination: {\n limit: view.pageSize,\n offset: 0,\n },\n });\n } else {\n await refetch();\n }\n onDeactivate?.(massSelectionFilter, view.massSelection);\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: [],\n });\n },\n });\n },\n }),\n [t, deactivateRecordsMutation, view.massSelection, dispatch, view.libraryId, allVisibleKeys, refetch],\n );\n\n return {\n deactivateMassAction: isEnabled ? _deactivateMassAction : null,\n };\n};\n"]}
|
|
@@ -7,12 +7,14 @@ import { ViewSettingsActionTypes } from '../manage-view-settings';
|
|
|
7
7
|
import { useMemo } from 'react';
|
|
8
8
|
import { useExplorerData } from '../_queries/useExplorerData';
|
|
9
9
|
import { useSharedTranslation } from '../../../hooks/useSharedTranslation';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { useConfirmModal } from '../../../hooks/useConfirmModal';
|
|
11
|
+
import { MASS_SELECTION_ALL } from '../_constants';
|
|
12
|
+
import { BREAK_TWO_LINES } from '../../../constants';
|
|
12
13
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
13
14
|
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
|
14
15
|
export const useDeleteLinkValues = ({ isEnabled, store: { view, dispatch }, filtersStore: { filters, filtersOperator }, pagination, allVisibleKeys, onDelete, refetch, }) => {
|
|
15
16
|
const { t } = useSharedTranslation();
|
|
17
|
+
const { openConfirmModal } = useConfirmModal();
|
|
16
18
|
const { saveValues } = useSaveValueBatchMutation();
|
|
17
19
|
const isLink = view.entrypoint.type === 'link';
|
|
18
20
|
const { data: linkData, canEditLinkAttributeValues: canUnlinkValues } = useExplorerData({
|
|
@@ -31,11 +33,7 @@ export const useDeleteLinkValues = ({ isEnabled, store: { view, dispatch }, filt
|
|
|
31
33
|
icon: _jsx(FontAwesomeIcon, { icon: faTrash }),
|
|
32
34
|
deselectAll: true,
|
|
33
35
|
callback: massSelectionFilter => {
|
|
34
|
-
|
|
35
|
-
width: '100%',
|
|
36
|
-
style: { content: { width: '90vw', maxWidth: '656px' } },
|
|
37
|
-
type: 'confirm',
|
|
38
|
-
icon: false,
|
|
36
|
+
openConfirmModal({
|
|
39
37
|
title: t('explorer.delete_link', {
|
|
40
38
|
count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,
|
|
41
39
|
}) ?? undefined,
|
|
@@ -45,7 +43,6 @@ export const useDeleteLinkValues = ({ isEnabled, store: { view, dispatch }, filt
|
|
|
45
43
|
BREAK_TWO_LINES +
|
|
46
44
|
t('global.are_you_sure'),
|
|
47
45
|
okText: t('global.submit') ?? undefined,
|
|
48
|
-
cancelText: t('global.cancel') ?? undefined,
|
|
49
46
|
onOk: async () => {
|
|
50
47
|
const entrypoint = view.entrypoint;
|
|
51
48
|
let values;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeleteLinkValues.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useDeleteLinkValues.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,yBAAyB,MAAM,uFAAuF,CAAC;AAE9H,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAA0B,OAAO,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"useDeleteLinkValues.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useDeleteLinkValues.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,yBAAyB,MAAM,uFAAuF,CAAC;AAE9H,OAAO,EAAoD,uBAAuB,EAAC,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAA0B,OAAO,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAG9C,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,OAAO,EAAC,MAAM,mCAAmC,CAAC;AAE1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAChC,SAAS,EACT,KAAK,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,EACvB,YAAY,EAAE,EAAC,OAAO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MAAM,GAAG,CAAC,EAAE,CAAC;wBACpB,MAAM,UAAU,CACZ;4BACI,EAAE,EAAE,UAAU,CAAC,cAAc;4BAC7B,OAAO,EAAE;gCACL,EAAE,EAAE,UAAU,CAAC,eAAe;6BACjC;yBACJ,EACD,MAAM,EACN,SAAS,EACT,IAAI,CACP,CAAC;wBAEF,QAAQ,EAAE,CACN,mBAAmB,EACnB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAc,CAAC,CAC5C,CAAC;wBACF,MAAM,OAAO,EAAE,CAAC;oBACpB,CAAC;oBACD,QAAQ,CAAC;wBACL,IAAI,EAAE,uBAAuB,CAAC,iBAAiB;wBAC/C,OAAO,EAAE,EAAE;qBACd,CAAC,CAAC;gBACP,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,EACF,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAChF,CAAC;IAEF,OAAO;QACH,gBAAgB,EAAE,SAAS,IAAI,eAAe,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI;KAC5E,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 useSaveValueBatchMutation from '_ui/components/RecordEdition/EditRecordContent/hooks/useExecuteSaveValueBatchMutation';\nimport {type FeatureHook, type IEntrypointLink, type IMassActions} from '../_types';\nimport {type IViewSettingsAction, type IViewSettingsState, ViewSettingsActionTypes} from '../manage-view-settings';\nimport {type Dispatch, type Key, useMemo} from 'react';\nimport {useExplorerData} from '../_queries/useExplorerData';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {useConfirmModal} from '_ui/hooks/useConfirmModal';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {BREAK_TWO_LINES} from '_ui/constants';\nimport {type IValueToSubmit} from '_ui/components/RecordEdition/EditRecordContent/_types';\nimport {type IUIFiltersState} from '_ui/components/Filters/context/filtersReducer';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faTrash} from '@fortawesome/free-solid-svg-icons';\n\nexport const useDeleteLinkValues = ({\n isEnabled,\n store: {view, dispatch},\n filtersStore: {filters, filtersOperator},\n pagination,\n allVisibleKeys,\n onDelete,\n refetch,\n}: FeatureHook<{\n pagination: null | {limit: number; offset: number};\n store: {\n view: IViewSettingsState;\n dispatch: Dispatch<IViewSettingsAction>;\n };\n filtersStore: IUIFiltersState;\n allVisibleKeys: string[];\n onDelete?: IMassActions['callback'];\n refetch: ReturnType<typeof useExplorerData>['refetch'];\n}>) => {\n const {t} = useSharedTranslation();\n const {openConfirmModal} = useConfirmModal();\n const {saveValues} = useSaveValueBatchMutation();\n\n const isLink = view.entrypoint.type === 'link';\n const {data: linkData, canEditLinkAttributeValues: canUnlinkValues} = useExplorerData({\n entrypoint: view.entrypoint,\n libraryId: view.libraryId,\n attributeIds: view.attributesIds,\n fulltextSearch: view.fulltextSearch,\n pagination,\n sorts: view.sort,\n filtersOperator,\n filters,\n skip: !isLink,\n });\n\n const _unlinkMassAction: IMassActions = useMemo(\n () => ({\n label: t('explorer.massAction.deactivate'),\n icon: <FontAwesomeIcon icon={faTrash} />,\n deselectAll: true,\n callback: massSelectionFilter => {\n openConfirmModal({\n title:\n t('explorer.delete_link', {\n count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,\n }) ?? undefined,\n content:\n t('explorer.delete_link_description', {\n count: view.massSelection === MASS_SELECTION_ALL ? Infinity : view.massSelection.length,\n }) +\n BREAK_TWO_LINES +\n t('global.are_you_sure'),\n okText: t('global.submit') ?? undefined,\n onOk: async () => {\n const entrypoint = view.entrypoint as IEntrypointLink;\n let values: IValueToSubmit[];\n if (\n view.massSelection === MASS_SELECTION_ALL ||\n allVisibleKeys.every(key => view.massSelection.includes(key))\n ) {\n values =\n (linkData?.records ?? []).map(({id_value}) => ({\n attribute: entrypoint.linkAttributeId,\n idValue: id_value ?? null,\n value: null,\n })) ?? [];\n } else {\n values = (linkData?.records ?? []).reduce<IValueToSubmit[]>((acc, {id_value, key}) => {\n if (view.massSelection.includes(key)) {\n acc.push({\n attribute: entrypoint.linkAttributeId,\n idValue: id_value ?? null,\n value: null,\n });\n }\n return acc;\n }, []);\n }\n\n if (values.length > 0) {\n await saveValues(\n {\n id: entrypoint.parentRecordId,\n library: {\n id: entrypoint.parentLibraryId,\n },\n },\n values,\n undefined,\n true,\n );\n\n onDelete?.(\n massSelectionFilter,\n values.map(({idValue}) => idValue as Key),\n );\n await refetch();\n }\n dispatch({\n type: ViewSettingsActionTypes.SET_SELECTED_KEYS,\n payload: [],\n });\n },\n });\n },\n }),\n [t, saveValues, view.massSelection, dispatch, view.libraryId, allVisibleKeys],\n );\n\n return {\n unlinkMassAction: isEnabled && canUnlinkValues ? _unlinkMassAction : null,\n };\n};\n"]}
|
|
@@ -53,10 +53,12 @@ export const useEditAttributeMassAction = ({ isEnabled, store: { view }, totalCo
|
|
|
53
53
|
setSelectedAttribute(undefined);
|
|
54
54
|
setEditionMapping([]);
|
|
55
55
|
};
|
|
56
|
-
const isMappingCompleted = useMemo(() =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const isMappingCompleted = useMemo(() => {
|
|
57
|
+
const editionMappingValuesLength = editionMapping.reduce((acc, curr) => acc + curr.values.length, 0);
|
|
58
|
+
return valuesOccurrences.noValueCount === 0
|
|
59
|
+
? editionMappingValuesLength === valuesOccurrences.occurrences.length
|
|
60
|
+
: editionMappingValuesLength + 1; // for undefined values
|
|
61
|
+
}, [editionMapping, valuesOccurrences]);
|
|
60
62
|
const bulkCounter = useMemo(() => (view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length), [view.massSelection, totalCount]);
|
|
61
63
|
const onOkButtonClick = async () => {
|
|
62
64
|
if (!selectedAttribute || !isMappingCompleted) {
|
|
@@ -68,7 +70,7 @@ export const useEditAttributeMassAction = ({ isEnabled, store: { view }, totalCo
|
|
|
68
70
|
libraryId: view.libraryId,
|
|
69
71
|
recordsFilters: massSelectionFilter,
|
|
70
72
|
attributeId: selectedAttribute.id,
|
|
71
|
-
|
|
73
|
+
mapping: editionMapping,
|
|
72
74
|
},
|
|
73
75
|
});
|
|
74
76
|
closeModal();
|
|
@@ -100,7 +102,13 @@ export const useEditAttributeMassAction = ({ isEnabled, store: { view }, totalCo
|
|
|
100
102
|
return {
|
|
101
103
|
editAttributeMassAction: _editAttributeMassAction,
|
|
102
104
|
editAttributeMassActionModal: (_jsxs(EditAttributeMassActionModal, { isOpen: openModal, attributes: editableAttributes, setSelectedAttribute: setSelectedAttribute, massSelectionFilter: massSelectionFilter, elementsCount: bulkCounter, disableOkButton: !isMappingCompleted, onOkButtonClick: onOkButtonClick, onCancelButtonClick: closeModal, children: [selectedAttribute != null && valuesOccurrences.loading ? _jsx(Loading, {}) : null, selectedAttribute?.type === AttributeType.tree && (_jsx(EditTreeAttributeValuesMapping, { selectedAttribute: selectedAttribute, valuesOccurrences: valuesOccurrences, setAttributeMapping: (before, after) => {
|
|
103
|
-
setEditionMapping(
|
|
105
|
+
setEditionMapping([
|
|
106
|
+
{
|
|
107
|
+
values: (editionMapping[0]?.values ?? [])
|
|
108
|
+
.filter(value => value.before !== before)
|
|
109
|
+
.concat([{ before, after }]),
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
104
112
|
} }))] })),
|
|
105
113
|
};
|
|
106
114
|
};
|