From 0d2123a5c8cad7758ae026bc22bfb187509ea327 Mon Sep 17 00:00:00 2001 From: "Paul B. Beskow" Date: Tue, 19 Nov 2024 13:10:48 +0100 Subject: [PATCH] feat(frontend): add section on global urls --- .../components/workstation/diffViewer.tsx | 33 ++++++++--------- frontend/components/workstation/form.tsx | 14 ++++++-- .../workstation/globalAllowURLListInput.tsx | 35 +++++++++++++++++++ .../components/workstation/urlListInput.tsx | 5 ++- frontend/lib/rest/generatedDto/index.ts | 17 +++++++-- pkg/service/core/service_workstations.go | 8 +++++ 6 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 frontend/components/workstation/globalAllowURLListInput.tsx diff --git a/frontend/components/workstation/diffViewer.tsx b/frontend/components/workstation/diffViewer.tsx index fa722897..bb2b1e37 100644 --- a/frontend/components/workstation/diffViewer.tsx +++ b/frontend/components/workstation/diffViewer.tsx @@ -1,6 +1,6 @@ import { Diff, - WorkstationDiffContainerImage, + WorkstationDiffContainerImage, WorkstationDiffDisableGlobalURLAllowList, WorkstationDiffMachineType, WorkstationDiffOnPremAllowList, WorkstationDiffURLAllowList } from "../../lib/rest/generatedDto"; @@ -8,9 +8,10 @@ import {Heading} from "@navikt/ds-react"; import {MinusCircleIcon, PlusCircleIcon} from "@navikt/aksel-icons"; export const WorkstationDiffDescriptions: { [key: string]: string } = { - [WorkstationDiffContainerImage]: "Kjøremiljø", - [WorkstationDiffMachineType]: "Maskin type", - [WorkstationDiffURLAllowList]: "URL Filter", + [WorkstationDiffDisableGlobalURLAllowList]: "Skru av globale åpninger", + [WorkstationDiffContainerImage]: "Utviklingsmiljø", + [WorkstationDiffMachineType]: "Maskintype", + [WorkstationDiffURLAllowList]: "Tillate URL-er", [WorkstationDiffOnPremAllowList]: "On-prem kilder", }; @@ -29,20 +30,16 @@ const DiffViewerComponent: React.FC = ({diff}) => { return (
{WorkstationDiffDescriptions[key]} - {value?.value ? ( -

{value.value}

- ) : ( -
- {(value?.added?.length ?? 0) > 0 && ( -

{value?.added.join(', ')}

- )} - {(value?.removed?.length ?? 0) > 0 && ( -

{value?.removed.join(', ')}

- )} -
- )} +
+ {(value?.added?.length ?? 0) > 0 && ( +

{value?.added.join(', ')}

+ )} + {(value?.removed?.length ?? 0) > 0 && ( +

{value?.removed.join(', ')}

+ )} +
); })} diff --git a/frontend/components/workstation/form.tsx b/frontend/components/workstation/form.tsx index e44bbd42..c224e3c3 100644 --- a/frontend/components/workstation/form.tsx +++ b/frontend/components/workstation/form.tsx @@ -16,6 +16,7 @@ import MachineTypeSelector from "./machineTypeSelector"; import ContainerImageSelector from "./containerImageSelector"; import FirewallTagSelector from "./firewallTagSelector"; import UrlListInput from "./urlListInput"; +import GlobalAllowUrlListInput from "./globalAllowURLListInput"; interface WorkstationInputFormProps { workstation?: WorkstationOutput; @@ -41,10 +42,15 @@ const WorkstationInputForm = (props: WorkstationInputFormProps) => { const existingFirewallRules = workstation ? workstation.config ? workstation.config.firewallRulesAllowList : [] : [] const [selectedFirewallHosts, setSelectedFirewallHosts] = useState(new Set(existingFirewallRules)) const [urlList, setUrlList] = useState(workstation ? workstation.urlAllowList : []) + const [disableGlobalURLAllowList, setDisableGlobalURLAllowList] = useState(false) const [machineType, setMachineType] = useState(workstationOptions?.machineTypes?.[0]?.machineType ?? ""); const [containerImage, setContainerImage] = useState(workstationOptions?.containerImages?.[0]?.image ?? ""); const runningJobs = workstationJobs?.jobs?.filter((job): job is WorkstationJob => job !== undefined && job.state === WorkstationJobStateRunning); + const handleDisableGlobalURLAllowList = (value: any) => { + setDisableGlobalURLAllowList(value === "true") + } + const handleUrlListUpdate = (event: any) => { setUrlList(event.target.value.split("\n")) } @@ -66,7 +72,8 @@ const WorkstationInputForm = (props: WorkstationInputFormProps) => { machineType: machineType, containerImage: containerImage, onPremAllowList: Array.from(selectedFirewallHosts), - urlAllowList: urlList + urlAllowList: urlList, + disableGlobalURLAllowList: disableGlobalURLAllowList }; try { @@ -100,7 +107,10 @@ const WorkstationInputForm = (props: WorkstationInputFormProps) => { onToggleSelected={handleFirewallTagChange} /> +
{(workstation === null || workstation === undefined) ? diff --git a/frontend/components/workstation/globalAllowURLListInput.tsx b/frontend/components/workstation/globalAllowURLListInput.tsx new file mode 100644 index 00000000..b4595c5f --- /dev/null +++ b/frontend/components/workstation/globalAllowURLListInput.tsx @@ -0,0 +1,35 @@ +import {Textarea, RadioGroup, Radio, Stack} from "@navikt/ds-react"; + +interface GlobalAllowURLListInputProps { + urlList: string[]; + onDisableGlobalURLAllowList: (event: any) => void; +} + +const GlobalAllowUrlListInput: React.FC = ({ urlList, onDisableGlobalURLAllowList }) => { + return ( +
+ + + Ja (anbefalt) + Nei + + +