Skip to content

Commit

Permalink
Merge pull request #149 from FINTLabs/FKS-635-frontend-update-en-ressurs
Browse files Browse the repository at this point in the history
Added edit resource
  • Loading branch information
Linda-fintlabs authored Oct 15, 2024
2 parents 4f92bca + 1cdad77 commit 104c199
Show file tree
Hide file tree
Showing 16 changed files with 732 additions and 134 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ jobs:
- path: /beta/fintlabs-no
environment: beta
org: fintlabs-no
- path: /bfk-no
environment: api
org: bfk-no
- path: /afk-no
environment: api
org: afk-no
- path: /ofk-no
environment: api
org: ofk-no
# - path: /bfk-no
# environment: api
# org: bfk-no
# - path: /afk-no
# environment: api
# org: afk-no
# - path: /ofk-no
# environment: api
# org: ofk-no
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down Expand Up @@ -142,12 +142,12 @@ jobs:
include:
- org: fintlabs-no
cluster: aks-beta-fint-2021-11-23
- org: bfk-no
cluster: aks-api-fint-2022-02-08
- org: afk-no
cluster: aks-api-fint-2022-02-08
- org: ofk-no
cluster: aks-api-fint-2022-02-08
# - org: bfk-no
# cluster: aks-api-fint-2022-02-08
# - org: afk-no
# cluster: aks-api-fint-2022-02-08
# - org: ofk-no
# cluster: aks-api-fint-2022-02-08

steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion app/components/common/ResponseAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ResponseAlert = (
) => {
if (responseCode === undefined) return null

if (responseCode === "201") {
if (responseCode === "201" || responseCode === "202") {
return (
<AlertWithCloseButton variant="success">
{successText}
Expand Down
55 changes: 28 additions & 27 deletions app/components/resource-admin/ResourceInfoBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,7 @@ export const ResourceInfoBlock: any = (props: { resource: IResource }) => {
<Heading size="small" level="3">KildesystemID:</Heading>
<BodyShort textColor="subtle">{props.resource.resourceId}</BodyShort>
</li>
<li>
<Heading size="small" level="3">Ressurstype:</Heading>
<BodyShort textColor="subtle">{props.resource.resourceType}</BodyShort>
</li>
<li>
<Heading size="small" level="3">Applikasjonstilgangstype:</Heading>
<BodyShort textColor="subtle">{props.resource.applicationAccessType}</BodyShort>
</li>
<li>
<Heading size="small" level="3">Tilgangsrolle:</Heading>
<BodyShort textColor="subtle">{props.resource.applicationAccessRole}</BodyShort>
</li>
<li>
<Heading size="small" level="3">Tilgangstype:</Heading>
<BodyShort textColor="subtle">{props.resource.accessType}</BodyShort>
</li>
<li>
<Heading size="small" level="3">Plattform:</Heading>
<BodyShort textColor="subtle">{
props.resource.platform.map((item, index) => (
<span key={index}>
{item}
{index < props.resource.platform.length - 1 ? ', ' : ''}
</span>
))}
</BodyShort>
</li>

<li>
<Heading size="small" level="3">Ressurseier:</Heading>
<BodyShort textColor="subtle">{props.resource.resourceOwnerOrgUnitName}</BodyShort>
Expand Down Expand Up @@ -86,6 +60,33 @@ export const ResourceInfoBlock: any = (props: { resource: IResource }) => {
))}
</BodyShort>
</li>
<li>
<Heading size="small" level="3">Ressurstype:</Heading>
<BodyShort textColor="subtle">{props.resource.resourceType}</BodyShort>
</li>
{/*<li>
<Heading size="small" level="3">Applikasjonstilgangstype:</Heading>
<BodyShort textColor="subtle">{props.resource.applicationAccessType}</BodyShort>
</li>*/}
{/*<li>
<Heading size="small" level="3">Tilgangsrolle:</Heading>
<BodyShort textColor="subtle">{props.resource.applicationAccessRole}</BodyShort>
</li>*/}
{/*<li>
<Heading size="small" level="3">Tilgangstype:</Heading>
<BodyShort textColor="subtle">{props.resource.accessType}</BodyShort>
</li>*/}
{/*<li>
<Heading size="small" level="3">Plattform:</Heading>
<BodyShort textColor="subtle">{
props.resource.platform.map((item, index) => (
<span key={index}>
{item}
{index < props.resource.platform.length - 1 ? ', ' : ''}
</span>
))}
</BodyShort>
</li>*/}
</ul>
</GuidePanel>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, {SetStateAction} from "react";
import {INewApplicationResource} from "~/components/resource-admin/types";
import {IApplicationResource} from "~/components/resource-admin/types";
import {Checkbox, CheckboxGroup, Radio, RadioGroup, Select, TextField, VStack} from "@navikt/ds-react";

interface ResourceDataProps {
newApplicationResource: INewApplicationResource
setNewApplicationResource: React.Dispatch<SetStateAction<INewApplicationResource>>
newApplicationResource: IApplicationResource
setNewApplicationResource: React.Dispatch<SetStateAction<IApplicationResource>>
}

export default function ApplicationResourceData({
newApplicationResource,
setNewApplicationResource
setNewApplicationResource,
}: ResourceDataProps) {

const doesValueContainNumbersOnly = (value: string) => {
Expand All @@ -23,7 +23,7 @@ export default function ApplicationResourceData({
<TextField className={"input-large"}
label="Ressurs ID"
description={"Skriv inn unik id til ressursen uten mellomrom"}
value={newApplicationResource.resourceId}
value={newApplicationResource.resourceId || ""}
onChange={(event) =>
setNewApplicationResource({
...newApplicationResource,
Expand All @@ -34,16 +34,19 @@ export default function ApplicationResourceData({
<TextField className={"input-large"}
label="Navn på ressurs"
description={"Fullt navn på ressursen"}
value={newApplicationResource.resourceName}
value={newApplicationResource.resourceName || ""}
onChange={(event) => setNewApplicationResource({
...newApplicationResource,
resourceName: event.target.value
})}/>
</li>
{/*
Denne skal brukes på et senere tidspungt, foreløpig hardkodes pga. ApplicationResource er eneste valg
<li>
<Select
className={"input-medium"}
label={"Velg ressurstype"}
value={newApplicationResource.resourceType}
onChange={(event) => setNewApplicationResource({
...newApplicationResource,
resourceType: event.target.value
Expand All @@ -52,29 +55,35 @@ export default function ApplicationResourceData({
<option value={""}></option>
<option value={"ApplicationResource"}>Applikasjonsressurs</option>
</Select>
</li>
</li>*/}
{/*
Denne skal brukes på et senere tidspungt, foreløpig hardkodes
<li>
<CheckboxGroup legend="Velg plattform" onChange={(value: string[]) => {
setNewApplicationResource((prevState) => {
return {
...prevState,
platform: value
};
});
}}>
<CheckboxGroup legend="Velg plattform"
value={newApplicationResource.platform || []}
onChange={(value: string[]) => {
setNewApplicationResource((prevState) => {
return {
...prevState,
platform: value
};
});
}}>
<Checkbox value="win">Win</Checkbox>
<Checkbox value="mac">Mac</Checkbox>
<Checkbox value="linux">Linux</Checkbox>
<Checkbox value="web">Web</Checkbox>
<Checkbox value="android">Android</Checkbox>
<Checkbox value="ios">iOS</Checkbox>
</CheckboxGroup>
</li>
</li>*/}
{/*
Denne skal brukes på et senere tidspungt, foreløpig hardkodes
<li>
<Select
className={"input-medium"}
label={"Velg tilgangstype"}

value={newApplicationResource.accessType}
onChange={(event) => setNewApplicationResource({
...newApplicationResource,
accessType: event.target.value
Expand All @@ -83,19 +92,20 @@ export default function ApplicationResourceData({
<option value={"Device based license"}>Device based license</option>
</Select>
</li>
</li>*/}
<li>
<TextField className={"input-small"}
label="Ressursgrense"
description={"Totalt antall av ressursen"}
value={newApplicationResource.resourceLimit}
value={newApplicationResource.resourceLimit || 0}
onChange={(event) => setNewApplicationResource({
...newApplicationResource,
resourceLimit: Number(event.target.value)
})}/>
</li>
<li>
<CheckboxGroup legend="Velg roller ressursen skal være gyldig for"
value={newApplicationResource.validForRoles || []}
onChange={(value: string[]) => {
setNewApplicationResource((prevState) => {
return {
Expand All @@ -109,25 +119,22 @@ export default function ApplicationResourceData({
</CheckboxGroup>
</li>
<li>
<Select
className={"input-medium"}
label={"Velg applikasjonskategori"}
onChange={(e) => {
const selectedAppCategory = e.target.value;
setNewApplicationResource((prevState) => {
return {
...prevState,
applicationCategory: selectedAppCategory ? [selectedAppCategory] : []
};
});
}}
>
<option value={""}></option>
<option value={"Pedagogisk programvare"}>Pedagogisk programvare</option>
</Select>
<CheckboxGroup legend="Velg applikasjonskategori"
value={newApplicationResource.applicationCategory || []}
onChange={(value: string[]) => {
setNewApplicationResource((prevState) => {
return {
...prevState,
applicationCategory: value
};
});
}}>
<Checkbox value={"Pedagogisk programvare"}>Pedagogisk programvare</Checkbox>
</CheckboxGroup>
</li>
<li>
<RadioGroup legend="Har ressursen en kostnad?"
value={newApplicationResource.hasCost || false}
onChange={(value: boolean) => setNewApplicationResource({
...newApplicationResource,
hasCost: value
Expand All @@ -138,6 +145,7 @@ export default function ApplicationResourceData({
</li>
<li>
<RadioGroup legend="Håndhevingsregel"
value={newApplicationResource.licenseEnforcement || false}
onChange={(value: string) => setNewApplicationResource({
...newApplicationResource,
licenseEnforcement: value
Expand All @@ -150,8 +158,8 @@ export default function ApplicationResourceData({
<li>
<TextField className={"input-small"}
label="Kostnad ressurs (pr. stk.)"
value={newApplicationResource.unitCost || 0}
inputMode="numeric"
value={newApplicationResource.unitCost}
{...(!doesValueContainNumbersOnly(String(newApplicationResource.unitCost)) ? {error: "Kan ikke inneholde annet enn tall"} : {})}
onChange={(event) => doesValueContainNumbersOnly(event.target.value) && setNewApplicationResource({
...newApplicationResource,
Expand All @@ -161,6 +169,7 @@ export default function ApplicationResourceData({
</li>
<li>
<RadioGroup legend="Status"
value={newApplicationResource.status || false}
onChange={(value: string) => setNewApplicationResource({
...newApplicationResource,
status: value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import {Accordion, Box, Checkbox, HStack, TextField} from "@navikt/ds-react";
import type { IUnitItem } from "~/data/types";
import React, {useEffect, useState} from "react";
import {Accordion, Box, Checkbox, HGrid, TextField} from "@navikt/ds-react";
import type {IUnitItem} from "~/data/types";

interface ValidForOrgUnitSelectorProps {
orgUnitList: IUnitItem[];
Expand Down Expand Up @@ -32,7 +32,7 @@ const ValidForOrgUnitSelector = ({
(unit) => unit.organisationUnitId !== changedOrgUnit.organisationUnitId
);
} else {
newSelected = [...selectedOrgUnits, { ...changedOrgUnit }];
newSelected = [...selectedOrgUnits, {...changedOrgUnit}];
}
//console.log(`Valgt enhet ${changedOrgUnit.organisationUnitId}:`, changedOrgUnit);
setSelectedOrgUnits(newSelected);
Expand All @@ -45,11 +45,10 @@ const ValidForOrgUnitSelector = ({
};

const handleAntallChange = (orgUnitId: string, value: string) => {
const antall = Math.max(0, Math.min(parseInt(value), 1000000));
//console.log(`Endret antall for enhet ${orgUnitId}:`, antall);
const antall = Math.max(0, parseInt(value));
const updatedOrgUnits = newOrgUnitList.map((unit) =>
unit.organisationUnitId === orgUnitId
? { ...unit, limit: isNaN(antall) ? undefined : antall }
? {...unit, limit: isNaN(antall) ? undefined : antall}
: unit
);
setNewOrgUnitList(updatedOrgUnits);
Expand All @@ -60,11 +59,11 @@ const ValidForOrgUnitSelector = ({
return (
<Accordion.Item key={orgUnit.id + " " + orgUnit.organisationUnitId}>
<Accordion.Header>
<HStack gap={"24"} align={"center"} justify={"center"}>
<HGrid gap={"24"} columns={2}>
<Box>
<Checkbox
className={"org-unit-checkbox"}
checked={orgUnit.isChecked}
checked={orgUnit.isChecked || false}
onClick={(event) => {
event.stopPropagation();
toggleOrgUnit(orgUnit);
Expand All @@ -77,9 +76,7 @@ const ValidForOrgUnitSelector = ({
{orgUnit.isChecked && (
<TextField
label={"Antall"}

min="0"
max="100"
value={orgUnit.limit?.toString() || ""}
onChange={(event) =>
handleAntallChange(
Expand All @@ -92,7 +89,7 @@ const ValidForOrgUnitSelector = ({
)}

</Box>
</HStack>
</HGrid>
</Accordion.Header>
{!locksChildNodes && (
<Accordion.Content>
Expand Down
Loading

0 comments on commit 104c199

Please sign in to comment.