Skip to content

Commit

Permalink
fix(web): fix add index bug (#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal authored Oct 31, 2023
1 parent 537225e commit 525a063
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
5 changes: 3 additions & 2 deletions web/src/pages/app/database/mods/AddIndexModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => {
const createIndexMutation = useCreateIndexMutation();
const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);

const { register, control, handleSubmit } = useForm<FormData>({
const { register, control, handleSubmit, reset } = useForm<FormData>({
defaultValues: {
name: "",
capped: false,
Expand Down Expand Up @@ -85,7 +85,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => {
const onSubmit: SubmitHandler<FormData> = useCallback(
async (value) => {
const keys = value.keys.reduce<Record<string, number | string>>((acc, cur) => {
acc[cur.name] = cur.type;
acc[cur.name] = Number(cur.type) || cur.type;
return acc;
}, {});

Expand Down Expand Up @@ -118,6 +118,7 @@ const AddIndexModal = (props: { children: React.ReactElement }) => {
<>
{React.cloneElement(children, {
onClick: () => {
reset();
onOpen();
},
})}
Expand Down
18 changes: 8 additions & 10 deletions web/src/pages/app/database/mods/IndexModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ const IndexModal = (props: { children: React.ReactElement }) => {
</HStack>
</Td>
<Td>
<Center>
<PopConfirm
onConfirm={() => dropIndexMutation.mutateAsync(v.name)}
title={String(t("Delete"))}
placement="left"
description={t("CollectionPanel.ConfirmDeleteIndex")}
>
<CloseButton fontSize={10} />
</PopConfirm>
</Center>
<PopConfirm
onConfirm={() => dropIndexMutation.mutateAsync(v.name)}
title={String(t("Delete"))}
placement="left"
description={t("CollectionPanel.ConfirmDeleteIndex")}
>
<CloseButton fontSize={10} />
</PopConfirm>
</Td>
</Tr>
))}
Expand Down
4 changes: 1 addition & 3 deletions web/src/pages/app/database/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
{
Expand Down

0 comments on commit 525a063

Please sign in to comment.