Skip to content

Commit

Permalink
refactor(web): separate update of debug info from function update (la…
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk authored Jun 30, 2023
1 parent b388c5f commit c02820b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
11 changes: 11 additions & 0 deletions web/src/apis/v1/api-auto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ declare namespace Definitions {
methods?: string[];
code?: string /* The source code of the function */;
tags?: string[];
};

export type UpdateFunctionDebugDto = {
params?: {};
};

Expand Down Expand Up @@ -509,6 +512,14 @@ declare namespace Paths {
export type Responses = any;
}

namespace FunctionControllerUpdateDebug {
export type QueryParameters = any;

export type BodyParameters = Definitions.UpdateFunctionDebugDto;

export type Responses = any;
}

namespace FunctionControllerCompile {
export type QueryParameters = any;

Expand Down
20 changes: 20 additions & 0 deletions web/src/apis/v1/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ export async function FunctionControllerRemove(
});
}

/**
* Update function debug info
*/
export async function FunctionControllerUpdateDebug(
params: Definitions.UpdateFunctionDebugDto,
): Promise<{
error: string;
data: Definitions.CloudFunction;
}> {
// /v1/apps/{appid}/functions/{name}/debug
let _params: { [key: string]: any } = {
appid: useGlobalStore.getState().currentApp?.appid || "",
...params,
};
return request(`/v1/apps/${_params.appid}/functions/${_params.name}/debug/params`, {
method: "PATCH",
data: params,
});
}

/**
* Compile a function
*/
Expand Down
11 changes: 3 additions & 8 deletions web/src/pages/app/functions/mods/DebugPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Panel from "@/components/Panel";
import Resize from "@/components/Resize";
import { COLOR_MODE, Pages, PanelMinHeight } from "@/constants";

import { useCompileMutation, useUpdateFunctionMutation } from "../../service";
import { useCompileMutation, useUpdateDebugFunctionMutation } from "../../service";
import useFunctionStore from "../../store";
import AIChatPanel from "../AIChatPanel";
import VersionHistoryPanel from "../VersionHistoryPanel";
Expand All @@ -44,7 +44,7 @@ export default function DebugPanel(props: { containerRef: any; showOverlay: bool
const { t } = useTranslation();
const { getFunctionUrl, currentFunction, setCurrentFunction, setCurrentRequestId } =
useFunctionStore((state: any) => state);
const updateFunctionMutation = useUpdateFunctionMutation();
const updateDebugFunctionMutation = useUpdateDebugFunctionMutation();
const globalStore = useGlobalStore((state) => state);

const functionCache = useFunctionCache();
Expand Down Expand Up @@ -98,13 +98,8 @@ export default function DebugPanel(props: { containerRef: any; showOverlay: bool
runningMethod: runningMethod,
};

updateFunctionMutation.mutateAsync({
description: currentFunction?.desc,
code: currentFunction?.source.code,
methods: currentFunction?.methods,
websocket: currentFunction?.websocket,
updateDebugFunctionMutation.mutateAsync({
name: currentFunction?.name,
tags: currentFunction?.tags,
params: params,
});

Expand Down
21 changes: 21 additions & 0 deletions web/src/pages/app/functions/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FunctionControllerGetHistory,
FunctionControllerRemove,
FunctionControllerUpdate,
FunctionControllerUpdateDebug,
} from "@/apis/v1/apps";
import useFunctionCache from "@/hooks/useFunctionCache";

Expand Down Expand Up @@ -101,6 +102,26 @@ export const useUpdateFunctionMutation = () => {
);
};

export const useUpdateDebugFunctionMutation = () => {
const queryClient = useQueryClient();
return useMutation(
(values: any) => {
const updatedValues = {
...values,
name: encodeURIComponent(values.name),
};
return FunctionControllerUpdateDebug(updatedValues);
},
{
onSuccess(data) {
if (!data.error) {
queryClient.invalidateQueries(queryKeys.useFunctionListQuery);
}
},
},
);
};

export const useDeleteFunctionMutation = () => {
const store = useFunctionStore();
const functionCache = useFunctionCache();
Expand Down

0 comments on commit c02820b

Please sign in to comment.