Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): prefill parameters for workflow submit form. Fixes #12124 #13766

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sairam91
Copy link

@sairam91 sairam91 commented Oct 15, 2024

Fixes #12124

Motivation

This PR adds support for developers to prefil submit workflow form by passing in the values through query parameters.

To prefil a submit workflow developers can pass in the following query parameters

sidePanel=submit-new-workflow
template=<template that the workflow should follow>
parameters[key]=value // Here the key would be the parameter for the job and value would be the value of the parameter.
You should provide the keys that are supported by the specified template

Modifications

  • Updated workflow-list component
  • Updated submit-workflow-panel.tsx component to default entry point if provided.
  • Updated workflow-creator.tsx to read default values from query parameters.
  • The workflow will be prefilled with the parameters that the template supports
  • Added new shared helper function to parse query parameter of the format ?parameters[key]=value.

Verification

isShown={!!getSidePanel()}
onClose={() => {
// Remove any lingering query params
const qParams: {[key: string]: string | null} = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicate can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this is necessary? The navigation.goto() function already has logic to automatically strip out the query parameters if there's been a path change: https://github.com/argoproj/argo-ui/blob/54f36c723d9a0e5d3386689298cbb9c27767fa00/src/components/navigation.ts#L20-L21

If there hasn't been a path change, I think it's fine to leave these query parameters in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the workflow this would fix is

  • Open the submit page prefilled through the URL
  • Close the submit page
  • Click on Submit again,

In this case, if the parameters are preserved, we would open the prefilled page. Removing the parameters will ensure the developer can start the page fresh without pre filled data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. IMO, it'd be better to remove this, because if a developer wants to start fresh, they can click on the "Workflows" icon on the left bar (or navigate to another page and back again)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I tried that workflow and the developer would need to go back to the workflows tab and re-trigger a workflow.

Most likely the developer who lands on this page through query parameters would try to Submit it.

Removing the extra added query parameters in this PR, will make the developer experience much better as they can recover quickly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that makes sense. I checked and this is the only page using a<SlidingPanel> that calls navigation.goto() on close. Every other page just sets a parameter on close, e.g.

<SlidingPanel isShown={!!sidePanel} onClose={() => setSidePanel(null)} isMiddle={true}>

I'm not sure why this page is special in that respect, but it could be a developer experience thing

@agilgur5 agilgur5 changed the title fix(ui): prefill parameters for workflow submit form. Fixes #1214 feat(ui): prefill parameters for workflow submit form. Fixes #12124 Oct 16, 2024
@MasonM
Copy link
Contributor

MasonM commented Oct 16, 2024

Good start! A couple initial comments:

  1. This project uses the history library, so I think (but I'm not sure) the useEffect() hooks need to incorporate it as a dependency. That means passing through the history object to the affected components. Ideally, we'd use useQueryParams() too, but when I tried that, the history.listen() callback wouldn't fire. I think that's due to the interdependency with the workflowTemplates/workflowParameters props.
  2. It'd be simpler to push the logic for handling workflow parameters to ui/src/app/workflows/components/submit-workflow-panel.tsx

Here's a commit that does both things: MasonM@d2c11c8

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. [...] Ideally, we'd use useQueryParams() too, but when I tried that, the history.listen() callback wouldn't fire. I think that's due to the interdependency with the workflowTemplates/workflowParameters props

In this case, I don't think it's necessary, because the URL should not change after the page loads, since the purpose is deeplinking. history.listen() is to make sure the state and query params match.
It could still be used, but may be unnecessary complexity in this case.

  1. It'd be simpler to push the logic for handling workflow parameters to ui/src/app/workflows/components/submit-workflow-panel.tsx

Agree, that was what I thought on first glance of this yesterday too, but hadn't commented yet since it's still draft and wanted to see if you or Sairam would pick that up in iteration 🙂

Signed-off-by: Sairam Arunachalam <[email protected]>
ui/src/app/shared/get_workflow_params.ts Outdated Show resolved Hide resolved
isShown={!!getSidePanel()}
onClose={() => {
// Remove any lingering query params
const qParams: {[key: string]: string | null} = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this is necessary? The navigation.goto() function already has logic to automatically strip out the query parameters if there's been a path change: https://github.com/argoproj/argo-ui/blob/54f36c723d9a0e5d3386689298cbb9c27767fa00/src/components/navigation.ts#L20-L21

If there hasn't been a path change, I think it's fine to leave these query parameters in.

ui/src/app/workflows/components/submit-workflow-panel.tsx Outdated Show resolved Hide resolved
ui/src/app/shared/get_workflow_params.ts Outdated Show resolved Hide resolved
ui/src/app/shared/get_workflow_params.ts Outdated Show resolved Hide resolved

// Add the sidePanel query parameter if it exists
params.append('sidePanel', getSidePanel());
params.append('template', queryParams.get('template'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this component is taking an allow-list approach to query parameters, but you could get rid of this extra code by changing const params = new URLSearchParams() to const params = new URLSearchParams(history.location.search);

I'm not sure what side-effects that'll have, though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could preserve all the parameters. We might have to try different scenarios to check for side-effects.

Signed-off-by: Sairam Arunachalam <[email protected]>
@@ -126,7 +126,7 @@ export function WorkflowsList({match, location, history}: RouteComponentProps<an
}
storage.setItem('options', options, {} as WorkflowListRenderOptions);

const params = new URLSearchParams();
const params = new URLSearchParams(history.location.search);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one side-effect of this change: if you visit http://localhost:8080/workflows?namespace=argo and refresh the page, it'll append &namespace=argo each time you refresh. That's happening because historyUrl() isn't deduplicating query parameters, which it should IMO. Here's a commit that fixes that: MasonM@8b48d5b

I haven't extensively tested that, so it's possible there's other side-effects

Comment on lines 13 to 14
const path = createPath({pathname: '/workflows', search: '?parameters[key1]=value1&parameters[key2]=value2'});
history.location.search = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing because window.location.search should only contain the query string, not the path:

Suggested change
const path = createPath({pathname: '/workflows', search: '?parameters[key1]=value1&parameters[key2]=value2'});
history.location.search = path;
history.location.search = '?parameters[key1]=value1&parameters[key2]=value2';

Also, if you haven't already, you should install the Jest extension in the DevContainer so you can debug the tests and set breakpoints:
Screenshot 2024-10-17 at 11 25 15 AM

Comment on lines 24 to 25
const path = createPath({pathname: '/workflows', search: '?parameters[key1]=value1&parameters[key2]=value2&test=123'});
history.location.search = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:

Suggested change
const path = createPath({pathname: '/workflows', search: '?parameters[key1]=value1&parameters[key2]=value2&test=123'});
history.location.search = path;
history.location.search = '?parameters[key1]=value1&parameters[key2]=value2&test=123';

Signed-off-by: Sairam Arunachalam <[email protected]>
@sairam91 sairam91 marked this pull request as ready for review October 18, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: Prefill parameters for the workflow submit form
3 participants