Skip to content

Commit ffc812c

Browse files
committed
feat: add reset node traffic functionality
1 parent 9a56d64 commit ffc812c

File tree

13 files changed

+111
-18
lines changed

13 files changed

+111
-18
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@monaco-editor/react": "^4.7.0",
6060
"@noble/post-quantum": "^0.5.2",
6161
"@paralleldrive/cuid2": "2.2.2",
62-
"@remnawave/backend-contract": "2.2.31",
62+
"@remnawave/backend-contract": "2.2.32",
6363
"@simplewebauthn/browser": "^13.2.2",
6464
"@stablelib/base64": "^2.0.1",
6565
"@stablelib/x25519": "^2.0.1",
@@ -194,4 +194,4 @@
194194
"inquirer": "9.3.5"
195195
}
196196
}
197-
}
197+
}

public/locales/en/remnawave.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,5 +1779,10 @@
17791779
"failed-to-load-documentation": "Failed to load documentation",
17801780
"loading-documentation": "Loading documentation..."
17811781
}
1782+
},
1783+
"reset-node-traffic": {
1784+
"feature": {
1785+
"reset-traffic": "Reset Traffic"
1786+
}
17821787
}
17831788
}

src/features/ui/dashboard/nodes/delete-node/delete-node.feature.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function DeleteNodeFeature(props: IProps) {
2828
return (
2929
<Menu.Item
3030
color="red.5"
31-
leftSection={isPending ? <Loader color="red" size={14} /> : <TbTrash size={14} />}
31+
leftSection={isPending ? <Loader color="red" size="1rem" /> : <TbTrash size="1rem" />}
3232
onClick={handleDeleteNode}
3333
>
3434
{t('common.delete')}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './reset-node-traffic.feature'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './props.interface'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { GetOneNodeCommand } from '@remnawave/backend-contract'
2+
3+
export interface IProps {
4+
handleClose: () => void
5+
node: GetOneNodeCommand.Response['response']
6+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useTranslation } from 'react-i18next'
2+
import { Loader, Menu } from '@mantine/core'
3+
import { TbRefresh } from 'react-icons/tb'
4+
5+
import { useResetNodeTraffic } from '@shared/api/hooks'
6+
7+
import { IProps } from './interfaces'
8+
9+
export function ResetNodeTrafficFeature(props: IProps) {
10+
const { t } = useTranslation()
11+
const { handleClose, node } = props
12+
13+
const { mutate: resetNodeTraffic, isPending } = useResetNodeTraffic({
14+
route: {
15+
uuid: node.uuid
16+
},
17+
mutationFns: {
18+
onSuccess: async () => {
19+
handleClose()
20+
}
21+
}
22+
})
23+
24+
return (
25+
<Menu.Item
26+
leftSection={
27+
isPending ? <Loader color="teal" size="1rem" /> : <TbRefresh size="1rem" />
28+
}
29+
onClick={() => resetNodeTraffic({})}
30+
>
31+
{t('reset-node-traffic.feature.reset-traffic')}
32+
</Menu.Item>
33+
)
34+
}

src/features/ui/dashboard/nodes/restart-node-button/restart-node-button.feature.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ export function RestartNodeButtonFeature(props: IProps) {
3030
<Menu.Item
3131
color="teal"
3232
disabled={node.isDisabled}
33-
leftSection={isRestartNodePending ? <Loader color="teal" size="1rem" /> : <TbReload />}
33+
leftSection={
34+
isRestartNodePending ? (
35+
<Loader color="teal" size="1rem" />
36+
) : (
37+
<TbReload size="1rem" />
38+
)
39+
}
3440
onClick={() => restartNode({})}
3541
>
3642
{t('restart-node-button.feature.restart')}

src/shared/api/hooks/nodes/nodes.mutation.hooks.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DisableNodeCommand,
55
EnableNodeCommand,
66
ReorderNodeCommand,
7+
ResetNodeTrafficCommand,
78
RestartAllNodesCommand,
89
RestartNodeCommand,
910
UpdateNodeCommand
@@ -195,3 +196,27 @@ export const useRestartNode = createMutationHook({
195196
}
196197
}
197198
})
199+
200+
export const useResetNodeTraffic = createMutationHook({
201+
endpoint: ResetNodeTrafficCommand.TSQ_url,
202+
responseSchema: ResetNodeTrafficCommand.ResponseSchema,
203+
routeParamsSchema: ResetNodeTrafficCommand.RequestSchema,
204+
requestMethod: ResetNodeTrafficCommand.endpointDetails.REQUEST_METHOD,
205+
rMutationParams: {
206+
onSuccess: () => {
207+
notifications.show({
208+
title: 'Success',
209+
message: 'Node traffic reset successfully',
210+
color: 'teal'
211+
})
212+
},
213+
onError: (error) => {
214+
notifications.show({
215+
title: `Reset Node Traffic`,
216+
message:
217+
error instanceof Error ? error.message : `Request failed with unknown error.`,
218+
color: 'red'
219+
})
220+
}
221+
}
222+
})

0 commit comments

Comments
 (0)