adds visualizer button to output toolbar

This commit is contained in:
Alex Corey 2021-06-14 11:08:26 -04:00 committed by Shane McDonald
parent 736cd4df36
commit cf6b6d831f
No known key found for this signature in database
GPG Key ID: 6F374AF6E9EB9374
2 changed files with 32 additions and 4 deletions

View File

@ -1,9 +1,14 @@
import React, { useContext } from 'react';
import { useHistory } from 'react-router-dom';
import { t } from '@lingui/macro';
import { shape } from 'prop-types';
import { Badge as PFBadge, Button, Tooltip } from '@patternfly/react-core';
import { CompassIcon, WrenchIcon } from '@patternfly/react-icons';
import {
CompassIcon,
WrenchIcon,
ProjectDiagramIcon,
} from '@patternfly/react-icons';
import styled from 'styled-components';
import StatusIcon from '../../../components/StatusIcon';
import {
@ -58,11 +63,15 @@ const StatusIconWithMargin = styled(StatusIcon)`
function WorkflowOutputToolbar({ job }) {
const dispatch = useContext(WorkflowDispatchContext);
const history = useHistory();
const { nodes, showLegend, showTools } = useContext(WorkflowStateContext);
const totalNodes = nodes.reduce((n, node) => n + !node.isDeleted, 0) - 1;
const navToWorkflow = () => {
history.push(
`/templates/workflow_job_template/${job.unified_job_template}/visualizer`
);
};
return (
<Toolbar id="workflow-output-toolbar">
<ToolbarJob>
@ -70,6 +79,15 @@ function WorkflowOutputToolbar({ job }) {
<b>{job.name}</b>
</ToolbarJob>
<ToolbarActions>
<ActionButton
ouiaId="edit-workflow"
aria-label={t`Edit workflow`}
id="edit-workflow"
variant="plain"
onClick={navToWorkflow}
>
<ProjectDiagramIcon />
</ActionButton>
<div>{t`Total Nodes`}</div>
<Badge isRead>{totalNodes}</Badge>
<Tooltip content={t`Toggle Legend`} position="bottom">

View File

@ -18,6 +18,9 @@ const workflowContext = {
showTools: false,
};
function shouldFind(element) {
expect(wrapper.find(element)).toHaveLength(1);
}
describe('WorkflowOutputToolbar', () => {
beforeAll(() => {
const nodes = [
@ -45,6 +48,13 @@ describe('WorkflowOutputToolbar', () => {
wrapper.unmount();
});
test('should render correct toolbar item', () => {
shouldFind(`Button[ouiaId="edit-workflow"]`);
shouldFind('Button#workflow-output-toggle-legend');
shouldFind('Badge');
shouldFind('Button#workflow-output-toggle-tools');
});
test('Shows correct number of nodes', () => {
// The start node (id=1) and deleted nodes (isDeleted=true) should be ignored
expect(wrapper.find('Badge').text()).toBe('1');