From c23943017d0d57ee28550cc93a6f2dcaa2cefc16 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Tue, 30 Apr 2024 01:20:46 -0300 Subject: [PATCH] Refactor: Global Variables table are now populated by backend and delete button works --- .../pages/GlobalVariablesPage/index.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx b/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx index ad88bc6f2..867a078b7 100644 --- a/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx @@ -2,15 +2,25 @@ import IconComponent from "../../../../components/genericIconComponent"; import { Button } from "../../../../components/ui/button"; import { ColDef, ColGroupDef, SelectionChangedEvent } from "ag-grid-community"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import AddNewVariableButton from "../../../../components/addNewVariableButtonComponent/addNewVariableButton"; import Dropdown from "../../../../components/dropdownComponent"; import ForwardedIconComponent from "../../../../components/genericIconComponent"; import TableComponent from "../../../../components/tableComponent"; import { Badge } from "../../../../components/ui/badge"; import { cn } from "../../../../utils/utils"; +import { useGlobalVariablesStore } from "../../../../stores/globalVariables"; export default function GlobalVariablesPage() { + const rows: Array<{type: string | undefined; id: string; name: string}> = []; + const globalVariablesEntries = useGlobalVariablesStore(state => state.globalVariablesEntries); + const removeGlobalVariable = useGlobalVariablesStore(state => state.removeGlobalVariable); + const globalVariables = useGlobalVariablesStore(state => state.globalVariables); + globalVariablesEntries.forEach((e) => { + const globalVariableObj = globalVariables[e] + rows.push({type: globalVariableObj.type, id: globalVariableObj.id, name: e}) + }) + const BadgeRenderer = (props) => { return (
@@ -21,6 +31,10 @@ export default function GlobalVariablesPage() { ); }; + useEffect(() => { + setRowData(rows) + }, [globalVariables]) + const DropdownEditor = ({ options, value, onValueChange }) => { return ( @@ -98,6 +112,12 @@ export default function GlobalVariablesPage() { const [selectedRows, setSelectedRows] = useState([]); + function removeVariables() { + selectedRows.forEach(row => { + removeGlobalVariable(row) + }) + } + return (
@@ -119,6 +139,7 @@ export default function GlobalVariablesPage() { variant="primary" className="group px-2" disabled={selectedRows.length === 0} + onClick={removeVariables} >