Fixed global variables disappearing after refresh (#1954)

This commit is contained in:
Lucas Oliveira 2024-05-23 12:03:33 +01:00 committed by GitHub
commit 8813f4e5c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 8 deletions

View file

@ -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
: ""

View file

@ -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() {
<IconComponent
name="Trash2"
className={cn(
"h-5 w-5 text-destructive group-disabled:text-primary"
"h-5 w-5 text-destructive group-disabled:text-primary",
)}
/>
</Button>
@ -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"

View file

@ -13,7 +13,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
delete newFields[field];
set({ unavaliableFields: newFields });
},
globalVariablesEntries: [],
globalVariablesEntries: undefined,
globalVariables: {},
setGlobalVariables: (variables) => {
set({
@ -45,5 +45,5 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
getVariableId: (name) => {
return get().globalVariables[name]?.id;
},
})
}),
);

View file

@ -1,5 +1,5 @@
export type GlobalVariablesStore = {
globalVariablesEntries: Array<string>;
globalVariablesEntries: Array<string> | undefined;
globalVariables: {
[name: string]: {
id: string;