Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): support function rename #1343

Merged
merged 2 commits into from
Jul 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { debounce } from "lodash";
import { TextIcon } from "@/components/CommonIcon";
import InputTag from "@/components/InputTag";
import { SUPPORTED_METHODS } from "@/constants";
import { changeURL } from "@/utils/format";

import { useCreateFunctionMutation, useUpdateFunctionMutation } from "../../../service";
import useFunctionStore from "../../../store";
Expand All @@ -44,7 +45,7 @@ const CreateModal = (props: {
}) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const store = useFunctionStore();
const { showSuccess } = useGlobalStore();
const { showSuccess, currentApp } = useGlobalStore();

const { functionItem, children = null, tagList } = props;
const isEdit = !!functionItem;
Expand Down Expand Up @@ -93,14 +94,18 @@ const CreateModal = (props: {
sort: null,
},
{
enabled: isOpen,
enabled: isOpen && !isEdit,
},
);

const onSubmit = async (data: any) => {
let res: any = {};
if (isEdit) {
res = await updateFunctionMutation.mutateAsync(data);
res = await updateFunctionMutation.mutateAsync({
...data,
name: functionItem.name,
newName: data.name,
});
} else {
res = await createFunctionMutation.mutateAsync(data);
}
Expand All @@ -110,6 +115,7 @@ const CreateModal = (props: {
onClose();
store.setCurrentFunction(res.data);
reset(defaultValues);
navigate(`/app/${currentApp.appid}/function/${res.data.name}`);
}
};

Expand Down Expand Up @@ -137,12 +143,7 @@ const CreateModal = (props: {
<ModalBody>
<VStack align="flex-start">
<FormControl isInvalid={!!errors?.name}>
<div
className={clsx(
"mb-3 flex h-12 w-full items-center border-b-2",
isEdit ? "rounded-md bg-gray-100" : "",
)}
>
<div className="mb-3 flex h-12 w-full items-center border-b-2">
<input
{...register("name", {
pattern: {
Expand All @@ -152,7 +153,6 @@ const CreateModal = (props: {
})}
id="name"
placeholder={String(t("FunctionPanel.FunctionNameTip"))}
disabled={isEdit}
className="h-8 w-full border-l-2 border-primary-600 bg-transparent pl-4 text-2xl font-medium"
style={{ outline: "none", boxShadow: "none" }}
onChange={debounce((e) => {
Expand Down Expand Up @@ -248,12 +248,7 @@ const CreateModal = (props: {
<span className="line-clamp-1">{item.name}</span>
</div>
</div>
<div
className={clsx(
"mb-3 flex h-4 items-center truncate",
// darkMode ? "text-gray-300" : "text-second",
)}
>
<div className="mb-3 flex h-4 items-center truncate">
{item.description}
</div>
<div className="flex w-full overflow-hidden pb-4">
Expand All @@ -277,10 +272,7 @@ const CreateModal = (props: {
</div>
<div
onClick={() => {
const currentURL = window.location.pathname;
const lastIndex = currentURL.lastIndexOf("/");
const newURL = currentURL.substring(0, lastIndex) + `/recommended`;
navigate(newURL);
navigate(changeURL(`/recommended`));
}}
>
<FuncTemplate>
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/app/functions/mods/TriggerModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function TriggerModal(props: { children: React.ReactElement }) {
{React.cloneElement(props.children, {
onClick: () => {
onOpen();
triggerListQuery.refetch();
},
})}

Expand Down