@omniumretail/component-library 1.0.61 → 1.0.63

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/main.css CHANGED
@@ -280,6 +280,20 @@
280
280
  .Hfh5KLg4Y_g44Ajhx9aV .anticon-close:hover {
281
281
  color: var(--color-black);
282
282
  }
283
+ .yhGDUJJiYhqjPCJgNdjI .Gj9zvBh4toFNL6uoWOIk {
284
+ display: flex;
285
+ gap: 12px;
286
+ }
287
+ .yhGDUJJiYhqjPCJgNdjI .BvTiplJPlDM4ob_yobaL {
288
+ display: flex;
289
+ flex-direction: row;
290
+ gap: 12px;
291
+ font-family: "SilkaBold";
292
+ text-decoration: underline;
293
+ }
294
+ .yhGDUJJiYhqjPCJgNdjI .BvTiplJPlDM4ob_yobaL div {
295
+ cursor: pointer;
296
+ }
283
297
  /*!*******************************************************************************************************************************************************************!*\
284
298
  !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./node_modules/sass-loader/dist/cjs.js!./src/components/DatePicker/styles.module.scss ***!
285
299
  \*******************************************************************************************************************************************************************/
@@ -8,5 +8,6 @@ export interface ModalWithTableProps {
8
8
  isLoading?: boolean;
9
9
  confirmLoading?: boolean;
10
10
  initialRowSelectedInfo?: any;
11
+ advancedTagsList?: string[];
11
12
  }
12
13
  export declare const ModalWithTable: (props: ModalWithTableProps) => JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { Meta, Story } from "@storybook/react";
2
+ import { ErrorNotificationProps } from '.';
3
+ declare const _default: Meta<import("@storybook/react").Args>;
4
+ export default _default;
5
+ export declare const Primary: Story<ErrorNotificationProps>;
@@ -0,0 +1,9 @@
1
+ export interface ErrorNotificationProps {
2
+ message: string;
3
+ description: string;
4
+ }
5
+ type NotificationType = 'success' | 'info' | 'warning' | 'error';
6
+ export declare const Notification: ({ message, description }: ErrorNotificationProps) => {
7
+ openNotificationWithIcon: (type: NotificationType) => void;
8
+ };
9
+ export {};
@@ -1,6 +1,8 @@
1
1
  import { TagProps } from 'antd';
2
2
  export interface customTagProps extends TagProps {
3
- customTags?: any;
4
- tagsInfo?: any;
3
+ customTags?: string[];
4
+ tagsInfo?: (tags: string[]) => void;
5
+ advancedTagsInfo?: (tags: string[]) => void;
6
+ advancedTags?: string[];
5
7
  }
6
8
  export declare const TagField: (props: customTagProps) => JSX.Element;
@@ -22,3 +22,4 @@ export * from './CategoryResponse';
22
22
  export * from './Upload';
23
23
  export * from './UserInfo';
24
24
  export * from './CategoryReadOnly';
25
+ export * from './Notification';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.0.61",
3
+ "version": "1.0.63",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -84,7 +84,7 @@ const Template: Story<ModalWithTableProps> = (args) => {
84
84
  return (
85
85
  <>
86
86
  <button onClick={() => onClickMe()}> Button </button>
87
- <ModalWithTable {...args} modalData={setModalData} isLoading={isFetching} tableData={data} isOpen={isModalOpen}></ModalWithTable>
87
+ <ModalWithTable {...args} modalData={setModalData} isLoading={isFetching} tableData={data} isOpen={isModalOpen} advancedTagsList={['Country', 'County']}></ModalWithTable>
88
88
  </>
89
89
  );
90
90
  }
@@ -16,6 +16,8 @@ export interface ModalWithTableProps {
16
16
  isLoading?: boolean;
17
17
  confirmLoading?: boolean;
18
18
  initialRowSelectedInfo?: any;
19
+ // Tags List for advanced search
20
+ advancedTagsList?: string[];
19
21
  }
20
22
  function objectsAreEqual(obj1: any, obj2: any) {
21
23
  const keys1 = Object.keys(obj1);
@@ -46,7 +48,8 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
46
48
  tableData,
47
49
  modalData,
48
50
  isLoading,
49
- initialRowSelectedInfo
51
+ initialRowSelectedInfo,
52
+ advancedTagsList
50
53
  } = props;
51
54
 
52
55
  const prevIsOpenRef = useRef<boolean>();
@@ -60,6 +63,7 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
60
63
  pageInfo: {},
61
64
  rowSelectionInfo: [],
62
65
  tagsInfo: [],
66
+ advancedTagsInfo: [],
63
67
  selectedData: [],
64
68
  });
