Skip to content

Commit

Permalink
fix empty URL parameters (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoelzer authored Oct 15, 2024
1 parent 8d3c787 commit 633d04e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ui/src/components/pages/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function LoginForm({ setIsLoggedIn }: Props) {
<div className="fields">
<TextField required data-testid="organization" id="organization" label="Organization" value={organization} onChange={(event) => setOrganization(event.target.value)} />
<TextField required data-testid="username" id="username" label="Username" value={username} onChange={(event) => setUsername(event.target.value)} />
<TextField required data-testid="password" id="password" type="password" label="password" value={password} onChange={(event) => setPassword(event.target.value)} />
<TextField required data-testid="password" id="password" type="password" label="Password" value={password} onChange={(event) => setPassword(event.target.value)} />
{error && <h3 data-testid="error_message" style={{ color: "red" }}>{error}</h3>}
<Button data-testid="login_button" variant="contained" type="submit" onClick={handleLogin}>Login</Button>
</div>
Expand Down
21 changes: 15 additions & 6 deletions ui/src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,28 @@ export async function submitForm(urlParameters: FieldParametersType, formParamet
path = path.substring(0, posBracketStart+1) + "name" + path.substring(posBracketEnd);
}

queryParameters.forEach((query, index) => {
if(index === 0) {
path += "?";
// replace variables within the path
Object.keys(values).forEach(key => {
path = path.replace("{" + key + "}", String(values[key]));
});

// add query parameters to path
queryParameters.forEach((query) => {
let queryValue = undefined;
if(query in values) {
queryValue = values[query];
}
else {
path += "&";
queryValue = urlParameters[query]?.schema?.default;
}
if(queryValue !== undefined) {
path += path.includes("?") ? "&" : "?";
path += encodeURIComponent(query) + "=" + encodeURIComponent(queryValue);
}
path += encodeURIComponent(query) + "={" + query + "}";
})

values = {...values};
Object.keys(values).forEach(key => {
path = path.replace("{" + key + "}", String(values[key]));
if(!(key in formParameters)) {
//remove fields which are not used as form parameter
delete values[key];
Expand Down
8 changes: 6 additions & 2 deletions ui/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export type FieldParameterType = {
in?: string,
items?: FieldParameterType,
properties?: FieldParametersType,
additionalProperties?: FieldParameterType,
enums?: {key: string, label: string}[]
additionalProperties?: FieldParameterType
enums?: {key: string, label: string}[],
schema?: {
default: boolean|string,
type: string
}
};

export type FieldParametersType = {
Expand Down

0 comments on commit 633d04e

Please sign in to comment.