mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-25 11:58:22 +08:00
Refactor globalVariables.ts to include unavaliableFields in useGlobalVariablesStore
This commit is contained in:
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user