65
69
  const pageBase = { currentPage: 1 };
@@ -68,6 +72,7 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
68
72
  const [pageInfo, setPageInfo] = useState<any>(pageBase);
69
73
  const [rowSelectionInfo, setRowSelectionInfo] = useState<any>(undefined);
70
74
  const [tagsInfo, setTagsInfo] = useState<any>([]);
75
+ const [advancedTagsInfo, setAdvancedTagsInfo] = useState<any>([]);
71
76
  const [selectedData, setSelectedData] = useState<any>([]);
72
77
 
73
78
  useEffect(() => {
@@ -78,6 +83,7 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
78
83
  pageInfo: pageInfo,
79
84
  rowSelectionInfo: rowSelectionInfo,
80
85
  tagsInfo: tagsInfo,
86
+ advancedTagsInfo: advancedTagsInfo,
81
87
  selectedData: selectedData,
82
88
  });
83
89
  }
@@ -92,12 +98,12 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
92
98
  setPageInfo(initialValues.pageInfo);
93
99
  setRowSelectionInfo(initialValues.rowSelectionInfo);
94
100
  setTagsInfo(initialValues.tagsInfo);
101
+ setAdvancedTagsInfo(initialValues.advancedTagsInfo)
95
102
  setSelectedData(initialValues.selectedData);
96
103
  };
97
104
 
98
105
  const saveChanges = () => {
99
106
  setOpen(false);
100
-
101
107
  if (tableData?.rowSelection?.type === 'radio') {
102
108
  setSelectedData([selectedData[selectedData.length - 1]]);
103
109
  }
@@ -112,12 +118,13 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
112
118
  pageInfo: pageInfo,
113
119
  rowSelectionInfo: rowSelectionInfo,
114
120
  tagsInfo: tagsInfo,
121
+ advancedTagsInfo: advancedTagsInfo,
115
122
  open: open,
116
123
  selectedData: selectedData,
117
124
  };
118
125
 
119
126
  modalData(modalDataObj);
120
- }, [tagsInfo, open, rowSelectionInfo, selectedData]);
127
+ }, [tagsInfo, advancedTagsInfo, open, rowSelectionInfo, selectedData]);
121
128
 
122
129
  useEffect(() => {
123
130
  const selectedRowKeys = rowSelectionInfo || tableData.rowSelection.selectedRowKeys;
@@ -172,6 +179,12 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
172
179
  }
173
180
  }, [tagsInfo]);
174
181
 
182
+ useEffect(() => {
183
+ if (advancedTagsInfo.length > 0) {
184
+ setConfirmLoading(true);
185
+ }
186
+ }, [advancedTagsInfo]);
187
+
175
188
  useEffect(() => {
176
189
  setConfirmLoading(isLoading!);
177
190
  }, [isLoading]);
@@ -203,7 +216,7 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
203
216
  className={modalClasses}
204
217
  >
205
218
  <div className={styles.tagsWrapper}>
206
- <TagField tagsInfo={setTagsInfo} />
219
+ <TagField tagsInfo={setTagsInfo} advancedTagsInfo={setAdvancedTagsInfo} advancedTags={advancedTagsList} />
207
220
  </div>
208
221
 
209
222
  <div className={styles.tableWrapper}>
