From bb19f134479c5c01015a6f9e225235e7c5277cd6 Mon Sep 17 00:00:00 2001 From: heheer <71265218+newfish-cmyk@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:44:44 +0800 Subject: [PATCH] fix(web): fix ui & date range (#1382) * fix(web):fix ui & date range * fix(web): fix date range --- web/src/components/DateRangePicker/index.tsx | 6 +- .../pages/app/setting/AppEnvList/index.tsx | 2 +- .../setting/AppInfoList/InfoDetail/index.tsx | 40 ++++------- .../pages/app/setting/AppInfoList/index.tsx | 67 +++++++++++-------- web/src/pages/app/setting/Usage/index.tsx | 44 +++++++----- web/src/pages/app/setting/index.tsx | 2 +- web/src/pages/home/mods/StatusBadge/index.tsx | 6 +- 7 files changed, 90 insertions(+), 77 deletions(-) diff --git a/web/src/components/DateRangePicker/index.tsx b/web/src/components/DateRangePicker/index.tsx index 8ec30d7aee..a6dc4c6100 100644 --- a/web/src/components/DateRangePicker/index.tsx +++ b/web/src/components/DateRangePicker/index.tsx @@ -76,7 +76,7 @@ export default function DateRangePicker(props: { return (
@@ -84,14 +84,14 @@ export default function DateRangePicker(props: { variant={"unstyled"} value={fromValue} onChange={handleFromChange} - className="!w-24 !pl-4" + className="flex-1 text-center" /> - diff --git a/web/src/pages/app/setting/AppEnvList/index.tsx b/web/src/pages/app/setting/AppEnvList/index.tsx index 67a7cee889..4d72432bac 100644 --- a/web/src/pages/app/setting/AppEnvList/index.tsx +++ b/web/src/pages/app/setting/AppEnvList/index.tsx @@ -27,7 +27,7 @@ const AppEnvList = (props: { onClose?: () => {} }) => { const envValue = useRef(convertToEnv(environmentQuery?.data?.data)); return ( <> -
+
+
- - + + +
{title} - - - - {leftData.map((item) => ( -
- {item.key} : - {item.value} -
- ))} - - - {rightData.map((item) => ( -
- {item.key} : - {item.value} -
- ))} - -
+ {data.map((item) => ( +
+ {item.key} + {item.value} +
+ ))} +
); diff --git a/web/src/pages/app/setting/AppInfoList/index.tsx b/web/src/pages/app/setting/AppInfoList/index.tsx index fb7335c182..4000938e47 100644 --- a/web/src/pages/app/setting/AppInfoList/index.tsx +++ b/web/src/pages/app/setting/AppInfoList/index.tsx @@ -2,10 +2,11 @@ import { useTranslation } from "react-i18next"; import { MdPlayCircleOutline, MdRestartAlt } from "react-icons/md"; import { RiDeleteBin6Line, RiShutDownLine } from "react-icons/ri"; import { useNavigate } from "react-router-dom"; -import { Box, Button, HStack, useColorMode } from "@chakra-ui/react"; +import { Box, Button, HStack, useColorMode, VStack } from "@chakra-ui/react"; import clsx from "clsx"; import { APP_PHASE_STATUS, APP_STATUS, COLOR_MODE, Routes } from "@/constants/index"; +import { formatDate } from "@/utils/format"; import InfoDetail from "./InfoDetail"; @@ -28,22 +29,20 @@ const AppEnvList = () => { return ( <> -
-
- - - {currentApp?.name} - - - +
+ + + + {currentApp?.name} + { currentApp?.phase !== APP_PHASE_STATUS.Stopped && currentApp?.phase !== APP_PHASE_STATUS.Started } - variant={"text"} + color={"grayModern.600"} + bg={"none"} + _hover={{ color: "primary.600" }} onClick={() => { updateCurrentApp( currentApp!, @@ -85,7 +86,9 @@ const AppEnvList = () => { className="mr-2" fontWeight={"semibold"} size={"sm"} - variant={"text"} + color={"grayModern.600"} + bg={"none"} + _hover={{ color: "primary.600" }} onClick={(event: any) => { event?.preventDefault(); updateCurrentApp(currentApp!, APP_STATUS.Stopped); @@ -102,25 +105,34 @@ const AppEnvList = () => { navigate(Routes.dashboard); }} > - -
-
+ +
{ key: t("Spec.RAM"), value: `${currentApp?.bundle?.resource.limitMemory} ${t("Unit.MB")}`, }, - ]} - rightData={[ { key: t("Spec.Database"), value: `${currentApp?.bundle?.resource.databaseCapacity! / 1024} ${t("Unit.GB")}`, @@ -140,6 +150,7 @@ const AppEnvList = () => { value: `${currentApp?.bundle?.resource.storageCapacity! / 1024} ${t("Unit.GB")}`, }, ]} + className={darkMode ? "w-60" : "w-60 bg-[#F8FAFB]"} />
diff --git a/web/src/pages/app/setting/Usage/index.tsx b/web/src/pages/app/setting/Usage/index.tsx index 817ffb1c42..5f31ac6553 100644 --- a/web/src/pages/app/setting/Usage/index.tsx +++ b/web/src/pages/app/setting/Usage/index.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useMemo } from "react"; import { useTranslation } from "react-i18next"; import { Avatar, Button, Center, Spinner, useColorMode } from "@chakra-ui/react"; import { useQuery } from "@tanstack/react-query"; @@ -29,11 +29,17 @@ const DATA_DURATION = 6 * 24 * 60 * 60 * 1000; export default function Usage() { const { t } = useTranslation(); const darkMode = useColorMode().colorMode === "dark"; - const [startTime, setStartTime] = React.useState( - new Date(new Date().getTime() - DATA_DURATION), - ); - - const [endTime, setEndTime] = React.useState(new Date()); + const [endTime, setEndTime] = React.useState(() => { + const today = new Date(); + today.setHours(23, 59, 59, 999); + return today; + }); + const [startTime, setStartTime] = React.useState(() => { + const today = new Date(); + today.setTime(today.getTime() - DATA_DURATION); + today.setHours(0, 0, 0, 0); + return today; + }); const { userInfo } = useGlobalStore((state) => state); const { data: accountRes } = useAccountQuery(); @@ -42,8 +48,8 @@ export default function Usage() { ["billing", startTime, endTime], async () => { return BillingControllerGetExpense({ - startTime: startTime?.toISOString(), - endTime: endTime?.toISOString(), + startTime: startTime?.getTime(), + endTime: endTime?.getTime(), }); }, ); @@ -52,8 +58,8 @@ export default function Usage() { ["chargeOrderAmount", startTime, endTime], async () => { return AccountControllerGetChargeOrderAmount({ - startTime: startTime?.toISOString(), - endTime: endTime?.toISOString(), + startTime: startTime?.getTime(), + endTime: endTime?.getTime(), }); }, ); @@ -62,16 +68,22 @@ export default function Usage() { ["billingByDay", startTime, endTime], async () => { return BillingControllerGetExpenseByDay({ - startTime: startTime?.toISOString(), - endTime: endTime?.toISOString(), + startTime: startTime?.getTime(), + endTime: endTime?.getTime(), }); }, ); - const chartData = ((billingAmountByDayRes?.data as Array) || []).map((item) => ({ - totalAmount: item.totalAmount, - date: formatDate(item.day).slice(5, 10), - })); + const chartData = useMemo( + () => + ((billingAmountByDayRes?.data as Array) || []) + .sort((a, b) => new Date(a.day).getTime() - new Date(b.day).getTime()) + .map((item) => ({ + totalAmount: item.totalAmount, + date: formatDate(item.day).slice(5, 10), + })), + [billingAmountByDayRes?.data], + ); return (
diff --git a/web/src/pages/app/setting/index.tsx b/web/src/pages/app/setting/index.tsx index 060098ca67..c22b4cbc08 100644 --- a/web/src/pages/app/setting/index.tsx +++ b/web/src/pages/app/setting/index.tsx @@ -61,7 +61,7 @@ const SettingModal = (props: { }, })} - + diff --git a/web/src/pages/home/mods/StatusBadge/index.tsx b/web/src/pages/home/mods/StatusBadge/index.tsx index f74b70f876..1716871147 100644 --- a/web/src/pages/home/mods/StatusBadge/index.tsx +++ b/web/src/pages/home/mods/StatusBadge/index.tsx @@ -24,7 +24,7 @@ export default function StatusBadge(props: { }) { const { statusConditions = APP_PHASE_STATUS.Started, state, className } = props; return ( -
+
+
+ +
)}
);