From 8813f4e5c355095e33837640fae3e87e42abafe4 Mon Sep 17 00:00:00 2001
From: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com>
Date: Thu, 23 May 2024 12:03:33 +0100
Subject: [PATCH] Fixed global variables disappearing after refresh (#1954)
---
.../src/components/inputGlobalComponent/index.tsx | 2 ++
.../SettingsPage/pages/GlobalVariablesPage/index.tsx | 11 ++++++-----
src/frontend/src/stores/globalVariables.ts | 4 ++--
.../src/types/zustand/globalVariables/index.ts | 2 +-
4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/frontend/src/components/inputGlobalComponent/index.tsx b/src/frontend/src/components/inputGlobalComponent/index.tsx
index 2ca1aed22..7c82f975b 100644
--- a/src/frontend/src/components/inputGlobalComponent/index.tsx
+++ b/src/frontend/src/components/inputGlobalComponent/index.tsx
@@ -34,6 +34,7 @@ export default function InputGlobalComponent({
useEffect(() => {
if (data.node?.template[name])
if (
+ globalVariablesEntries &&
!globalVariablesEntries.includes(data.node?.template[name].value) &&
data.node?.template[name].load_from_db
) {
@@ -138,6 +139,7 @@ export default function InputGlobalComponent({
)}
selectedOption={
data?.node?.template[name].load_from_db &&
+ globalVariablesEntries &&
globalVariablesEntries.includes(data?.node?.template[name].value ?? "")
? data?.node?.template[name].value
: ""
diff --git a/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx b/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx
index b2cebc963..9717fea8d 100644
--- a/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx
+++ b/src/frontend/src/pages/SettingsPage/pages/GlobalVariablesPage/index.tsx
@@ -16,13 +16,13 @@ import { cn } from "../../../../utils/utils";
export default function GlobalVariablesPage() {
const globalVariablesEntries = useGlobalVariablesStore(
- (state) => state.globalVariablesEntries
+ (state) => state.globalVariablesEntries,
);
const removeGlobalVariable = useGlobalVariablesStore(
- (state) => state.removeGlobalVariable
+ (state) => state.removeGlobalVariable,
);
const globalVariables = useGlobalVariablesStore(
- (state) => state.globalVariables
+ (state) => state.globalVariables,
);
const setErrorData = useAlertStore((state) => state.setErrorData);
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
@@ -55,6 +55,7 @@ export default function GlobalVariablesPage() {
name: string;
default_fields: string | undefined;
}> = [];
+ if (globalVariablesEntries === undefined) return;
globalVariablesEntries.forEach((entrie) => {
const globalVariableObj = globalVariables[entrie];
rows.push({
@@ -156,7 +157,7 @@ export default function GlobalVariablesPage() {
@@ -176,7 +177,7 @@ export default function GlobalVariablesPage() {
overlayNoRowsTemplate="No data available"
onSelectionChanged={(event: SelectionChangedEvent) => {
setSelectedRows(
- event.api.getSelectedRows().map((row) => row.name)
+ event.api.getSelectedRows().map((row) => row.name),
);
}}
rowSelection="multiple"
diff --git a/src/frontend/src/stores/globalVariables.ts b/src/frontend/src/stores/globalVariables.ts
index 3adf8cbf8..8c477507e 100644
--- a/src/frontend/src/stores/globalVariables.ts
+++ b/src/frontend/src/stores/globalVariables.ts
@@ -13,7 +13,7 @@ export const useGlobalVariablesStore = create(
delete newFields[field];
set({ unavaliableFields: newFields });
},
- globalVariablesEntries: [],
+ globalVariablesEntries: undefined,
globalVariables: {},
setGlobalVariables: (variables) => {
set({
@@ -45,5 +45,5 @@ export const useGlobalVariablesStore = create(
getVariableId: (name) => {
return get().globalVariables[name]?.id;
},
- })
+ }),
);
diff --git a/src/frontend/src/types/zustand/globalVariables/index.ts b/src/frontend/src/types/zustand/globalVariables/index.ts
index d22170ed2..4b178088c 100644
--- a/src/frontend/src/types/zustand/globalVariables/index.ts
+++ b/src/frontend/src/types/zustand/globalVariables/index.ts
@@ -1,5 +1,5 @@
export type GlobalVariablesStore = {
- globalVariablesEntries: Array;
+ globalVariablesEntries: Array | undefined;
globalVariables: {
[name: string]: {
id: string;