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();
|
refreshFlows();
|
||||||
const res = await getGlobalVariables();
|
const res = await getGlobalVariables();
|
||||||
setGlobalVariables(res);
|
setGlobalVariables(res);
|
||||||
setUnavailableFields(getUnavailableFields(res));
|
|
||||||
checkHasStore();
|
checkHasStore();
|
||||||
fetchApiData();
|
fetchApiData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
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";
|
import { deleteGlobalVariable } from "../controllers/API";
|
||||||
|
import { getUnavailableFields } from "../utils/utils";
|
||||||
|
|
||||||
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
|
|
@ -20,6 +21,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
set({
|
set({
|
||||||
globalVariables: variables,
|
globalVariables: variables,
|
||||||
globalVariablesEntries: Object.keys(variables),
|
globalVariablesEntries: Object.keys(variables),
|
||||||
|
unavaliableFields: getUnavailableFields(variables)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addGlobalVariable: (name, id, type, default_fields) => {
|
addGlobalVariable: (name, id, type, default_fields) => {
|
||||||
|
|
@ -28,6 +30,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
set({
|
set({
|
||||||
globalVariables: newVariables,
|
globalVariables: newVariables,
|
||||||
globalVariablesEntries: Object.keys(newVariables),
|
globalVariablesEntries: Object.keys(newVariables),
|
||||||
|
unavaliableFields: getUnavailableFields(newVariables)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeGlobalVariable:async (name) => {
|
removeGlobalVariable:async (name) => {
|
||||||
|
|
@ -39,6 +42,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
set({
|
set({
|
||||||
globalVariables: newVariables,
|
globalVariables: newVariables,
|
||||||
globalVariablesEntries: Object.keys(newVariables),
|
globalVariablesEntries: Object.keys(newVariables),
|
||||||
|
unavaliableFields: getUnavailableFields(newVariables)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getVariableId: (name) => {
|
getVariableId: (name) => {
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,12 @@ export function toTitleCase(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUnavailableFields(
|
export function getUnavailableFields(
|
||||||
variables:{[key: string]: { id: string; type: string,default_fields:string[] }}
|
variables:{[key: string]: { default_fields?:string[] }}
|
||||||
): Set<string> {
|
): Set<string> {
|
||||||
const set = new Set<string>();
|
const set = new Set<string>();
|
||||||
Object.keys(variables).forEach((key) => {
|
Object.keys(variables).forEach((key) => {
|
||||||
if(variables[key].default_fields){
|
if(variables[key].default_fields){
|
||||||
variables[key].default_fields.forEach((field) => {
|
variables[key].default_fields!.forEach((field) => {
|
||||||
set.add(field);
|
set.add(field);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue