@leav/ui 1.12.0-36d55f01 → 1.12.0-38b7d0f2
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/_gqlTypes/index.d.ts +243 -94
- package/dist/_gqlTypes/index.js +190 -48
- package/dist/_gqlTypes/index.js.map +1 -1
- package/dist/components/Explorer/DataView.js +1 -1
- package/dist/components/Explorer/DataView.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/EditAttributeMassActionModal.d.ts +4 -9
- package/dist/components/Explorer/actions-mass/edit-attribute/EditAttributeMassActionModal.js +3 -11
- package/dist/components/Explorer/actions-mass/edit-attribute/EditAttributeMassActionModal.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.d.ts +8 -8
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.js +26 -13
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/TreeNodeRemap.d.ts +7 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/TreeNodeRemap.js +30 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/TreeNodeRemap.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/_types.d.ts +23 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/_types.js +2 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/_types.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useMassEditableAttributes.d.ts +4 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useMassEditableAttributes.js +46 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useMassEditableAttributes.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.d.ts +12 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.js +24 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.d.ts +13 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.js +28 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.js.map +1 -0
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.d.ts +8 -2
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js +104 -80
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useMassActions.js +18 -13
- package/dist/components/Explorer/actions-mass/useMassActions.js.map +1 -1
- package/dist/locales/en/shared.json +4 -4
- package/dist/locales/fr/shared.json +5 -5
- package/package.json +3 -3
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.d.ts +0 -8
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.js +0 -40
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.js.map +0 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.d.ts +0 -17
- package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.js +0 -42
- package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.js.map +0 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useListEditableAttributeHook.d.ts +0 -5
- package/dist/components/Explorer/actions-mass/edit-attribute/useListEditableAttributeHook.js +0 -20
- package/dist/components/Explorer/actions-mass/edit-attribute/useListEditableAttributeHook.js.map +0 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useListTreeAttributeValuesHook.d.ts +0 -12
- package/dist/components/Explorer/actions-mass/edit-attribute/useListTreeAttributeValuesHook.js +0 -30
- package/dist/components/Explorer/actions-mass/edit-attribute/useListTreeAttributeValuesHook.js.map +0 -1
|
@@ -2,88 +2,52 @@ 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 {
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
7
|
+
import { faEdit } from '@fortawesome/free-solid-svg-icons';
|
|
8
|
+
import { KitAlert, KitEmpty, KitNotification, KitSelect, KitSpace, KitTypography } from 'aristid-ds';
|
|
9
|
+
import { localizedTranslation } from '@leav/utils';
|
|
10
|
+
import { useSaveValueBulkMutation } from '../../../_gqlTypes';
|
|
6
11
|
import { useSharedTranslation } from '../../../hooks/useSharedTranslation';
|
|
7
|
-
import {
|
|
12
|
+
import { ERROR_ALERT_DURATION, INFO_NOTIFICATION_DURATION } from '../../../constants';
|
|
13
|
+
import { useLang } from '../../../hooks';
|
|
8
14
|
import { MASS_SELECTION_ALL } from '../_constants';
|
|
9
15
|
import { EditTreeAttributeValuesMapping } from './edit-attribute/EditTreeAttributeValuesMapping';
|
|
10
16
|
import { EditAttributeMassActionModal } from './edit-attribute/EditAttributeMassActionModal';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
import { KitAlert, KitNotification } from 'aristid-ds';
|
|
14
|
-
import { ERROR_ALERT_DURATION, INFO_NOTIFICATION_DURATION } from '../../../constants';
|
|
15
|
-
import { Loading } from '../../../components/Loading';
|
|
16
|
-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
17
|
-
import { faEdit } from '@fortawesome/free-solid-svg-icons';
|
|
17
|
+
import { useMassEditableAttributes } from './edit-attribute/useMassEditableAttributes';
|
|
18
|
+
const EDITION_MAPPING_DEFAULT_VALUES = { count: 0, mapping: [] };
|
|
18
19
|
export const useEditAttributeMassAction = ({ isEnabled, store: { view }, totalCount, }) => {
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
editAttributeMassAction: null,
|
|
22
|
-
editAttributeMassActionModal: null,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
20
|
+
const { lang: availableLanguages } = useLang();
|
|
25
21
|
const { t } = useSharedTranslation();
|
|
26
|
-
const [selectedAttribute, setSelectedAttribute] = useState(undefined);
|
|
27
|
-
const [massSelectionFilter, setMassSelectionFilter] = useState([]);
|
|
28
22
|
const [openModal, setOpenModal] = useState(false);
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
libraryId: view.libraryId,
|
|
34
|
-
recordFilters: massSelectionFilter,
|
|
35
|
-
});
|
|
23
|
+
// Represent the current selection, used to apply modifications to correct records
|
|
24
|
+
const [massSelectionFilters, setMassSelectionFilters] = useState([]);
|
|
25
|
+
const editableAttributes = useMassEditableAttributes({ libraryId: view.libraryId });
|
|
26
|
+
const [selectedAttribute, setSelectedAttribute] = useState(null);
|
|
36
27
|
const [executeSaveValueBulk] = useSaveValueBulkMutation();
|
|
28
|
+
const [editionMapping, setEditionMapping] = useState(EDITION_MAPPING_DEFAULT_VALUES);
|
|
37
29
|
useEffect(() => {
|
|
38
|
-
setEditionMapping(
|
|
30
|
+
setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);
|
|
39
31
|
}, [selectedAttribute]);
|
|
40
|
-
const
|
|
41
|
-
label: t('explorer.massAction.editAttribute'),
|
|
42
|
-
icon: _jsx(FontAwesomeIcon, { icon: faEdit }),
|
|
43
|
-
deselectAll: false,
|
|
44
|
-
callback: _massSelectionFilter => {
|
|
45
|
-
setMassSelectionFilter(_massSelectionFilter);
|
|
46
|
-
setEditionMapping([]);
|
|
47
|
-
setOpenModal(true);
|
|
48
|
-
},
|
|
49
|
-
}), [t, view.massSelection]);
|
|
50
|
-
const closeModal = () => {
|
|
32
|
+
const _closeModal = () => {
|
|
51
33
|
setOpenModal(false);
|
|
52
|
-
|
|
53
|
-
setSelectedAttribute(
|
|
54
|
-
setEditionMapping(
|
|
34
|
+
setMassSelectionFilters([]);
|
|
35
|
+
setSelectedAttribute(null);
|
|
36
|
+
setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);
|
|
55
37
|
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
? editionMappingValuesLength === valuesOccurrences.occurrences.length
|
|
60
|
-
: editionMappingValuesLength + 1; // for undefined values
|
|
61
|
-
}, [editionMapping, valuesOccurrences]);
|
|
62
|
-
const bulkCounter = useMemo(() => (view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length), [view.massSelection, totalCount]);
|
|
63
|
-
const onOkButtonClick = async () => {
|
|
64
|
-
if (!selectedAttribute || !isMappingCompleted) {
|
|
38
|
+
const bulkCount = view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length;
|
|
39
|
+
const _saveEditionMapping = () => {
|
|
40
|
+
if (!selectedAttribute || editionMapping.count === 0) {
|
|
65
41
|
return;
|
|
66
42
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
closeModal();
|
|
77
|
-
KitNotification.info({
|
|
78
|
-
message: t('explorer.massAction.editAttribute_submit_notification_title'),
|
|
79
|
-
description: t('explorer.massAction.editAttribute_submit_notification_description', {
|
|
80
|
-
counter: bulkCounter,
|
|
81
|
-
}),
|
|
82
|
-
duration: INFO_NOTIFICATION_DURATION,
|
|
83
|
-
closable: true,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
43
|
+
executeSaveValueBulk({
|
|
44
|
+
variables: {
|
|
45
|
+
libraryId: view.libraryId,
|
|
46
|
+
recordsFilters: massSelectionFilters,
|
|
47
|
+
attributeId: selectedAttribute.id,
|
|
48
|
+
mapping: editionMapping.mapping,
|
|
49
|
+
},
|
|
50
|
+
}).catch(() => {
|
|
87
51
|
KitAlert.error({
|
|
88
52
|
showIcon: true,
|
|
89
53
|
duration: ERROR_ALERT_DURATION,
|
|
@@ -91,25 +55,85 @@ export const useEditAttributeMassAction = ({ isEnabled, store: { view }, totalCo
|
|
|
91
55
|
description: t('explorer.massAction.editAttribute_submit_error'),
|
|
92
56
|
closable: true,
|
|
93
57
|
});
|
|
94
|
-
}
|
|
58
|
+
});
|
|
59
|
+
_closeModal();
|
|
60
|
+
KitNotification.info({
|
|
61
|
+
message: t('explorer.massAction.editAttribute_submit_notification_title'),
|
|
62
|
+
description: t('explorer.massAction.editAttribute_submit_notification_description', {
|
|
63
|
+
count: editionMapping.count,
|
|
64
|
+
}) ?? undefined,
|
|
65
|
+
duration: INFO_NOTIFICATION_DURATION,
|
|
66
|
+
closable: true,
|
|
67
|
+
});
|
|
95
68
|
};
|
|
96
|
-
|
|
69
|
+
// TODO: https://aristid.atlassian.net/browse/LEAVC-830
|
|
70
|
+
if (!isEnabled || editableAttributes.length === 0) {
|
|
97
71
|
return {
|
|
98
72
|
editAttributeMassAction: null,
|
|
99
73
|
editAttributeMassActionModal: null,
|
|
100
74
|
};
|
|
101
75
|
}
|
|
102
76
|
return {
|
|
103
|
-
editAttributeMassAction:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
77
|
+
editAttributeMassAction: {
|
|
78
|
+
label: t('explorer.massAction.editAttribute'),
|
|
79
|
+
icon: _jsx(FontAwesomeIcon, { icon: faEdit }),
|
|
80
|
+
deselectAll: false,
|
|
81
|
+
callback: (_massSelectionFilter) => {
|
|
82
|
+
setMassSelectionFilters(_massSelectionFilter);
|
|
83
|
+
setSelectedAttribute(null);
|
|
84
|
+
setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);
|
|
85
|
+
setOpenModal(true);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
editAttributeMassActionModal: (_jsxs(EditAttributeMassActionModal, { isOpen: openModal, bulkCount: bulkCount, onOkButtonClick: _saveEditionMapping, onCancelButtonClick: _closeModal, children: [_jsxs(KitSpace, { direction: "vertical", size: "xxs", style: { width: '100%' }, children: [_jsx(KitTypography.Text, { children: t('explorer.massAction.editAttribute_attribute_select_title') }), _jsx(KitSelect, { size: "large", allowClear: false, placeholder: t('explorer.massAction.editAttribute_attribute_select_placeholder'), options: editableAttributes.map(attribute => ({
|
|
89
|
+
label: localizedTranslation(attribute.label, availableLanguages),
|
|
90
|
+
value: attribute.id,
|
|
91
|
+
})), onChange: (attributeId) => {
|
|
92
|
+
setSelectedAttribute(editableAttributes.find(attribute => attribute.id === attributeId));
|
|
93
|
+
} })] }), selectedAttribute != null &&
|
|
94
|
+
(selectedAttribute.hasEmptyDependency ? (_jsx(EditTreeAttributeValuesMapping, { libraryId: view.libraryId, attribute: selectedAttribute, massSelectionFilters: massSelectionFilters, setAttributeMapping: ({ before, after, occurrenceCount }) => {
|
|
95
|
+
setEditionMapping(before === after
|
|
96
|
+
? {
|
|
97
|
+
count: editionMapping.count - occurrenceCount,
|
|
98
|
+
mapping: [
|
|
99
|
+
{
|
|
100
|
+
values: (editionMapping.mapping[0]?.values ?? []).filter(value => value.before !== before),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
}
|
|
104
|
+
: {
|
|
105
|
+
count: editionMapping.count + occurrenceCount,
|
|
106
|
+
mapping: [
|
|
107
|
+
{
|
|
108
|
+
values: (editionMapping.mapping[0]?.values ?? [])
|
|
109
|
+
.filter(value => value.before !== before)
|
|
110
|
+
.concat([{ before, after }]),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
} })) : selectedAttribute.isSimpleWorkflow ? (_jsx(EditTreeAttributeValuesMapping, { libraryId: view.libraryId, attribute: selectedAttribute, massSelectionFilters: massSelectionFilters, setAttributeMapping: ({ before, after, occurrenceCount }) => {
|
|
115
|
+
setEditionMapping(before === after
|
|
116
|
+
? {
|
|
117
|
+
count: editionMapping.count - occurrenceCount,
|
|
118
|
+
mapping: [
|
|
119
|
+
{
|
|
120
|
+
values: (editionMapping.mapping[0]?.values ?? []).filter(value => value.before !== before),
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
}
|
|
124
|
+
: {
|
|
125
|
+
count: editionMapping.count + occurrenceCount,
|
|
126
|
+
mapping: [
|
|
127
|
+
{
|
|
128
|
+
values: (editionMapping.mapping[0]?.values ?? [])
|
|
129
|
+
.filter(value => value.before !== before)
|
|
130
|
+
.concat([{ before, after }]),
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
} })) : selectedAttribute.isMonoDependencyWorkflow ? (
|
|
135
|
+
/* TODO: */
|
|
136
|
+
_jsx(KitEmpty, { description: "WIP" })) : null)] })),
|
|
113
137
|
};
|
|
114
138
|
};
|
|
115
139
|
//# sourceMappingURL=useEditAttributeMassAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditAttributeMassAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useEditAttributeMassAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAEH,aAAa,EAEb,wBAAwB,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAC,8BAA8B,EAAC,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAC,4BAA4B,EAAC,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAAC,4BAA4B,EAAC,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAAC,6BAA6B,EAAC,MAAM,gDAAgD,CAAC;AAC7F,OAAO,EAAC,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BAAuB,EAAE,wBAAwB;QACjD,4BAA4B,EAAE,CAC1B,MAAC,4BAA4B,IACzB,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACxC,aAAa,EAAE,WAAW,EAC1B,eAAe,EAAE,CAAC,kBAAkB,EACpC,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,UAAU,aAE9B,iBAAiB,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,KAAC,OAAO,KAAG,CAAC,CAAC,CAAC,IAAI,EAC3E,iBAAiB,EAAE,IAAI,KAAK,aAAa,CAAC,IAAI,IAAI,CAC/C,KAAC,8BAA8B,IAC3B,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;wBACnC,iBAAiB,CAAC;4BACd;gCACI,MAAM,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;qCACpC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;qCACxC,MAAM,CAAC,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC;6BACjC;yBACJ,CAAC,CAAC;oBACP,CAAC,GACH,CACL,IAC0B,CAClC;KACJ,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 AttributeDetailsFragment,\n AttributeType,\n type RecordFilterInput,\n useSaveValueBulkMutation,\n} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {useEffect, useMemo, useState} from 'react';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {type FeatureHook, type IMassActions} from '../_types';\nimport {type IViewSettingsState} from '../manage-view-settings';\nimport {EditTreeAttributeValuesMapping} from './edit-attribute/EditTreeAttributeValuesMapping';\nimport {EditAttributeMassActionModal} from './edit-attribute/EditAttributeMassActionModal';\nimport {useListEditableAttributeHook} from './edit-attribute/useListEditableAttributeHook';\nimport {useCountValuesOccurrencesHook} from './edit-attribute/useCountValuesOccurrencesHook';\nimport {KitAlert, KitNotification} from 'aristid-ds';\nimport {ERROR_ALERT_DURATION, INFO_NOTIFICATION_DURATION} from '_ui/constants';\nimport {Loading} from '_ui/components/Loading';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faEdit} from '@fortawesome/free-solid-svg-icons';\n\nexport const useEditAttributeMassAction = ({\n isEnabled,\n store: {view},\n totalCount,\n}: FeatureHook<{\n store: {\n view: IViewSettingsState;\n };\n totalCount: number;\n}>) => {\n if (!isEnabled) {\n return {\n editAttributeMassAction: null,\n editAttributeMassActionModal: null,\n };\n }\n\n const {t} = useSharedTranslation();\n\n const [selectedAttribute, setSelectedAttribute] = useState<AttributeDetailsFragment | undefined>(undefined);\n const [massSelectionFilter, setMassSelectionFilter] = useState<RecordFilterInput[]>([]);\n const [openModal, setOpenModal] = useState<boolean>(false);\n const [editionMapping, setEditionMapping] = useState<\n Array<{values: Array<{before: string | null; after: string | null}>}>\n >([]);\n\n const editableAttributes = useListEditableAttributeHook({libraryId: view.libraryId});\n const valuesOccurrences = useCountValuesOccurrencesHook({\n attributeId: selectedAttribute?.id,\n libraryId: view.libraryId,\n recordFilters: massSelectionFilter,\n });\n\n const [executeSaveValueBulk] = useSaveValueBulkMutation();\n\n useEffect(() => {\n setEditionMapping([]);\n }, [selectedAttribute]);\n\n const _editAttributeMassAction: IMassActions = useMemo(\n () => ({\n label: t('explorer.massAction.editAttribute'),\n icon: <FontAwesomeIcon icon={faEdit} />,\n deselectAll: false,\n callback: _massSelectionFilter => {\n setMassSelectionFilter(_massSelectionFilter);\n setEditionMapping([]);\n setOpenModal(true);\n },\n }),\n [t, view.massSelection],\n );\n\n const closeModal = () => {\n setOpenModal(false);\n setMassSelectionFilter([]);\n setSelectedAttribute(undefined);\n setEditionMapping([]);\n };\n\n const isMappingCompleted = useMemo(() => {\n const editionMappingValuesLength = editionMapping.reduce((acc, curr) => acc + curr.values.length, 0);\n\n return valuesOccurrences.noValueCount === 0\n ? editionMappingValuesLength === valuesOccurrences.occurrences.length\n : editionMappingValuesLength + 1; // for undefined values\n }, [editionMapping, valuesOccurrences]);\n\n const bulkCounter = useMemo(\n () => (view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length),\n [view.massSelection, totalCount],\n );\n\n const onOkButtonClick = async () => {\n if (!selectedAttribute || !isMappingCompleted) {\n return;\n }\n try {\n await executeSaveValueBulk({\n variables: {\n libraryId: view.libraryId,\n recordsFilters: massSelectionFilter,\n attributeId: selectedAttribute.id,\n mapping: editionMapping,\n },\n });\n\n closeModal();\n KitNotification.info({\n message: t('explorer.massAction.editAttribute_submit_notification_title'),\n description: t('explorer.massAction.editAttribute_submit_notification_description', {\n counter: bulkCounter,\n }),\n duration: INFO_NOTIFICATION_DURATION,\n closable: true,\n });\n } catch (error) {\n KitAlert.error({\n showIcon: true,\n duration: ERROR_ALERT_DURATION,\n message: t('error.error_occurred'),\n description: t('explorer.massAction.editAttribute_submit_error'),\n closable: true,\n });\n }\n };\n\n if (editableAttributes.length === 0) {\n return {\n editAttributeMassAction: null,\n editAttributeMassActionModal: null,\n };\n }\n\n return {\n editAttributeMassAction: _editAttributeMassAction,\n editAttributeMassActionModal: (\n <EditAttributeMassActionModal\n isOpen={openModal}\n attributes={editableAttributes}\n setSelectedAttribute={setSelectedAttribute}\n massSelectionFilter={massSelectionFilter}\n elementsCount={bulkCounter}\n disableOkButton={!isMappingCompleted}\n onOkButtonClick={onOkButtonClick}\n onCancelButtonClick={closeModal}\n >\n {selectedAttribute != null && valuesOccurrences.loading ? <Loading /> : null}\n {selectedAttribute?.type === AttributeType.tree && (\n <EditTreeAttributeValuesMapping\n selectedAttribute={selectedAttribute}\n valuesOccurrences={valuesOccurrences}\n setAttributeMapping={(before, after) => {\n setEditionMapping([\n {\n values: (editionMapping[0]?.values ?? [])\n .filter(value => value.before !== before)\n .concat([{before, after}]),\n },\n ]);\n }}\n />\n )}\n </EditAttributeMassActionModal>\n ),\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"useEditAttributeMassAction.js","sourceRoot":"","sources":["../../../../src/components/Explorer/actions-mass/useEditAttributeMassAction.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnG,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAyD,wBAAwB,EAAC,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAE,0BAA0B,EAAC,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAC,8BAA8B,EAAC,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAC,4BAA4B,EAAC,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAAC,yBAAyB,EAAC,MAAM,4CAA4C,CAAC;AAGrF,MAAM,8BAA8B,GAAG,EAAC,KAAK,EAAE,CAAC,EAAE,OAAO,E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AC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CACpD,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CACnC;yCACJ;qCACJ;iCACJ;gCACH,CAAC,CAAC;oCACI,KAAK,EAAE,cAAc,CAAC,KAAK,GAAG,eAAe;oCAC7C,OAAO,EAAE;wCACL;4CACI,MAAM,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;iDAC5C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;iDACxC,MAAM,CAAC,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC;yCACjC;qCACJ;iCACJ,CACV,CAAC;wBACN,CAAC,GACH,CACL,CAAC,CAAC,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,CAAC,CAAC;oBAC7C,WAAW;oBACX,KAAC,QAAQ,IAAC,WAAW,EAAC,KAAK,GAAG,CACjC,CAAC,CAAC,CAAC,IAAI,CAAC,IACc,CAClC;KACJ,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 {useEffect, useState} from 'react';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faEdit} from '@fortawesome/free-solid-svg-icons';\nimport {KitAlert, KitEmpty, KitNotification, KitSelect, KitSpace, KitTypography} from 'aristid-ds';\nimport {localizedTranslation} from '@leav/utils';\nimport {type RecordFilterInput, type SaveValueBulkMappingInput, useSaveValueBulkMutation} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {ERROR_ALERT_DURATION, INFO_NOTIFICATION_DURATION} from '_ui/constants';\nimport {useLang} from '_ui/hooks';\nimport {MASS_SELECTION_ALL} from '../_constants';\nimport {type FeatureHook} from '../_types';\nimport {type IViewSettingsState} from '../manage-view-settings';\nimport {EditTreeAttributeValuesMapping} from './edit-attribute/EditTreeAttributeValuesMapping';\nimport {EditAttributeMassActionModal} from './edit-attribute/EditAttributeMassActionModal';\nimport {useMassEditableAttributes} from './edit-attribute/useMassEditableAttributes';\nimport {type MassEditableAttribute} from './edit-attribute/_types';\n\nconst EDITION_MAPPING_DEFAULT_VALUES = {count: 0, mapping: []};\n\nexport const useEditAttributeMassAction = ({\n isEnabled,\n store: {view},\n totalCount,\n}: FeatureHook<{\n store: {\n view: IViewSettingsState;\n };\n totalCount: number;\n}>) => {\n const {lang: availableLanguages} = useLang();\n const {t} = useSharedTranslation();\n\n const [openModal, setOpenModal] = useState(false);\n\n // Represent the current selection, used to apply modifications to correct records\n const [massSelectionFilters, setMassSelectionFilters] = useState<RecordFilterInput[]>([]);\n\n const editableAttributes = useMassEditableAttributes({libraryId: view.libraryId});\n\n const [selectedAttribute, setSelectedAttribute] = useState<MassEditableAttribute | null>(null);\n const [executeSaveValueBulk] = useSaveValueBulkMutation();\n const [editionMapping, setEditionMapping] = useState<{count: number; mapping: SaveValueBulkMappingInput[]}>(\n EDITION_MAPPING_DEFAULT_VALUES,\n );\n useEffect(() => {\n setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);\n }, [selectedAttribute]);\n\n const _closeModal = () => {\n setOpenModal(false);\n setMassSelectionFilters([]);\n setSelectedAttribute(null);\n setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);\n };\n\n const bulkCount = view.massSelection === MASS_SELECTION_ALL ? totalCount : view.massSelection.length;\n\n const _saveEditionMapping = () => {\n if (!selectedAttribute || editionMapping.count === 0) {\n return;\n }\n\n executeSaveValueBulk({\n variables: {\n libraryId: view.libraryId,\n recordsFilters: massSelectionFilters,\n attributeId: selectedAttribute.id,\n mapping: editionMapping.mapping,\n },\n }).catch(() => {\n KitAlert.error({\n showIcon: true,\n duration: ERROR_ALERT_DURATION,\n message: t('error.error_occurred'),\n description: t('explorer.massAction.editAttribute_submit_error'),\n closable: true,\n });\n });\n\n _closeModal();\n\n KitNotification.info({\n message: t('explorer.massAction.editAttribute_submit_notification_title'),\n description:\n t('explorer.massAction.editAttribute_submit_notification_description', {\n count: editionMapping.count,\n }) ?? undefined,\n duration: INFO_NOTIFICATION_DURATION,\n closable: true,\n });\n };\n\n // TODO: https://aristid.atlassian.net/browse/LEAVC-830\n if (!isEnabled || editableAttributes.length === 0) {\n return {\n editAttributeMassAction: null,\n editAttributeMassActionModal: null,\n };\n }\n\n return {\n editAttributeMassAction: {\n label: t('explorer.massAction.editAttribute'),\n icon: <FontAwesomeIcon icon={faEdit} />,\n deselectAll: false,\n callback: (_massSelectionFilter: RecordFilterInput[]) => {\n setMassSelectionFilters(_massSelectionFilter);\n setSelectedAttribute(null);\n setEditionMapping(EDITION_MAPPING_DEFAULT_VALUES);\n setOpenModal(true);\n },\n },\n editAttributeMassActionModal: (\n <EditAttributeMassActionModal\n isOpen={openModal}\n bulkCount={bulkCount}\n onOkButtonClick={_saveEditionMapping}\n onCancelButtonClick={_closeModal}\n >\n <KitSpace direction=\"vertical\" size=\"xxs\" style={{width: '100%'}}>\n <KitTypography.Text>\n {t('explorer.massAction.editAttribute_attribute_select_title')}\n </KitTypography.Text>\n <KitSelect\n size=\"large\"\n allowClear={false}\n placeholder={t('explorer.massAction.editAttribute_attribute_select_placeholder')}\n options={editableAttributes.map(attribute => ({\n label: localizedTranslation(attribute.label, availableLanguages),\n value: attribute.id,\n }))}\n onChange={(attributeId: string) => {\n setSelectedAttribute(editableAttributes.find(attribute => attribute.id === attributeId)!);\n }}\n />\n </KitSpace>\n {selectedAttribute != null &&\n (selectedAttribute.hasEmptyDependency ? (\n <EditTreeAttributeValuesMapping\n libraryId={view.libraryId}\n attribute={selectedAttribute}\n massSelectionFilters={massSelectionFilters}\n setAttributeMapping={({before, after, occurrenceCount}) => {\n setEditionMapping(\n before === after\n ? {\n count: editionMapping.count - occurrenceCount,\n mapping: [\n {\n values: (editionMapping.mapping[0]?.values ?? []).filter(\n value => value.before !== before,\n ),\n },\n ],\n }\n : {\n count: editionMapping.count + occurrenceCount,\n mapping: [\n {\n values: (editionMapping.mapping[0]?.values ?? [])\n .filter(value => value.before !== before)\n .concat([{before, after}]),\n },\n ],\n },\n );\n }}\n />\n ) : selectedAttribute.isSimpleWorkflow ? (\n <EditTreeAttributeValuesMapping\n libraryId={view.libraryId}\n attribute={selectedAttribute}\n massSelectionFilters={massSelectionFilters}\n setAttributeMapping={({before, after, occurrenceCount}) => {\n setEditionMapping(\n before === after\n ? {\n count: editionMapping.count - occurrenceCount,\n mapping: [\n {\n values: (editionMapping.mapping[0]?.values ?? []).filter(\n value => value.before !== before,\n ),\n },\n ],\n }\n : {\n count: editionMapping.count + occurrenceCount,\n mapping: [\n {\n values: (editionMapping.mapping[0]?.values ?? [])\n .filter(value => value.before !== before)\n .concat([{before, after}]),\n },\n ],\n },\n );\n }}\n />\n ) : selectedAttribute.isMonoDependencyWorkflow ? (\n /* TODO: */\n <KitEmpty description=\"WIP\" />\n ) : null)}\n </EditAttributeMassActionModal>\n ),\n };\n};\n"]}
|
|
@@ -100,20 +100,25 @@ export const useMassActions = ({ isEnabled, store: { dispatch, view }, filtersSt
|
|
|
100
100
|
label: t('explorer.massAction.toggle_selection.select_page', { count: view.pageSize }),
|
|
101
101
|
onClick: () => _setSelectedKeys([...new Set([...view.massSelection, ...allVisibleKeys])]),
|
|
102
102
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
:
|
|
108
|
-
onClick: async () => {
|
|
109
|
-
if (hasSelectedAllAvailableItems) {
|
|
110
|
-
_setSelectedKeys([]);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
103
|
+
!hasSelectedAllAvailableItems
|
|
104
|
+
? {
|
|
105
|
+
key: 'select_all_selection',
|
|
106
|
+
label: t('explorer.massAction.toggle_selection.select_all', { count: totalCountFiltered }),
|
|
107
|
+
onClick: async () => {
|
|
113
108
|
_setSelectedKeys(MASS_SELECTION_ALL);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
: null,
|
|
112
|
+
hasSelectedAllAvailableItems ||
|
|
113
|
+
(!hasSelectedAllAvailableItems && !hasSelectedAllVisibleItems && view.massSelection.length >= 2)
|
|
114
|
+
? {
|
|
115
|
+
key: 'deselect_all_selection',
|
|
116
|
+
label: t('explorer.massAction.toggle_selection.deselect_all'),
|
|
117
|
+
onClick: async () => {
|
|
118
|
+
_setSelectedKeys([]);
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: null,
|
|
117
122
|
],
|
|
118
123
|
}, children: _jsx(KitCheckbox, { "aria-checked": hasSelectedSomeItems ? 'mixed' : hasSelectedAllAvailableItems ? 'true' : 'false', indeterminate: hasSelectedSomeItems, checked: hasSelectedAllAvailableItems, children: _jsxs(KitSpace, { size: "xxs", children: [_jsx(ResultsCount, { t: t, isInactive: isInactive, totalCountFiltered: totalCountFiltered, totalCountLibrary: totalCountLibrary }), _jsx(FontAwesomeIcon, { icon: faCaretDown, size: "2xs" })] }) }) }));
|
|
119
124
|
const _setSelectedKeys = useCallback((keys) => dispatch({
|
|
@@ -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,CA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AAC,CAAC;wBACzB,CAAC;6BAAM,CAAC;4BACJ,gBAAgB,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,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 hasSelectedAllVisibleItems =\n view.massSelection.length >= allVisibleKeys.length &&\n allVisibleKeys.find(visibleKey => view.massSelection.includes(visibleKey)) !== undefined;\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 : hasSelectedAllVisibleItems\n ? {\n key: 'toggle_page_selection',\n label: t('explorer.massAction.toggle_selection.deselect_page', {count: view.pageSize}),\n onClick: () =>\n _setSelectedKeys(\n [...view.massSelection].filter(key => allVisibleKeys.includes[key]),\n ),\n }\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 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,EA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C,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';\nimport {IKitDropdown} from 'aristid-ds/dist/Kit/Navigation/DropDown/types';\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 hasSelectedAllVisibleItems =\n view.massSelection.length >= allVisibleKeys.length &&\n allVisibleKeys.find(visibleKey => view.massSelection.includes(visibleKey)) !== undefined;\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 : hasSelectedAllVisibleItems\n ? {\n key: 'toggle_page_selection',\n label: t('explorer.massAction.toggle_selection.deselect_page', {count: view.pageSize}),\n onClick: () =>\n _setSelectedKeys(\n [...view.massSelection].filter(key => allVisibleKeys.includes[key]),\n ),\n }\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 !hasSelectedAllAvailableItems\n ? {\n key: 'select_all_selection',\n label: t('explorer.massAction.toggle_selection.select_all', {count: totalCountFiltered}),\n onClick: async () => {\n _setSelectedKeys(MASS_SELECTION_ALL);\n },\n }\n : null,\n hasSelectedAllAvailableItems ||\n (!hasSelectedAllAvailableItems && !hasSelectedAllVisibleItems && view.massSelection.length >= 2)\n ? {\n key: 'deselect_all_selection',\n label: t('explorer.massAction.toggle_selection.deselect_all'),\n onClick: async () => {\n _setSelectedKeys([]);\n },\n }\n : null,\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"]}
|
|
@@ -730,17 +730,17 @@
|
|
|
730
730
|
"deactivate_message": "Elements deleted",
|
|
731
731
|
"deactivate_description": "{{count, number}}/{{total, number}} element for which you have permissions have been deleted. Others remain unchanged.",
|
|
732
732
|
"editAttribute": "Edit an attribute",
|
|
733
|
-
"editAttribute_description_one": "{{count, number}} element
|
|
734
|
-
"editAttribute_description_other": "{{
|
|
733
|
+
"editAttribute_description_one": "{{count, number}} element selected",
|
|
734
|
+
"editAttribute_description_other": "{{count, number}} elements selected",
|
|
735
735
|
"editAttribute_attribute_select_title": "Attribute to edit",
|
|
736
736
|
"editAttribute_attribute_select_placeholder": "Select an attribute",
|
|
737
|
-
"editAttribute_value_select_placeholder": "Select a value",
|
|
738
737
|
"editAttribute_value_occurrences_to_edit_one": "{{count, number}} element to edit",
|
|
739
738
|
"editAttribute_value_occurrences_to_edit_other": "{{count, number}} elements to edit",
|
|
740
739
|
"editAttribute_value_undefined": "Undefined",
|
|
741
740
|
"editAttribute_value_do_not_change": "Do not change",
|
|
742
741
|
"editAttribute_submit_notification_title": "Bulk edit request",
|
|
743
|
-
"
|
|
742
|
+
"editAttribute_submit_notification_description_one": "Your request to edit {{count, number}} item has been received. You will be notified once the operation is complete.",
|
|
743
|
+
"editAttribute_submit_notification_description_other": "Your request to edit {{count, number}} items has been received. You will be notified once the operation is complete.",
|
|
744
744
|
"editAttribute_submit_error": "An error occurred while requesting a bulk edit. Please contact an administrator.",
|
|
745
745
|
"export": "Export",
|
|
746
746
|
"export_message": "Export request",
|
|
@@ -730,18 +730,18 @@
|
|
|
730
730
|
"deactivate_message": "Élements supprimés",
|
|
731
731
|
"deactivate_description": "{{count, number}}/{{total, number}} éléments pour lesquels vous disposez des permissions nécessaires ont été supprimés. Les autres éléments restent inchangés.",
|
|
732
732
|
"editAttribute": "Modifier un attribut",
|
|
733
|
-
"editAttribute_description_one": "{{count, number}} élément
|
|
734
|
-
"editAttribute_description_other": "{{count, number}} éléments
|
|
733
|
+
"editAttribute_description_one": "{{count, number}} élément sélectionné",
|
|
734
|
+
"editAttribute_description_other": "{{count, number}} éléments sélectionnés",
|
|
735
735
|
"editAttribute_attribute_select_title": "Attribut à modifier",
|
|
736
736
|
"editAttribute_attribute_select_placeholder": "Sélectionnez un attribut",
|
|
737
|
-
"editAttribute_value_select_placeholder": "Sélectionnez une valeur",
|
|
738
737
|
"editAttribute_value_occurrences_to_edit_one": "{{count, number}} élément à traiter",
|
|
739
738
|
"editAttribute_value_occurrences_to_edit_other": "{{count, number}} éléments à traiter",
|
|
740
739
|
"editAttribute_value_undefined": "Non défini",
|
|
741
740
|
"editAttribute_value_do_not_change": "Ne pas changer",
|
|
742
741
|
"editAttribute_submit_notification_title": "Demande de modification en masse",
|
|
743
|
-
"
|
|
744
|
-
"
|
|
742
|
+
"editAttribute_submit_notification_description_one": "Votre demande de modification de {{count, number}} élément a bien été prise en compte. Vous serez notifié une fois l’opération terminée.",
|
|
743
|
+
"editAttribute_submit_notification_description_other": "Votre demande de modification de {{count, number}} éléments a bien été prise en compte. Vous serez notifié une fois l’opération terminée.",
|
|
744
|
+
"editAttribute_submit_error": "Une erreur est survenue lors de la demande d’une modification en masse. Veuillez contacter un administrateur.",
|
|
745
745
|
"export": "Exporter",
|
|
746
746
|
"export_message": "Demande d'export",
|
|
747
747
|
"export_description_one": "Votre demande d’export de {{total, number}} élément a bien été prise en compte. Vous recevrez une notification dès que le fichier sera prêt.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leav/ui",
|
|
3
|
-
"version": "1.12.0-
|
|
3
|
+
"version": "1.12.0-38b7d0f2",
|
|
4
4
|
"description": "Shared React components and hooks",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepublishOnly": "yarn build",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/lodash.isequal": "^4",
|
|
43
43
|
"@types/react": "18.2.14",
|
|
44
44
|
"@types/react-dom": "18.2.6",
|
|
45
|
-
"aristid-ds": "15.3.1-
|
|
45
|
+
"aristid-ds": "15.3.1-05878d4",
|
|
46
46
|
"babel-jest": "29.7.0",
|
|
47
47
|
"graphql": "16.13.2",
|
|
48
48
|
"i18next": "22.5.1",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@apollo/client": ">=3.8.1",
|
|
63
|
-
"aristid-ds": "15.3.1-
|
|
63
|
+
"aristid-ds": "15.3.1-05878d4",
|
|
64
64
|
"i18next": ">=22.5.1",
|
|
65
65
|
"react": "^18.2.0",
|
|
66
66
|
"react-dom": "^18.2.0",
|
package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type FunctionComponent } from 'react';
|
|
2
|
-
import { type ITreeAttributeNodeValue } from './useListTreeAttributeValuesHook';
|
|
3
|
-
export declare const EditTreeAttributeValueLine: FunctionComponent<{
|
|
4
|
-
treeNodeValues: ITreeAttributeNodeValue[];
|
|
5
|
-
valueOccurrenceNodeId: string | null;
|
|
6
|
-
valueOccurrenceCount: number;
|
|
7
|
-
setAttributeMapping: (before: string | null, after: string | null) => void;
|
|
8
|
-
}>;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useSharedTranslation } from '../../../../hooks/useSharedTranslation';
|
|
3
|
-
import { KitIdCard, KitSelect, KitTypography } from 'aristid-ds';
|
|
4
|
-
import styled from 'styled-components';
|
|
5
|
-
const DivContainer = styled.div `
|
|
6
|
-
display: grid;
|
|
7
|
-
align-items: center;
|
|
8
|
-
grid-template-columns: repeat(3, 1fr);
|
|
9
|
-
grid-column-gap: calc(var(--general-spacing-l) * 1px);
|
|
10
|
-
`;
|
|
11
|
-
const UNDEFINED_VALUE = '__null__';
|
|
12
|
-
const DEFAULT_ID_CARD_COLOR = 'rgba(200, 200, 200, 1)';
|
|
13
|
-
export const EditTreeAttributeValueLine = ({ treeNodeValues, valueOccurrenceNodeId, valueOccurrenceCount, setAttributeMapping }) => {
|
|
14
|
-
const { t } = useSharedTranslation();
|
|
15
|
-
const treeNodeValueOfOccurrence = treeNodeValues.find(node => node.id === valueOccurrenceNodeId);
|
|
16
|
-
if (!treeNodeValueOfOccurrence) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const allowedDependentValues = treeNodeValueOfOccurrence ? treeNodeValueOfOccurrence.allowedDependentValues : null;
|
|
20
|
-
const selectOptions = treeNodeValues
|
|
21
|
-
.filter(treeNode => treeNode.id !== valueOccurrenceNodeId)
|
|
22
|
-
.filter(treeNode => allowedDependentValues == null || // if no allowedDependentValues, all values are allowed
|
|
23
|
-
!!allowedDependentValues.find(dv => dv.nodeId === treeNode.id))
|
|
24
|
-
.map(treeNode => ({
|
|
25
|
-
label: treeNode.label,
|
|
26
|
-
value: treeNode.id || UNDEFINED_VALUE,
|
|
27
|
-
}));
|
|
28
|
-
if (selectOptions.length === 0 && valueOccurrenceNodeId) {
|
|
29
|
-
selectOptions.push({
|
|
30
|
-
label: t('explorer.massAction.editAttribute_value_do_not_change'),
|
|
31
|
-
value: valueOccurrenceNodeId,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return (_jsxs(DivContainer, { children: [_jsx(KitIdCard, { title: treeNodeValueOfOccurrence.label, color: treeNodeValueOfOccurrence.color || DEFAULT_ID_CARD_COLOR }), _jsx(KitTypography.Text, { children: t('explorer.massAction.editAttribute_value_occurrences_to_edit', {
|
|
35
|
-
count: valueOccurrenceCount,
|
|
36
|
-
}) }), _jsx(KitSelect, { options: selectOptions, size: "middle", allowClear: false, placeholder: t('explorer.massAction.editAttribute_value_select_placeholder'), onChange: value => {
|
|
37
|
-
setAttributeMapping(valueOccurrenceNodeId, value === UNDEFINED_VALUE ? null : value || null);
|
|
38
|
-
} })] }));
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=EditTreeAttributeValueLine.js.map
|
package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditTreeAttributeValueLine.js","sourceRoot":"","sources":["../../../../../src/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValueLine.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAE/D,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;CAK9B,CAAC;AAEF,MAAM,eAAe,GAAG,UAAU,CAAC;AACnC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAEvD,MAAM,CAAC,MAAM,0BAA0B,GAKlC,CAAC,EAAC,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,mBAAmB,EAAC,EAAE,EAAE;IACxF,MAAM,EAAC,CAAC,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAEnC,MAAM,yBAAyB,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,qBAAqB,CAAC,CAAC;IACjG,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,CA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AAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;gBACjG,CAAC,GACH,IACS,CAClB,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 AttributeDetailsTreeAttributeFragment} from '_ui/_gqlTypes';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {KitIdCard, KitSelect, KitTypography} from 'aristid-ds';\nimport {type FunctionComponent} from 'react';\nimport styled from 'styled-components';\nimport {type ITreeAttributeNodeValue} from './useListTreeAttributeValuesHook';\n\nconst DivContainer = styled.div`\n display: grid;\n align-items: center;\n grid-template-columns: repeat(3, 1fr);\n grid-column-gap: calc(var(--general-spacing-l) * 1px);\n`;\n\nconst UNDEFINED_VALUE = '__null__';\nconst DEFAULT_ID_CARD_COLOR = 'rgba(200, 200, 200, 1)';\n\nexport const EditTreeAttributeValueLine: FunctionComponent<{\n treeNodeValues: ITreeAttributeNodeValue[];\n valueOccurrenceNodeId: string | null;\n valueOccurrenceCount: number;\n setAttributeMapping: (before: string | null, after: string | null) => void;\n}> = ({treeNodeValues, valueOccurrenceNodeId, valueOccurrenceCount, setAttributeMapping}) => {\n const {t} = useSharedTranslation();\n\n const treeNodeValueOfOccurrence = treeNodeValues.find(node => node.id === valueOccurrenceNodeId);\n if (!treeNodeValueOfOccurrence) {\n return null;\n }\n\n const allowedDependentValues = treeNodeValueOfOccurrence ? treeNodeValueOfOccurrence.allowedDependentValues : null;\n\n const selectOptions = treeNodeValues\n .filter(treeNode => treeNode.id !== valueOccurrenceNodeId)\n .filter(\n treeNode =>\n allowedDependentValues == null || // if no allowedDependentValues, all values are allowed\n !!allowedDependentValues.find(dv => dv.nodeId === treeNode.id),\n )\n .map(treeNode => ({\n label: treeNode.label,\n value: treeNode.id || UNDEFINED_VALUE,\n }));\n\n if (selectOptions.length === 0 && valueOccurrenceNodeId) {\n selectOptions.push({\n label: t('explorer.massAction.editAttribute_value_do_not_change'),\n value: valueOccurrenceNodeId,\n });\n }\n\n return (\n <DivContainer>\n <KitIdCard\n title={treeNodeValueOfOccurrence.label}\n color={treeNodeValueOfOccurrence.color || DEFAULT_ID_CARD_COLOR}\n />\n <KitTypography.Text>\n {t('explorer.massAction.editAttribute_value_occurrences_to_edit', {\n count: valueOccurrenceCount,\n })}\n </KitTypography.Text>\n <KitSelect\n options={selectOptions}\n size=\"middle\"\n allowClear={false}\n placeholder={t('explorer.massAction.editAttribute_value_select_placeholder')}\n onChange={value => {\n setAttributeMapping(valueOccurrenceNodeId, value === UNDEFINED_VALUE ? null : value || null);\n }}\n />\n </DivContainer>\n );\n};\n"]}
|
package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type RecordFilterInput } from '../../../../_gqlTypes';
|
|
2
|
-
export type ValuesOccurrences = {
|
|
3
|
-
noValueCount: number;
|
|
4
|
-
occurrences: Array<{
|
|
5
|
-
count: number;
|
|
6
|
-
value: {
|
|
7
|
-
id: string;
|
|
8
|
-
};
|
|
9
|
-
}>;
|
|
10
|
-
loading?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export type ValueOccurrence = ValuesOccurrences['occurrences'][0];
|
|
13
|
-
export declare const useCountValuesOccurrencesHook: ({ attributeId, libraryId, recordFilters, }: {
|
|
14
|
-
attributeId?: string;
|
|
15
|
-
libraryId: string;
|
|
16
|
-
recordFilters: RecordFilterInput[];
|
|
17
|
-
}) => ValuesOccurrences;
|
package/dist/components/Explorer/actions-mass/edit-attribute/useCountValuesOccurrencesHook.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
|
|
2
|
-
// This file is released under LGPL V3
|
|
3
|
-
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
4
|
-
import { useCountValuesOccurrencesLazyQuery } from '../../../../_gqlTypes';
|
|
5
|
-
import { useEffect, useMemo } from 'react';
|
|
6
|
-
export const useCountValuesOccurrencesHook = ({ attributeId, libraryId, recordFilters, }) => {
|
|
7
|
-
const [countValuesOccurrences, { data: valuesOccurrences, loading }] = useCountValuesOccurrencesLazyQuery({
|
|
8
|
-
fetchPolicy: 'no-cache',
|
|
9
|
-
nextFetchPolicy: 'no-cache',
|
|
10
|
-
});
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (attributeId) {
|
|
13
|
-
countValuesOccurrences({
|
|
14
|
-
variables: {
|
|
15
|
-
attribute: attributeId,
|
|
16
|
-
library: libraryId,
|
|
17
|
-
recordFilters,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}, [attributeId, libraryId, recordFilters]);
|
|
22
|
-
const noValueCount = useMemo(() => {
|
|
23
|
-
if (!valuesOccurrences) {
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
26
|
-
return valuesOccurrences.listDistinctValues?.find(v => !('treeNode' in v) || v.treeNode === null)?.count || 0;
|
|
27
|
-
}, [valuesOccurrences]);
|
|
28
|
-
const occurrences = useMemo(() => {
|
|
29
|
-
if (!valuesOccurrences) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return (valuesOccurrences.listDistinctValues
|
|
33
|
-
?.filter(v => 'treeNode' in v && v.treeNode !== null)
|
|
34
|
-
.map(v => ({ count: v.count, value: { id: v.treeNode.id } })) || []);
|
|
35
|
-
}, [valuesOccurrences]);
|
|
36
|
-
return {
|
|
37
|
-
occurrences,
|
|
38
|
-
noValueCount,
|
|
39
|
-
loading,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=useCountValuesOccurrencesHook.js.map
|