From 525a063987604ea7d96e2555d8274c48cf66844e Mon Sep 17 00:00:00 2001 From: 0fatal <72899968+0fatal@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:43:03 +0800 Subject: [PATCH] fix(web): fix add index bug (#1626) --- .../app/database/mods/AddIndexModal/index.tsx | 5 +++-- .../app/database/mods/IndexModal/index.tsx | 18 ++++++++---------- web/src/pages/app/database/service.ts | 4 +--- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/web/src/pages/app/database/mods/AddIndexModal/index.tsx b/web/src/pages/app/database/mods/AddIndexModal/index.tsx index 0d3bad01e8..d9f97e69ad 100644 --- a/web/src/pages/app/database/mods/AddIndexModal/index.tsx +++ b/web/src/pages/app/database/mods/AddIndexModal/index.tsx @@ -53,7 +53,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => { const createIndexMutation = useCreateIndexMutation(); const [showAdvancedOptions, setShowAdvancedOptions] = useState(false); - const { register, control, handleSubmit } = useForm({ + const { register, control, handleSubmit, reset } = useForm({ defaultValues: { name: "", capped: false, @@ -85,7 +85,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => { const onSubmit: SubmitHandler = useCallback( async (value) => { const keys = value.keys.reduce>((acc, cur) => { - acc[cur.name] = cur.type; + acc[cur.name] = Number(cur.type) || cur.type; return acc; }, {}); @@ -118,6 +118,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => { <> {React.cloneElement(children, { onClick: () => { + reset(); onOpen(); }, })} diff --git a/web/src/pages/app/database/mods/IndexModal/index.tsx b/web/src/pages/app/database/mods/IndexModal/index.tsx index b7977e17f5..9c1086b083 100644 --- a/web/src/pages/app/database/mods/IndexModal/index.tsx +++ b/web/src/pages/app/database/mods/IndexModal/index.tsx @@ -115,16 +115,14 @@ const IndexModal = (props: { children: React.ReactElement }) => { -
- dropIndexMutation.mutateAsync(v.name)} - title={String(t("Delete"))} - placement="left" - description={t("CollectionPanel.ConfirmDeleteIndex")} - > - - -
+ dropIndexMutation.mutateAsync(v.name)} + title={String(t("Delete"))} + placement="left" + description={t("CollectionPanel.ConfirmDeleteIndex")} + > + + ))} diff --git a/web/src/pages/app/database/service.ts b/web/src/pages/app/database/service.ts index 352106f30b..71060a0089 100644 --- a/web/src/pages/app/database/service.ts +++ b/web/src/pages/app/database/service.ts @@ -366,9 +366,7 @@ export const useCreateIndexMutation = (config?: { onSuccess: (data: any) => void return useMutation( async (values: any) => { - const result = await db - .collection(currentDB?.name!) - .createIndex(values.fields, values.options); + const result = await db.collection(currentDB?.name!).createIndex(values.keys, values.options); return result; }, {