@omniumretail/component-library 1.1.56 → 1.1.57

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.
@@ -4,6 +4,7 @@ interface categoryContent {
4
4
  categorySidebarData: any;
5
5
  chooseResponseType?: boolean;
6
6
  responseTypeOptions?: any;
7
+ hasHeader?: boolean;
7
8
  }
8
9
  export declare const CategoryContent: (props: categoryContent) => import("react/jsx-runtime").JSX.Element;
9
10
  export {};
@@ -21,6 +21,7 @@ interface SidebarProps {
21
21
  categorySidebarInfo: any;
22
22
  categoryContentFinalData: any;
23
23
  data: DataNode[];
24
+ hasHeader?: boolean;
24
25
  }
25
26
  export declare const CategorySidebar: (props: SidebarProps) => import("react/jsx-runtime").JSX.Element;
26
27
  export {};
@@ -4,6 +4,7 @@ interface Category {
4
4
  serverReadyData: any;
5
5
  chooseResponse?: boolean;
6
6
  responseTypeOptions?: any;
7
+ hasHeader?: boolean;
7
8
  }
8
9
  export declare const Category: (props: Category) => import("react/jsx-runtime").JSX.Element;
9
10
  export {};
@@ -1 +1 @@
1
- export declare const SingleQuestion: ({ key, provided, snapshot, remove, name, showGrade, handleChanges, showCheckbox, responseTypeOptions, ...restField }: any) => import("react/jsx-runtime").JSX.Element;
1
+ export declare const SingleQuestion: ({ key, provided, snapshot, remove, name, showGrade, handleChanges, showCheckbox, responseTypeOptions, hasHeader, ...restField }: any) => import("react/jsx-runtime").JSX.Element;
@@ -3,5 +3,6 @@ export interface QuestionsProps {
3
3
  showCheckbox?: boolean;
4
4
  handleChanges: any;
5
5
  responseTypeOptions: any;
6
+ hasHeader?: boolean;
6
7
  }
7
8
  export declare const Questions: (props: QuestionsProps) => import("react/jsx-runtime").JSX.Element;
@@ -42,6 +42,7 @@ export interface ResponsiveTableCustomProps extends TableProps<any> {
42
42
  width: string;
43
43
  }[];
44
44
  buttonActionName?: string;
45
+ buttonActionLabel?: (record: any) => string;
45
46
  buttonActionMethod?: () => void;
46
47
  buttonActionStyle?: string;
47
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -14,95 +14,7 @@ const Template: Story<any> = (args) => {
14
14
  console.log(serverData);
15
15
  }, [serverData])
16
16
 
17
- return <Category {...args} chooseResponse serverReadyData={setServerData} data={[
18
- {
19
- "title": "2 (Q: 0) (G: 2)",
20
- "key": "0",
21
- "data": {
22
- "categoryName": "2",
23
- "openAnswer": false,
24
- "isYesOrNo": true,
25
- "generalEvaluationLevel": "0",
26
- "grade": "2",
27
- "questions": [
28
- {
29
- "emphasis": true,
30
- "info": "lol",
31
- "mandatory": false,
32
- "question": ""
33
- }
34
- ]
35
- },
36
- "children": []
37
- },
38
- {
39
- "title": "1 (Q: 0) (G: 1)",
40
- "key": "1",
41
- "data": {
42
- "categoryName": "1",
43
- "openAnswer": false,
44
- "isYesOrNo": false,
45
- "generalEvaluationLevel": "0",
46
- "grade": "1",
47
- "questions": []
48
- },
49
- "children": [
50
- {
51
- "title": "1.1 (Q: 0) (G: 1.1)",
52
- "key": "1.0",
53
- "data": {
54
- "categoryName": "1.1",
55
- "openAnswer": false,
56
- "isYesOrNo": false,
57
- "generalEvaluationLevel": "0",
58
- "grade": "1.1",
59
- "questions": []
60
- },
61
- "children": [
62
- {
63
- "title": "1.1.1 (Q: 0) (G: 1.1.1)",
64
- "key": "1.0.0",
65
- "data": {
66
- "categoryName": "1.1.1",
67
- "openAnswer": false,
68
- "isYesOrNo": false,
69
- "generalEvaluationLevel": "0",
70
- "grade": "1.1.1",
71
- "questions": []
72
- },
73
- "children": []
74
- }
75
- ]
76
- }
77
- ]
78
- },
79
- {
80
- "title": "3 (Q: 0) (G: 3)",
81
- "key": "2",
82
- "data": {
83
- "categoryName": "3",
84
- "openAnswer": true,
85
- "isYesOrNo": false,
86
- "generalEvaluationLevel": "0",
87
- "grade": "3",
88
- "questions": []
89
- },
90
- "children": []
91
- }
92
- ]} responseTypeOptions={[
93
- {
94
- "value": "B867BEA8-E0A4-44D2-BBDA-7CB89334D80E",
95
- "label": "teste3Update",
96
- },
97
- {
98
- "value": "B8267BEA8-E0A4-44D2-BBDA-7CB89334D80E",
99
- "label": "test2eUpdate",
100
- },
101
- {
102
- "value": "B867B4EA8-E0A4-44D2-BBDA-7CB89334D80E",
103
- "label": "testeU4pdate",
104
- }
105
- ]}></Category>
17
+ return <Category {...args} chooseResponse serverReadyData={setServerData} hasHeader data={[]}></Category>
106
18
  };
