-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): prefill parameters for workflow submit form. Fixes #1214
Signed-off-by: Sairam Arunachalam <[email protected]>
- Loading branch information
Showing
8 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {createBrowserHistory} from 'history'; | ||
|
||
import {getWorkflowParametersFromQuery} from './get_workflow_params'; | ||
|
||
describe('get_workflow_params', () => { | ||
it('should return an empty object when there are no query parameters', () => { | ||
const history = createBrowserHistory(); | ||
const result = getWorkflowParametersFromQuery(history); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return the parameters provided in the URL', () => { | ||
const history = createBrowserHistory(); | ||
history.location.search = '?parameters[key1]=value1¶meters[key2]=value2'; | ||
const result = getWorkflowParametersFromQuery(history); | ||
expect(result).toEqual({ | ||
key1: 'value1', | ||
key2: 'value2' | ||
}); | ||
}); | ||
|
||
it('should not return any key value pairs which are not in parameters query ', () => { | ||
const history = createBrowserHistory(); | ||
history.location.search = '?retryparameters[key1]=value1&retryparameters[key2]=value2'; | ||
const result = getWorkflowParametersFromQuery(history); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should only return the parameters provided in the URL', () => { | ||
const history = createBrowserHistory(); | ||
history.location.search = '?parameters[key1]=value1¶meters[key2]=value2&test=123'; | ||
const result = getWorkflowParametersFromQuery(history); | ||
expect(result).toEqual({ | ||
key1: 'value1', | ||
key2: 'value2' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {History} from 'history'; | ||
|
||
function extractKey(inputString: string): string | null { | ||
// Use regular expression to match the key within square brackets | ||
const match = inputString.match(/^parameters\[(.*?)\]$/); | ||
|
||
// If a match is found, return the captured key | ||
if (match) { | ||
return match[1]; | ||
} | ||
|
||
// If no match is found, return null or an empty string | ||
return null; // Or return ''; | ||
} | ||
/** | ||
* Returns the workflow parameters from the query parameters. | ||
*/ | ||
export function getWorkflowParametersFromQuery(history: History): {[key: string]: string} { | ||
const queryParams = new URLSearchParams(history.location.search); | ||
|
||
const parameters: {[key: string]: string} = {}; | ||
for (const [key, value] of queryParams.entries()) { | ||
const q = extractKey(key); | ||
if (q) { | ||
parameters[q] = value; | ||
} | ||
} | ||
|
||
return parameters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters