From 26d90f3255b8931259e30795f963d8a73f16da9c Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Wed, 23 Aug 2023 11:49:37 +0800 Subject: [PATCH] gpu alias --- .../public/locales/zh/common.json | 2 +- .../src/components/GPUItem/index.tsx | 19 ++++++++++++++----- .../providers/applaunchpad/src/pages/_app.tsx | 5 ++++- .../src/pages/api/platform/resourcePrice.ts | 19 +------------------ .../src/pages/app/edit/components/Form.tsx | 4 ++-- .../applaunchpad/src/pages/app/edit/index.tsx | 1 - 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/frontend/providers/applaunchpad/public/locales/zh/common.json b/frontend/providers/applaunchpad/public/locales/zh/common.json index 497531c61401..74bd90b745a7 100644 --- a/frontend/providers/applaunchpad/public/locales/zh/common.json +++ b/frontend/providers/applaunchpad/public/locales/zh/common.json @@ -1,7 +1,7 @@ { "cpu": "CPU", "memory": "内存", - "storage": "存储券", + "storage": "存储卷", "gpu": "GPU", "Applications": "应用列表", "Create Application": "新建应用", diff --git a/frontend/providers/applaunchpad/src/components/GPUItem/index.tsx b/frontend/providers/applaunchpad/src/components/GPUItem/index.tsx index 72aa0428e301..babb42d6241c 100644 --- a/frontend/providers/applaunchpad/src/components/GPUItem/index.tsx +++ b/frontend/providers/applaunchpad/src/components/GPUItem/index.tsx @@ -1,24 +1,33 @@ import { Box, Flex } from '@chakra-ui/react'; -import React from 'react'; +import React, { useMemo } from 'react'; import MyIcon from '../Icon'; import { GpuType } from '@/types/app'; import { useTranslation } from 'next-i18next'; +import { useUserStore } from '@/store/user'; const GPUItem = ({ gpu }: { gpu?: GpuType }) => { const { t } = useTranslation(); + const { userSourcePrice } = useUserStore(); + + const gpuAlias = useMemo(() => { + const gpuItem = userSourcePrice?.gpu?.find((item) => item.type === gpu?.type); + + return gpuItem?.alias || gpu?.type || ''; + }, [gpu?.type, userSourcePrice?.gpu]); + return ( - {gpu?.type && ( + {gpuAlias && ( <> - {gpu.type} + {gpuAlias} / )} - {!!gpu?.type ? gpu?.amount : 0} + {!!gpuAlias ? gpu?.amount : 0} {t('Card')} @@ -26,4 +35,4 @@ const GPUItem = ({ gpu }: { gpu?: GpuType }) => { ); }; -export default GPUItem; +export default React.memo(GPUItem); diff --git a/frontend/providers/applaunchpad/src/pages/_app.tsx b/frontend/providers/applaunchpad/src/pages/_app.tsx index afb703140b58..d98cfec7a55c 100644 --- a/frontend/providers/applaunchpad/src/pages/_app.tsx +++ b/frontend/providers/applaunchpad/src/pages/_app.tsx @@ -16,6 +16,7 @@ import { loadInitData } from '@/store/static'; import { useRouter } from 'next/router'; import { appWithTranslation, useTranslation } from 'next-i18next'; import { getLangStore, setLangStore } from '@/utils/cookieUtils'; +import { useUserStore } from '@/store/user'; import 'nprogress/nprogress.css'; import '@/styles/reset.scss'; @@ -40,6 +41,7 @@ const App = ({ Component, pageProps }: AppProps) => { const router = useRouter(); const { i18n } = useTranslation(); const { setScreenWidth, loading, setLastRoute, initFormSliderList } = useGlobalStore(); + const { loadUserSourcePrice } = useUserStore(); const { Loading } = useLoading(); const [refresh, setRefresh] = useState(false); const { openConfirm, ConfirmChild } = useConfirm({ @@ -55,6 +57,7 @@ const App = ({ Component, pageProps }: AppProps) => { (async () => { const { SEALOS_DOMAIN, FORM_SLIDER_LIST_CONFIG } = await (() => loadInitData())(); initFormSliderList(FORM_SLIDER_LIST_CONFIG); + loadUserSourcePrice(); try { const res = await sealosApp.getSession(); @@ -74,7 +77,7 @@ const App = ({ Component, pageProps }: AppProps) => { NProgress.done(); return response; - }, [initFormSliderList, openConfirm]); + }, []); // add resize event useEffect(() => { diff --git a/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts b/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts index c2032f1c161e..e4779509681d 100644 --- a/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts +++ b/frontend/providers/applaunchpad/src/pages/api/platform/resourcePrice.ts @@ -179,22 +179,5 @@ function countGpuSource(rawData: PriceCrdType, gpuNodes: GpuNodeType[]) { }); }); - return gpuList.length === 0 - ? [ - { - alias: 'Tesla-P40', - type: 'Tesla-P40', - price: 0.82, - inventory: 11, - vm: 24 - }, - { - alias: '4090', - type: 'NVIDIA-GeForce-RTX-4090', - price: 0.82, - inventory: 1, - vm: 23.98828125 - } - ] - : gpuList; + return gpuList.length === 0 ? undefined : gpuList; } diff --git a/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx b/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx index 47e236644257..a5f1096d083c 100644 --- a/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx +++ b/frontend/providers/applaunchpad/src/pages/app/edit/components/Form.tsx @@ -226,12 +226,12 @@ const Form = ({ icon: 'nvidia', label: ( - {item.type} + {item.alias} | - {t('vm')} : {item.vm}G + {t('vm')} : {Math.round(item.vm)}G | diff --git a/frontend/providers/applaunchpad/src/pages/app/edit/index.tsx b/frontend/providers/applaunchpad/src/pages/app/edit/index.tsx index 9721518c34fd..29f88410f822 100644 --- a/frontend/providers/applaunchpad/src/pages/app/edit/index.tsx +++ b/frontend/providers/applaunchpad/src/pages/app/edit/index.tsx @@ -265,7 +265,6 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) => }, onSettled() { setIsLoading(false); - refetchPrice(); } } );