Refactored InputGlobalComponent to use removeGlobalVariable instead of deleteGlobalVariable

This commit is contained in:
anovazzi1 2024-04-30 13:23:00 -03:00
commit de1d5ddf00
3 changed files with 7 additions and 5 deletions

View file

@ -43,9 +43,7 @@ export default function InputGlobalComponent({
function handleDelete(key: string) {
const id = getVariableId(key);
if (id !== undefined) {
deleteGlobalVariable(id)
.then((_) => {
removeGlobalVariable(key);
removeGlobalVariable(key).then((_) => {
if (
data?.node?.template[name].value === key &&
data?.node?.template[name].load_from_db

View file

@ -1,5 +1,6 @@
import { create } from "zustand";
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
import { deleteGlobalVariable } from "../controllers/API";
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
(set, get) => ({
@ -29,7 +30,10 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
globalVariablesEntries: Object.keys(newVariables),
});
},
removeGlobalVariable: (name) => {
removeGlobalVariable:async (name) => {
const id = get().globalVariables[name]?.id;
if (id === undefined) return;
await deleteGlobalVariable(id)
const newVariables = { ...get().globalVariables };
delete newVariables[name];
set({

View file

@ -5,7 +5,7 @@ export type GlobalVariablesStore = {
[name: string]: { id: string; type?: string, default_fields?: string[]};
}) => void;
addGlobalVariable: (name: string, id: string, type?: string, default_fields?: string[]) => void;
removeGlobalVariable: (name: string) => void;
removeGlobalVariable: (name: string) => Promise<void>;
getVariableId: (name: string) => string | undefined;
unavaliableFields: Set<string>;
setUnavaliableFields: (fields: Set<string>) => void;