Refactored InputGlobalComponent to use removeGlobalVariable instead of deleteGlobalVariable
This commit is contained in:
parent
2625e320c9
commit
de1d5ddf00
3 changed files with 7 additions and 5 deletions
|
|
@ -43,9 +43,7 @@ export default function InputGlobalComponent({
|
||||||
function handleDelete(key: string) {
|
function handleDelete(key: string) {
|
||||||
const id = getVariableId(key);
|
const id = getVariableId(key);
|
||||||
if (id !== undefined) {
|
if (id !== undefined) {
|
||||||
deleteGlobalVariable(id)
|
removeGlobalVariable(key).then((_) => {
|
||||||
.then((_) => {
|
|
||||||
removeGlobalVariable(key);
|
|
||||||
if (
|
if (
|
||||||
data?.node?.template[name].value === key &&
|
data?.node?.template[name].value === key &&
|
||||||
data?.node?.template[name].load_from_db
|
data?.node?.template[name].load_from_db
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
|
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
|
||||||
|
import { deleteGlobalVariable } from "../controllers/API";
|
||||||
|
|
||||||
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
|
|
@ -29,7 +30,10 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
globalVariablesEntries: Object.keys(newVariables),
|
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 };
|
const newVariables = { ...get().globalVariables };
|
||||||
delete newVariables[name];
|
delete newVariables[name];
|
||||||
set({
|
set({
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export type GlobalVariablesStore = {
|
||||||
[name: string]: { id: string; type?: string, default_fields?: string[]};
|
[name: string]: { id: string; type?: string, default_fields?: string[]};
|
||||||
}) => void;
|
}) => void;
|
||||||
addGlobalVariable: (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;
|
getVariableId: (name: string) => string | undefined;
|
||||||
unavaliableFields: Set<string>;
|
unavaliableFields: Set<string>;
|
||||||
setUnavaliableFields: (fields: Set<string>) => void;
|
setUnavaliableFields: (fields: Set<string>) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue