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
41 changes: 11 additions & 30 deletions GUI/src/components/ApiEndpointCard/Endpoints/OpenAPI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
PreDefinedEndpointEnvVariables,
} from "../../../../types/endpoint";
import { RequestVariablesRowData } from "../../../../types/request-variables";
import useServiceStore from "store/new-services.store";
import api from "../../../../services/api-dev";

type EndpointOpenAPIProps = {
Expand All @@ -30,14 +29,13 @@ const EndpointOpenAPI: React.FC<EndpointOpenAPIProps> = ({
requestTab,
setRequestTab,
}) => {
const [openApiUrl, setOpenApiUrl] = useState<string>(endpoint.openApiUrl ?? "");
const [openApiUrl, setOpenApiUrl] = useState<string>(endpoint?.definitions[0]?.openApiUrl ?? "");
const [selectedEndpoint, setSelectedEndpoint] = useState<EndpointDefinition | undefined>(
endpoint.definitions.find((e) => e.isSelected)
);
const [openApiEndpoints, setOpenApiEndpoints] = useState<EndpointDefinition[]>(endpoint.definitions ?? []);
const [key, setKey] = useState<number>(0);
const { t } = useTranslation();
const { setEndpoints } = useServiceStore();

useEffect(() => setKey(key + 1), [isLive]);

Expand Down Expand Up @@ -165,10 +163,11 @@ const EndpointOpenAPI: React.FC<EndpointOpenAPIProps> = ({
label,
path,
url: endpointUrl,
openApiUrl,
type: "openApi",
methodType: method,
supported: false,
isSelected: false,
supported: true,
isSelected: true,
dataType: "custom",
});
return;
Expand All @@ -185,9 +184,10 @@ const EndpointOpenAPI: React.FC<EndpointOpenAPIProps> = ({
type: "openApi",
methodType: method,
supported: true,
isSelected: false,
isSelected: true,
description: data.summary ?? data.description,
url: endpointUrl,
openApiUrl,
dataType: "custom",
body: body
? {
Expand All @@ -212,14 +212,8 @@ const EndpointOpenAPI: React.FC<EndpointOpenAPIProps> = ({
});
});
setOpenApiEndpoints(paths);
setEndpoints((prevEndpoints) => {
prevEndpoints.forEach((prevEndpoint) => {
if (prevEndpoint.endpointId !== endpoint.endpointId) return;
prevEndpoint.definitions = paths;
prevEndpoint.openApiUrl = openApiUrl;
});
return prevEndpoints;
});
endpoint.definitions = paths;
endpoint.definitions[0].openApiUrl = openApiUrl;
setKey(key + 1);
};

Expand All @@ -239,25 +233,12 @@ const EndpointOpenAPI: React.FC<EndpointOpenAPIProps> = ({
const onSelectEndpoint = (selection: Option | null) => {
const newSelectedEndpoint = openApiEndpoints.find((openApiEndpoint) => openApiEndpoint.label === selection?.label);
setSelectedEndpoint(newSelectedEndpoint);
setEndpoints((prevEndpoints) => {
return updateSelectedEndpoint(prevEndpoints, newSelectedEndpoint);
});
if (!newSelectedEndpoint) return;
endpoint.definitions = [];
endpoint.definitions.push(newSelectedEndpoint);
setKey(key + 1);
};

const updateSelectedEndpoint = (
prevEndpoints: EndpointData[],
newSelectedEndpoint: EndpointDefinition | undefined
) => {
return prevEndpoints.map((prevEndpoint) => {
if (prevEndpoint.endpointId !== endpoint.endpointId) return prevEndpoint;
prevEndpoint.definitions.forEach((definedEndpoint) => {
definedEndpoint.isSelected = definedEndpoint === newSelectedEndpoint;
});
return prevEndpoint;
});
};

return (
<Track direction="vertical" align="stretch" gap={16}>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const RequestVariables: React.FC<RequestVariablesProps> = ({
const getInitialTabsRawData = (): RequestVariablesTabsRawData => {
return tabs.reduce((tabsRawData, tab) => {
const endpointData = endpoint.definitions[0];
if (!endpointData || !endpointData[tab]) return tabsRawData;
return { ...tabsRawData, [tab]: endpointData[tab]?.rawData[isLive ? "value" : "testValue"] ?? "" };
}, {});
};
Expand Down Expand Up @@ -165,7 +166,9 @@ const RequestVariables: React.FC<RequestVariablesProps> = ({
row[field] = newValue;
});

newRowsData[requestTab.tab] = maintainSingleEmptyRow(newRowsData[requestTab.tab] || []);
if (endpoint.type === "custom") {
newRowsData[requestTab.tab] = maintainSingleEmptyRow(newRowsData[requestTab.tab] || []);
}
updateEndpointData(newRowsData, endpoint);
if (requestTab.tab === "params")
onParametersChange(
Expand Down
2 changes: 2 additions & 0 deletions GUI/src/store/new-services.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ const useServiceStore = create<ServiceStoreState>((set, get, store) => ({
}));

function extractMapValues(element: any) {
if (!element) return {};

if (element.rawData && element.rawData.length > 0) {
return element.rawData.value;
}
Expand Down
1 change: 0 additions & 1 deletion GUI/src/types/endpoint/endpoint-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type EndpointData = {
type?: EndpointType;
isCommon?: boolean;
isNew?: boolean;
openApiUrl?: string;
hasTestEnv?: boolean;
serviceId?: string;
definitions: EndpointDefinition[];
Expand Down
1 change: 1 addition & 0 deletions GUI/src/types/endpoint/endpoint-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type EndpointDefinition = {
supported: boolean;
isSelected: boolean;
url?: string;
openApiUrl?: string;
description?: string;
params?: {
variables: EndpointVariableData[];
Expand Down
Loading