Enhance node update functionality to include base address
- Added `BaseAddress` property to `UpdateNodeCommand` and `UpdateNodeBody` for improved node management. - Implemented validation for the base address in `UpdateNodeCommandHandler`, ensuring it is a valid absolute URI. - Updated `Node` class to support address updates, including logic to invalidate cached clients on address changes. - Enhanced frontend components to handle base address input in the node editing dialog and API requests. - Updated validation rules to enforce base address requirements in `UpdateNodeCommandValidator`.
This commit is contained in:
@@ -14,13 +14,15 @@ export function EditNodeDialog({ node, open, onOpenChange }: { node: NodeDto; op
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
const [name, setName] = useState(node.name)
|
||||
const [baseAddress, setBaseAddress] = useState(node.baseAddress)
|
||||
const [location, setLocation] = useState(node.location ?? '')
|
||||
const [isEnabled, setIsEnabled] = useState(node.isEnabled)
|
||||
const [username, setUsername] = useState('')
|
||||
const [username, setUsername] = useState(node.username)
|
||||
const [password, setPassword] = useState('')
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: () => updateNode(node.id, name.trim(), location.trim() || undefined, isEnabled, username.trim() || undefined, password || undefined),
|
||||
mutationFn: () =>
|
||||
updateNode(node.id, name.trim(), baseAddress.trim(), location.trim() || undefined, isEnabled, username.trim() || undefined, password || undefined),
|
||||
onSuccess: async () => {
|
||||
toast.success(t('admin.nodes.updated'))
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-nodes'] })
|
||||
@@ -46,6 +48,16 @@ export function EditNodeDialog({ node, open, onOpenChange }: { node: NodeDto; op
|
||||
<Label htmlFor="editName">{t('admin.nodes.name')}</Label>
|
||||
<Input id="editName" value={name} onChange={(e) => setName(e.target.value)} required />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="editBaseAddress">{t('admin.nodes.baseAddress')}</Label>
|
||||
<Input
|
||||
id="editBaseAddress"
|
||||
placeholder="https://panel.example.com:2053"
|
||||
value={baseAddress}
|
||||
onChange={(e) => setBaseAddress(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="editLocation">{t('admin.nodes.location')}</Label>
|
||||
<Input id="editLocation" value={location} onChange={(e) => setLocation(e.target.value)} />
|
||||
@@ -62,7 +74,7 @@ export function EditNodeDialog({ node, open, onOpenChange }: { node: NodeDto; op
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="editPassword">
|
||||
{t('admin.nodes.password')} ({t('admin.nodes.optional')})
|
||||
{t('admin.nodes.password')} ({t('admin.nodes.passwordKeepUnchanged')})
|
||||
</Label>
|
||||
<Input
|
||||
id="editPassword"
|
||||
@@ -72,11 +84,12 @@ export function EditNodeDialog({ node, open, onOpenChange }: { node: NodeDto; op
|
||||
data-1p-ignore
|
||||
data-bwignore
|
||||
data-form-type="other"
|
||||
placeholder="••••••••"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={!name.trim() || mutation.isPending}>
|
||||
<Button type="submit" disabled={!name.trim() || !baseAddress.trim() || mutation.isPending}>
|
||||
{t('admin.roles.save')}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
@@ -12,6 +12,7 @@ export function registerNode(name: string, baseAddress: string, username: string
|
||||
export function updateNode(
|
||||
id: string,
|
||||
name: string,
|
||||
baseAddress: string,
|
||||
location: string | undefined,
|
||||
isEnabled: boolean,
|
||||
username: string | undefined,
|
||||
@@ -19,7 +20,7 @@ export function updateNode(
|
||||
) {
|
||||
return apiRequest<NodeDto>(`/admin/nodes/${id}`, {
|
||||
method: 'PUT',
|
||||
body: { name, location: location ?? null, isEnabled, username: username ?? null, password: password ?? null },
|
||||
body: { name, baseAddress, location: location ?? null, isEnabled, username: username ?? null, password: password ?? null },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3482,6 +3482,7 @@ export interface components {
|
||||
};
|
||||
UpdateNodeBody: {
|
||||
name: string;
|
||||
baseAddress: string;
|
||||
location: null | string;
|
||||
isEnabled: boolean;
|
||||
username: null | string;
|
||||
|
||||
@@ -443,6 +443,7 @@ const resources = {
|
||||
allowedRoles: 'Доступно ролям',
|
||||
isPublishedLabel: 'Опубликовать инбаунд',
|
||||
optional: 'необязательно',
|
||||
passwordKeepUnchanged: 'оставьте пустым, чтобы не менять',
|
||||
},
|
||||
apps: {
|
||||
create: 'Добавить приложение',
|
||||
@@ -1011,6 +1012,7 @@ const resources = {
|
||||
allowedRoles: 'Allowed for roles',
|
||||
isPublishedLabel: 'Publish inbound',
|
||||
optional: 'optional',
|
||||
passwordKeepUnchanged: 'leave blank to keep unchanged',
|
||||
},
|
||||
apps: {
|
||||
create: 'Add app',
|
||||
|
||||
Reference in New Issue
Block a user