Skip to content

Commit

Permalink
Fix Config Bug
Browse files Browse the repository at this point in the history
- Increase the Config Type flexibility
- Allow infinitely nested configs

Fixes PelicanPlatform#380
  • Loading branch information
CannonLock committed Nov 16, 2023
1 parent d9c61e9 commit 092c417
Showing 1 changed file with 18 additions and 125 deletions.
143 changes: 18 additions & 125 deletions origin_ui/src/app/(dashboard)/config/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,122 +35,21 @@ import {isLoggedIn} from "@/helpers/login";

type duration = number | `${number}${"ns" | "us" | "µs" | "ms" |"s" | "m" | "h"}`;

interface Config {
ConfigDir: string;
Debug: boolean;
TLSSkipVerify: boolean;
IssuerKey: string;
Logging: {
Level: string;
LogLocation?: string;
},
Transport: {
DialerTimeout: duration;
DialerKeepAlive: duration;
MaxIdleConns: number;
IdleConnTimeout: duration;
TLSHandshakeTimeout: duration;
ExpectContinueTimeout: duration;
ResponseHeaderTimeout: duration;
}
Federation: {
DiscoveryUrl?: string;
TopologyNamespaceUrl?: string;
DirectorUrl?: string;
NamespaceUrl?: string;
JwkUrl?: string;
}
Client: {
StoppedTransferTimeout: number;
SlowTransferRampupTime: number;
SlowTransferWindow: number;
DisableHttpProxy: boolean;
DisableProxyFallback: boolean;
MinimumDownloadSpeed: number;
}
DisableHttpProxy: boolean
DisableProxyFallback: boolean;
MinimumDownloadSpeed: number;
Origin: {
Url: string;
ExportVolume?: string;
NamespacePrefix?: string;
Multiuser: boolean;
UseCmsd: boolean;
UIPasswordFile: string;
SelfTest: boolean;
EnableUI: boolean;
EnableIssuer: boolean;
ScitokensRestrictedPaths?: boolean
ScitokensMapSubject: boolean
ScitokensDefaultUser?: string;
ScitokensUsernameClaim?: string;
ScitokensNameMapFile?: string;
};
Director: {
DefaultResponse: string;
CacheResponseHostnames?: string[];
OriginResponseHostnames?: string[];
MaxMindKeyFile?: string;
GeoIPLocation: string;
};
Registry: {
DbLocation: string;
};
Server: {
TLSCertificate: string;
TLSCACertificateFile: string;
TLSCACertificateDirectory?: string;
TLSCAKey: string;
TLSKey: string;
Port: number;
Address: string;
ExternalAddress?: string;
Hostname?: string;
IssuerJwks?: string;
};
OIDC: {
ClientIDFile: string;
ClientSecretFile: string;
DeviceAuthEndpoint?: string;
TokenEndpoint?: string;
UserInfoEndpoint?: string;
};
Xrootd: {
Port: number;
RunLocation: string;
RobotsTxtFile: string;
ScitokensConfig: string;
Mount?: string;
MacaroonsKeyFile?: string;
Authfile?: string;
ManagerHost?: string;
SummaryMonitoringHost?: string;
DetailedMonitoringHost?: string;
LocalMonitoringHost?: string;
Sitename?: string;
};
Monitoring: {
DataLocation: string;
PortLower: number;
PortHigher: number;
};
Plugin: {
Token?: string;
}
StagePlugin: {
Hook: boolean;
MountPrefix?: string
OriginPrefix?: string
ShadowOriginPrefix?: string
}
type Config = {
[key: string]: ConfigValue
}

function sortConfig (a: any, b: any) {
if(typeof a[1] == 'object' && typeof b[1] != 'object'){
type ConfigValue = Config | string | number | boolean | null | string[] | number[] | duration


function sortConfig (a: [string, ConfigValue], b: [string, ConfigValue]) {

let isConfig = (value: ConfigValue) => { return typeof value == 'object' && value !== null && !Array.isArray(value)}

if(isConfig(a[1]) && !isConfig(b[1])){
return 1
}
if(typeof a[1] != 'object' && typeof b[1] == 'object'){
if(!isConfig(a[1]) && isConfig(b[1])){
return -1
}
return a[0].localeCompare(b[0])
Expand All @@ -160,7 +59,7 @@ function sortConfig (a: any, b: any) {
interface ConfigDisplayProps {
id: string[]
name: string
value: Partial<Config> | string[] | number[] | string | number | boolean | null
value: Config | ConfigValue
level: number
}

Expand Down Expand Up @@ -194,9 +93,7 @@ function ConfigDisplay({id, name, value, level = 1}: ConfigDisplayProps) {
variant={"outlined"}
value={value}
/>
}

if(Array.isArray(value)){
} else if(Array.isArray(value)){
formElement = <TextField
fullWidth
disabled
Expand All @@ -206,9 +103,7 @@ function ConfigDisplay({id, name, value, level = 1}: ConfigDisplayProps) {
variant={"outlined"}
value={value.join(", ")}
/>
}

if(typeof value === 'boolean'){
} else if(typeof value === 'boolean'){
formElement = (
<FormControl fullWidth>
<InputLabel id={`${id.join("-")}-number-input`}>{name}</InputLabel>
Expand Down Expand Up @@ -277,7 +172,7 @@ function ConfigDisplay({id, name, value, level = 1}: ConfigDisplayProps) {
interface TableOfContentsProps {
id: string[]
name: string
value: Partial<Config> | string | number | boolean | any
value: Config | ConfigValue
level: number
}

Expand All @@ -290,7 +185,7 @@ function TableOfContents({id, name, value, level = 1}: TableOfContentsProps) {
}

let subContents = undefined
if(value !== null && typeof value == 'object'){
if(value !== null && !Array.isArray(value) && typeof value == 'object'){
let subValues = Object.entries(value)
subValues.sort(sortConfig)
subContents = subValues.map(([key, value]) => {
Expand Down Expand Up @@ -345,10 +240,8 @@ function TableOfContents({id, name, value, level = 1}: TableOfContentsProps) {
{ name ? headerPointer : undefined}
{ subContents && level != 1 ?
<Box sx={{
maxHeight: open ? Object.entries(value).length * 23 + "px" : 0,
transition: "max-height 0.1s ease-in-out",
cursor: "pointer",
overflow: "hidden",
display: open ? "block" : "none",
cursor: "pointer"
}}
>
{subContents}
Expand Down

0 comments on commit 092c417

Please sign in to comment.