From 8f301872183fdb4cc8711750fac3907467a3f65b Mon Sep 17 00:00:00 2001 From: Ricco Xie Date: Sat, 4 Nov 2023 18:20:58 +0800 Subject: [PATCH] fix: confirm btn is not visible in modals gh-93. perf: change document card font size. perf: document card btn style. fix: document card btn translation text. --- src/components/Document/list.tsx | 62 +++++++++++++------ src/components/Header/index.tsx | 40 +++++++++--- .../Settings/config/detail/arrayInput.tsx | 45 ++++++++++---- .../Settings/config/detail/synonyms.tsx | 41 ++++++++---- src/pages/dashboard.tsx | 38 +++++++++--- src/pages/key/index.tsx | 40 +++++++++--- 6 files changed, 193 insertions(+), 73 deletions(-) diff --git a/src/components/Document/list.tsx b/src/components/Document/list.tsx index 285efd2..d960651 100644 --- a/src/components/Document/list.tsx +++ b/src/components/Document/list.tsx @@ -1,4 +1,4 @@ -import { openConfirmModal } from '@mantine/modals'; +import { modals } from '@mantine/modals'; import { useMeiliClient } from '@/src/hooks/useMeiliClient'; import { showTaskErrorNotification, showTaskSubmitNotification } from '@/src/utils/text'; import { toast } from '@/src/utils/toast'; @@ -62,24 +62,43 @@ export const DocumentList = ({ docs = [], showIndex = false, refetchDocs }: Prop const pk = doc.primaryKey; console.debug('onClickDocumentDel', 'pk', pk); if (pk) { - openConfirmModal({ + const modalId = 'deleteDocumentModal'; + modals.open({ + modalId, title: t('delete_document'), centered: true, children: ( -

- {t('delete.tip') + ' '} - - {/* @ts-ignore */} - document ({pk}: {doc.content[pk]}) in index {doc.indexId} - - ? -

+
+

+ {t('delete.tip') + ' '} + + {/* @ts-ignore */} + document ({pk}: {doc.content[pk]}) in index {doc.indexId} + + ? +

+
+ + +
+
), - labels: { confirm: t('confirm'), cancel: t('cancel') }, - onConfirm: () => { - // @ts-ignore - removeDocumentsMutation.mutate({ indexId: doc.indexId, docId: [doc.content[pk]] }); - }, }); } else { toast.error(t('delete.require_primaryKey', { indexId: doc.indexId })); @@ -101,7 +120,10 @@ export const DocumentList = ({ docs = [], showIndex = false, refetchDocs }: Prop const list = useMemo(() => { return docs.map((d, i) => { return ( -
+
@@ -118,11 +140,11 @@ export const DocumentList = ({ docs = [], showIndex = false, refetchDocs }: Prop
- -
diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index ea2e0fb..7e47092 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -18,7 +18,7 @@ import { MeiliSearch, Version } from 'meilisearch'; import { useQuery } from '@tanstack/react-query'; import { useInstanceStats } from '@/src/hooks/useInstanceStats'; import _ from 'lodash'; -import { openConfirmModal } from '@mantine/modals'; +import { modals } from '@mantine/modals'; import { getTimeText, showTaskSubmitNotification } from '@/src/utils/text'; import { validateKeysRouteAvailable } from '@/src/utils/conn'; import { useNavigatePreCheck } from '@/src/hooks/useRoutePreCheck'; @@ -80,17 +80,37 @@ export const Header: FC = ({ client, className }) => { }, [clipboard, currentInstance?.host]); const onClickDump = useCallback(() => { - openConfirmModal({ + const modalId = 'createDumpModal'; + modals.open({ + modalId, title: t('instance:dump.dialog.title'), centered: true, - children:

{t('instance:dump.dialog.tip', { name: currentInstance.name })}

, - labels: { confirm: t('confirm'), cancel: t('cancel') }, - confirmProps: { color: 'orange' }, - onConfirm: () => { - client.createDump().then((value) => { - showTaskSubmitNotification(value); - }); - }, + children: ( +
+

{t('instance:dump.dialog.tip', { name: currentInstance.name })}

+
+ + +
+
+ ), }); }, [client, currentInstance.name, t]); diff --git a/src/components/Settings/config/detail/arrayInput.tsx b/src/components/Settings/config/detail/arrayInput.tsx index d27396c..eb5a213 100644 --- a/src/components/Settings/config/detail/arrayInput.tsx +++ b/src/components/Settings/config/detail/arrayInput.tsx @@ -2,7 +2,7 @@ import clsx from 'clsx'; import { useForm } from 'react-hook-form'; import { IconPlus, IconCircleMinus, IconArrowUp, IconArrowDown } from '@tabler/icons-react'; import { PropsWithoutRef, useCallback, useMemo, useState } from 'react'; -import { openConfirmModal } from '@mantine/modals'; +import { modals } from '@mantine/modals'; import _ from 'lodash'; import { arrayMove } from '@/src/utils/array'; import { useTranslation } from 'react-i18next'; @@ -67,18 +67,37 @@ export function ArrayInput({ const onClickItemDel = useCallback( (index: number) => { console.debug('🚀 ~ file: ArrayInput onClickItemDel', index); - - openConfirmModal({ - title: t('setting.index.config.remove_this.item'), + const modalId = 'removeItemModal'; + modals.open({ + modalId, + title: t('setting.index.config.remove_this_item'), centered: true, - children:

{t('setting.index.config.are_you_sure_you_want_to_remove_item', { item: array[index] })}

, - labels: { confirm: t('confirm'), cancel: t('cancel') }, - confirmProps: { color: 'red' }, - onConfirm: async () => { - const updated = _.without(array, array[index]); - setArray(updated); - onMutation(updated); - }, + children: ( +
+

{t('setting.index.config.are_you_sure_you_want_to_remove_item', { item: array[index] })}

{' '} +
+ + +
+
+ ), }); }, [array, onMutation, t] @@ -86,7 +105,7 @@ export function ArrayInput({ return useMemo( () => ( -
+
{(isAdding ? array : defaultValue).map((item, i) => (
= ({ client, classNa const onClickItemDel = useCallback( (key: string) => { console.debug('🚀 ~ file: Synonyms onClickItemDel', key); - - openConfirmModal({ - title: t('setting.index.config.remove_this.item'), + const modalId = 'removeItemModal'; + modals.open({ + modalId, + title: t('setting.index.config.remove_this_item'), centered: true, - children:

{t('setting.index.config.are_you_sure_you_want_to_remove_item', { item: key })}

, - labels: { confirm: t('confirm'), cancel: t('cancel') }, - confirmProps: { color: 'red' }, - onConfirm: async () => { - const updated = _.omit(query.data, [key]); - mutation.mutate(updated); - }, + children: ( +
+

{t('setting.index.config.are_you_sure_you_want_to_remove_item', { item: key })}

{' '} +
+ + +
+
+ ), }); }, [mutation, t, query.data] diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 8e93c3c..3da66fa 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -6,7 +6,7 @@ import { Footer } from '@/src/components/Footer'; import { useForm } from '@mantine/form'; import { IconBooks, IconCirclePlus, IconCircleX, IconKey, IconListCheck, IconPencilMinus } from '@tabler/icons-react'; import { testConnection, validateKeysRouteAvailable } from '@/src/utils/conn'; -import { openConfirmModal } from '@mantine/modals'; +import { modals } from '@mantine/modals'; import { getTimeText } from '@/src/utils/text'; import _ from 'lodash'; import { useNavigatePreCheck } from '@/src/hooks/useRoutePreCheck'; @@ -110,18 +110,38 @@ function Dashboard() { const onClickRemoveInstance = useCallback( (ins: Instance) => { - openConfirmModal({ + const modalId = 'removeInsModal'; + modals.open({ + modalId, title: t('instance.remove.title'), centered: true, children: ( -

- {t('instance.remove.tip')} ({ins.name})? -

+
+

+ {t('instance.remove.tip')} ({ins.name})? +

+
+ + +
+
), - labels: { confirm: t('confirm'), cancel: t('cancel') }, - onConfirm: () => { - removeInstance(ins.id); - }, }); }, [removeInstance, t] diff --git a/src/pages/key/index.tsx b/src/pages/key/index.tsx index 74b4d71..63c8292 100644 --- a/src/pages/key/index.tsx +++ b/src/pages/key/index.tsx @@ -15,7 +15,7 @@ import { IconCheck, IconCopy } from '@tabler/icons-react'; import { Footer } from '@/src/components/Footer'; import { useForm } from '@mantine/form'; import { useIndexes } from '@/src/hooks/useIndexes'; -import { openConfirmModal } from '@mantine/modals'; +import { modals } from '@mantine/modals'; import { toast } from '@/src/utils/toast'; import { useCurrentInstance } from '@/src/hooks/useCurrentInstance'; import { useTranslation } from 'react-i18next'; @@ -100,17 +100,37 @@ function Keys() { const onClickDelKey = useCallback( (key: Key) => { - openConfirmModal({ + const modalId = 'delKeyModal'; + modals.open({ + modalId, title: t('delete.title'), centered: true, - children:

{t('delete.tip')}

, - labels: { confirm: t('confirm'), cancel: t('cancel') }, - confirmProps: { color: 'red' }, - onConfirm: () => { - client.deleteKey(key.uid).finally(() => { - refreshKeys(); - }); - }, + children: ( +
+

{t('delete.tip')}

+
+ + +
+
+ ), }); }, [client, refreshKeys, t]