@c-rex/components 0.3.0-build.38 → 0.3.0-build.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-rex/components",
3
- "version": "0.3.0-build.38",
3
+ "version": "0.3.0-build.39",
4
4
  "files": [
5
5
  "src"
6
6
  ],
@@ -15,6 +15,7 @@ type Props = {
15
15
  removeRestrictParam?: boolean;
16
16
  selected?: boolean;
17
17
  onClick?: () => void;
18
+ multipleSelection?: boolean;
18
19
  };
19
20
 
20
21
  export const RestrictionNavigationItem: FC<Props> = ({
@@ -23,6 +24,7 @@ export const RestrictionNavigationItem: FC<Props> = ({
23
24
  restrictField,
24
25
  removeRestrictParam = false,
25
26
  selected = false,
27
+ multipleSelection = true,
26
28
  }) => {
27
29
  const [restrict, setRestrict] = useQueryState("restrict", {
28
30
  shallow: false,
@@ -35,6 +37,7 @@ export const RestrictionNavigationItem: FC<Props> = ({
35
37
  restrictField,
36
38
  removeRestrictParam,
37
39
  selected,
40
+ multipleSelection,
38
41
  currentRestrict: restrict,
39
42
  });
40
43
 
@@ -72,6 +75,7 @@ export const RestrictionDropdownItem: FC<Props> = ({
72
75
  restrictField,
73
76
  selected = false,
74
77
  onClick,
78
+ multipleSelection = true
75
79
  }) => {
76
80
  const [restrict, setRestrict] = useQueryState("restrict", {
77
81
  shallow: false,
@@ -83,6 +87,7 @@ export const RestrictionDropdownItem: FC<Props> = ({
83
87
  shortId,
84
88
  restrictField,
85
89
  selected,
90
+ multipleSelection,
86
91
  currentRestrict: restrict,
87
92
  });
88
93
 
@@ -121,7 +126,7 @@ function getRestrictionValue({
121
126
  restrictField,
122
127
  removeRestrictParam = false,
123
128
  selected = false,
124
-
129
+ multipleSelection = true,
125
130
  currentRestrict,
126
131
  }: {
127
132
  shortId?: string;
@@ -129,11 +134,12 @@ function getRestrictionValue({
129
134
  removeRestrictParam?: boolean;
130
135
  selected?: boolean;
131
136
  currentRestrict: string | null;
137
+ multipleSelection?: boolean;
132
138
  }): { restrictionValue: string | null; shouldRemoveRestrictParam: boolean } {
133
139
  let restrictParam = "";
134
140
  let shouldRemoveRestrictParam = removeRestrictParam;
135
141
 
136
- if (currentRestrict) {
142
+ if (currentRestrict && multipleSelection) {
137
143
  if (selected) {
138
144
  const restrictionsLength = currentRestrict.split(",").length;
139
145
  //if there is only one restriction, we can remove the whole restrict param
@@ -29,7 +29,6 @@ type Props = {
29
29
  hasMoreItems?: boolean,
30
30
  showAllWhenEmpty?: boolean,
31
31
  onRequestMore?: () => void,
32
- stripLabelPrefix?: string,
33
32
  itemsByRow?: {
34
33
  [DEVICE_OPTIONS.MOBILE]: number,
35
34
  [DEVICE_OPTIONS.TABLET]: number,
@@ -264,7 +263,6 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
264
263
  hasMoreItems = false,
265
264
  showAllWhenEmpty = true,
266
265
  onRequestMore,
267
- stripLabelPrefix,
268
266
  navigationMenuListClassName = "items-center justify-start gap-4 flex-row",
269
267
  itemsByRow = {
270
268
  [DEVICE_OPTIONS.MOBILE]: 2,
@@ -274,9 +272,6 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
274
272
  }) => {
275
273
  const t = useTranslations();
276
274
  const setRestrictionList = useRestrictionStore((state) => state.setRestrictionList);
277
- const formatLabel = stripLabelPrefix
278
- ? (label: string) => label.replace(new RegExp(`^${stripLabelPrefix}`, "i"), "")
279
- : undefined;
280
275
 
281
276
  const [params] = useQueryStates({
282
277
  restrict: parseAsString,
@@ -373,7 +368,7 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
373
368
 
374
369
  {!enableHierarchy && visibleItems.map((item) => {
375
370
  const rawLabel = getLabelByLang(item.labels, lang);
376
- const label = rawLabel && formatLabel ? formatLabel(rawLabel) : rawLabel;
371
+ const label = rawLabel
377
372
  return (
378
373
  <RestrictionNavigationItem
379
374
  key={item.shortId}
@@ -389,7 +384,7 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
389
384
  const shortId = rootNode.item.shortId || "";
390
385
  const hasChildren = rootNode.children.length > 0;
391
386
  const rawLabel = getLabelByLang(rootNode.item.labels, lang);
392
- const label = rawLabel && formatLabel ? formatLabel(rawLabel) : rawLabel;
387
+ const label = rawLabel
393
388
  const rootSelected = restrictionValues.includes(shortId);
394
389
  const hasActiveDescendant = hasChildren && hasSelectedDescendant(rootNode, selectedRestrictionIds);
395
390
  const shouldHighlightBranch = hasActiveDescendant && !rootSelected;
@@ -415,7 +410,7 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
415
410
  selectedRestrictionIds={selectedRestrictionIds}
416
411
  lang={lang}
417
412
  highlighted={shouldHighlightBranch}
418
- formatLabel={formatLabel}
413
+
419
414
  />
420
415
  </NavigationMenuItem>
421
416
  );
@@ -434,7 +429,6 @@ export const RestrictionSelectionCommandMenu: FC<Props> = ({
434
429
  selectedRestrictionIds={selectedRestrictionIds}
435
430
  lang={lang}
436
431
  highlighted={false}
437
- formatLabel={formatLabel}
438
432
  />
439
433
  </NavigationMenuItem>
440
434
  )}
@@ -32,6 +32,8 @@ type Props = {
32
32
  [DEVICE_OPTIONS.TABLET]: number,
33
33
  [DEVICE_OPTIONS.DESKTOP]: number,
34
34
  }
35
+ multipleSelection?: boolean;
36
+ updatePosition?: boolean;
35
37
  }
36
38
 
37
39
  type RestrictionTreeNode = {
@@ -122,7 +124,9 @@ export const RestrictionSelectionMenu: FC<Props> = ({
122
124
  [DEVICE_OPTIONS.MOBILE]: 2,
123
125
  [DEVICE_OPTIONS.TABLET]: 4,
124
126
  [DEVICE_OPTIONS.DESKTOP]: 7,
125
- }
127
+ },
128
+ multipleSelection = true,
129
+ updatePosition = true
126
130
  }) => {
127
131
  const t = useTranslations();
128
132
  const setRestrictionList = useRestrictionStore((state) => state.setRestrictionList);
@@ -154,6 +158,8 @@ export const RestrictionSelectionMenu: FC<Props> = ({
154
158
  const sortedItems = useMemo(() => {
155
159
  //if shortId it is on the restrictionValues, it should be on top of the list, otherwise keep the original order
156
160
 
161
+ if (updatePosition === false) return items;
162
+
157
163
  const sorted = [...items].sort((a, b) => {
158
164
  const aShortId = a.shortId || "";
159
165
  const bShortId = b.shortId || "";
@@ -173,7 +179,7 @@ export const RestrictionSelectionMenu: FC<Props> = ({
173
179
  return aIndex - bIndex; // sort by index in restrictionValues
174
180
  });
175
181
  return sorted;
176
- }, [items, restrictionValues]);
182
+ }, [items, restrictionValues, updatePosition]);
177
183
 
178
184
  const hierarchyRoots = useMemo(() => {
179
185
  if (!enableHierarchy) return [];
@@ -293,6 +299,7 @@ export const RestrictionSelectionMenu: FC<Props> = ({
293
299
  <RestrictionNavigationItem
294
300
  key={item.shortId}
295
301
  shortId={item.shortId!}
302
+ multipleSelection={multipleSelection}
296
303
  restrictField={restrictField as string}
297
304
  label={getLabelByLang(item.labels, lang)}
298
305
  selected={restrictionValues.includes(item.shortId!)}
@@ -315,6 +322,7 @@ export const RestrictionSelectionMenu: FC<Props> = ({
315
322
  restrictField={restrictField}
316
323
  label={label}
317
324
  selected={restrictionValues.includes(shortId)}
325
+ multipleSelection={multipleSelection}
318
326
  />
319
327
  );
320
328
  }
@@ -364,6 +372,7 @@ export const RestrictionSelectionMenu: FC<Props> = ({
364
372
  >
365
373
  <RestrictionDropdownItem
366
374
  shortId={item.shortId!}
375
+ multipleSelection={multipleSelection}
367
376
  restrictField={restrictField as string}
368
377
  label={getLabelByLang(item.labels, lang)}
369
378
  selected={restrictionValues.includes(item.shortId!)}
@@ -29,7 +29,6 @@ export type TaxonomyRestrictionCommandMenuProps = {
29
29
  fetchMode?: RestrictionMenuFetchMode;
30
30
  showAllWhenEmpty?: boolean;
31
31
  queryParams?: GenericQueryParams;
32
- stripLabelPrefix?: string;
33
32
  };
34
33
 
35
34
  export const TaxonomyRestrictionCommandMenu: FC<TaxonomyRestrictionCommandMenuProps> = ({
@@ -42,7 +41,6 @@ export const TaxonomyRestrictionCommandMenu: FC<TaxonomyRestrictionCommandMenuPr
42
41
  fetchMode = "deferred",
43
42
  showAllWhenEmpty = true,
44
43
  navigationMenuListClassName = "items-center justify-start gap-4 flex-row",
45
- stripLabelPrefix,
46
44
  }) => {
47
45
  const [loadAll, setLoadAll] = useState(false);
48
46
  const RequestComponent = ComponentOptions[requestType] as unknown as FC<GenericRequestProps>;
@@ -102,7 +100,6 @@ export const TaxonomyRestrictionCommandMenu: FC<TaxonomyRestrictionCommandMenuPr
102
100
  }
103
101
  }}
104
102
  navigationMenuListClassName={navigationMenuListClassName}
105
- stripLabelPrefix={stripLabelPrefix}
106
103
  />
107
104
  );
108
105
  }}
@@ -34,6 +34,8 @@ export type TaxonomyRestrictionMenuProps = {
34
34
  fetchMode?: RestrictionMenuFetchMode;
35
35
  showAllWhenEmpty?: boolean;
36
36
  queryParams?: GenericQueryParams;
37
+ multipleSelection?: boolean;
38
+ updatePosition?: boolean;
37
39
  };
38
40
 
39
41
  const DEFAULT_ITEMS_BY_ROW = {
@@ -52,6 +54,8 @@ export const TaxonomyRestrictionMenu: FC<TaxonomyRestrictionMenuProps> = ({
52
54
  fetchMode = "deferred",
53
55
  showAllWhenEmpty = true,
54
56
  navigationMenuListClassName = "items-center justify-start gap-4 flex-row",
57
+ multipleSelection = true,
58
+ updatePosition = true,
55
59
  }) => {
56
60
  const [loadAll, setLoadAll] = useState(false);
57
61
  const RequestComponent = ComponentOptions[requestType] as unknown as FC<GenericRequestProps>;
@@ -113,6 +117,8 @@ export const TaxonomyRestrictionMenu: FC<TaxonomyRestrictionMenuProps> = ({
113
117
  }
114
118
  }}
115
119
  navigationMenuListClassName={navigationMenuListClassName}
120
+ multipleSelection={multipleSelection}
121
+ updatePosition={updatePosition}
116
122
  />
117
123
  );
118
124
  }}