107
19
 
108
20
  export const Primary = Template.bind({});
@@ -15,6 +15,7 @@ interface categoryContent {
15
15
  categorySidebarData: any;
16
16
  chooseResponseType?: boolean;
17
17
  responseTypeOptions?: any;
18
+ hasHeader?: boolean;
18
19
  }
19
20
 
20
21
  const defaultInitialValues = {
@@ -30,7 +31,8 @@ export const CategoryContent = (props: categoryContent) => {
30
31
  categoryContentShow,
31
32
  categorySidebarData,
32
33
  chooseResponseType,
33
- responseTypeOptions
34
+ responseTypeOptions,
35
+ hasHeader
34
36
  } = props;
35
37
 
36
38
  const [contentInfo, setContentInfo] = useState<any>(defaultInitialValues);
@@ -79,6 +81,8 @@ export const CategoryContent = (props: categoryContent) => {
79
81
  setSwitchYesOrNoAnswStatus(initialValues?.isYesOrNo || false);
80
82
  }, [form, initialValues]);
81
83
 
84
+ console.log();
85
+
82
86
  return (
83
87
  <div className={styles.categoryContent}>
84
88
  <div className={styles.title}>{t('components.categoryContent.editCategory')}</div>
@@ -107,7 +111,11 @@ export const CategoryContent = (props: categoryContent) => {
107
111
  rules={[{ required: true, message: t('components.categoryContent.categoryNameError')! }]}
108
112
  validateTrigger="onBlur"
109
113
  >
110
- <InputField placeholder={t('components.categoryContent.categoryName')!} onBlur={handleInputChange} />
114
+ <InputField
115
+ disabled={categorySidebarData?.data?.key === "0" && hasHeader}
116
+ placeholder={t('components.categoryContent.categoryName')!}
117
+ onBlur={handleInputChange}
118
+ />
111
119
  </Form.Item>
112
120
  </div>
113
121
 
@@ -214,6 +222,7 @@ export const CategoryContent = (props: categoryContent) => {
214
222
  showCheckbox={chooseResponseType && true}
215
223
  handleChanges={handleInputChange}
216
224
  responseTypeOptions={responseTypeOptions}
225
+ hasHeader={categorySidebarData?.data?.key === "0" && hasHeader}
217
226
  />
218
227
  </Form.Item>
219
228
  </div>
@@ -30,6 +30,7 @@ interface SidebarProps {
30
30
  categorySidebarInfo: any;
31
31
  categoryContentFinalData: any;
32
32
  data: DataNode[];
33
+ hasHeader?: boolean;
33
34
  }
34
35
 
35
36
  function get_element_by_index(data: DataNode[], index: string | number): DataNode | null {
@@ -81,10 +82,30 @@ export const CategorySidebar = (props: SidebarProps) => {
81
82
  const {
82
83
  categoryContentData,
83
84
  categoryContentFinalData,
84
- data
85
+ data,
86
+ hasHeader
85
87
  } = props;
86
88
 
87
- const [gData, setGData] = useState(data);
89
+ const [gData, setGData] = useState<DataNode[]>(() => {
90
+ // Adiciona a categoria "Header" se hasHeader for true
91
+ if (hasHeader && data?.length === 0) {
92
+ const headerCategory: DataNode = {
93
+ title: 'Header',
94
+ key: '0',
95
+ data: {
96
+ categoryName: 'Header',
97
+ generalEvaluationLevel: '',
98
+ grade: '',
99
+ openAnswer: false,
100
+ questions: []
101
+ },
102
+ children: []
103
+ };
104
+ return [headerCategory, ...data];
105
+ }
106
+ return data;
107
+ });
108
+
88
109
  const [expandedKeys] = useState([]);
89
110
  const [sidebarInfo, setSidebarInfo] = useState<any>(undefined);
90
111
 
@@ -100,6 +121,10 @@ export const CategorySidebar = (props: SidebarProps) => {
100
121
  const { data: nodeData } = info.node as DataNode;
101
122
  const questions: Questions[] | undefined = nodeData?.questions;
102
123
 
124
+ if (hasHeader && (dragKey === '0' || dropKey === '0')) {
125
+ return;
126
+ }
127
+
103
128
  if (questions && questions.length > 0) {
104
129
  // console.log('you cant add a subcategory to a category with questions');
105
130
  return;
@@ -166,17 +191,24 @@ export const CategorySidebar = (props: SidebarProps) => {
166
191
  }
167
192
  }
168
193
 
169
- function generateCategoryKeys(categories: any[], parentKey: string = ''): any[] {
170
- let keyCounter = 0;
171
- return categories.map((category: any, index: number) => {
172
- const categoryKey = `${parentKey}${parentKey ? '.' : ''}${keyCounter++}`;
173
- let children: any = [];
194
+ function generateCategoryKeys(categories: DataNode[], parentKey: string = ''): DataNode[] {
195
+ let keyCounter = parentKey === '' ? 1 : parseInt(parentKey, 10) + 1; // Inicia o contador de chaves
196
+
197
+ return categories.map((category: DataNode) => {
198
+ if (hasHeader && (category.key === '0')) {
199
+ return category; // Mantém a chave do Header fixa
200
+ }
201
+
202
+ const categoryKey = `${keyCounter++}`; // Incrementa o contador para cada categoria
203
+
204
+ let children: DataNode[] = [];
174
205
  if (category.children) {
175
- children = generateCategoryKeys(category.children, categoryKey);
206
+ children = generateCategoryKeys(category.children, categoryKey); // Gera chaves para os filhos recursivamente
176
207
  }
177
- return { ...category, key: categoryKey, children };
208
+
209
+ return { ...category, key: categoryKey, children }; // Atualiza a chave e os filhos
178
210
  });
179
- }
211
+ }
180
212
 
181
213
  setGData(generateCategoryKeys(data));
182
214
  };
@@ -240,15 +272,15 @@ export const CategorySidebar = (props: SidebarProps) => {
240
272
  <div className={styles.categorySidebar}>
241
273
  <div className={styles.title}>Categorias</div>
242
274
  <Button icon={<PlusOutlined />} onClick={addCategory}>
243
- { t('components.categorySidBar.addCategory') }
275
+ {t('components.categorySidBar.addCategory')}
244
276
  </Button>
245
277
 
246
278
  {
247
- sidebarInfo &&
279
+ sidebarInfo && (hasHeader ? sidebarInfo[0] !== '0' : true) && (
248
280
  <Button icon={<MinusOutlined />} onClick={removeCategory}>
249
- { t('components.categorySidBar.removeCategory') }
281
+ {t('components.categorySidBar.removeCategory')}
250
282
  </Button>
251
- }
283
+ )}
252
284
 
253
285
 
254
286
  <div className={styles.categoryViewer}>
@@ -8,13 +8,15 @@ interface Category {
8
8
  serverReadyData: any;
9
9
  chooseResponse?: boolean;
10
10
  responseTypeOptions?: any;
11
+ hasHeader?: boolean;
11
12
  }
12
13
 
13
14
  export const Category = (props: Category) => {
14
15
  const {
15
16
  data,
16
17
  chooseResponse,
17
- responseTypeOptions
18
+ responseTypeOptions,
19
+ hasHeader
18
20
  } = props;
19
21
 
20
22
  const [categoryContentInfo, setCategoryContentInfo] = useState<any>();
@@ -38,6 +40,7 @@ export const Category = (props: Category) => {
38
40
  categoryContentData={categoryContentInfo}
39
41
  data={data}
40
42
  categoryContentFinalData={setFinalData}
43
+ hasHeader={hasHeader}
41
44
  />
42
45
  </div>
43
46
  <div className={styles.contentWrapper}>
@@ -47,6 +50,7 @@ export const Category = (props: Category) => {
47
50
  categoryContentInfo={setCategoryContentInfo}
48
51
  categoryContentShow={showContent}
49
52
  categorySidebarData={categorySidebarInfo}
53
+ hasHeader={hasHeader}
50
54
  />
51
55
  </div>
52
56
  </div>
@@ -5,7 +5,7 @@ import styles from './styles.module.scss';
5
5
  import { useState } from 'react';
6
6
  import { Select } from 'antd';
7
7
 
8
- export const SingleQuestion = ({ key, provided, snapshot, remove, name, showGrade, handleChanges, showCheckbox, responseTypeOptions, ...restField }: any) => {
8
+ export const SingleQuestion = ({ key, provided, snapshot, remove, name, showGrade, handleChanges, showCheckbox, responseTypeOptions, hasHeader, ...restField }: any) => {
9
9
  const [mandatoryCheckbox, setMandatoryCheckbox] = useState<boolean>(false);
10
10
  const [emphasisCheckbox, setEmphasisCheckbox] = useState<boolean>(false);
11
11
 
@@ -88,29 +88,34 @@ export const SingleQuestion = ({ key, provided, snapshot, remove, name, showGrad
88
88
  <div className={styles.questionFooter}>
89
89
  <div />
90
90
 
91
- <div className={styles.checkboxContainer}>
92
- <Form.Item
93
- {...restField}
94
- name={[name, 'mandatory']}
95
- valuePropName='checked'
96
- >
97
- <Checkbox onChange={(e) => onCheckboxMandatoryHandler(e.target.checked)} checked={mandatoryCheckbox} />
98
- </Form.Item>
99
-
100
- <span>{t('components.category.mandatoryAnswer')}</span>
101
- </div>
102
-
103
- <div className={styles.checkboxContainer}>
104
- <Form.Item
105
- {...restField}
106
- name={[name, 'emphasis']}
107
- valuePropName='checked'
108
- >
109
- <Checkbox onChange={(e) => onCheckboxEmphasisHandler(e.target.checked)} checked={emphasisCheckbox} />
110
- </Form.Item>
111
-
112
- <span>{t('components.category.emphasisAnswer')}</span>
113
- </div>
91
+ {!hasHeader &&
92
+ <>
93
+
94
+ <div className={styles.checkboxContainer}>
95
+ <Form.Item
96
+ {...restField}
97
+ name={[name, 'mandatory']}
98
+ valuePropName='checked'
99
+ >
100
+ <Checkbox onChange={(e) => onCheckboxMandatoryHandler(e.target.checked)} checked={mandatoryCheckbox} />
101
+ </Form.Item>
102
+
103
+ <span>{t('components.category.mandatoryAnswer')}</span>
104
+ </div>
105
+
106
+ <div className={styles.checkboxContainer}>
107
+ <Form.Item
108
+ {...restField}
109
+ name={[name, 'emphasis']}
110
+ valuePropName='checked'
111
+ >
112
+ <Checkbox onChange={(e) => onCheckboxEmphasisHandler(e.target.checked)} checked={emphasisCheckbox} />
113
+ </Form.Item>
114
+
115
+ <span>{t('components.category.emphasisAnswer')}</span>
116
+ </div>
117
+ </>
118
+ }
114
119
 
115
120
  <div className={styles.checkboxContainer}>
116
121
  <Form.Item
@@ -12,6 +12,7 @@ export interface QuestionsProps {
12
12
  showCheckbox?: boolean;
13
13
  handleChanges: any;
14
14
  responseTypeOptions: any;
15
+ hasHeader?: boolean;
15
16
  }
16
17
 
17
18
  export const Questions = (props: QuestionsProps) => {
@@ -19,7 +20,8 @@ export const Questions = (props: QuestionsProps) => {
19
20
  showGrade = true,
20
21
  showCheckbox,
21
22
  handleChanges,
22
- responseTypeOptions
23
+ responseTypeOptions,
24
+ hasHeader
23
25
  } = props;
24
26
 
25
27
  const formContext = useContext(FieldContext);
@@ -60,7 +62,8 @@ export const Questions = (props: QuestionsProps) => {
60
62
  showGrade={showGrade}
61
63
  showCheckbox={showCheckbox}
62
64
  handleChanges={handleChanges}
63
- responseTypeOptions={responseTypeOptions}
65
+ responseTypeOptions={responseTypeOptions}
66
+ hasHeader={hasHeader}
64
67
  />
65
68
  </>
66
69
  )}
@@ -20,6 +20,10 @@ const Template: Story<ResponsiveTableCustomProps> = (args) => {
20
20
  // For example, trigger an API call
21
21
  };
22
22
 
23
+ const getButtonLabel = (record: any) => {
24
+ return (record as any)?.type === "Efetivo" ? "Pog" : "Nao";
25
+ };
26
+
23
27
  return <ResponsiveTable
24
28
  scroll={{ x: 4000 }}
25
29
  columnsSortChange={handleSortByColumnChange} paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} rowSelectionInfo={setRowSelectionInfo}
@@ -34,7 +38,7 @@ const Template: Story<ResponsiveTableCustomProps> = (args) => {
34
38
  key: '3', label: 'label 3'
35
39
  }
36
40
  ]}
37
- fixedColumns={[{ dataIndex: 'action', side: 'right' }]} buttonActionName="POG" {...args}>
41
+ fixedColumns={[{ dataIndex: 'action', side: 'right' }]} buttonActionMethod={() => handleSortByColumnChange} buttonActionLabel={getButtonLabel} {...args}>
38
42
  </ResponsiveTable>;
39
43
  };
40
44
 
@@ -57,7 +61,7 @@ Primary.args = {
57
61
  mecanographicNumber: "32",
58
62
  store: `Levi's Sta Catarina`,
59
63
  role: `Comercial`,
60
- type: `Efetivo`
64
+ type: `NEfetivo`
61
65
  },
62
66
  {
63
67
  id: `3`,
@@ -65,7 +69,7 @@ Primary.args = {
65
69
  mecanographicNumber: "3212",
66
70
  store: `Levi's Sta Catarina`,
67
71
  role: `Funcionário`,
68
- type: `Efetivo`
72
+ type: `NEfetivo`
69
73
  },
70
74
  {
71
75
  id: `4`,
@@ -48,6 +48,7 @@ export interface ResponsiveTableCustomProps extends TableProps<any> {
48
48
  fixedColumns?: { dataIndex: string; side: 'left' | 'right' }[];
49
49
  customColumnWidths?: { columnName: string; width: string }[];
50
50
  buttonActionName?: string;
51
+ buttonActionLabel?: (record: any) => string;
51
52
  buttonActionMethod?: () => void;
52
53
  buttonActionStyle?: string;
53
54
  }
@@ -77,7 +78,8 @@ export const ResponsiveTable = (props: ResponsiveTableCustomProps) => {
77
78
  customColumnWidths,
78
79
  buttonActionName,
79
80
  buttonActionMethod,
80
- buttonActionStyle
81
+ buttonActionStyle,
82
+ buttonActionLabel
81
83
  } = props;
82
84
 
83
85
  const [customFilters, setCustomFilters] = useState<any>([]);
@@ -201,12 +203,14 @@ export const ResponsiveTable = (props: ResponsiveTableCustomProps) => {
201
203
  dataIndex: 'action',
202
204
  ellipsis: false,
203
205
  align: 'right',
204
- render: () => {
205
- if (!items?.[0]) return null;
206
+ render: (_: any, record: any) => {
207
+ if (!items?.[0]) return null;
208
+ const buttonLabel = buttonActionLabel ? buttonActionLabel(record) : null;
209
+
206
210
  return (
207
211
  <Space size="middle">
208
- {buttonActionName &&
209
- <Button customClass={buttonActionStyle} onClick={() => buttonActionMethod?.()}>{buttonActionName}</Button>
212
+ {(buttonActionName || buttonActionLabel) &&
213
+ <Button customClass={buttonActionStyle} onClick={() => buttonActionMethod?.()}>{buttonActionName || buttonLabel}</Button>
210
214
  }
211
215
 
212
216
  <Dropdown menu={{ items }}>