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: Add a link in the UI for WorkflowTemplate. Fixes #4760 #8208

Merged
merged 8 commits into from
Mar 28, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {NotificationType, Page, SlidingPanel} from 'argo-ui';
import * as React from 'react';
import {useContext, useEffect, useState} from 'react';
import {RouteComponentProps} from 'react-router';
import {CronWorkflow} from '../../../../models';
import {CronWorkflow, Link} from '../../../../models';
import {uiUrl} from '../../../shared/base';
import {ErrorNotice} from '../../../shared/components/error-notice';
import {Loading} from '../../../shared/components/loading';
Expand Down Expand Up @@ -87,6 +87,99 @@ export const CronWorkflowDetails = ({match, location, history}: RouteComponentPr
.catch(setError),
disabled: !cronWorkflow || !cronWorkflow.spec.suspend || edited
};

const openLink = (link: Link) => {
if ((window.event as MouseEvent).ctrlKey || (window.event as MouseEvent).metaKey) {
window.open(link.url, '_blank');
} else {
document.location.href = link.url;
}
};

const getItems = () => {
const items = [
{
title: 'Submit',
iconClassName: 'fa fa-plus',
disabled: edited,
action: () =>
services.workflows
.submit('cronwf', name, namespace)
.then(wf => navigation.goto(uiUrl(`workflows/${wf.metadata.namespace}/${wf.metadata.name}`)))
.then(() => setError(null))
.catch(setError)
},
{
title: 'Update',
iconClassName: 'fa fa-save',
disabled: !edited,
action: () => {
// magic - we get the latest from the server and then apply the changes from the rendered version to this
return services.cronWorkflows
.get(name, namespace)
.then(latest =>
services.cronWorkflows.update(
{
...latest,
spec: cronWorkflow.spec,
metadata: {...cronWorkflow.metadata, resourceVersion: latest.metadata.resourceVersion}
},
cronWorkflow.metadata.name,
cronWorkflow.metadata.namespace
)
)
.then(setCronWorkflow)
.then(() => notifications.show({content: 'Updated', type: NotificationType.Success}))
.then(() => setError(null))
.then(() => setEdited(false))
.catch(setError);
}
},
suspendButton,
{
title: 'Delete',
iconClassName: 'fa fa-trash',
disabled: edited,
action: () => {
popup.confirm('confirm', 'Are you sure you want to delete this cron workflow?').then(yes => {
if (yes) {
services.cronWorkflows
.delete(name, namespace)
.then(() => navigation.goto(uiUrl('cron-workflows/' + namespace)))
.then(() => setError(null))
.catch(setError);
}
});
}
},
{
title: 'Share',
iconClassName: 'fa fa-share-alt',
action: () => setSidePanel('share')
}
];

if (cronWorkflow?.spec?.workflowSpec?.workflowTemplateRef) {
alexec marked this conversation as resolved.
Show resolved Hide resolved
const templateName = cronWorkflow.spec.workflowSpec.workflowTemplateRef.name;
const clusterScope = cronWorkflow.spec.workflowSpec.workflowTemplateRef.clusterScope;
const url: string = clusterScope ? `/cluster-workflow-templates/${templateName}` : `/workflow-templates/${cronWorkflow.metadata.namespace}/${templateName}`;

const templateLink: Link = {
name: 'Workflow Template Link',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change to “Open Workflow Template” and use the same icon as left-hand-nav does.

scope: 'workflow',
url
};

items.push({
title: templateLink.name,
iconClassName: 'fa fa-external-link-alt',
action: () => openLink(templateLink)
});
}

return items;
};

return (
<Page
title='Cron Workflow Details'
Expand All @@ -97,67 +190,7 @@ export const CronWorkflowDetails = ({match, location, history}: RouteComponentPr
{title: name, path: uiUrl('cron-workflows/' + namespace + '/' + name)}
],
actionMenu: {
items: [
{
title: 'Submit',
iconClassName: 'fa fa-plus',
disabled: edited,
action: () =>
services.workflows
.submit('cronwf', name, namespace)
.then(wf => navigation.goto(uiUrl(`workflows/${wf.metadata.namespace}/${wf.metadata.name}`)))
.then(() => setError(null))
.catch(setError)
},
{
title: 'Update',
iconClassName: 'fa fa-save',
disabled: !edited,
action: () => {
// magic - we get the latest from the server and then apply the changes from the rendered version to this
return services.cronWorkflows
.get(name, namespace)
.then(latest =>
services.cronWorkflows.update(
{
...latest,
spec: cronWorkflow.spec,
metadata: {...cronWorkflow.metadata, resourceVersion: latest.metadata.resourceVersion}
},
cronWorkflow.metadata.name,
cronWorkflow.metadata.namespace
)
)
.then(setCronWorkflow)
.then(() => notifications.show({content: 'Updated', type: NotificationType.Success}))
.then(() => setError(null))
.then(() => setEdited(false))
.catch(setError);
}
},
suspendButton,
{
title: 'Delete',
iconClassName: 'fa fa-trash',
disabled: edited,
action: () => {
popup.confirm('confirm', 'Are you sure you want to delete this cron workflow?').then(yes => {
if (yes) {
services.cronWorkflows
.delete(name, namespace)
.then(() => navigation.goto(uiUrl('cron-workflows/' + namespace)))
.then(() => setError(null))
.catch(setError);
}
});
}
},
{
title: 'Share',
iconClassName: 'fa fa-share-alt',
action: () => setSidePanel('share')
}
]
items: getItems()
}
}}>
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ export const WorkflowDetails = ({history, location, match}: RouteComponentProps<
});
});
}

if (workflow?.spec?.workflowTemplateRef) {
const templateName: string = workflow.spec.workflowTemplateRef.name;
const clusterScope: boolean = workflow.spec.workflowTemplateRef.clusterScope;
const url: string = clusterScope ? `/cluster-workflow-templates/${templateName}` : `/workflow-templates/${workflow.metadata.namespace}/${templateName}`;

const templateLink: Link = {
name: 'Workflow Template Link',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change to “Open Workflow Template” and use the same icon as left-hand-nav does.

scope: 'workflow',
url
};

items.push({
title: templateLink.name,
iconClassName: 'fa fa-external-link-alt',
action: () => openLink(templateLink)
});
}

return items;
};

Expand Down