Skip to content

Commit db9686f

Browse files
LPD-24670 Mark invalid items without mutating the original ones
1 parent 1c6bd75 commit db9686f

File tree

3 files changed

+83
-43
lines changed
  • modules/apps/frontend-data-set

3 files changed

+83
-43
lines changed

modules/apps/frontend-data-set/frontend-data-set-admin-web/src/main/resources/META-INF/resources/item/selector/FDSAdminItemSelector.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,36 @@ const views = [
2525
name: 'list',
2626
schema: {
2727
description: 'description',
28+
isItemValid: 'isItemValid',
2829
symbol: 'symbol',
2930
title: 'label',
31+
tooltipText: 'tooltipText',
3032
},
3133
setItemComponentProps: ({item, props}: {item: any; props: any}) => {
3234
if (
3335
!item.dataSetToDataSetCardsSections.length &&
3436
!item.dataSetToDataSetTableSections.length &&
3537
!item.dataSetToDataSetListSections.length
3638
) {
37-
3839
return {
39-
...props, // we need to avoid item mutation
40+
...props,
4041
item: {
4142
...item,
42-
symbol: 'warning',
43-
tooltip: 'perico'
44-
}
45-
}
46-
43+
isItemValid: false,
44+
tooltipText: Liferay.Language.get(
45+
'no-visualization-modes-has-been-defined'
46+
),
47+
},
48+
};
49+
} else {
50+
return {
51+
...props,
52+
item: {
53+
...item,
54+
isItemValid: true,
55+
},
56+
};
4757
}
48-
49-
return props;
5058
},
5159
},
5260
];

modules/apps/frontend-data-set/frontend-data-set-web/src/main/resources/META-INF/resources/utils/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,12 @@ export interface IListTitleRenderer {
244244
export interface IListSchema {
245245
description: string;
246246
image?: string;
247+
isItemValid?: string;
247248
sticker?: string;
248249
symbol: string;
249250
title: string;
250251
titleRenderer: IListTitleRenderer;
252+
tooltipText?: string;
251253
}
252254

253255
export type ISchema = ITableSchema | ICardSchema | IListSchema;

modules/apps/frontend-data-set/frontend-data-set-web/src/main/resources/META-INF/resources/views/list/List.tsx

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ClayIcon from '@clayui/icon';
88
import ClayLayout from '@clayui/layout';
99
import ClayList from '@clayui/list';
1010
import ClaySticker from '@clayui/sticker';
11+
import {ClayTooltipProvider} from '@clayui/tooltip';
1112
import classNames from 'classnames';
1213
import {getObjectValueFromPath} from 'frontend-js-web';
1314
import React, {forwardRef, useContext} from 'react';
@@ -25,7 +26,6 @@ import {
2526
IView,
2627
} from '../../utils/types';
2728
import ViewsContext from '../ViewsContext';
28-
import Tooltip, { ClayTooltipProvider } from '@clayui/tooltip';
2929

3030
const Title = ({
3131
item,
@@ -57,12 +57,14 @@ const ListItem = forwardRef<HTMLLIElement, any>(
5757
(
5858
{
5959
className,
60+
clayListItemProps,
6061
item,
6162
items,
6263
onItemSelectionChange,
6364
schema,
6465
}: {
6566
className: string;
67+
clayListItemProps: Object;
6668
item: any;
6769
items: any[];
6870
onItemSelectionChange: Function;
@@ -78,8 +80,16 @@ const ListItem = forwardRef<HTMLLIElement, any>(
7880
selectionType,
7981
} = useContext(FrontendDataSetContext);
8082

81-
const {description, image, sticker, symbol, title, titleRenderer} =
82-
schema;
83+
const {
84+
description,
85+
image,
86+
isItemValid,
87+
sticker,
88+
symbol,
89+
title,
90+
titleRenderer,
91+
tooltipText,
92+
} = schema;
8393

8494
const SelectionInput =
8595
selectionType === 'single' ? ClayRadio : ClayCheckbox;
@@ -94,14 +104,14 @@ const ListItem = forwardRef<HTMLLIElement, any>(
94104
active: selectedItemsValue?.includes(itemId),
95105
}),
96106
flex: true,
107+
...clayListItemProps,
97108
};
98109

110+
const itemValid = isItemValid && item[isItemValid] === true;
111+
99112
return (
100-
<ClayList.Item
101-
{...props}
102-
ref={ref}
103-
>
104-
{!selectable ? (
113+
<ClayList.Item {...props} ref={ref}>
114+
{selectable && (
105115
<ClayList.ItemField className="justify-content-center selection-control">
106116
<SelectionInput
107117
checked={
@@ -117,9 +127,29 @@ const ListItem = forwardRef<HTMLLIElement, any>(
117127
value={itemId}
118128
/>
119129
</ClayList.ItemField>
120-
):
121-
<ClayList.ItemField className="justify-content-center selection-control"></ClayList.ItemField>
122-
}
130+
)}
131+
132+
{isItemValid && item[isItemValid] === false && tooltipText && (
133+
<ClayList.ItemField>
134+
<ClayTooltipProvider>
135+
<span title={item[tooltipText]}>
136+
<ClaySticker displayType="warning">
137+
<ClayIcon symbol="exclamation-circle" />
138+
</ClaySticker>
139+
</span>
140+
</ClayTooltipProvider>
141+
</ClayList.ItemField>
142+
)}
143+
144+
{isItemValid && item[isItemValid] === true && (
145+
<ClayList.ItemField>
146+
<ClayTooltipProvider>
147+
<ClaySticker displayType="unstyled">
148+
<ClayIcon symbol="catalog" />
149+
</ClaySticker>
150+
</ClayTooltipProvider>
151+
</ClayList.ItemField>
152+
)}
123153

124154
{image && item[image] ? (
125155
<ClayList.ItemField>
@@ -133,25 +163,22 @@ const ListItem = forwardRef<HTMLLIElement, any>(
133163
item[symbol] && (
134164
<ClayList.ItemField>
135165
<ClayTooltipProvider>
136-
<span
137-
className="ml-1 text-secondary"
138-
data-tooltip-align="top"
139-
title={Liferay.Language.get(
140-
'no-visualization-modes-has-been-defined'
141-
)}
166+
<span
167+
className="ml-1 text-secondary"
168+
data-tooltip-align="top"
169+
title={Liferay.Language.get(
170+
'no-visualization-modes-has-been-defined'
171+
)}
172+
>
173+
<ClaySticker
174+
{...(sticker && item[sticker])}
142175
>
143-
<ClaySticker {...(sticker && item[sticker])}>
144-
{item[symbol] && (
145-
<ClayIcon symbol={item[symbol]} />
146-
)}
147-
148-
</ClaySticker>
149-
</span>
150-
151-
152-
</ClayTooltipProvider>
153-
154-
176+
{item[symbol] && (
177+
<ClayIcon symbol={item[symbol]} />
178+
)}
179+
</ClaySticker>
180+
</span>
181+
</ClayTooltipProvider>
155182
</ClayList.ItemField>
156183
)
157184
)}
@@ -178,28 +205,30 @@ const ListItem = forwardRef<HTMLLIElement, any>(
178205
)}
179206
</ClayList.ItemField>
180207

181-
<ClayList.ItemField>
182-
{(itemsActions || item.actionDropdownItems) && (
208+
{(itemsActions || item.actionDropdownItems) && (
209+
<ClayList.ItemField>
183210
<Actions
184211
actions={itemsActions || item.actionDropdownItems}
185212
itemData={item}
186213
itemId={itemId}
187214
items={items}
188215
onItemSelectionChange={onItemSelectionChange}
189216
/>
190-
)}
191-
</ClayList.ItemField>
217+
</ClayList.ItemField>
218+
)}
192219
</ClayList.Item>
193220
);
194221
}
195222
);
196223

197224
const ListItemOptionalDropTarget = ({
225+
clayListItemProps,
198226
item,
199227
items,
200228
onItemSelectionChange,
201229
schema,
202230
}: {
231+
clayListItemProps?: object;
203232
item: any;
204233
items: any[];
205234
onItemSelectionChange: Function;
@@ -213,10 +242,11 @@ const ListItemOptionalDropTarget = ({
213242

214243
const props = {
215244
className,
245+
clayListItemProps,
216246
item,
217247
items,
218248
onItemSelectionChange,
219-
ref:dropRef,
249+
ref: dropRef,
220250
schema,
221251
};
222252

0 commit comments

Comments
 (0)