Refactor globalVariables.ts to include unavaliableFields in useGlobalVariablesStore
This commit is contained in:
parent
242bd55a24
commit
56342f4489
3 changed files with 6 additions and 3 deletions
|
|
@ -96,7 +96,6 @@ export default function App() {
|
|||
refreshFlows();
|
||||
const res = await getGlobalVariables();
|
||||
setGlobalVariables(res);
|
||||
setUnavailableFields(getUnavailableFields(res));
|
||||
checkHasStore();
|
||||
fetchApiData();
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { create } from "zustand";
|
||||
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
|
||||
import { deleteGlobalVariable } from "../controllers/API";
|
||||
import { getUnavailableFields } from "../utils/utils";
|
||||
|
||||
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||
(set, get) => ({
|
||||
|
|
@ -20,6 +21,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
|||
set({
|
||||
globalVariables: variables,
|
||||
globalVariablesEntries: Object.keys(variables),
|
||||
unavaliableFields: getUnavailableFields(variables)
|
||||
});
|
||||
},
|
||||
addGlobalVariable: (name, id, type, default_fields) => {
|
||||
|
|
@ -28,6 +30,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
|||
set({
|
||||
globalVariables: newVariables,
|
||||
globalVariablesEntries: Object.keys(newVariables),
|
||||
unavaliableFields: getUnavailableFields(newVariables)
|
||||
});
|
||||
},
|
||||
removeGlobalVariable:async (name) => {
|
||||
|
|
@ -39,6 +42,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
|||
set({
|
||||
globalVariables: newVariables,
|
||||
globalVariablesEntries: Object.keys(newVariables),
|
||||
unavaliableFields: getUnavailableFields(newVariables)
|
||||
});
|
||||
},
|
||||
getVariableId: (name) => {
|
||||
|
|
|
|||
|
|
@ -92,12 +92,12 @@ export function toTitleCase(
|
|||
}
|
||||
|
||||
export function getUnavailableFields(
|
||||
variables:{[key: string]: { id: string; type: string,default_fields:string[] }}
|
||||
variables:{[key: string]: { default_fields?:string[] }}
|
||||
): Set<string> {
|
||||
const set = new Set<string>();
|
||||
Object.keys(variables).forEach((key) => {
|
||||
if(variables[key].default_fields){
|
||||
variables[key].default_fields.forEach((field) => {
|
||||
variables[key].default_fields!.forEach((field) => {
|
||||
set.add(field);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue