Skip to content

Commit

Permalink
Add in the edit UI for Exports
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock authored and jhiemstrawisc committed Mar 12, 2024
1 parent 4282531 commit 2bfe6be
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/validate-parameters/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"CustomRegistrationFields",
"OIDCAuthenticationRequirements",
"AuthorizationTemplates",
"IPMapping"
"IPMapping",
"Exports"
]


Expand Down
16 changes: 7 additions & 9 deletions web_ui/frontend/components/Config/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AuthorizationTemplate, CustomRegistrationField,
Duration,
Duration, Export,
GeoIPOverride,
Institution, IPMapping,
OIDCAuthenticationRequirement,
Expand All @@ -9,18 +9,14 @@ import {
} from "@/components/Config/index.d";
import {BooleanField, DurationField, IntegerField, StringField, StringSliceField} from "../Config";
import React from "react";
import {IntegerFieldProps} from "./IntegerField";
import {StringFieldProps} from "./StringField";
import {DurationFieldProps} from "./DurationField";
import {BooleanFieldProps} from "./BooleanField";
import {StringSliceFieldProps} from "./StringSliceField";
import {CustomRegistrationFieldForm, ObjectField} from "./ObjectField";
import {ObjectFieldProps} from "@/components/Config/ObjectField/ObjectField";
import {
CustomRegistrationFieldForm,
ExportForm,
ObjectField,
GeoIPOverrideForm,
InstitutionForm,
OIDCAuthenticationRequirementForm
} from "@/components/Config/ObjectField";
} from "./ObjectField";
import {buildPatch} from "@/components/Config/util";
import IPMappingForm from "@/components/Config/ObjectField/IPMappingForm";
import AuthorizationTemplateForm from "@/components/Config/ObjectField/AuthorizationTemplateForm";
Expand Down Expand Up @@ -61,6 +57,8 @@ const Field = ({ onChange, ...props}: ParameterInputProps) => {
return <ObjectField onChange={handleChange<IPMapping[]>} name={props.name} value={props.Value as IPMapping[]} Form={IPMappingForm} keyGetter={v => "all" in v ? v.all : v.source}/>
case "CustomRegistrationFields":
return <ObjectField onChange={handleChange<CustomRegistrationField[]>} name={props.name} value={props.Value as CustomRegistrationField[]} Form={CustomRegistrationFieldForm} keyGetter={v => v.name}/>
case "Exports":
return <ObjectField onChange={handleChange<Export[]>} name={props.name} value={props.Value as Export[]} Form={ExportForm} keyGetter={v => v.federationprefix}/>
default:
console.log("Unknown type: " + props.type)
}
Expand Down
52 changes: 52 additions & 0 deletions web_ui/frontend/components/Config/ObjectField/ExportForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {Capability, Institution} from "@/components/Config/index.d";
import React from "react";
import {Box, Button} from "@mui/material";

import {FormProps, ModalProps} from "@/components/Config/ObjectField/ObjectField";
import {MultiSelectField, SelectField, StringField} from "../../Config";
import {Export} from "@/components/Config/index.d";

const verifyForm = (x: Export) => {
return x.storageprefix != "" && x.federationprefix != "" && x.capabilities.length > 0
}

const ExportForm = ({ onSubmit, value }: FormProps<Export>) => {

const [storagePrefix, setStoragePrefix] = React.useState<string>(value?.storageprefix || "")
const [federationPrefix, setFederationPrefix] = React.useState<string>(value?.federationprefix || "")
const [capabilities, setCapabilities] = React.useState<Capability[]>(value?.capabilities || [])

const submitHandler = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

const exportValue = {
storageprefix: storagePrefix,
federationprefix: federationPrefix,
capabilities: capabilities
}


if(!verifyForm(exportValue)) {
return
}

onSubmit(exportValue);
}

return (
<form onSubmit={submitHandler}>
<Box my={2}>
<StringField name={"StoragePrefix"} value={storagePrefix} onChange={setStoragePrefix} />
</Box>
<Box mb={2}>
<StringField name={"FederationPrefix"} value={federationPrefix} onChange={setFederationPrefix} />
</Box>
<Box mb={2}>
<MultiSelectField<Capability> name={"Capabilities"} value={capabilities} onChange={setCapabilities} possibleValues={["PublicReads", "DirectReads", "Writes", "Listings", "Reads"]}/>
</Box>
<Button type={"submit"}>Submit</Button>
</form>
)
}

export default ExportForm;
3 changes: 2 additions & 1 deletion web_ui/frontend/components/Config/ObjectField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import OIDCAuthenticationRequirementForm from "./OIDCAuthenticationRequirementFo
import IPMappingForm from "./IPMappingForm";
import CustomRegistrationFieldForm from "./CustomRegistrationFieldForm";
import OptionForm from "./OptionForm";
import ExportForm from "./ExportForm";

export {ObjectField, InstitutionForm, GeoIPOverrideForm, OIDCAuthenticationRequirementForm, IPMappingForm, OptionForm, CustomRegistrationFieldForm}
export {ObjectField, InstitutionForm, GeoIPOverrideForm, OIDCAuthenticationRequirementForm, IPMappingForm, OptionForm, CustomRegistrationFieldForm, ExportForm}
11 changes: 10 additions & 1 deletion web_ui/frontend/components/Config/index.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ParameterMetadata {

export interface ParameterValue {
Type: string;
Value: string | number | boolean | string[] | undefined | Coordinate[] | Institution[] | CustomRegistrationField[] | OIDCAuthenticationRequirement[] | AuthorizationTemplate[] | IPMapping[] | GeoIPOverride[];
Value: string | number | boolean | string[] | undefined | Coordinate[] | Institution[] | CustomRegistrationField[] | OIDCAuthenticationRequirement[] | AuthorizationTemplate[] | IPMapping[] | GeoIPOverride[] | Export[];
}

export type ParameterInputProps = Parameter & {
Expand Down Expand Up @@ -75,3 +75,12 @@ export interface IPMappingFine {
}

export type IPMapping = IPMappingAll | IPMappingFine;


export type Capability = "PublicReads" | "DirectReads" | "Writes" | "Listings" | "Reads";

export interface Export {
storageprefix: string;
federationprefix: string;
capabilities: Capability[];
}

0 comments on commit 2bfe6be

Please sign in to comment.