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: Specify conditions in query parameters #14113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Page} from 'argo-ui/src/components/page/page';
import {SlidingPanel} from 'argo-ui/src/components/sliding-panel/sliding-panel';
import * as React from 'react';
import {useContext, useEffect, useState} from 'react';
import {useContext, useEffect, useRef, useState} from 'react';
import {Link, RouteComponentProps} from 'react-router-dom';

import {uiUrl} from '../shared/base';
Expand All @@ -26,9 +26,10 @@ import './cluster-workflow-template-list.scss';
export function ClusterWorkflowTemplateList({history, location}: RouteComponentProps<any>) {
const {navigation} = useContext(Context);
const queryParams = new URLSearchParams(location.search);
const isFirstRender = useRef(true);
const [templates, setTemplates] = useState<models.ClusterWorkflowTemplate[]>();
const [error, setError] = useState<Error>();
const [sidePanel, setSidePanel] = useState(queryParams.get('sidePanel'));
const [sidePanel, setSidePanel] = useState(queryParams.get('sidePanel') === 'true');

async function fetchClusterWorkflowTemplates() {
try {
Expand All @@ -42,11 +43,27 @@ export function ClusterWorkflowTemplateList({history, location}: RouteComponentP

useEffect(
useQueryParams(history, p => {
setSidePanel(p.get('sidePanel'));
setSidePanel(p.get('sidePanel') === 'true');
}),
[history]
);

useEffect(() => {
if (isFirstRender.current) {
isFirstRender.current = false;
return;
}
const params = new URLSearchParams();
if (sidePanel) {
params.set('sidePanel', 'true');
}

history.push({
pathname: uiUrl('cluster-workflow-templates'),
search: params.toString()
});
}, [history, sidePanel]);

useEffect(() => {
fetchClusterWorkflowTemplates();
}, []);
Expand Down Expand Up @@ -116,7 +133,7 @@ export function ClusterWorkflowTemplateList({history, location}: RouteComponentP
{
title: 'Create New Cluster Workflow Template',
iconClassName: 'fa fa-plus',
action: () => setSidePanel('new')
action: () => setSidePanel(true)
}
]
}
Expand Down
24 changes: 17 additions & 7 deletions ui/src/cron-workflows/cron-workflow-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,23 @@ export function CronWorkflowList({match, location, history}: RouteComponentProps
isFirstRender.current = false;
return;
}
history.push(
historyUrl('cron-workflows' + (nsUtils.getManagedNamespace() ? '' : '/{namespace}'), {
namespace,
sidePanel
})
);
}, [namespace, sidePanel]);
const params = new URLSearchParams();
if (sidePanel) {
params.set('sidePanel', 'true');
}
if (labels.length > 0) {
params.set('labels', labels.join(','));
}
if (states.length > 0) {
params.set('states', states.join(','));
}
history.push({
pathname: historyUrl('cron-workflows' + (nsUtils.getManagedNamespace() ? '' : '/{namespace}'), {
namespace
}),
search: params.toString()
});
}, [namespace, sidePanel, labels, states]);

// internal state
const [error, setError] = useState<Error>();
Expand Down
30 changes: 23 additions & 7 deletions ui/src/workflow-templates/workflow-template-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ export function WorkflowTemplateList({match, location, history}: RouteComponentP
isFirstRender.current = false;
return;
}
history.push(
historyUrl('workflow-templates' + (nsUtils.getManagedNamespace() ? '' : '/{namespace}'), {
namespace,
sidePanel
})
);
}, [namespace, sidePanel]);
const params = new URLSearchParams();
if (sidePanel) {
params.set('sidePanel', 'true');
}
if (namePattern) {
params.set('namePattern', namePattern);
}
if (labels.length > 0) {
params.set('labels', labels.join(','));
}
if (pagination.offset) {
params.set('offset', pagination.offset);
}
if (pagination.limit !== 500) {
params.set('limit', pagination.limit.toString());
}
history.push({
pathname: historyUrl('workflow-templates' + (nsUtils.getManagedNamespace() ? '' : '/{namespace}'), {
namespace
}),
search: params.toString()
});
}, [namespace, sidePanel, namePattern, labels, pagination.offset, pagination.limit]);

// internal state
const [error, setError] = useState<Error>();
Expand Down