Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions GUI/src/pages/ServiceFlowPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const ServiceFlowPage: FC = () => {
};

void loadData();

// Cleanup function to reset state when component unmounts (including browser back button)
return () => {
useServiceStore.getState().resetState();
};
}, [id]);

const edges = useServiceStore((state) => state.edges);
Expand All @@ -69,15 +74,15 @@ const ServiceFlowPage: FC = () => {
}}
saveOnClick={async () => {
setHasUnsavedChanges(false);
if (!id) {
if (id) {
await useServiceStore.getState().loadService(id);
} else {
const serviceId = useServiceStore.getState().serviceId;
const serviceResponse = await useServiceStore.getState().loadService(serviceId);
if (serviceResponse) {
useServiceListStore.getState().setSelectedService(serviceResponse?.data);
navigate(ROUTES.replaceWithId(ROUTES.EDITSERVICE_ROUTE, serviceId));
}
} else {
await useServiceStore.getState().loadService(id);
}
}}
/>
Expand Down
35 changes: 19 additions & 16 deletions GUI/src/store/new-services.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
unmarkAsNewService: () => set({ isNewService: false }),
setServiceId: (id) => set({ serviceId: id }),
setNodes: (nodes) => {
if (nodes instanceof Function) {
if (typeof nodes === 'function') {
set((state) => {
return {
nodes: nodes(state.nodes),
Expand All @@ -240,7 +240,7 @@
}
},
setEdges: (edges) => {
if (edges instanceof Function) {
if (typeof edges === 'function') {
set((state) => {
return {
edges: edges(state.edges),
Expand Down Expand Up @@ -294,17 +294,18 @@
});
}

chips.push({
name: 'Base Response',
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
data: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
});

chips.push({
name: 'Status Code',
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.statusCodeValue`,
data: `${endpoint?.name.replaceAll(' ', '_')}_res.response.statusCodeValue`,
});
chips.push(
{
name: 'Base Response',
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
data: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
},
{
name: 'Status Code',
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.statusCodeValue`,
data: `${endpoint?.name.replaceAll(' ', '_')}_res.response.statusCodeValue`,
}
);

const variable: EndpointResponseVariable = {
name: endpoint?.name ?? '',
Expand Down Expand Up @@ -391,6 +392,8 @@
serviceId: uuid(),
description: '',
slot: '',
examples: [],
entities: [],
secrets: { prod: [], test: [] },
availableVariables: { prod: [], test: [] },
isCommon: false,
Expand Down Expand Up @@ -438,7 +441,7 @@

if (!nodes || nodes.length === 0) nodes = initialNodes;

if (!endpoints || !(endpoints instanceof Array)) endpoints = [];
if (!endpoints || !Array.isArray(endpoints)) endpoints = [];

nodes = nodes.map((node: any) => {
if (node.type !== 'custom') return node;
Expand All @@ -453,8 +456,8 @@
});

const initialHistoryState = {
nodes: JSON.parse(JSON.stringify(nodes)),

Check warning on line 459 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wnu&open=AZ0FZP-dUsnleY9H2wnu&pullRequest=941
edges: JSON.parse(JSON.stringify(edges)),

Check warning on line 460 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wnv&open=AZ0FZP-dUsnleY9H2wnv&pullRequest=941
};

set({
Expand Down Expand Up @@ -677,15 +680,15 @@
title: i18next.t('newService.toast.missingFields'),
message: i18next.t('newService.toast.serviceMissingFields'),
});
return Promise.reject(new Error(i18next.t('newService.toast.missingFields') ?? 'Error'));
throw new Error(i18next.t('newService.toast.missingFields') ?? 'Error');
}

const { isNewService, onServiceSave } = get();

try {
await onServiceSave(ServiceState.Ready);
} catch (e: any) {
return Promise.reject(new Error(i18next.t('toast.cannot-save-flow') ?? (e?.message as string) ?? 'Error'));
throw new Error(i18next.t('toast.cannot-save-flow') ?? (e?.message as string) ?? 'Error');
}

if (isNewService) {
Expand Down Expand Up @@ -855,12 +858,12 @@

const currentState = stateOverride
? {
nodes: JSON.parse(JSON.stringify(stateOverride.nodes)),

Check warning on line 861 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wny&open=AZ0FZP-dUsnleY9H2wny&pullRequest=941
edges: JSON.parse(JSON.stringify(stateOverride.edges)),

Check warning on line 862 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wnz&open=AZ0FZP-dUsnleY9H2wnz&pullRequest=941
}
: {
nodes: JSON.parse(JSON.stringify(nodes)),

Check warning on line 865 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn0&open=AZ0FZP-dUsnleY9H2wn0&pullRequest=941
edges: JSON.parse(JSON.stringify(edges)),

Check warning on line 866 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn1&open=AZ0FZP-dUsnleY9H2wn1&pullRequest=941
};

const lastState = history[historyIndex];
Expand Down Expand Up @@ -888,7 +891,7 @@
const { history, historyIndex } = get();
if (historyIndex > 0) {
const previousState = history[historyIndex - 1];
let nodes = JSON.parse(JSON.stringify(previousState.nodes));

Check warning on line 894 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn2&open=AZ0FZP-dUsnleY9H2wn2&pullRequest=941

nodes = nodes.map((node: any) => {
if (node.type !== 'custom') return node;
Expand All @@ -906,7 +909,7 @@

set({
nodes: nodes,
edges: JSON.parse(JSON.stringify(previousState.edges)),

Check warning on line 912 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn3&open=AZ0FZP-dUsnleY9H2wn3&pullRequest=941
historyIndex: historyIndex - 1,
hasUnsavedChanges: true,
});
Expand All @@ -917,7 +920,7 @@
const { history, historyIndex } = get();
if (historyIndex < history.length - 1) {
const nextState = history[historyIndex + 1];
let nodes = JSON.parse(JSON.stringify(nextState.nodes));

Check warning on line 923 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn4&open=AZ0FZP-dUsnleY9H2wn4&pullRequest=941

nodes = nodes.map((node: any) => {
if (node.type !== 'custom') return node;
Expand All @@ -935,7 +938,7 @@

set({
nodes: nodes,
edges: JSON.parse(JSON.stringify(nextState.edges)),

Check warning on line 941 in GUI/src/store/new-services.store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `structuredClone(…)` over `JSON.parse(JSON.stringify(…))` to create a deep clone.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ0FZP-dUsnleY9H2wn5&open=AZ0FZP-dUsnleY9H2wn5&pullRequest=941
historyIndex: historyIndex + 1,
hasUnsavedChanges: true,
});
Expand Down
Loading