Skip to content

Commit 3d72820

Browse files
feat(web): optimize the state display of application list (#1403)
* feat: add color for the delete IconText * fix: fix the error color in light and dark mode * feat: optimize the state of app * chore: update * fix(web): fix app state display --------- Co-authored-by: heheer <[email protected]>
1 parent 87ba558 commit 3d72820

File tree

5 files changed

+61
-42
lines changed

5 files changed

+61
-42
lines changed

web/src/constants/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ export enum SUPPORTED_METHODS {
3535
export enum APP_PHASE_STATUS {
3636
Creating = "Creating",
3737
Created = "Created",
38-
Started = "Started",
3938
Starting = "Starting",
40-
Restarting = "Restarting",
41-
Deleting = "Deleting",
42-
Deleted = "Deleted",
39+
Started = "Started",
4340
Stopping = "Stopping",
4441
Stopped = "Stopped",
42+
Deleting = "Deleting",
43+
Deleted = "Deleted",
4544
}
4645

4746
export enum BUCKET_POLICY_TYPE {

web/src/pages/globalStore.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { create } from "zustand";
33
import { devtools } from "zustand/middleware";
44
import { immer } from "zustand/middleware/immer";
55

6-
import { APP_STATUS, CHAKRA_UI_COLOR_MODE_KEY } from "@/constants";
6+
import { APP_PHASE_STATUS, APP_STATUS, CHAKRA_UI_COLOR_MODE_KEY } from "@/constants";
77
import { formatPort } from "@/utils/format";
88

99
import { TApplicationDetail, TRegion, TRuntime } from "@/apis/typing";
@@ -93,7 +93,11 @@ const useGlobalStore = create<State>()(
9393
set((state) => {
9494
if (state.currentApp) {
9595
state.currentApp.phase =
96-
newState === APP_STATUS.Restarting ? "Restarting" : "Stopping";
96+
newState === APP_STATUS.Running
97+
? APP_PHASE_STATUS.Starting
98+
: newState === APP_STATUS.Restarting
99+
? "Restarting"
100+
: APP_PHASE_STATUS.Stopping;
97101
}
98102
});
99103
}

web/src/pages/home/index.tsx

+2-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const APP_LIST_QUERY_KEY = ["appListQuery"];
1212

1313
function HomePage() {
1414
const [shouldRefetch, setShouldRefetch] = useState(true);
15+
1516
useEffect(() => {
1617
setTimeout(() => {
1718
setShouldRefetch(true);
@@ -39,22 +40,11 @@ function HomePage() {
3940
},
4041
);
4142

42-
if (appListQuery.isLoading) {
43-
return null;
44-
}
45-
4643
return (appListQuery.data?.data || []).length === 0 ? (
4744
<Empty />
4845
) : (
4946
<div className="mx-auto mt-10 flex w-11/12 flex-col lg:w-8/12">
50-
<List
51-
appListQuery={appListQuery}
52-
setShouldRefetch={() => {
53-
setTimeout(() => {
54-
setShouldRefetch(true);
55-
}, 1500);
56-
}}
57-
/>
47+
<List appListQuery={appListQuery} />
5848
</div>
5949
);
6050
}

web/src/pages/home/mods/List/index.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
MenuList,
1717
useColorModeValue,
1818
} from "@chakra-ui/react";
19-
import { useMutation } from "@tanstack/react-query";
19+
import { useMutation, useQueryClient } from "@tanstack/react-query";
2020

2121
import CopyText from "@/components/CopyText";
2222
import FileTypeIcon from "@/components/FileTypeIcon";
@@ -25,6 +25,7 @@ import { APP_PHASE_STATUS, APP_STATUS, Pages } from "@/constants";
2525
import { formatDate } from "@/utils/format";
2626
import getRegionById from "@/utils/getRegionById";
2727

28+
import { APP_LIST_QUERY_KEY } from "../../index";
2829
import CreateAppModal from "../CreateAppModal";
2930
import DeleteAppModal from "../DeleteAppModal";
3031
import StatusBadge from "../StatusBadge";
@@ -35,15 +36,16 @@ import { TApplicationItem } from "@/apis/typing";
3536
import { ApplicationControllerUpdateState } from "@/apis/v1/applications";
3637
import useGlobalStore from "@/pages/globalStore";
3738

38-
function List(props: { appListQuery: any; setShouldRefetch: any }) {
39+
function List(props: { appListQuery: any }) {
3940
const navigate = useNavigate();
4041
const { t } = useTranslation();
4142

4243
const { setCurrentApp, regions } = useGlobalStore();
4344

4445
const [searchKey, setSearchKey] = useState("");
4546

46-
const { appListQuery, setShouldRefetch } = props;
47+
const queryClient = useQueryClient();
48+
const { appListQuery } = props;
4749
const bg = useColorModeValue("lafWhite.200", "lafDark.200");
4850

4951
const updateAppStateMutation = useMutation((params: any) =>
@@ -173,7 +175,7 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
173175
: APP_STATUS.Restarting,
174176
});
175177
if (!res.error) {
176-
setShouldRefetch(true);
178+
queryClient.invalidateQueries(APP_LIST_QUERY_KEY);
177179
}
178180
}}
179181
>
@@ -190,11 +192,13 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
190192
display={"block"}
191193
onClick={async (event: any) => {
192194
event?.preventDefault();
193-
await updateAppStateMutation.mutateAsync({
195+
const res = await updateAppStateMutation.mutateAsync({
194196
appid: item.appid,
195-
state: APP_PHASE_STATUS.Stopped,
197+
state: APP_STATUS.Stopped,
196198
});
197-
setShouldRefetch(true);
199+
if (!res.error) {
200+
queryClient.invalidateQueries(APP_LIST_QUERY_KEY);
201+
}
198202
}}
199203
>
200204
<a className="text-primary block" href="/stop">
@@ -203,7 +207,10 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
203207
</MenuItem>
204208
)}
205209

206-
<DeleteAppModal item={item} onSuccess={() => setShouldRefetch(true)}>
210+
<DeleteAppModal
211+
item={item}
212+
onSuccess={() => queryClient.invalidateQueries(APP_LIST_QUERY_KEY)}
213+
>
207214
<MenuItem minH="40px" display={"block"}>
208215
<a className="block text-error-500" href="/delete">
209216
{t("DeleteApp")}

web/src/pages/home/mods/StatusBadge/index.tsx

+35-16
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,43 @@ export default function StatusBadge(props: {
2424
}) {
2525
const { statusConditions = APP_PHASE_STATUS.Started, state, className } = props;
2626
return (
27-
<div className={clsx("flex", className)}>
28-
<div
29-
className={clsx(
30-
styles.badgeStyle,
31-
styles[colorScheme[statusConditions]],
32-
"px-2 py-1 lg:px-3",
33-
)}
34-
>
35-
<span>{statusConditions}</span>
36-
</div>
37-
{statusConditions === APP_PHASE_STATUS.Started ||
38-
(state !== APP_PHASE_STATUS.Restarting && statusConditions === APP_PHASE_STATUS.Stopped) ? (
39-
""
27+
<>
28+
{state === "Restarting" ? (
29+
<div className={clsx("flex", className)}>
30+
<div
31+
className={clsx(
32+
styles.badgeStyle,
33+
styles[colorScheme["Restarting"]],
34+
"px-2 py-1 lg:px-3",
35+
)}
36+
>
37+
<span>{"Restarting"}</span>
38+
</div>
39+
<div className="flex items-center pr-2">
40+
<Spinner size="xs" />
41+
</div>
42+
</div>
4043
) : (
41-
<div className="flex items-center pr-2">
42-
<Spinner size="xs" />
44+
<div className={clsx("flex", className)}>
45+
<div
46+
className={clsx(
47+
styles.badgeStyle,
48+
styles[colorScheme[statusConditions]],
49+
"px-2 py-1 lg:px-3",
50+
)}
51+
>
52+
<span>{statusConditions}</span>
53+
</div>
54+
{statusConditions === APP_PHASE_STATUS.Started ||
55+
statusConditions === APP_PHASE_STATUS.Stopped ? (
56+
""
57+
) : (
58+
<div className="flex items-center pr-2">
59+
<Spinner size="xs" />
60+
</div>
61+
)}
4362
</div>
4463
)}
45-
</div>
64+
</>
4665
);
4766
}

0 commit comments

Comments
 (0)