reset button interfaces
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
BridgeInfo,
|
||||
BridgeRemoveRequest,
|
||||
FullState,
|
||||
InterfaceResetDefaultsRequest,
|
||||
InterfaceResetDefaultsResponse,
|
||||
InterfaceInfo,
|
||||
RouteInfo,
|
||||
} from '../types/network';
|
||||
@@ -82,6 +84,13 @@ export const fetchFullState = async (): Promise<FullState> => {
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const resetInterfaceDefaults = async (
|
||||
req: InterfaceResetDefaultsRequest,
|
||||
): Promise<InterfaceResetDefaultsResponse> => {
|
||||
const res = await api.post<InterfaceResetDefaultsResponse>('/network/interfaces/reset-defaults', req);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getNetworkStateWebSocketUrl = (): string => {
|
||||
const url = new URL(BASE);
|
||||
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
fetchFullState,
|
||||
getNetworkStateWebSocketUrl,
|
||||
removeBridge,
|
||||
resetInterfaceDefaults,
|
||||
} from '../api/apiClient';
|
||||
import type {
|
||||
EthernetProfile,
|
||||
@@ -34,6 +35,7 @@ import type {
|
||||
BridgeLinkStateWatcherStatus,
|
||||
FullState,
|
||||
InterfaceInfo,
|
||||
InterfaceResetDefaultsResponse,
|
||||
} from '../types/network';
|
||||
|
||||
const { Title, Paragraph } = Typography;
|
||||
@@ -47,6 +49,7 @@ export default function Network() {
|
||||
const [watcherStatuses, setWatcherStatuses] = useState<Record<string, BridgeLinkStateWatcherStatus>>({});
|
||||
const [watcherBridgeName, setWatcherBridgeName] = useState<string>();
|
||||
const [watcherBusyBridge, setWatcherBusyBridge] = useState<string>();
|
||||
const [resetBusyInterface, setResetBusyInterface] = useState<string>();
|
||||
|
||||
const getNetworkPageState = (silent = false) => {
|
||||
fetchFullState()
|
||||
@@ -227,8 +230,24 @@ export default function Network() {
|
||||
<span>—</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Actions',
|
||||
key: 'actions',
|
||||
width: 160,
|
||||
render: (_: unknown, record: InterfaceInfo) => (
|
||||
<Popconfirm
|
||||
title={`Reset ${record.name} to defaults?`}
|
||||
description="Sets MTU to 1500, enables autoneg, and brings the interface up."
|
||||
onConfirm={() => handleResetInterface(record.name)}
|
||||
okText="Reset"
|
||||
cancelText="Cancel"
|
||||
>
|
||||
<Button loading={resetBusyInterface === record.name}>Reset defaults</Button>
|
||||
</Popconfirm>
|
||||
),
|
||||
},
|
||||
],
|
||||
[],
|
||||
[resetBusyInterface],
|
||||
);
|
||||
|
||||
const bridgeColumns: ColumnsType<BridgeInfo> = useMemo(
|
||||
@@ -392,6 +411,31 @@ export default function Network() {
|
||||
});
|
||||
}
|
||||
|
||||
function handleResetInterface(ifname: string) {
|
||||
setResetBusyInterface(ifname);
|
||||
resetInterfaceDefaults({ interfaces: [ifname] })
|
||||
.then((response: InterfaceResetDefaultsResponse) => {
|
||||
const result = response.results[0];
|
||||
notification.success({
|
||||
message: 'Success',
|
||||
description: result?.message
|
||||
? `${ifname}: ${result.message}`
|
||||
: `${ifname} reset to defaults`,
|
||||
});
|
||||
getNetworkPageState(true);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
notification.error({
|
||||
message: 'Error',
|
||||
description: (error as Error).message ?? `Failed to reset ${ifname}`,
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
setResetBusyInterface(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ padding: 16 }}>
|
||||
<Row justify="space-between" align="middle" style={{ marginBottom: 12 }}>
|
||||
|
||||
@@ -63,6 +63,21 @@ export interface BridgeLinkStateEnableRequest {
|
||||
recovery_holdoff_seconds: number;
|
||||
}
|
||||
|
||||
export interface InterfaceResetDefaultsRequest {
|
||||
interfaces: string[];
|
||||
}
|
||||
|
||||
export interface InterfaceResetDefaultsResult {
|
||||
interface: string;
|
||||
mtu?: number | null;
|
||||
ethernet_profile?: EthernetProfile | null;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface InterfaceResetDefaultsResponse {
|
||||
results: InterfaceResetDefaultsResult[];
|
||||
}
|
||||
|
||||
export interface BridgeMemberLinkStateInfo {
|
||||
ifname: string;
|
||||
admin_up?: boolean | null;
|
||||
|
||||
Reference in New Issue
Block a user