@pega/lists-react 10.0.0-build.16.2 → 10.0.0-build.16.4
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/lib/Core/Components/RenderingEngine/RenderView.d.ts.map +1 -1
- package/lib/Core/Components/RenderingEngine/RenderView.js +8 -0
- package/lib/Core/Components/RenderingEngine/RenderView.js.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useGroup/GroupRenderer.d.ts.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useGroup/GroupRenderer.js +52 -48
- package/lib/Core/Components/Toolbar/hooks/useGroup/GroupRenderer.js.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useRowFocus.d.ts +2 -2
- package/lib/Core/Components/Toolbar/hooks/useRowFocus.d.ts.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useRowFocus.js +15 -6
- package/lib/Core/Components/Toolbar/hooks/useRowFocus.js.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useSort/Row.d.ts +13 -11
- package/lib/Core/Components/Toolbar/hooks/useSort/Row.d.ts.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useSort/Row.js +21 -26
- package/lib/Core/Components/Toolbar/hooks/useSort/Row.js.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useSort/SortRenderer.d.ts.map +1 -1
- package/lib/Core/Components/Toolbar/hooks/useSort/SortRenderer.js +44 -32
- package/lib/Core/Components/Toolbar/hooks/useSort/SortRenderer.js.map +1 -1
- package/lib/Core/Views/Gallery/GalleryA11y.d.ts +25 -0
- package/lib/Core/Views/Gallery/GalleryA11y.d.ts.map +1 -1
- package/lib/Core/Views/Gallery/GalleryA11y.js +212 -0
- package/lib/Core/Views/Gallery/GalleryA11y.js.map +1 -1
- package/lib/Core/Views/Gallery/index.d.ts.map +1 -1
- package/lib/Core/Views/Gallery/index.js +2 -1
- package/lib/Core/Views/Gallery/index.js.map +1 -1
- package/lib/Core/Views/Timeline/Timeline.types.d.ts +2 -2
- package/lib/Core/Views/Timeline/Timeline.types.d.ts.map +1 -1
- package/lib/Core/Views/Timeline/Timeline.types.js.map +1 -1
- package/lib/Core/Views/Timeline/TimelineItem.d.ts.map +1 -1
- package/lib/Core/Views/Timeline/TimelineItem.js +2 -2
- package/lib/Core/Views/Timeline/TimelineItem.js.map +1 -1
- package/lib/Core/Views/Timeline/__tests__/Timeline.mocks.js +9 -9
- package/lib/Core/Views/Timeline/__tests__/Timeline.mocks.js.map +1 -1
- package/lib/Core/Views/Timeline/utils.d.ts.map +1 -1
- package/lib/Core/Views/Timeline/utils.js +11 -32
- package/lib/Core/Views/Timeline/utils.js.map +1 -1
- package/package.json +13 -15
- package/lib/Core/Hooks/useDragDrop.d.ts +0 -12
- package/lib/Core/Hooks/useDragDrop.d.ts.map +0 -1
- package/lib/Core/Hooks/useDragDrop.js +0 -231
- package/lib/Core/Hooks/useDragDrop.js.map +0 -1
- package/lib/Core/Hooks/useDragDrop.types.d.ts +0 -108
- package/lib/Core/Hooks/useDragDrop.types.d.ts.map +0 -1
- package/lib/Core/Hooks/useDragDrop.types.js +0 -2
- package/lib/Core/Hooks/useDragDrop.types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderView.d.ts","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"RenderView.d.ts","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AA4BlE,iBAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,WAAW,CAAC,IAAI,CAAA;CAAE,kDAW3F;;AAED,wBAAgC"}
|
|
@@ -13,6 +13,14 @@ const StyledDiv = styled.div(({ theme }) => {
|
|
|
13
13
|
&:has(> span > *) {
|
|
14
14
|
margin-block: ${theme.base.spacing};
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
// Many filters scroll within a capped area instead of crowding out the results (e.g. on browser zoom).
|
|
18
|
+
// position: relative contains absolutely positioned helper text (e.g. screen-reader hints) so it is clipped here instead of stretching the scroll height of the table container.
|
|
19
|
+
// flex-shrink: 0 stops the flex parent from squeezing the slot below its cap on short cards, as overflow makes its min-height 0.
|
|
20
|
+
position: relative;
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
max-block-size: 10rem;
|
|
23
|
+
overflow-y: auto;
|
|
16
24
|
`;
|
|
17
25
|
});
|
|
18
26
|
StyledDiv.defaultProps = defaultThemeProp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderView.js","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qEAAqE;AACrE,aAAa;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACzC,OAAO;;;;;sBAKa,KAAK,CAAC,IAAI,CAAC,OAAO
|
|
1
|
+
{"version":3,"file":"RenderView.js","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qEAAqE;AACrE,aAAa;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACzC,OAAO;;;;;sBAKa,KAAK,CAAC,IAAI,CAAC,OAAO;;;;;;;;;;GAUrC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAC1C,SAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAA4D;IAC1F,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU,EAAE;QACf,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,IAAI;KACL,CAAC;IAEF,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAE9E,OAAO,YAAY,CAAC,CAAC,CAAC,KAAC,SAAS,oBAAe,IAAI,YAAG,YAAY,GAAa,CAAC,CAAC,CAAC,IAAI,CAAC;AACzF,CAAC;AAED,eAAe,IAAI,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { memo } from 'react';\nimport styled from 'styled-components';\n\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\n// TODO remove ts-ignore once ComponentResolverFactory migrated to TS\n// @ts-ignore\n\nimport { resolveViewComponent } from './ComponentResolverFactory';\n\nconst StyledDiv = styled.div(({ theme }) => {\n return `\n // FIXME: Ideally, the meta passed to the table should reflect whether the PromotedFilters are configured or not. But, currently RS doesn't support change in meta after load.\n // Handling it via CSS for now. Once meta update is possible in RS, the consumer of RS should make sure that correct externalFilters are set in meta.\n // Add margin only if some content is rendered in render view. Adding span as RS by default injects a span for external renderers.\n &:has(> span > *) {\n margin-block: ${theme.base.spacing};\n }\n\n // Many filters scroll within a capped area instead of crowding out the results (e.g. on browser zoom).\n // position: relative contains absolutely positioned helper text (e.g. screen-reader hints) so it is clipped here instead of stretching the scroll height of the table container.\n // flex-shrink: 0 stops the flex parent from squeezing the slot below its cap on short cards, as overflow makes its min-height 0.\n position: relative;\n flex-shrink: 0;\n max-block-size: 10rem;\n overflow-y: auto;\n `;\n});\n\nStyledDiv.defaultProps = defaultThemeProp;\nfunction RenderView({ view, type }: { view: RsCoreTypes.View; type: keyof RsCoreTypes.Meta }) {\n const { state, meta, getContext, renderFactory, rsID } = view;\n const engineContext = {\n ...getContext(),\n [String(meta[type])]: state?.externalState?.[String(meta[type])],\n rsID\n };\n\n const resolvedView = resolveViewComponent(type, renderFactory, engineContext);\n\n return resolvedView ? <StyledDiv data-test-id={type}>{resolvedView}</StyledDiv> : null;\n}\n\nexport default memo(RenderView);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupRenderer.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useGroup/GroupRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GroupRenderer.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useGroup/GroupRenderer.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kDAAkD,CAAC;AAI9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAoF/C,UAAU,kBAAkB;IAC1B,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACxD,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC;IAC9B,aAAa,EAAE,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACjD,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,QAAA,MAAM,aAAa,GAAI,4FAQpB,kBAAkB,4CA0JpB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
3
|
+
import styled, { css } from 'styled-components';
|
|
4
|
+
import { Button, createUID, defaultThemeProp, Flex, Icon, useI18n } from '@pega/cosmos-react-core';
|
|
5
|
+
import { DragDropList, DragDropManager, DragHandle } from '@pega/cosmos-react-dnd';
|
|
6
6
|
import { FieldType, REPEATING_STRUCTURE_TEMPLATES } from 'pega-repeating-structures-core';
|
|
7
7
|
import useRowFocus from '../useRowFocus';
|
|
8
|
-
import useDragDrop from '../../../../Hooks/useDragDrop';
|
|
9
8
|
import FieldSelector from '../../FieldSelector';
|
|
10
9
|
import { getColumnById, getValidGroupFieldsInRow } from './utils';
|
|
11
10
|
import DateFunctionSelector from './DateFunctionSelector';
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const GROUP_ITEM_TYPE = 'rs-group-item';
|
|
12
|
+
const StyledRow = styled(Flex)(({ $isDragging }) => css `
|
|
13
|
+
opacity: ${$isDragging ? 0.5 : 1};
|
|
14
|
+
`);
|
|
15
|
+
StyledRow.defaultProps = defaultThemeProp;
|
|
16
|
+
// Must keep a stable identity, otherwise every render would remount the rows.
|
|
17
|
+
const GroupRowRenderer = ({ data: { group, index, groupFieldDefs, groupingOptions, columns, dateFunctions, template, fieldDefs, focusRowId, focusRowRef, handleColumnChange, handleDateFuncChange, removeGroup }, dragRef, previewRef, isDragging }) => {
|
|
18
|
+
const t = useI18n();
|
|
19
|
+
const fieldLabel = columns?.find(f => f.field.id === group.columnId)?.label;
|
|
20
|
+
return (_jsxs(StyledRow, { ref: previewRef, "$isDragging": isDragging, container: { alignItems: 'center', wrap: 'nowrap', gap: 0.5 }, children: [_jsx(DragHandle, { itemId: group.id, ref: dragRef, contextualLabel: fieldLabel }), _jsx(Flex, { item: { grow: 1 }, ref: group.id === focusRowId ? focusRowRef : null, children: _jsx(FieldSelector, { label: t('field'), labelHidden: true, value: group.columnId, disabled: !!group.customFunction, onChange: (newID) => handleColumnChange(group, index, newID), fieldDefs: groupFieldDefs }) }), _jsx(DateFunctionSelector, { template: template, group: group, groupingOptions: groupingOptions, dateFunctions: dateFunctions, fieldDefs: fieldDefs, onChange: (newFunc) => handleDateFuncChange(group, index, newFunc) }), _jsx(Button, { icon: true, variant: 'simple', onClick: () => removeGroup(index), label: t('delete_group'), children: _jsx(Icon, { name: 'trash' }) })] }));
|
|
21
|
+
};
|
|
16
22
|
const GroupRenderer = ({ appliedGroups, groupingOptions, setGroups, columns, dateFunctions, template, fieldDefs }) => {
|
|
17
23
|
const t = useI18n();
|
|
18
24
|
const { focusRowRef, focusRowId, setFocusRowId } = useRowFocus();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const dropIndex = Number(dest.getAttribute('data-index'));
|
|
23
|
-
const dragIndex = Number(src.getAttribute('data-index'));
|
|
24
|
-
if (dragIndex !== dropIndex) {
|
|
25
|
-
const existingGroups = appliedGroups.map(v => ({ ...v }));
|
|
26
|
-
const dragGroup = existingGroups.splice(dragIndex, 1)[0];
|
|
27
|
-
existingGroups.splice(dropIndex, 0, dragGroup);
|
|
28
|
-
setGroups(existingGroups);
|
|
29
|
-
}
|
|
30
|
-
}, [appliedGroups, setGroups]);
|
|
31
|
-
const { dragProps, dropProps } = useDragDrop({
|
|
32
|
-
context: dragDropRef,
|
|
33
|
-
getAnimationSelector,
|
|
34
|
-
getGhostImageSelector: getAnimationSelector,
|
|
35
|
-
getDraggedObject: getAnimationSelector,
|
|
36
|
-
onDrop
|
|
37
|
-
});
|
|
25
|
+
const onReorder = useCallback((newItems) => {
|
|
26
|
+
setGroups(newItems.map(({ data }) => ({ ...data.group })));
|
|
27
|
+
}, [setGroups]);
|
|
38
28
|
const removeGroup = useCallback((index) => {
|
|
39
29
|
const existingGroups = appliedGroups.map(v => ({ ...v }));
|
|
40
30
|
existingGroups.splice(index, 1);
|
|
@@ -88,26 +78,40 @@ const GroupRenderer = ({ appliedGroups, groupingOptions, setGroups, columns, dat
|
|
|
88
78
|
addRow();
|
|
89
79
|
}
|
|
90
80
|
}, [appliedGroups, addRow]);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
const sharedRowProps = useMemo(() => ({
|
|
82
|
+
groupingOptions,
|
|
83
|
+
columns,
|
|
84
|
+
dateFunctions,
|
|
85
|
+
template,
|
|
86
|
+
fieldDefs,
|
|
87
|
+
focusRowId,
|
|
88
|
+
focusRowRef,
|
|
89
|
+
handleColumnChange,
|
|
90
|
+
handleDateFuncChange,
|
|
91
|
+
removeGroup
|
|
92
|
+
}), [
|
|
93
|
+
groupingOptions,
|
|
94
|
+
columns,
|
|
95
|
+
dateFunctions,
|
|
96
|
+
template,
|
|
97
|
+
fieldDefs,
|
|
98
|
+
focusRowId,
|
|
99
|
+
focusRowRef,
|
|
100
|
+
handleColumnChange,
|
|
101
|
+
handleDateFuncChange,
|
|
102
|
+
removeGroup
|
|
103
|
+
]);
|
|
104
|
+
const dragItems = useMemo(() => appliedGroups.map((group, index) => ({
|
|
105
|
+
id: group.id,
|
|
106
|
+
type: GROUP_ITEM_TYPE,
|
|
107
|
+
data: {
|
|
108
|
+
...sharedRowProps,
|
|
109
|
+
group,
|
|
110
|
+
index,
|
|
111
|
+
groupFieldDefs: getValidGroupFieldsInRow(fieldDefs, groupingOptions, group.columnId)
|
|
112
|
+
}
|
|
113
|
+
})), [appliedGroups, sharedRowProps, fieldDefs, groupingOptions]);
|
|
114
|
+
return (_jsxs(Flex, { container: { direction: 'column', gap: 2 }, children: [_jsx(DragDropManager, { children: _jsx(DragDropList, { as: Flex, container: { direction: 'column', gap: 1 }, accept: GROUP_ITEM_TYPE, items: dragItems, itemRenderer: GroupRowRenderer, onChange: onReorder }) }), template !== REPEATING_STRUCTURE_TEMPLATES.TIMELINE && (_jsx("div", { children: _jsx(Button, { variant: 'link', "aria-label": t('add_group'), onClick: addRow, children: _jsxs(Flex, { container: {
|
|
111
115
|
inline: true,
|
|
112
116
|
alignItems: 'start',
|
|
113
117
|
gap: 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupRenderer.js","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useGroup/GroupRenderer.tsx"],"names":[],"mappings":";;AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,S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,EACpE,SAAS,EAAE,wBAAwB,CACjC,SAAS,EACT,eAAe,EACf,KAAK,CAAC,QAAQ,CACf,GACD,GACG,EACP,KAAC,oBAAoB,IACnB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,CAAC,OAA8B,EAAE,EAAE,CAC3C,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,GAE7C,IACG,GACF,EACP,KAAC,MAAM,IACL,IAAI,QACJ,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EACjC,KAAK,EAAE,CAAC,CAAC,cAAc,CAAC,YAExB,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,IACJ,CACH,CACP,CAAC;gBACJ,CAAC,CAAC,GACG,EACN,QAAQ,KAAK,6BAA6B,CAAC,QAAQ,IAAI,CACtD,wBACE,KAAC,MAAM,IAAC,OAAO,EAAC,MAAM,gBAAa,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,MAAM,YAChE,MAAC,IAAI,IACH,SAAS,EAAE;4BACT,MAAM,EAAE,IAAI;4BACZ,UAAU,EAAE,OAAO;4BACnB,GAAG,EAAE,CAAC;yBACP,EACD,EAAE,EAAC,MAAM,aAET,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,EACpB,yBAAO,CAAC,CAAC,KAAK,CAAC,GAAQ,IAClB,GACA,GACL,CACP,KAhGmD,UAAU,CAiGzD,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import styled from 'styled-components';\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport { Button, createUID, Flex, Icon, useI18n } from '@pega/cosmos-react-core';\nimport { FieldType, REPEATING_STRUCTURE_TEMPLATES } from 'pega-repeating-structures-core';\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport type { Group } from 'pega-repeating-structures-core/types/State.types';\n\nimport useRowFocus from '../useRowFocus';\nimport useDragDrop from '../../../../Hooks/useDragDrop';\nimport FieldSelector from '../../FieldSelector';\nimport type { GroupingOptions } from '../../Grouping.types';\n\nimport { getColumnById, getValidGroupFieldsInRow } from './utils';\nimport DateFunctionSelector from './DateFunctionSelector';\nimport type { AppliedGroup } from './useGroup';\n\nconst DropSelector = '[data-drop]';\n\nconst StyledDragHandle = styled(Button)`\n cursor: grab;\n`;\n\ninterface GroupRendererProps {\n appliedGroups: AppliedGroup[];\n groupingOptions: GroupingOptions;\n setGroups: (groups: (Group | { id: string })[]) => void;\n columns: RsCoreTypes.Column[];\n dateFunctions: RsCoreTypes.Meta['dateFunctions'];\n template: RsCoreTypes.Meta['template'];\n fieldDefs: RsCoreTypes.Meta['fieldDefs'];\n}\n\nconst GroupRenderer = ({\n appliedGroups,\n groupingOptions,\n setGroups,\n columns,\n dateFunctions,\n template,\n fieldDefs\n}: GroupRendererProps) => {\n const t = useI18n();\n const { focusRowRef, focusRowId, setFocusRowId } = useRowFocus();\n\n const dragDropRef = useRef<HTMLDivElement>(null);\n const getAnimationSelector = useCallback((target: Element) => target.closest(DropSelector), []);\n const onDrop = useCallback(\n (dest: Element, src: Element) => {\n const dropIndex = Number(dest.getAttribute('data-index'));\n const dragIndex = Number(src.getAttribute('data-index'));\n if (dragIndex !== dropIndex) {\n const existingGroups = appliedGroups.map(v => ({ ...v }));\n const dragGroup = existingGroups.splice(dragIndex, 1)[0];\n existingGroups.splice(dropIndex, 0, dragGroup);\n setGroups(existingGroups);\n }\n },\n [appliedGroups, setGroups]\n );\n const { dragProps, dropProps } = useDragDrop({\n context: dragDropRef,\n getAnimationSelector,\n getGhostImageSelector: getAnimationSelector,\n getDraggedObject: getAnimationSelector,\n onDrop\n });\n\n const removeGroup = useCallback(\n (index: number) => {\n const existingGroups = appliedGroups.map(v => ({ ...v }));\n existingGroups.splice(index, 1);\n setGroups(existingGroups);\n\n if (existingGroups.length > 0)\n setFocusRowId(\n index === appliedGroups.length - 1\n ? existingGroups[index - 1].id\n : existingGroups[index].id\n );\n },\n [appliedGroups, setGroups, setFocusRowId]\n );\n\n const handleColumnChange = useCallback(\n (group: Group, index: number, newID: string) => {\n if (newID === group.columnId) return; // Ignore re-selecting the same\n const groupedColumn = getColumnById(newID, columns);\n const updatedGroup: Group = {\n ...group,\n columnId: newID,\n dateFunction: undefined, // Reset for non-date/time fields,\n order: groupedColumn?.sortOrder || 'asc' // Set sort order from column else default to 'asc'\n };\n\n // For date/datetime field, pick a date function by default (if enabled)\n const fieldType = groupedColumn?.field.type;\n if (dateFunctions && (fieldType === FieldType.DATE || fieldType === FieldType.DATE_TIME)) {\n updatedGroup.dateFunction = groupingOptions.dateFuncs[newID]\n ? groupingOptions.dateFuncs[newID].available[0] // If the field is already picked before\n : groupingOptions.dateGroupVariants[fieldType][0]; // When picking the field for the first time\n }\n\n setGroups([\n ...appliedGroups.slice(0, index),\n updatedGroup,\n ...appliedGroups.slice(index + 1)\n ]);\n },\n [appliedGroups, groupingOptions, setGroups, dateFunctions, columns]\n );\n\n const handleDateFuncChange = useCallback(\n (group: Group, index: number, newFunc: Group['dateFunction']) => {\n if (newFunc === group.dateFunction) return; // Ignore re-selecting the same\n const updatedGroup = { ...group, dateFunction: newFunc };\n setGroups([\n ...appliedGroups.slice(0, index),\n updatedGroup,\n ...appliedGroups.slice(index + 1)\n ]);\n },\n [setGroups, appliedGroups]\n );\n\n const addRow = useCallback(() => {\n const newRow = { id: createUID(), columnId: '', order: 'asc' };\n const existingGroups = [...appliedGroups, newRow];\n setGroups(existingGroups);\n setFocusRowId(newRow.id);\n }, [appliedGroups, setGroups, setFocusRowId]);\n\n useEffect(() => {\n if (!appliedGroups.length) {\n addRow();\n }\n }, [appliedGroups, addRow]);\n\n return (\n <Flex container={{ direction: 'column', gap: 2 }} key='grouping'>\n <Flex container={{ direction: 'column', gap: 1 }} className='group-content' ref={dragDropRef}>\n {appliedGroups.map((group, index) => {\n const fieldLabel = columns?.find(f => f.field.id === group.columnId)?.label;\n const dragHandleLabel = fieldLabel\n ? t('drag_to_reorder_field', [fieldLabel])\n : t('drag_to_reorder');\n\n return (\n <div {...dropProps} data-index={index} key={group.id}>\n <Flex\n container={{\n justify: 'between',\n alignItems: 'center',\n direction: 'row',\n wrap: 'nowrap',\n itemGap: 0.5\n }}\n ref={appliedGroups[index].id === focusRowId ? focusRowRef : null}\n >\n <Flex item={{ grow: 1 }}>\n <Flex\n container={{\n justify: 'start',\n alignItems: 'center',\n direction: 'row',\n wrap: 'nowrap',\n itemGap: 0.5\n }}\n >\n <StyledDragHandle\n forwardedAs='div'\n role='button'\n icon\n variant='simple'\n compact\n aria-label={dragHandleLabel}\n {...dragProps}\n >\n <Icon name='drag' />\n </StyledDragHandle>\n <Flex item={{ grow: 1 }}>\n <FieldSelector\n label={t('field')}\n labelHidden\n value={group.columnId}\n disabled={!!group.customFunction}\n onChange={(newID: string) => handleColumnChange(group, index, newID)}\n fieldDefs={getValidGroupFieldsInRow(\n fieldDefs,\n groupingOptions,\n group.columnId\n )}\n />\n </Flex>\n <DateFunctionSelector\n template={template}\n group={group}\n groupingOptions={groupingOptions}\n dateFunctions={dateFunctions}\n fieldDefs={fieldDefs}\n onChange={(newFunc: Group['dateFunction']) =>\n handleDateFuncChange(group, index, newFunc)\n }\n />\n </Flex>\n </Flex>\n <Button\n icon\n variant='simple'\n onClick={() => removeGroup(index)}\n label={t('delete_group')}\n >\n <Icon name='trash' />\n </Button>\n </Flex>\n </div>\n );\n })}\n </Flex>\n {template !== REPEATING_STRUCTURE_TEMPLATES.TIMELINE && (\n <div>\n <Button variant='link' aria-label={t('add_group')} onClick={addRow}>\n <Flex\n container={{\n inline: true,\n alignItems: 'start',\n gap: 1\n }}\n as='span'\n >\n <Icon name='plus' />\n <span>{t('add')}</span>\n </Flex>\n </Button>\n </div>\n )}\n </Flex>\n );\n};\n\nexport default GroupRenderer;\n"]}
|
|
1
|
+
{"version":3,"file":"GroupRenderer.js","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useGroup/GroupRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAI1F,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAG1D,MAAM,eAAe,GAAG,eAAe,CAAC;AAExC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAC5B,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;eACX,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;GACjC,CACF,CAAC;AAEF,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAkB1C,8EAA8E;AAC9E,MAAM,gBAAgB,GAAG,CAAC,EACxB,IAAI,EAAE,EACJ,KAAK,EACL,KAAK,EACL,cAAc,EACd,eAAe,EACf,OAAO,EACP,aAAa,EACb,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACZ,EACD,OAAO,EACP,UAAU,E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,KAAK,CAAC,GAAQ,IAClB,GACA,GACL,CACP,KA3BmD,UAAU,CA4BzD,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Button, createUID, defaultThemeProp, Flex, Icon, useI18n } from '@pega/cosmos-react-core';\nimport { DragDropList, DragDropManager, DragHandle } from '@pega/cosmos-react-dnd';\nimport type { DraggableItem, ItemRendererProps } from '@pega/cosmos-react-dnd';\nimport { FieldType, REPEATING_STRUCTURE_TEMPLATES } from 'pega-repeating-structures-core';\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport type { Group } from 'pega-repeating-structures-core/types/State.types';\n\nimport useRowFocus from '../useRowFocus';\nimport FieldSelector from '../../FieldSelector';\nimport type { GroupingOptions } from '../../Grouping.types';\n\nimport { getColumnById, getValidGroupFieldsInRow } from './utils';\nimport DateFunctionSelector from './DateFunctionSelector';\nimport type { AppliedGroup } from './useGroup';\n\nconst GROUP_ITEM_TYPE = 'rs-group-item';\n\nconst StyledRow = styled(Flex)<{ $isDragging?: boolean }>(\n ({ $isDragging }) => css`\n opacity: ${$isDragging ? 0.5 : 1};\n `\n);\n\nStyledRow.defaultProps = defaultThemeProp;\n\ninterface GroupRowData {\n group: AppliedGroup;\n index: number;\n groupFieldDefs: RsCoreTypes.Meta['fieldDefs'];\n groupingOptions: GroupingOptions;\n columns: RsCoreTypes.Column[];\n dateFunctions: RsCoreTypes.Meta['dateFunctions'];\n template: RsCoreTypes.Meta['template'];\n fieldDefs: RsCoreTypes.Meta['fieldDefs'];\n focusRowId: string;\n focusRowRef: ReturnType<typeof useRowFocus>['focusRowRef'];\n handleColumnChange: (group: Group, index: number, newID: string) => void;\n handleDateFuncChange: (group: Group, index: number, newFunc: Group['dateFunction']) => void;\n removeGroup: (index: number) => void;\n}\n\n// Must keep a stable identity, otherwise every render would remount the rows.\nconst GroupRowRenderer = ({\n data: {\n group,\n index,\n groupFieldDefs,\n groupingOptions,\n columns,\n dateFunctions,\n template,\n fieldDefs,\n focusRowId,\n focusRowRef,\n handleColumnChange,\n handleDateFuncChange,\n removeGroup\n },\n dragRef,\n previewRef,\n isDragging\n}: ItemRendererProps<GroupRowData>) => {\n const t = useI18n();\n const fieldLabel = columns?.find(f => f.field.id === group.columnId)?.label;\n\n return (\n <StyledRow\n ref={previewRef}\n $isDragging={isDragging}\n container={{ alignItems: 'center', wrap: 'nowrap', gap: 0.5 }}\n >\n <DragHandle itemId={group.id} ref={dragRef} contextualLabel={fieldLabel} />\n <Flex item={{ grow: 1 }} ref={group.id === focusRowId ? focusRowRef : null}>\n <FieldSelector\n label={t('field')}\n labelHidden\n value={group.columnId}\n disabled={!!group.customFunction}\n onChange={(newID: string) => handleColumnChange(group, index, newID)}\n fieldDefs={groupFieldDefs}\n />\n </Flex>\n <DateFunctionSelector\n template={template}\n group={group}\n groupingOptions={groupingOptions}\n dateFunctions={dateFunctions}\n fieldDefs={fieldDefs}\n onChange={(newFunc: Group['dateFunction']) => handleDateFuncChange(group, index, newFunc)}\n />\n <Button icon variant='simple' onClick={() => removeGroup(index)} label={t('delete_group')}>\n <Icon name='trash' />\n </Button>\n </StyledRow>\n );\n};\n\ninterface GroupRendererProps {\n appliedGroups: AppliedGroup[];\n groupingOptions: GroupingOptions;\n setGroups: (groups: (Group | { id: string })[]) => void;\n columns: RsCoreTypes.Column[];\n dateFunctions: RsCoreTypes.Meta['dateFunctions'];\n template: RsCoreTypes.Meta['template'];\n fieldDefs: RsCoreTypes.Meta['fieldDefs'];\n}\n\nconst GroupRenderer = ({\n appliedGroups,\n groupingOptions,\n setGroups,\n columns,\n dateFunctions,\n template,\n fieldDefs\n}: GroupRendererProps) => {\n const t = useI18n();\n const { focusRowRef, focusRowId, setFocusRowId } = useRowFocus();\n\n const onReorder = useCallback(\n (newItems: DraggableItem<GroupRowData>[]) => {\n setGroups(newItems.map(({ data }) => ({ ...data.group })));\n },\n [setGroups]\n );\n\n const removeGroup = useCallback(\n (index: number) => {\n const existingGroups = appliedGroups.map(v => ({ ...v }));\n existingGroups.splice(index, 1);\n setGroups(existingGroups);\n\n if (existingGroups.length > 0)\n setFocusRowId(\n index === appliedGroups.length - 1\n ? existingGroups[index - 1].id\n : existingGroups[index].id\n );\n },\n [appliedGroups, setGroups, setFocusRowId]\n );\n\n const handleColumnChange = useCallback(\n (group: Group, index: number, newID: string) => {\n if (newID === group.columnId) return; // Ignore re-selecting the same\n const groupedColumn = getColumnById(newID, columns);\n const updatedGroup: Group = {\n ...group,\n columnId: newID,\n dateFunction: undefined, // Reset for non-date/time fields,\n order: groupedColumn?.sortOrder || 'asc' // Set sort order from column else default to 'asc'\n };\n\n // For date/datetime field, pick a date function by default (if enabled)\n const fieldType = groupedColumn?.field.type;\n if (dateFunctions && (fieldType === FieldType.DATE || fieldType === FieldType.DATE_TIME)) {\n updatedGroup.dateFunction = groupingOptions.dateFuncs[newID]\n ? groupingOptions.dateFuncs[newID].available[0] // If the field is already picked before\n : groupingOptions.dateGroupVariants[fieldType][0]; // When picking the field for the first time\n }\n\n setGroups([\n ...appliedGroups.slice(0, index),\n updatedGroup,\n ...appliedGroups.slice(index + 1)\n ]);\n },\n [appliedGroups, groupingOptions, setGroups, dateFunctions, columns]\n );\n\n const handleDateFuncChange = useCallback(\n (group: Group, index: number, newFunc: Group['dateFunction']) => {\n if (newFunc === group.dateFunction) return; // Ignore re-selecting the same\n const updatedGroup = { ...group, dateFunction: newFunc };\n setGroups([\n ...appliedGroups.slice(0, index),\n updatedGroup,\n ...appliedGroups.slice(index + 1)\n ]);\n },\n [setGroups, appliedGroups]\n );\n\n const addRow = useCallback(() => {\n const newRow = { id: createUID(), columnId: '', order: 'asc' };\n const existingGroups = [...appliedGroups, newRow];\n setGroups(existingGroups);\n setFocusRowId(newRow.id);\n }, [appliedGroups, setGroups, setFocusRowId]);\n\n useEffect(() => {\n if (!appliedGroups.length) {\n addRow();\n }\n }, [appliedGroups, addRow]);\n\n const sharedRowProps = useMemo(\n () => ({\n groupingOptions,\n columns,\n dateFunctions,\n template,\n fieldDefs,\n focusRowId,\n focusRowRef,\n handleColumnChange,\n handleDateFuncChange,\n removeGroup\n }),\n [\n groupingOptions,\n columns,\n dateFunctions,\n template,\n fieldDefs,\n focusRowId,\n focusRowRef,\n handleColumnChange,\n handleDateFuncChange,\n removeGroup\n ]\n );\n\n const dragItems: DraggableItem<GroupRowData>[] = useMemo(\n () =>\n appliedGroups.map((group, index) => ({\n id: group.id,\n type: GROUP_ITEM_TYPE,\n data: {\n ...sharedRowProps,\n group,\n index,\n groupFieldDefs: getValidGroupFieldsInRow(fieldDefs, groupingOptions, group.columnId)\n }\n })),\n [appliedGroups, sharedRowProps, fieldDefs, groupingOptions]\n );\n\n return (\n <Flex container={{ direction: 'column', gap: 2 }} key='grouping'>\n <DragDropManager>\n <DragDropList\n as={Flex}\n container={{ direction: 'column', gap: 1 }}\n accept={GROUP_ITEM_TYPE}\n items={dragItems}\n itemRenderer={GroupRowRenderer}\n onChange={onReorder}\n />\n </DragDropManager>\n {template !== REPEATING_STRUCTURE_TEMPLATES.TIMELINE && (\n <div>\n <Button variant='link' aria-label={t('add_group')} onClick={addRow}>\n <Flex\n container={{\n inline: true,\n alignItems: 'start',\n gap: 1\n }}\n as='span'\n >\n <Icon name='plus' />\n <span>{t('add')}</span>\n </Flex>\n </Button>\n </div>\n )}\n </Flex>\n );\n};\n\nexport default GroupRenderer;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function useRowFocus(): {
|
|
2
|
-
focusRowRef:
|
|
2
|
+
focusRowRef: (node: HTMLElement | null) => void;
|
|
3
3
|
focusRowId: string;
|
|
4
|
-
setFocusRowId:
|
|
4
|
+
setFocusRowId: (id: string) => void;
|
|
5
5
|
};
|
|
6
6
|
//# sourceMappingURL=useRowFocus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRowFocus.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Toolbar/hooks/useRowFocus.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,WAAW
|
|
1
|
+
{"version":3,"file":"useRowFocus.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Toolbar/hooks/useRowFocus.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,WAAW;wBAWM,WAAW,GAAG,IAAI;;wBAPlB,MAAM;EAe9C"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
2
|
import { getFocusables } from '@pega/cosmos-react-core';
|
|
3
3
|
export default function useRowFocus() {
|
|
4
|
-
const
|
|
5
|
-
const [focusRowId,
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const pendingFocusRef = useRef(false);
|
|
5
|
+
const [focusRowId, setFocusRowIdState] = useState('');
|
|
6
|
+
const setFocusRowId = useCallback((id) => {
|
|
7
|
+
pendingFocusRef.current = true;
|
|
8
|
+
setFocusRowIdState(id);
|
|
9
|
+
}, []);
|
|
10
|
+
// A callback ref, because the row may mount after its id is set (DragDropList syncs its items
|
|
11
|
+
// internally), so an effect in the owner would run too early.
|
|
12
|
+
const focusRowRef = useCallback((node) => {
|
|
13
|
+
if (!node || !pendingFocusRef.current)
|
|
14
|
+
return;
|
|
15
|
+
const focusables = getFocusables({ current: node });
|
|
8
16
|
focusables.firstToFocus?.focus();
|
|
9
|
-
|
|
17
|
+
pendingFocusRef.current = false;
|
|
18
|
+
}, []);
|
|
10
19
|
return { focusRowRef, focusRowId, setFocusRowId };
|
|
11
20
|
}
|
|
12
21
|
//# sourceMappingURL=useRowFocus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRowFocus.js","sourceRoot":"","sources":["../../../../../Core/Components/Toolbar/hooks/useRowFocus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useRowFocus.js","sourceRoot":"","sources":["../../../../../Core/Components/Toolbar/hooks/useRowFocus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IAE9D,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,EAAU,EAAE,EAAE;QAC/C,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,8FAA8F;IAC9F,8DAA8D;IAC9D,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,IAAwB,EAAE,EAAE;QAC3D,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO;YAAE,OAAO;QAC9C,MAAM,UAAU,GAAG,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,UAAU,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC;QACjC,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC;IAClC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nimport { getFocusables } from '@pega/cosmos-react-core';\n\nexport default function useRowFocus() {\n const pendingFocusRef = useRef(false);\n const [focusRowId, setFocusRowIdState] = useState<string>('');\n\n const setFocusRowId = useCallback((id: string) => {\n pendingFocusRef.current = true;\n setFocusRowIdState(id);\n }, []);\n\n // A callback ref, because the row may mount after its id is set (DragDropList syncs its items\n // internally), so an effect in the owner would run too early.\n const focusRowRef = useCallback((node: HTMLElement | null) => {\n if (!node || !pendingFocusRef.current) return;\n const focusables = getFocusables({ current: node });\n focusables.firstToFocus?.focus();\n pendingFocusRef.current = false;\n }, []);\n\n return { focusRowRef, focusRowId, setFocusRowId };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default Row;
|
|
2
|
-
declare function Row({ updateSortItemId, updateSortItemOrder, removeSortItem, sortItems, index, id, order, sequence,
|
|
2
|
+
declare function Row({ updateSortItemId, updateSortItemOrder, removeSortItem, sortItems, index, id, order, sequence, itemId, dragDisabled, dragRef, previewRef, isDragging, focusRowRef, fieldDefs, columns }: {
|
|
3
3
|
updateSortItemId: any;
|
|
4
4
|
updateSortItemOrder: any;
|
|
5
5
|
removeSortItem: any;
|
|
@@ -8,8 +8,11 @@ declare function Row({ updateSortItemId, updateSortItemOrder, removeSortItem, so
|
|
|
8
8
|
id: any;
|
|
9
9
|
order: any;
|
|
10
10
|
sequence: any;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
itemId: any;
|
|
12
|
+
dragDisabled: any;
|
|
13
|
+
dragRef: any;
|
|
14
|
+
previewRef: any;
|
|
15
|
+
isDragging: any;
|
|
13
16
|
focusRowRef: any;
|
|
14
17
|
fieldDefs: any;
|
|
15
18
|
columns: any;
|
|
@@ -25,15 +28,14 @@ declare namespace Row {
|
|
|
25
28
|
let index: PropTypes.Validator<number>;
|
|
26
29
|
let order: PropTypes.Validator<NonNullable<NonNullable<string | number | null | undefined>>>;
|
|
27
30
|
let sequence: PropTypes.Validator<NonNullable<NonNullable<string | number | null | undefined>>>;
|
|
28
|
-
let
|
|
31
|
+
let itemId: PropTypes.Requireable<string>;
|
|
32
|
+
let dragDisabled: PropTypes.Requireable<boolean>;
|
|
33
|
+
let dragRef: PropTypes.Requireable<(...args: any[]) => any>;
|
|
34
|
+
let previewRef: PropTypes.Requireable<(...args: any[]) => any>;
|
|
35
|
+
let isDragging: PropTypes.Requireable<boolean>;
|
|
36
|
+
let focusRowRef: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | {
|
|
29
37
|
[x: string]: any;
|
|
30
|
-
}
|
|
31
|
-
let dropProps: PropTypes.Requireable<{
|
|
32
|
-
[x: string]: any;
|
|
33
|
-
}>;
|
|
34
|
-
let focusRowRef: PropTypes.Requireable<{
|
|
35
|
-
[x: string]: any;
|
|
36
|
-
}>;
|
|
38
|
+
} | null | undefined>>;
|
|
37
39
|
let fieldDefs: PropTypes.Validator<any[]>;
|
|
38
40
|
}
|
|
39
41
|
let displayName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/Row.jsx"],"names":[],"mappings":";AAiCA
|
|
1
|
+
{"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/Row.jsx"],"names":[],"mappings":";AAiCA;;;;;;;;;;;;;;;;;mDAmFC;;;;;;;;;;;;;;;;;;;;;;;;sBApHqB,YAAY"}
|
|
@@ -2,46 +2,38 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import styled, { css } from 'styled-components';
|
|
5
|
-
import { Button, defaultThemeProp, Flex, Icon, Option, Select
|
|
5
|
+
import { Button, defaultThemeProp, Flex, Icon, Option, Select } from '@pega/cosmos-react-core';
|
|
6
|
+
import { DragHandle } from '@pega/cosmos-react-dnd';
|
|
6
7
|
import FieldSelector from '../../FieldSelector';
|
|
7
8
|
import { keyFrom } from '../../../../Utils';
|
|
8
9
|
import useTranslate from '../../../../Hooks/useTranslate';
|
|
9
10
|
import { getValidSortColumnsInRow, getValidSortOrders } from './utils';
|
|
10
|
-
const StyledDragHandle = styled(
|
|
11
|
-
return css `
|
|
12
|
-
cursor: grab;
|
|
11
|
+
const StyledDragHandle = styled(DragHandle)(({ theme }) => css `
|
|
13
12
|
margin-block: calc(${theme.base.spacing} * 0.5);
|
|
14
13
|
|
|
15
14
|
@media (pointer: coarse) {
|
|
16
15
|
margin-block: calc(${theme.base.spacing} * 1.25);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
});
|
|
17
|
+
`);
|
|
20
18
|
StyledDragHandle.defaultProps = defaultThemeProp;
|
|
21
|
-
const
|
|
19
|
+
const StyledRow = styled(Flex)(({ $isDragging }) => css `
|
|
20
|
+
opacity: ${$isDragging ? 0.5 : 1};
|
|
21
|
+
`);
|
|
22
|
+
StyledRow.defaultProps = defaultThemeProp;
|
|
23
|
+
const Row = ({ updateSortItemId, updateSortItemOrder, removeSortItem, sortItems, index, id, order, sequence, itemId, dragDisabled, dragRef, previewRef, isDragging, focusRowRef, fieldDefs, columns }) => {
|
|
22
24
|
const [translate] = useTranslate();
|
|
23
|
-
const t = useI18n();
|
|
24
25
|
const validSortColumnsInRow = useMemo(() => getValidSortColumnsInRow(fieldDefs, sortItems, id), [fieldDefs, sortItems, id]);
|
|
25
26
|
if (!validSortColumnsInRow || !validSortColumnsInRow.length)
|
|
26
27
|
return null;
|
|
27
28
|
const validSortOrders = getValidSortOrders();
|
|
28
29
|
const { label } = validSortOrders.find(v => v.id === order) || {};
|
|
29
30
|
const fieldLabel = columns?.find(f => f.field.id === id)?.label;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
direction: 'row',
|
|
37
|
-
wrap: 'no-wrap',
|
|
38
|
-
itemGap: 0.5
|
|
39
|
-
}, ref: focusRowRef, children: [_jsx(StyledDragHandle, { forwardedAs: 'div', role: 'button', icon: true, variant: 'simple', compact: true, disabled: !dragProps, "aria-label": dragHandleLabel, ...dragProps, children: _jsx(Icon, { name: 'drag' }) }), _jsx(Flex, { item: { grow: 1, basis: '0' }, children: _jsx(FieldSelector, { label: translate('Field'), fieldDefs: validSortColumnsInRow, value: id, onChange: newID => updateSortItemId(newID, sequence), readOnly: !updateSortItemId }) }), _jsx(Flex, { item: { grow: 1, basis: '0' }, children: _jsxs(Select, { label: translate('Sort order'), className: 'select-sorts', "data-testid": 'SortSelector', value: label, onChange: e => {
|
|
40
|
-
const o = validSortOrders.find(v => v.label === e.target.value);
|
|
41
|
-
if (o) {
|
|
42
|
-
updateSortItemOrder(e, sequence, o.id);
|
|
43
|
-
}
|
|
44
|
-
}, children: [_jsx("option", { value: '', children: translate('Select...') }), validSortOrders.map((v, i) => (_jsx(Option, { value: v.label, children: translate(v.label) }, keyFrom(v.label, i))))] }) }), _jsx(Flex, { item: true, children: _jsx(Button, { icon: true, variant: 'simple', onClick: () => removeSortItem(index, order), label: translate('Remove sort'), disabled: !removeSortItem, children: _jsx(Icon, { name: 'trash' }) }) })] }) }));
|
|
31
|
+
return (_jsxs(StyledRow, { ref: previewRef, "$isDragging": isDragging, container: { alignItems: 'end', wrap: 'nowrap', gap: 0.5 }, children: [_jsx(StyledDragHandle, { itemId: itemId, ref: dragRef, contextualLabel: fieldLabel, disabled: dragDisabled }), _jsx(Flex, { item: { grow: 1, basis: '0' }, ref: focusRowRef, children: _jsx(FieldSelector, { label: translate('Field'), fieldDefs: validSortColumnsInRow, value: id, onChange: newID => updateSortItemId(newID, sequence), readOnly: !updateSortItemId }) }), _jsx(Flex, { item: { grow: 1, basis: '0' }, children: _jsxs(Select, { label: translate('Sort order'), className: 'select-sorts', "data-testid": 'SortSelector', value: label, onChange: e => {
|
|
32
|
+
const o = validSortOrders.find(v => v.label === e.target.value);
|
|
33
|
+
if (o) {
|
|
34
|
+
updateSortItemOrder(e, sequence, o.id);
|
|
35
|
+
}
|
|
36
|
+
}, children: [_jsx("option", { value: '', children: translate('Select...') }), validSortOrders.map((v, i) => (_jsx(Option, { value: v.label, children: translate(v.label) }, keyFrom(v.label, i))))] }) }), _jsx(Flex, { item: true, children: _jsx(Button, { icon: true, variant: 'simple', onClick: () => removeSortItem(index, order), label: translate('Remove sort'), disabled: !removeSortItem, children: _jsx(Icon, { name: 'trash' }) }) })] }));
|
|
45
37
|
};
|
|
46
38
|
Row.propTypes = {
|
|
47
39
|
updateSortItemId: PropTypes.func,
|
|
@@ -53,9 +45,12 @@ Row.propTypes = {
|
|
|
53
45
|
index: PropTypes.number.isRequired,
|
|
54
46
|
order: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
55
47
|
sequence: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
itemId: PropTypes.string,
|
|
49
|
+
dragDisabled: PropTypes.bool,
|
|
50
|
+
dragRef: PropTypes.func,
|
|
51
|
+
previewRef: PropTypes.func,
|
|
52
|
+
isDragging: PropTypes.bool,
|
|
53
|
+
focusRowRef: PropTypes.oneOfType([PropTypes.func, PropTypes.objectOf(PropTypes.any)]),
|
|
59
54
|
fieldDefs: PropTypes.arrayOf(PropTypes.any).isRequired
|
|
60
55
|
};
|
|
61
56
|
Row.displayName = 'Row';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.js","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/Row.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,
|
|
1
|
+
{"version":3,"file":"Row.js","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/Row.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,O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U;IACpD,cAAc,EAAE,SAAS,CAAC,IAAI;IAC9B,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,UAAU;IACtD,EAAE,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU;IACxE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IAClC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU;IAC3E,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU;IAC9E,MAAM,EAAE,SAAS,CAAC,MAAM;IACxB,YAAY,EAAE,SAAS,CAAC,IAAI;IAC5B,OAAO,EAAE,SAAS,CAAC,IAAI;IACvB,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,UAAU;CACvD,CAAC;AAEF,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC;AAExB,eAAe,GAAG,CAAC","sourcesContent":["import PropTypes from 'prop-types';\nimport { useMemo } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Button, defaultThemeProp, Flex, Icon, Option, Select } from '@pega/cosmos-react-core';\nimport { DragHandle } from '@pega/cosmos-react-dnd';\n\nimport FieldSelector from '../../FieldSelector';\nimport { keyFrom } from '../../../../Utils';\nimport useTranslate from '../../../../Hooks/useTranslate';\n\nimport { getValidSortColumnsInRow, getValidSortOrders } from './utils';\n\nconst StyledDragHandle = styled(DragHandle)(\n ({ theme }) => css`\n margin-block: calc(${theme.base.spacing} * 0.5);\n\n @media (pointer: coarse) {\n margin-block: calc(${theme.base.spacing} * 1.25);\n }\n `\n);\n\nStyledDragHandle.defaultProps = defaultThemeProp;\n\nconst StyledRow = styled(Flex)(\n ({ $isDragging }) => css`\n opacity: ${$isDragging ? 0.5 : 1};\n `\n);\n\nStyledRow.defaultProps = defaultThemeProp;\n\nconst Row = ({\n updateSortItemId,\n updateSortItemOrder,\n removeSortItem,\n sortItems,\n index,\n id,\n order,\n sequence,\n itemId,\n dragDisabled,\n dragRef,\n previewRef,\n isDragging,\n focusRowRef,\n fieldDefs,\n columns\n}) => {\n const [translate] = useTranslate();\n const validSortColumnsInRow = useMemo(\n () => getValidSortColumnsInRow(fieldDefs, sortItems, id),\n [fieldDefs, sortItems, id]\n );\n if (!validSortColumnsInRow || !validSortColumnsInRow.length) return null;\n const validSortOrders = getValidSortOrders();\n const { label } = validSortOrders.find(v => v.id === order) || {};\n const fieldLabel = columns?.find(f => f.field.id === id)?.label;\n\n return (\n <StyledRow\n ref={previewRef}\n $isDragging={isDragging}\n container={{ alignItems: 'end', wrap: 'nowrap', gap: 0.5 }}\n >\n <StyledDragHandle\n itemId={itemId}\n ref={dragRef}\n contextualLabel={fieldLabel}\n disabled={dragDisabled}\n />\n <Flex item={{ grow: 1, basis: '0' }} ref={focusRowRef}>\n <FieldSelector\n label={translate('Field')}\n fieldDefs={validSortColumnsInRow}\n value={id}\n onChange={newID => updateSortItemId(newID, sequence)}\n readOnly={!updateSortItemId}\n />\n </Flex>\n <Flex item={{ grow: 1, basis: '0' }}>\n <Select\n label={translate('Sort order')}\n className='select-sorts'\n data-testid='SortSelector'\n value={label}\n onChange={e => {\n const o = validSortOrders.find(v => v.label === e.target.value);\n if (o) {\n updateSortItemOrder(e, sequence, o.id);\n }\n }}\n >\n <option value=''>{translate('Select...')}</option>\n {validSortOrders.map((v, i) => (\n <Option key={keyFrom(v.label, i)} value={v.label}>\n {translate(v.label)}\n </Option>\n ))}\n </Select>\n </Flex>\n <Flex item>\n <Button\n icon\n variant='simple'\n onClick={() => removeSortItem(index, order)}\n label={translate('Remove sort')}\n disabled={!removeSortItem}\n >\n <Icon name='trash' />\n </Button>\n </Flex>\n </StyledRow>\n );\n};\n\nRow.propTypes = {\n updateSortItemId: PropTypes.func,\n updateSortItemOrder: PropTypes.func.isRequired,\n columns: PropTypes.arrayOf(PropTypes.any).isRequired,\n removeSortItem: PropTypes.func,\n sortItems: PropTypes.arrayOf(PropTypes.any).isRequired,\n id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,\n index: PropTypes.number.isRequired,\n order: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,\n sequence: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,\n itemId: PropTypes.string,\n dragDisabled: PropTypes.bool,\n dragRef: PropTypes.func,\n previewRef: PropTypes.func,\n isDragging: PropTypes.bool,\n focusRowRef: PropTypes.oneOfType([PropTypes.func, PropTypes.objectOf(PropTypes.any)]),\n fieldDefs: PropTypes.arrayOf(PropTypes.any).isRequired\n};\n\nRow.displayName = 'Row';\n\nexport default Row;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortRenderer.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/SortRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SortRenderer.d.ts","sourceRoot":"","sources":["../../../../../../Core/Components/Toolbar/hooks/useSort/SortRenderer.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kDAAkD,CAAC;AAC7E,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAMjG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AA2C1C,UAAU,iBAAiB;IACzB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC;IAC9B,eAAe,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACnE,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,QAAA,MAAM,YAAY,GAAI,8DAMnB,iBAAiB,4CAyJnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect,
|
|
2
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
3
3
|
import { Button, createUID, Flex, Icon, useI18n } from '@pega/cosmos-react-core';
|
|
4
|
+
import { DragDropList, DragDropManager } from '@pega/cosmos-react-dnd';
|
|
4
5
|
import { REPEATING_STRUCTURE_TEMPLATES } from 'pega-repeating-structures-core';
|
|
5
6
|
import useRowFocus from '../useRowFocus';
|
|
6
|
-
import useDragDrop from '../../../../Hooks/useDragDrop';
|
|
7
7
|
import { getValidSortColumnsInRow } from './utils';
|
|
8
8
|
import Row from './Row';
|
|
9
|
-
const
|
|
9
|
+
const SORT_ITEM_TYPE = 'rs-sort-item';
|
|
10
|
+
// Must keep a stable identity, otherwise every render would remount the rows.
|
|
11
|
+
const SortRowRenderer = ({ id, data, dragRef, previewRef, isDragging }) => {
|
|
12
|
+
const { sortItem, index, focusRowId, focusRowRef, ...rowProps } = data;
|
|
13
|
+
return (_jsx(Row, { ...rowProps, index: index, id: sortItem.columnId, order: sortItem.order, sequence: sortItem.sequence, itemId: id, dragRef: dragRef, previewRef: previewRef, isDragging: isDragging, focusRowRef: sortItem.id === focusRowId ? focusRowRef : null }));
|
|
14
|
+
};
|
|
10
15
|
const SortRenderer = ({ sortItems, columns, updateSortItems, template, fieldDefs }) => {
|
|
11
16
|
const t = useI18n();
|
|
12
17
|
const { focusRowRef, focusRowId, setFocusRowId } = useRowFocus();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
updateSortItemSequence(parseInt(src.getAttribute('data-sequence') ?? '', 10), parseInt(dest.getAttribute('data-sequence') ?? '', 10));
|
|
25
|
-
}, [updateSortItemSequence]);
|
|
26
|
-
const { dragProps, dropProps } = useDragDrop({
|
|
27
|
-
context: dragDropRef,
|
|
28
|
-
getAnimationSelector,
|
|
29
|
-
getGhostImageSelector: getAnimationSelector,
|
|
30
|
-
getDraggedObject: getAnimationSelector,
|
|
31
|
-
onDrop
|
|
32
|
-
});
|
|
18
|
+
const sortedItems = useMemo(() => sortItems.slice().sort((a, b) => a.sequence - b.sequence), [sortItems]);
|
|
19
|
+
// The first row of a Timeline is fixed and cannot be reordered, edited or removed.
|
|
20
|
+
const lockedItem = template === REPEATING_STRUCTURE_TEMPLATES.TIMELINE ? sortedItems[0] : undefined;
|
|
21
|
+
const lockedOffset = lockedItem ? 1 : 0;
|
|
22
|
+
const onReorder = useCallback((newItems) => {
|
|
23
|
+
const reordered = [
|
|
24
|
+
...(lockedItem ? [lockedItem] : []),
|
|
25
|
+
...newItems.map(i => i.data.sortItem)
|
|
26
|
+
];
|
|
27
|
+
updateSortItems(reordered.map((item, index) => ({ ...item, sequence: index + 1 })));
|
|
28
|
+
}, [lockedItem, updateSortItems]);
|
|
33
29
|
const addSortItem = useCallback(() => {
|
|
34
30
|
const validSortColumnsInRow = getValidSortColumnsInRow(fieldDefs, sortItems);
|
|
35
31
|
if (validSortColumnsInRow && validSortColumnsInRow.length) {
|
|
@@ -73,15 +69,31 @@ const SortRenderer = ({ sortItems, columns, updateSortItems, template, fieldDefs
|
|
|
73
69
|
addSortItem();
|
|
74
70
|
}
|
|
75
71
|
}, [sortItems, addSortItem]);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
const sharedRowProps = useMemo(() => ({
|
|
73
|
+
columns,
|
|
74
|
+
sortItems,
|
|
75
|
+
fieldDefs,
|
|
76
|
+
focusRowId,
|
|
77
|
+
focusRowRef,
|
|
78
|
+
updateSortItemId,
|
|
79
|
+
updateSortItemOrder,
|
|
80
|
+
removeSortItem
|
|
81
|
+
}), [
|
|
82
|
+
columns,
|
|
83
|
+
sortItems,
|
|
84
|
+
fieldDefs,
|
|
85
|
+
focusRowId,
|
|
86
|
+
focusRowRef,
|
|
87
|
+
updateSortItemId,
|
|
88
|
+
updateSortItemOrder,
|
|
89
|
+
removeSortItem
|
|
90
|
+
]);
|
|
91
|
+
const dragItems = useMemo(() => sortedItems.slice(lockedOffset).map((sortItem, i) => ({
|
|
92
|
+
id: sortItem.id,
|
|
93
|
+
type: SORT_ITEM_TYPE,
|
|
94
|
+
data: { ...sharedRowProps, sortItem, index: i + lockedOffset }
|
|
95
|
+
})), [sortedItems, lockedOffset, sharedRowProps]);
|
|
96
|
+
return (_jsxs(Flex, { container: { direction: 'column', gap: 2 }, children: [_jsx(DragDropManager, { children: _jsxs(Flex, { container: { direction: 'column', gap: 1 }, children: [lockedItem && (_jsx(Row, { updateSortItemOrder: updateSortItemOrder, columns: columns, sortItems: sortItems, index: 0, itemId: lockedItem.id, dragDisabled: true, id: lockedItem.columnId, order: lockedItem.order, sequence: lockedItem.sequence, focusRowRef: lockedItem.id === focusRowId ? focusRowRef : null, fieldDefs: fieldDefs })), _jsx(DragDropList, { as: Flex, container: { direction: 'column', gap: 1 }, accept: SORT_ITEM_TYPE, items: dragItems, itemRenderer: SortRowRenderer, onChange: onReorder })] }) }), _jsx("div", { children: _jsx(Button, { variant: 'link', "aria-label": t('add_sort'), onClick: addSortItem, children: _jsxs(Flex, { container: { inline: true, alignItems: 'start', gap: 1 }, as: 'span', children: [_jsx(Icon, { name: 'plus' }), _jsx("span", { children: t('add') })] }) }) })] }));
|
|
85
97
|
};
|
|
86
98
|
export default SortRenderer;
|
|
87
99
|
//# sourceMappingURL=SortRenderer.js.map
|