@omniumretail/component-library 1.1.73 → 1.1.74

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": "@omniumretail/component-library",
3
- "version": "1.1.73",
3
+ "version": "1.1.74",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -81,8 +81,6 @@ export const CategoryContent = (props: categoryContent) => {
81
81
  setSwitchYesOrNoAnswStatus(initialValues?.isYesOrNo || false);
82
82
  }, [form, initialValues]);
83
83
 
84
- console.log();
85
-
86
84
  return (
87
85
  <div className={styles.categoryContent}>
88
86
  <div className={styles.title}>{t('components.categoryContent.editCategory')}</div>
@@ -82,11 +82,11 @@ function remove_nested_element(data: DataNode[], index: string | number): DataNo
82
82
  export const CategorySidebar = (props: SidebarProps) => {
83
83
  const {
84
84
  categoryContentData,
85
- categoryContentFinalData,
86
85
  data,
87
86
  hasHeader
88
87
  } = props;
89
88
 
89
+ const [sidebarInfo, setSidebarInfo] = useState<any>(hasHeader ? ["0"] : undefined);
90
90
  const [gData, setGData] = useState<DataNode[]>(() => {
91
91
  // Adiciona a categoria "Header" se hasHeader for true
92
92
  if (hasHeader && data?.length === 0) {
@@ -127,7 +127,6 @@ export const CategorySidebar = (props: SidebarProps) => {
127
127
  });
128
128
 
129
129
  const [expandedKeys] = useState([]);
130
- const [sidebarInfo, setSidebarInfo] = useState<any>(undefined);
131
130
 
132
131
  const onDragEnter: TreeProps['onDragEnter'] = (info) => {
133
132
  // drag entered
@@ -242,6 +241,8 @@ export const CategorySidebar = (props: SidebarProps) => {
242
241
  ...prevCategories,
243
242
  { title: t('components.category.newCategory'), key: `${gData.length}` },
244
243
  ])
244
+
245
+ setSidebarInfo([`${gData.length}`]);
245
246
  }
246
247
 
247
248
  const removeCategory = () => {
@@ -257,28 +258,36 @@ export const CategorySidebar = (props: SidebarProps) => {
257
258
  selectKey: sidebarInfo,
258
259
  data: get_element_by_index(gData, sidebarInfo && sidebarInfo[0]),
259
260
  });
261
+
260
262
  }, [sidebarInfo]);
261
263
 
262
- useEffect(() => {
264
+ function updateCategoryTitles(categories: any[]): any[] {
265
+ return categories.map((category: any, index: number) => {
266
+ if (category?.data) {
267
+ const titleWithoutCounts = category.title.replace(/\(Q: \d+\)/g, '').replace(/\(G: \d+\)/g, '').trim();
268
+ const updatedTitle = `${titleWithoutCounts} ${category.data.questions ? '(Q: ' + category.data.questions.length + ')' : ''} ${category.data.grade ? '(G: ' + category.data.grade + ')' : ''}`;
269
+ const updatedChildren = category.children ? updateCategoryTitles(category.children) : null;
263
270
 
264
- const newGData = addPropertyByIndex(gData, sidebarInfo && sidebarInfo[0], "data", categoryContentData);
271
+ return { ...category, title: updatedTitle, children: updatedChildren };
272
+ }
273
+ return category;
274
+ });
275
+ }
265
276
 
266
- function updateCategoryTitles(categories: any[]): any[] {
267
- return categories.map((category: any, index: number) => {
268
- if (category?.data) {
269
- const titleWithoutCounts = category.title.replace(/\(Q: \d+\)/g, '').replace(/\(G: \d+\)/g, '').trim();
270
- const updatedTitle = `${titleWithoutCounts} ${category.data.questions ? '(Q: ' + category.data.questions.length + ')' : ''} ${category.data.grade ? '(G: ' + category.data.grade + ')' : ''}`;
271
- const updatedChildren = category.children ? updateCategoryTitles(category.children) : null;
272
-
273
- return { ...category, title: updatedTitle, children: updatedChildren };
274
- }
275
- return category;
276
- });
277
- }
277
+ useEffect(() => {
278
+ if (hasHeader) {
279
+ if (categoryContentData?.categoryName) {
280
+ const newGData = addPropertyByIndex(gData, sidebarInfo && sidebarInfo[0], "data", categoryContentData);
281
+ const updatedGData: any[] = updateCategoryTitles(newGData);
278
282
 
279
- const updatedGData: any[] = updateCategoryTitles(newGData);
283
+ setGData(updatedGData);
284
+ }
285
+ } else {
286
+ const newGData = addPropertyByIndex(gData, sidebarInfo && sidebarInfo[0], "data", categoryContentData);
287
+ const updatedGData: any[] = updateCategoryTitles(newGData);
280
288
 
281
- setGData(updatedGData);
289
+ setGData(updatedGData);
290
+ }
282
291
  }, [categoryContentData]);
283
292
 
284
293
  useEffect(() => {
@@ -292,7 +301,7 @@ export const CategorySidebar = (props: SidebarProps) => {
292
301
 
293
302
  return (
294
303
  <div className={styles.categorySidebar}>
295
- <div className={styles.title}>Categorias</div>
304
+ <div className={styles.title}>{t('components.categorySidBar.categories')}</div>
296
305
  <Button icon={<PlusOutlined />} onClick={addCategory}>
297
306
  {t('components.categorySidBar.addCategory')}
298
307
  </Button>
@@ -307,6 +316,7 @@ export const CategorySidebar = (props: SidebarProps) => {
307
316
 
308
317
  <div className={styles.categoryViewer}>
309
318
  <Tree
319
+ defaultSelectedKeys={hasHeader ? ["0"] : undefined}
310
320
  className="draggable-tree"
311
321
  defaultExpandedKeys={expandedKeys}
312
322
  draggable
@@ -315,6 +325,7 @@ export const CategorySidebar = (props: SidebarProps) => {
315
325
  onDrop={onDrop}
316
326
  treeData={gData}
317
327
  onSelect={onSelect}
328
+ selectedKeys={sidebarInfo}
318
329
  />
319
330
  </div>
320
331
  </div>
@@ -29,7 +29,7 @@ export const Category = (props: Category) => {
29
29
  }, [finalData]);
30
30
 
31
31
  useEffect(() => {
32
- setShowContent(categorySidebarInfo?.selectKey?.length > 0);
32
+ setShowContent(categorySidebarInfo?.selectKey?.length);
33
33
  }, [categorySidebarInfo]);
34
34
 
35
35
  return (
@@ -61,7 +61,8 @@
61
61
  },
62
62
  "categorySidBar": {
63
63
  "addCategory": "Add Category",
64
- "removeCategory": "Remove Category"
64
+ "removeCategory": "Remove Category",
65
+ "categories": "Categories"
65
66
  },
66
67
  "categoryContent": {
67
68
  "message": "Please select a category in the sidebar",
@@ -61,7 +61,8 @@
61
61
  },
62
62
  "categorySidBar": {
63
63
  "addCategory": "Agregar Categoría",
64
- "removeCategory": "Eliminar Categoría"
64
+ "removeCategory": "Eliminar Categoría",
65
+ "categories": "Categorías"
65
66
  },
66
67
  "categoryContent": {
67
68
  "message": "Por favor, seleccione una categoría en la barra lateral",
@@ -61,7 +61,8 @@
61
61
  },
62
62
  "categorySidBar": {
63
63
  "addCategory": "Adicionar categoria",
64
- "removeCategory": "Remover categoria"
64
+ "removeCategory": "Remover categoria",
65
+ "categories": "Categorias"
65
66
  },
66
67
  "categoryContent": {
67
68
  "message": "Por favor selecione uma categoria na barra lateral",