feat: add monitor edit feature
This commit is contained in:
parent
0859fa9884
commit
d889c930ed
@ -1,16 +1,12 @@
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { defaultErrorHandler, defaultSuccessHandler, trpc } from '../trpc';
|
||||||
import {
|
|
||||||
defaultErrorHandler,
|
|
||||||
defaultSuccessHandler,
|
|
||||||
getQueryKey,
|
|
||||||
trpc,
|
|
||||||
} from '../trpc';
|
|
||||||
|
|
||||||
export function useMonitorUpsert() {
|
export function useMonitorUpsert() {
|
||||||
const queryClient = useQueryClient();
|
const context = trpc.useContext();
|
||||||
const mutation = trpc.monitor.upsert.useMutation({
|
const mutation = trpc.monitor.upsert.useMutation({
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.resetQueries(getQueryKey(trpc.monitor.all));
|
context.monitor.all.reset({
|
||||||
|
workspaceId: data.workspaceId,
|
||||||
|
});
|
||||||
|
|
||||||
defaultSuccessHandler();
|
defaultSuccessHandler();
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Card, Select, Space } from 'antd';
|
import { Button, Card, Select, Space, Spin } from 'antd';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { trpc } from '../../api/trpc';
|
import { trpc } from '../../api/trpc';
|
||||||
@ -13,6 +13,7 @@ import { useSocketSubscribeList } from '../../api/socketio';
|
|||||||
import { last, uniqBy } from 'lodash-es';
|
import { last, uniqBy } from 'lodash-es';
|
||||||
import { ErrorTip } from '../ErrorTip';
|
import { ErrorTip } from '../ErrorTip';
|
||||||
import { ColorTag } from '../ColorTag';
|
import { ColorTag } from '../ColorTag';
|
||||||
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
interface MonitorInfoProps {
|
interface MonitorInfoProps {
|
||||||
monitorId: string;
|
monitorId: string;
|
||||||
@ -21,13 +22,18 @@ export const MonitorInfo: React.FC<MonitorInfoProps> = React.memo((props) => {
|
|||||||
const workspaceId = useCurrentWorkspaceId();
|
const workspaceId = useCurrentWorkspaceId();
|
||||||
const { monitorId } = props;
|
const { monitorId } = props;
|
||||||
const [currectResponse, setCurrentResponse] = useState(0);
|
const [currectResponse, setCurrentResponse] = useState(0);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { data: monitorInfo, isLoading } = trpc.monitor.get.useQuery({
|
const {
|
||||||
|
data: monitorInfo,
|
||||||
|
isInitialLoading,
|
||||||
|
isLoading,
|
||||||
|
} = trpc.monitor.get.useQuery({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
id: monitorId,
|
id: monitorId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading) {
|
if (isInitialLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +42,7 @@ export const MonitorInfo: React.FC<MonitorInfoProps> = React.memo((props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Spin spinning={isLoading}>
|
||||||
<Space className="w-full" direction="vertical">
|
<Space className="w-full" direction="vertical">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<Space direction="vertical">
|
<Space direction="vertical">
|
||||||
@ -56,6 +62,17 @@ export const MonitorInfo: React.FC<MonitorInfoProps> = React.memo((props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
navigate(`/monitor/${monitorInfo.id}/edit`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<MonitorHealthBar
|
<MonitorHealthBar
|
||||||
monitorId={monitorId}
|
monitorId={monitorId}
|
||||||
@ -79,7 +96,7 @@ export const MonitorInfo: React.FC<MonitorInfoProps> = React.memo((props) => {
|
|||||||
<MonitorDataChart monitorId={monitorId} />
|
<MonitorDataChart monitorId={monitorId} />
|
||||||
</Card>
|
</Card>
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</Spin>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
MonitorInfo.displayName = 'MonitorInfo';
|
MonitorInfo.displayName = 'MonitorInfo';
|
||||||
|
@ -33,11 +33,11 @@ export const MonitorEdit: React.FC = React.memo(() => {
|
|||||||
<MonitorInfoEditor
|
<MonitorInfoEditor
|
||||||
initialValues={monitor as MonitorInfoEditorValues}
|
initialValues={monitor as MonitorInfoEditorValues}
|
||||||
onSave={async (value) => {
|
onSave={async (value) => {
|
||||||
await mutation.mutateAsync({
|
const monitor = await mutation.mutateAsync({
|
||||||
...value,
|
...value,
|
||||||
workspaceId: currentWorkspaceId,
|
workspaceId: currentWorkspaceId,
|
||||||
});
|
});
|
||||||
navigate('/monitor', { replace: true });
|
navigate(`/monitor/${monitor.id}`, { replace: true });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user