@@ -0,0 +1,29 @@
1
+ import { Meta, Story } from "@storybook/react";
2
+ import { Notification, ErrorNotificationProps } from '.';
3
+
4
+ export default {
5
+ title: 'Notification',
6
+ component: Notification,
7
+ } as unknown as Meta;
8
+
9
+ const Template: Story<ErrorNotificationProps> = (args) => {
10
+
11
+ const { openNotificationWithIcon } = Notification({
12
+ message: args.message,
13
+ description: args.description,
14
+ });
15
+
16
+ return (
17
+ <>
18
+ {openNotificationWithIcon('error')}
19
+ </>
20
+ )
21
+ };
22
+ export const Primary = Template.bind({});
23
+ Primary.args = {
24
+ message: "Sucesso",
25
+ description: "Parabéns, conseguiste!"
26
+ };
27
+
28
+
29
+
@@ -0,0 +1,21 @@
1
+ import { notification } from 'antd';
2
+
3
+ export interface ErrorNotificationProps {
4
+ message: string;
5
+ description: string;
6
+ }
7
+
8
+ type NotificationType = 'success' | 'info' | 'warning' | 'error';
9
+
10
+ export const Notification = ({ message, description }: ErrorNotificationProps) => {
11
+ const openNotificationWithIcon = (type: NotificationType) => {
12
+ notification[type]({
13
+ message: message,
14
+ description: description,
15
+ });
16
+ };
17
+
18
+ return {
19
+ openNotificationWithIcon,
20
+ };
21
+ };
@@ -10,8 +10,11 @@ export default {
10
10
 
11
11
  const Template: Story<TagProps> = (args) => {
12
12
  const [tagsInfo, setTagsInfo] = useState<any>({});
13
+ const [advancedTagsInfo, setAdvancedTagsInfo] = useState<any>({});
14
+
15
+ console.log('page: basic', tagsInfo,'advanced', advancedTagsInfo);
13
16
 
14
- return <TagField {...args} tagsInfo={setTagsInfo}></TagField>;
17
+ return <TagField {...args} tagsInfo={setTagsInfo} advancedTagsInfo={setAdvancedTagsInfo}></TagField>;
15
18
  }
16
19
 
17
20
  export const Primary = Template.bind({});
@@ -8,17 +8,21 @@ import classNames from 'classnames';
8
8
  import { t } from 'i18next';
9
9
 
10
10
  export interface customTagProps extends TagProps {
11
- customTags?: any,
12
- tagsInfo?: any;
11
+ customTags?: string[],
12
+ tagsInfo?: (tags: string[]) => void,
13
+ advancedTagsInfo?: (tags: string[]) => void,
14
+ advancedTags?: string[],
13
15
  }
14
16
 
15
17
  export const TagField = (props: customTagProps) => {
16
- const { customTags = [] } = props;
18
+ const { customTags = [], advancedTags } = props;
17
19
 
18
- const [tags, setTags] = useState<string[]>(customTags);
20
+ const [tags, setTags] = useState<string[]>(customTags.filter(tag => !tag.includes('=')));
19
21
  const [inputVisible, setInputVisible] = useState<boolean>(false);
20
22
  const [inputValue, setInputValue] = useState('');
21
23
  const inputRef = useRef<InputRef>(null);
24
+ const [advancedTagList, setAdvancedTagList] = useState<string[]>([]);
25
+ const [allTags, setAllTags] = useState<string[]>([]);
22
26
 
23
27
  useEffect(() => {
24
28
  if (inputVisible) {
@@ -27,8 +31,16 @@ export const TagField = (props: customTagProps) => {
27
31
  }, [inputVisible]);
28
32
 
29
33
  const handleClose = (removedTag: string) => {
34
+ const newAllTags = allTags.filter((tag) => tag !== removedTag);
35
+ setAllTags(newAllTags);
36
+
30
37
  const newTags = tags.filter((tag) => tag !== removedTag);
31
38
  setTags(newTags);
39
+
40
+ if (advancedTags && advancedTagList.includes(removedTag)) {
41
+ const newAdvancedTags = advancedTagList.filter((tag) => tag !== removedTag);
42
+ setAdvancedTagList(newAdvancedTags);
43
+ }
32
44
  };
33
45
 
34
46
  const showInput = () => {
@@ -40,16 +52,57 @@ export const TagField = (props: customTagProps) => {
40
52
  };
41
53
 
42
54
  const handleInputConfirm = () => {
43
- if (inputValue && tags.indexOf(inputValue) === -1) {
44
- setTags([...tags, inputValue]);
55
+ let isAdvancedTag = false;
56
+ if (inputValue && allTags.indexOf(inputValue) === -1) {
57
+ setAllTags([...allTags, inputValue]); // Add to allTags
58
+ if (advancedTags && advancedTags.includes(inputValue.split('=')[0]) && !advancedTags.includes(inputValue)) {
59
+ setAdvancedTagList([...advancedTagList, inputValue]);
60
+ isAdvancedTag = true;
61
+ }
62
+
63
+ // Only add the inputValue to the tags array if it's not an advanced tag
64
+ if (!isAdvancedTag) {
65
+ setTags([...tags, inputValue]);
66
+ }
45
67
  }
68
+
46
69
  setInputVisible(false);
47
70
  setInputValue('');
71
+
72
+ const basicTags = tags.filter((tag) => !advancedTagList.includes(tag));
73
+ props.tagsInfo?.(basicTags);
74
+ props.advancedTagsInfo?.(advancedTagList);
75
+ };
76
+
77
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
78
+ const cursorPosition: any = e.currentTarget.selectionStart;
79
+ const advancedFilterMatch = advancedTags && advancedTags.find((filter: any) => inputValue.startsWith(`${filter}=`));
80
+ if (advancedFilterMatch) {
81
+ const filterLength = advancedFilterMatch.length;
82
+ if (cursorPosition <= filterLength && ![8, 46].includes(e.keyCode)) {
83
+ e.preventDefault();
84
+ }
85
+ }
86
+
87
+ // Prevent the input of '=' manually
88
+ if (e.key === "=") {
89
+ e.preventDefault();
90
+ }
48
91
  };
49
92
 
93
+ const doSomething = (e: any) => {
94
+ const tag = e.target.innerText;
95
+ if (!advancedTagList.map(tag => tag.split('=')[0]).includes(tag)) {
96
+ setInputValue(`${tag}=`);
97
+ setInputVisible(true);
98
+ }
99
+ };
100
+
101
+
50
102
  useEffect(() => {
51
- props?.tagsInfo(tags);
52
- }, [tags]);
103
+ props.tagsInfo?.(tags);
104
+ props.advancedTagsInfo?.(advancedTagList);
105
+ }, [tags, advancedTagList]);
53
106
 
54
107
  const forMap = (tag: string) => {
55
108
  const tagElem = (
@@ -69,8 +122,18 @@ export const TagField = (props: customTagProps) => {
69
122
  </span>
70
123
  );
71
124
  };
72
-
73
- const tagChild = tags.map(forMap);
125
+
126
+ const advancedTagsMap = (tag: string) => {
127
+ const disabled = advancedTagList.map(tag => tag.split('=')[0]).includes(tag);
128
+ return (
129
+ <div onClick={!disabled ? doSomething : undefined} key={tag} style={{ color: disabled ? 'gray' : undefined }}>
130
+ {tag}
131
+ </div>
132
+ )
133
+ }
134
+
135
+ const tagChild = allTags.map(forMap);
136
+ const advancedTagsChild = advancedTags && advancedTags.map(advancedTagsMap);
74
137
 
75
138
  return (
76
139
  <div className={styles.tagfield}>
@@ -81,15 +144,27 @@ export const TagField = (props: customTagProps) => {
81
144
  size="small"
82
145
  value={inputValue}
83
146
  onChange={handleInputChange}
147
+ onKeyDown={handleKeyDown}
84
148
  onPressEnter={handleInputConfirm}
85
149
  className={styles['tagfield__input']}
86
150
  />
87
151
  )}
88
152
  {!inputVisible && (
89
153
  <Tag onClick={showInput} className={classNames(styles['tagfield__creator'], 'site-tag-plus')}>
90
- <SearchOutlined /> { t('components.tag.search') }
154
+ <SearchOutlined /> {t('components.tag.search')}
91
155
  </Tag>
92
156
  )}
157
+ {
158
+ advancedTags &&
159
+ <div style={{ marginTop: 16, marginBottom: 16 }} className={styles.advancedTagsWrapper}>
160
+ <div className={styles.label}>
161
+ {t('components.tag.advancedFields')}:
162
+ </div>
163
+ <div className={styles.advancedTags}>
164
+ {advancedTagsChild}
165
+ </div>
166
+ </div>
167
+ }
93
168
  <div style={{ marginTop: 16 }}>
94
169
  <TweenOneGroup
95
170
  enter={{
@@ -40,4 +40,21 @@
40
40
  }
41
41
  }
42
42
  }
43
+
44
+ .advancedTagsWrapper {
45
+ display: flex;
46
+ gap: 12px;
47
+ }
48
+
49
+ .advancedTags {
50
+ display: flex;
51
+ flex-direction: row;
52
+ gap: 12px;
53
+ font-family: "SilkaBold";
54
+ text-decoration: underline;
55
+
56
+ div {
57
+ cursor: pointer;
58
+ }
59
+ }
43
60
  }
@@ -22,3 +22,4 @@ export * from './CategoryResponse';
22
22
  export * from './Upload';
23
23
  export * from './UserInfo';
24
24
  export * from './CategoryReadOnly';
25
+ export * from './Notification';
@@ -70,7 +70,8 @@
70
70
  "asc": "Crescente"
71
71
  },
72
72
  "tag": {
73
- "search": "Procurar"
73
+ "search": "Procurar",
74
+ "advancedFields": "Advanced Fields"
74
75
  },
75
76
  "table": {
76
77
  "selectAll": "Select All",
@@ -70,7 +70,8 @@
70
70
  "asc": "Crescente"
71
71
  },
72
72
  "tag": {
73
- "search": "Procurar"
73
+ "search": "Procurar",
74
+ "advancedFields": "Advanced Fields"
74
75
  },
75
76
  "table": {
76
77
  "selectAll": "Select All ES",
@@ -70,7 +70,8 @@
70
70
  "asc": "Crescente"
71
71
  },
72
72
  "tag": {
73
- "search": "Procurar"
73
+ "search": "Procurar",
74
+ "advancedFields": "Advanced Fields"
74
75
  },
75
76
  "table": {
76
77
  "selectAll": "Select All PT",