@omniumretail/component-library 1.2.26 → 1.2.27
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
|
@@ -225,13 +225,36 @@ export const CategorySidebar = (props: SidebarProps) => {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
const addCategory = () => {
|
|
228
|
+
// Função para obter a maior chave em gData
|
|
229
|
+
const getNextKey = (categories: DataNode[]): string => {
|
|
230
|
+
let maxKey = 0;
|
|
231
|
+
|
|
232
|
+
const traverse = (nodes: DataNode[]) => {
|
|
233
|
+
nodes.forEach((node) => {
|
|
234
|
+
const key = parseFloat(node.key as string); // Converte a chave para número
|
|
235
|
+
if (key > maxKey) {
|
|
236
|
+
maxKey = key;
|
|
237
|
+
}
|
|
238
|
+
if (node.children) {
|
|
239
|
+
traverse(node.children); // Recorre para os filhos
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
traverse(categories);
|
|
245
|
+
return `${Math.floor(maxKey) + 1}`; // Retorna a próxima chave como um número inteiro
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const newKey = getNextKey(gData); // Calcula a próxima chave disponível
|
|
249
|
+
|
|
228
250
|
setGData((prevCategories: DataNode[]) => [
|
|
229
251
|
...prevCategories,
|
|
230
|
-
{ title: t('components.category.newCategory'), key:
|
|
231
|
-
])
|
|
232
|
-
|
|
233
|
-
setSidebarInfo([
|
|
234
|
-
}
|
|
252
|
+
{ title: t('components.category.newCategory'), key: newKey },
|
|
253
|
+
]);
|
|
254
|
+
|
|
255
|
+
setSidebarInfo([newKey]); // Atualiza o estado do sidebar
|
|
256
|
+
};
|
|
257
|
+
|
|
235
258
|
|
|
236
259
|
const removeCategory = () => {
|
|
237
260
|
if (sidebarInfo) {
|