Skip to content
Merged
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
36 changes: 36 additions & 0 deletions DSL/Ruuter/services/POST/services/check-import-names.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declaration:
call: declare
version: 0.1
description: "Check which service names already exist and return them with timestamps appended where needed"
method: post
accepts: json
returns: json
namespace: service
allowlist:
body:
- field: names
type: string
description: "Comma-separated service names to check"
- field: timezone
type: string
description: "Timezone for timestamp generation"

extract_request_data:
assign:
names: ${incoming.body.names}
timezone: ${incoming.body.timezone}

check_names:
call: http.post
args:
url: "[#SERVICE_RESQL]/get-import-names"
body:
names: ${names}
timezone: ${timezone}
result: check_names_res

return_result:
status: 200
wrapper: false
return: ${check_names_res.response.body[0]}
next: end
25 changes: 21 additions & 4 deletions GUI/src/components/Flow/Controls/ImportExportControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { ChangeEvent, FC, useCallback, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AiOutlineExport, AiOutlineImport } from 'react-icons/ai';
import { checkImportNames } from 'resources/api-constants';
import api from 'services/api';
import { updateFlowInputRules } from 'services/flow-builder';
import useServiceStore from 'store/new-services.store';
import useToastStore from 'store/toasts.store';
Expand Down Expand Up @@ -32,10 +34,10 @@
const dataString = serializeFlowArtifact(getNodes(), getEdges(), buildServiceSettingsFromStore());
const fileName = `${serviceName != undefined && serviceName != '' ? serviceName : 'flow'}_${format(new Date(), 'yyyy_MM_dd_HH_mm_ss')}.json`;

if ('showSaveFilePicker' in window) {

Check warning on line 37 in GUI/src/components/Flow/Controls/ImportExportControls.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ5Ovzggr-d_ZZDXfLxE&open=AZ5Ovzggr-d_ZZDXfLxE&pullRequest=1026
try {
const blob = new Blob([dataString], { type: 'application/json' });
const handle = await (window as any).showSaveFilePicker({

Check warning on line 40 in GUI/src/components/Flow/Controls/ImportExportControls.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ5Ovzggr-d_ZZDXfLxF&open=AZ5Ovzggr-d_ZZDXfLxF&pullRequest=1026
suggestedName: fileName,
types: [
{
Expand Down Expand Up @@ -90,23 +92,38 @@
[setStoreNodes, setStoreEdges, setHasUnsavedChanges, saveToHistory, t],
);

const resolveImportedName = useCallback(async (title: string): Promise<string> => {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const res = await api.post(checkImportNames(), { names: title, timezone });
return (res.data as { names?: string })?.names ?? title;
} catch {
return title;
}
}, []);

const handleImport = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (!file) return;

const reader = new FileReader();
reader.onload = (e) => {
reader.onload = async (e) => {
try {
const content = e.target?.result as string;
const { nodes, edges, settings } = parseFlowArtifact(content);
const flowData = { nodes, edges } as FlowData;

const resolvedSettings = settings?.title
? { ...settings, title: await resolveImportedName(settings.title) }
: settings;

const currentNodes = getNodes().filter((node) => node.type !== 'ghost');

if (currentNodes.length === 1 && currentNodes[0].type === 'start') {
applyImportedFlow(flowData, settings);
applyImportedFlow(flowData, resolvedSettings);
} else {
setImportedFlowData({ ...flowData, settings });
setImportedFlowData({ ...flowData, settings: resolvedSettings });
setIsConfirmImportModalVisible(true);
}
} catch (error) {
Expand All @@ -116,13 +133,13 @@
.error({ title: t('global.notificationError'), message: t('serviceFlow.parseError') });
}
};
reader.readAsText(file);

Check warning on line 136 in GUI/src/components/Flow/Controls/ImportExportControls.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Blob#text()` over `FileReader#readAsText(blob)`.

See more on https://sonarcloud.io/project/issues?id=buerokratt_Service-Module&issues=AZ5Ovzggr-d_ZZDXfLxG&open=AZ5Ovzggr-d_ZZDXfLxG&pullRequest=1026

if (fileInputRef.current) {
fileInputRef.current.value = '';
}
},
[getNodes, applyImportedFlow, t],
[getNodes, applyImportedFlow, resolveImportedName, t],
);

const closeImportModal = useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions GUI/src/resources/api-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export const getAllEndpoints = (): string => `${baseUrl}/endpoints/all`;
export const testEndpointUrl = (): string => `${baseUrl}/services/test-endpoint`;
export const reindexEndpointUrl = (): string => `${baseUrl}/endpoints/reindex-endpoint`;
export const importMultipleServices = (): string => `${baseUrl}/services/import-services`;
export const checkImportNames = (): string => `${baseUrl}/services/check-import-names`;
Loading