@griddo/ax 10.3.7 → 10.3.8

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.
@@ -9,7 +9,7 @@ import { IconAction, FloatingPanel, Select, Tag } from "@ax/components";
9
9
  import AutoPanel from "./AutoPanel";
10
10
  import ItemList from "./ItemList";
11
11
  import ManualPanel from "./ManualPanel";
12
- import { useReference, ReferenceProvider, IReferenceState } from "./Context";
12
+ import { useReference, ReferenceProvider, IReferenceState, ISource, IRefField } from "./Context";
13
13
 
14
14
  import * as S from "./style";
15
15
 
@@ -21,7 +21,7 @@ const ReferenceFieldWithProvider = (props: IReferenceFieldProps) => (
21
21
 
22
22
  const ReferenceField = (props: IReferenceFieldProps) => {
23
23
  const {
24
- source,
24
+ sources,
25
25
  value,
26
26
  onChange,
27
27
  disabled,
@@ -44,9 +44,10 @@ const ReferenceField = (props: IReferenceFieldProps) => {
44
44
  const singleMode = selectionType && selectionType.length === 1;
45
45
  const isAuto = mode === "auto";
46
46
  const hasMaxItems = !!(value && value.fixed && maxItems && !isAuto && value.fixed.length >= maxItems);
47
+ const sourcesIDs = sources.map((source: ISource) => source.structuredData);
47
48
 
48
49
  const handleMode = (mode: string) => {
49
- const { fixed, order, quantity, filter, allLanguages, preferenceLanguage, fullRelations = false } = state;
50
+ const { fixed, order, quantity, allLanguages, preferenceLanguage, fullRelations = false } = state;
50
51
 
51
52
  const manualSources: string[] = state.selectedItems.reduce(
52
53
  (unique: string[], selItem: IStructuredDataContent) =>
@@ -54,34 +55,36 @@ const ReferenceField = (props: IReferenceFieldProps) => {
54
55
  []
55
56
  );
56
57
 
57
- const resetSource = mode === "manual" || source.length === 1 ? source : manualSources;
58
+ const resetSource = mode === "manual" || sourcesIDs.length === 1 ? sourcesIDs : manualSources;
59
+ const mappedSources: ISource[] = resetSource.map((source: string) => {
60
+ return { structuredData: source, filters: [], filterOperator: "OR", globalOperator: "AND" };
61
+ });
58
62
 
59
63
  const newValue =
60
64
  mode === "auto"
61
65
  ? {
62
66
  mode,
63
- source,
67
+ sources: mappedSources,
64
68
  order,
65
69
  quantity,
66
- filter,
67
70
  fullRelations,
68
71
  allLanguages,
69
72
  preferenceLanguage,
70
73
  }
71
74
  : {
72
75
  mode,
73
- source,
76
+ sources,
74
77
  fixed,
75
78
  fullRelations,
76
79
  };
77
80
  onChange(newValue);
78
- setModeAndSource(mode, resetSource);
79
- handleValidation && handleValidation(value.fixed, validators);
81
+ setModeAndSource(mode, mappedSources);
82
+ resetValidation && resetValidation();
80
83
  };
81
84
 
82
85
  useEffect(() => {
83
86
  const getSourcesTitles = async () => {
84
- const response = await structuredData.getDataTitles(source);
87
+ const response = await structuredData.getDataTitles(sourcesIDs);
85
88
  if (isReqOk(response?.status)) {
86
89
  return response.data;
87
90
  } else {
@@ -93,7 +96,11 @@ const ReferenceField = (props: IReferenceFieldProps) => {
93
96
  let isMounted = true;
94
97
  if (isMounted) {
95
98
  getSourcesTitles().then((result: IDataSource[]) => {
96
- let newState = { ...state, ...value, sourceTitles: result };
99
+ let sources = value && value.sources;
100
+ if (mode === "auto" && !sources && sourcesIDs[0]) {
101
+ sources = [{ structuredData: sourcesIDs[0], filters: [], filterOperator: "OR", globalOperator: "AND" }];
102
+ }
103
+ let newState = { ...state, ...value, sourceTitles: result, sources };
97
104
  if (value?.order) {
98
105
  const [order, orderDirection = "ASC"] = value.order.split("-");
99
106
  newState = { ...newState, order, orderDirection };
@@ -123,7 +130,7 @@ const ReferenceField = (props: IReferenceFieldProps) => {
123
130
  toggleModal();
124
131
  };
125
132
 
126
- const handleListDelete = (fixed: string[]) => {
133
+ const handleListDelete = (fixed: number[]) => {
127
134
  const newValue = {
128
135
  mode,
129
136
  fixed,
@@ -132,6 +139,14 @@ const ReferenceField = (props: IReferenceFieldProps) => {
132
139
  resetValidation && resetValidation();
133
140
  };
134
141
 
142
+ const handleListMove = (fixed: number[]) => {
143
+ const newValue = {
144
+ mode,
145
+ fixed,
146
+ };
147
+ onChange(newValue);
148
+ };
149
+
135
150
  const icon = isAuto ? "edit" : "add";
136
151
 
137
152
  const defaultOrders: any = {
@@ -150,17 +165,19 @@ const ReferenceField = (props: IReferenceFieldProps) => {
150
165
  <S.DataWrapper data-testid="auto-data-wrapper">
151
166
  <S.SourcesWrapper>
152
167
  {value &&
153
- value.source &&
154
- value.source.map((singleSource: string) => {
155
- const srcFilters = state.filter.filter((f: any) => f.source === singleSource);
156
- const srcTitle: any = state.sourceTitles.find((sour: any) => sour.id === singleSource);
157
- const title = srcTitle ? srcTitle.title : "";
168
+ value.sources &&
169
+ value.sources.map((singleSource: ISource) => {
170
+ const srcTitle: { id: string; title: string } = state.sourceTitles.find(
171
+ (source: { id: string; title: string }) => source.id === singleSource.structuredData
172
+ );
158
173
  return (
159
- <S.TypeContainer key={singleSource}>
160
- <S.Title>{title}</S.Title>
161
- {srcFilters.map((f: any) => (
162
- <Tag key={f.label} text={f.label} />
163
- ))}
174
+ <S.TypeContainer key={singleSource.structuredData}>
175
+ <S.Title>{srcTitle?.title}</S.Title>
176
+ <div>
177
+ {singleSource.filters?.map((f: any) => (
178
+ <Tag key={f.label} text={f.category ? `${f.category}: ${f.label}` : f.label} color={f.color} />
179
+ ))}
180
+ </div>
164
181
  </S.TypeContainer>
165
182
  );
166
183
  })}
@@ -196,7 +213,12 @@ const ReferenceField = (props: IReferenceFieldProps) => {
196
213
  const dataBlock = isAuto ? (
197
214
  <AutoData />
198
215
  ) : (
199
- <ItemList items={value?.fixed ? value.fixed : []} handleListDelete={handleListDelete} site={value?.site} />
216
+ <ItemList
217
+ items={value?.fixed ? value.fixed : []}
218
+ handleListDelete={handleListDelete}
219
+ handleListMove={handleListMove}
220
+ site={value?.site}
221
+ />
200
222
  );
201
223
 
202
224
  return (
@@ -234,8 +256,8 @@ const ReferenceField = (props: IReferenceFieldProps) => {
234
256
  };
235
257
 
236
258
  export interface IReferenceFieldProps {
237
- source: string[];
238
- value?: any;
259
+ sources: ISource[];
260
+ value?: IRefField;
239
261
  onChange: (value: any) => void;
240
262
  disabled?: boolean;
241
263
  site: ISite | null;
@@ -32,6 +32,7 @@ const SourcesWrapper = styled.div`
32
32
  `;
33
33
 
34
34
  const TypeContainer = styled.div`
35
+ display: flex;
35
36
  margin-bottom: ${(p) => p.theme.spacing.xs};
36
37
  `;
37
38
 
@@ -7,36 +7,36 @@ export const StyledSelect = styled(Select)<{
7
7
  alignRight: boolean | undefined;
8
8
  maxWidth?: number;
9
9
  }>`
10
- ${(p) => p.theme.textStyle?.fieldContent};
11
- color: ${(p) => p.theme.color?.textHighEmphasis};
12
- margin-bottom: ${(p) => p.theme.spacing?.xxs};
10
+ ${(p) => p.theme.textStyle.fieldContent};
11
+ color: ${(p) => p.theme.color.textHighEmphasis};
12
+ margin-bottom: ${(p) => p.theme.spacing.xxs};
13
13
 
14
14
  .react-select__control {
15
- background-color: ${(p) => p.theme.color?.interactiveBackground};
15
+ background-color: ${(p) => p.theme.color.interactiveBackground};
16
16
  box-sizing: border-box;
17
17
  border-radius: 4px;
18
- border-color: ${(p) => (p.error ? p.theme.color?.error : p.theme.color?.uiLine)};
18
+ border-color: ${(p) => (p.error ? p.theme.color.error : p.theme.color.uiLine)};
19
19
  box-shadow: none;
20
- height: ${(p) => p.theme.spacing?.l};
21
- max-width: calc(${(p) => p.theme.spacing?.xl} * 6);
20
+ height: ${(p) => p.theme.spacing.l};
21
+ max-width: calc(${(p) => p.theme.spacing.xl} * 6);
22
22
  cursor: pointer;
23
23
 
24
24
  :hover {
25
- border-color: ${(p) => (p.error ? p.theme.color?.error : p.theme.color?.uiLine)};
25
+ border-color: ${(p) => (p.error ? p.theme.color.error : p.theme.color.uiLine)};
26
26
  }
27
27
  .react-select__placeholder {
28
- color: ${(p) => p.theme.color?.textLowEmphasis};
28
+ color: ${(p) => p.theme.color.textLowEmphasis};
29
29
  }
30
30
  .react-select__indicator-separator {
31
31
  display: none;
32
32
  }
33
33
  .react-select__indicator {
34
- color: ${(p) => (p.isDisabled ? p.theme.color?.interactiveDisabled : p.theme.color?.interactive01)};
34
+ color: ${(p) => (p.isDisabled ? p.theme.color.interactiveDisabled : p.theme.color.interactive01)};
35
35
  }
36
36
  }
37
37
 
38
38
  .react-select__control--is-focused {
39
- border-color: ${(p) => (p.error ? p.theme.color?.error : p.theme.color?.interactive01)} !important;
39
+ border-color: ${(p) => (p.error ? p.theme.color.error : p.theme.color.interactive01)} !important;
40
40
  }
41
41
 
42
42
  .react-select__control--menu-is-open {
@@ -46,50 +46,50 @@ export const StyledSelect = styled(Select)<{
46
46
  }
47
47
 
48
48
  .react-select__control--is-disabled {
49
- border-color: ${(p) => p.theme.color?.interactiveDisabled};
49
+ border-color: ${(p) => p.theme.color.interactiveDisabled};
50
50
  }
51
51
 
52
52
  .react-select__menu {
53
53
  box-shadow: none;
54
54
  border-radius: 4px;
55
- min-width: calc(${(p) => p.theme.spacing?.xl} * 2);
56
- max-width: calc(${(p) => p.theme.spacing?.xl} * 6);
55
+ min-width: calc(${(p) => p.theme.spacing.xl} * 2);
56
+ max-width: calc(${(p) => p.theme.spacing.xl} * 6);
57
57
  margin-top: 0;
58
58
  z-index: 99;
59
59
  .react-select__menu-list {
60
60
  border: 1px solid ${(p) => p.theme.color.uiLine};
61
61
  border-radius: 4px;
62
- max-height: calc(${(p) => p.theme.spacing?.l} * 3);
62
+ max-height: calc(${(p) => p.theme.spacing.l} * 3);
63
63
  overflow: auto;
64
64
  padding: 0;
65
65
  .react-select__option {
66
- background-color: ${(p) => p.theme.color?.interactiveBackground};
67
- min-height: ${(p) => p.theme.spacing?.l};
66
+ background-color: ${(p) => p.theme.color.interactiveBackground};
67
+ min-height: ${(p) => p.theme.spacing.l};
68
68
  padding: ${(p) => `13px ${p.theme.spacing.s} 12px ${p.theme.spacing.s}`};
69
69
  &:first-child {
70
70
  ${(p) =>
71
71
  p.hasEmptyOption &&
72
72
  css`
73
73
  font-style: italic;
74
- color: ${(p) => p.theme.color?.textLowEmphasis};
75
- background-color: ${(p) => p.theme.color?.uiLineInverse};
74
+ color: ${(p) => p.theme.color.textLowEmphasis};
75
+ background-color: ${(p) => p.theme.color.uiLineInverse};
76
76
  `}
77
77
  }
78
78
  :hover {
79
79
  cursor: pointer;
80
- background-color: ${(p) => p.theme.color?.overlayHoverPrimary};
80
+ background-color: ${(p) => p.theme.color.overlayHoverPrimary};
81
81
  }
82
82
  :focus {
83
- background-color: ${(p) => p.theme.color?.overlayFocusPrimary};
84
- border: 0.5px solid ${(p) => p.theme.color?.interactive02};
83
+ background-color: ${(p) => p.theme.color.overlayFocusPrimary};
84
+ border: 0.5px solid ${(p) => p.theme.color.interactive02};
85
85
  }
86
86
  :active {
87
- background-color: ${(p) => p.theme.color?.overlayPressedPrimary};
87
+ background-color: ${(p) => p.theme.color.overlayPressedPrimary};
88
88
  }
89
89
  }
90
90
  .react-select__option--is-selected {
91
- color: ${(p) => p.theme.color?.textHighEmphasis};
92
- background-color: ${(p) => p.theme.color?.overlayPressedPrimary};
91
+ color: ${(p) => p.theme.color.textHighEmphasis};
92
+ background-color: ${(p) => p.theme.color.overlayPressedPrimary};
93
93
  }
94
94
  }
95
95
  }
@@ -4,7 +4,7 @@ import { Icon } from "@ax/components";
4
4
  import * as S from "./style";
5
5
 
6
6
  const Tag = (props: ITagProps): JSX.Element => {
7
- const { type, text, color, icon, onDeleteAction } = props;
7
+ const { type, text, color, icon, rounded = true, onDeleteAction } = props;
8
8
 
9
9
  const handleClick = () => {
10
10
  if (onDeleteAction) {
@@ -39,7 +39,7 @@ const Tag = (props: ITagProps): JSX.Element => {
39
39
  );
40
40
  default:
41
41
  return (
42
- <S.TagFixed color={color} data-testid="tag-fixed">
42
+ <S.TagFixed color={color} rounded={rounded} data-testid="tag-fixed">
43
43
  <S.TagText>
44
44
  <S.Title data-testid="tag-fixed-title">{text}</S.Title>
45
45
  {deleteIcon}
@@ -53,6 +53,7 @@ export interface ITagProps {
53
53
  type?: "status" | "fixed" | "interactive" | "square" | undefined;
54
54
  text: string;
55
55
  color?: string;
56
+ rounded?: boolean;
56
57
  icon?: string;
57
58
  onDeleteAction?: () => void;
58
59
  }
@@ -1,6 +1,6 @@
1
1
  import styled from "styled-components";
2
2
 
3
- export const TagStatus = styled.div`
3
+ const TagStatus = styled.div`
4
4
  ${(p) => p.theme.textStyle.uiXS};
5
5
  background-color: #ffffff;
6
6
  border: 1px solid ${(p) => p.theme.color.uiLine};
@@ -12,7 +12,7 @@ export const TagStatus = styled.div`
12
12
  text-transform: capitalize;
13
13
  `;
14
14
 
15
- export const TagSquare = styled.div<{ color: string | undefined }>`
15
+ const TagSquare = styled.div<{ color?: string; }>`
16
16
  ${(p) => p.theme.textStyle.uiXS};
17
17
  display: flex;
18
18
  background-color: ${(p) => (p.color ? p.color : p.theme.colors.uiBackground01)};
@@ -24,7 +24,7 @@ export const TagSquare = styled.div<{ color: string | undefined }>`
24
24
  text-transform: capitalize;
25
25
  `;
26
26
 
27
- export const Bullet = styled.span<{ color: string | undefined }>`
27
+ const Bullet = styled.span<{ color?: string }>`
28
28
  background-color: ${(p) => (p.color ? p.color : `#4096D6`)};
29
29
  display: inline-block;
30
30
  width: 8px;
@@ -33,10 +33,10 @@ export const Bullet = styled.span<{ color: string | undefined }>`
33
33
  margin-right: 4px;
34
34
  `;
35
35
 
36
- export const TagFixed = styled.div<{ color: string | undefined }>`
36
+ const TagFixed = styled.div<{ color?: string; rounded: boolean; }>`
37
37
  ${(p) => p.theme.textStyle.uiS};
38
38
  background-color: ${(p) => (p.color ? p.color : p.theme.color.interactive02)};
39
- border-radius: ${(p) => p.theme.spacing.s};
39
+ border-radius: ${(p) => p.rounded ? p.theme.spacing.s : "0"};
40
40
  box-sizing: border-box;
41
41
  color: ${(p) => p.theme.color.textMediumEmphasis};
42
42
  display: inline-block;
@@ -45,9 +45,9 @@ export const TagFixed = styled.div<{ color: string | undefined }>`
45
45
  margin-bottom: ${(p) => p.theme.spacing.xxs};
46
46
  `;
47
47
 
48
- export const Title = styled.div``;
48
+ const Title = styled.div``;
49
49
 
50
- export const IconWrapper = styled.div`
50
+ const IconWrapper = styled.div`
51
51
  height: 16px;
52
52
  margin-left: ${(p) => p.theme.spacing.xxs};
53
53
  cursor: pointer;
@@ -58,7 +58,7 @@ export const IconWrapper = styled.div`
58
58
  }
59
59
  `;
60
60
 
61
- export const IconTag = styled.div`
61
+ const IconTag = styled.div`
62
62
  height: 16px;
63
63
  margin-right: ${(p) => p.theme.spacing.xs};
64
64
  svg {
@@ -68,7 +68,9 @@ export const IconTag = styled.div`
68
68
  }
69
69
  `;
70
70
 
71
- export const TagText = styled.div`
71
+ const TagText = styled.div`
72
72
  display: flex;
73
73
  align-items: center;
74
74
  `;
75
+
76
+ export { TagStatus, TagSquare, Bullet, TagFixed, Title, IconWrapper, IconTag, TagText };
@@ -2,7 +2,7 @@ import { useEffect, useState, useLayoutEffect } from "react";
2
2
  import { IEmptyStateProps } from "@ax/types";
3
3
  import { useWindowSize } from "./window";
4
4
 
5
- const useCategoryColors = (): any => {
5
+ const useCategoryColors = (categories?: string[]): any => {
6
6
  const fixedColors = [
7
7
  "#FFE695",
8
8
  "#C1F0FF",
@@ -19,6 +19,11 @@ const useCategoryColors = (): any => {
19
19
  const colors = [...fixedColors];
20
20
  const [categoryColors, setCategoryColors] = useState({});
21
21
 
22
+ useEffect(() => {
23
+ categories && addCategoryColors(categories);
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
+ }, [categories]);
26
+
22
27
  const getColor = () => {
23
28
  return "hsl(" + 360 * Math.random() + "," + (25 + 70 * Math.random()) + "%," + (85 + 10 * Math.random()) + "%)";
24
29
  };