Hide edit button on workflow node details view for users that don't have the ability to edit the workflow

This commit is contained in:
mabashian
2020-09-09 09:44:09 -04:00
parent 945dfbb648
commit 19886f7ec3
3 changed files with 50 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ function getNodeType(node) {
} }
} }
function NodeViewModal({ i18n }) { function NodeViewModal({ i18n, readOnly }) {
const dispatch = useContext(WorkflowDispatchContext); const dispatch = useContext(WorkflowDispatchContext);
const { nodeToView } = useContext(WorkflowStateContext); const { nodeToView } = useContext(WorkflowStateContext);
const { unifiedJobTemplate } = nodeToView; const { unifiedJobTemplate } = nodeToView;
@@ -136,15 +136,20 @@ function NodeViewModal({ i18n }) {
title={unifiedJobTemplate.name} title={unifiedJobTemplate.name}
aria-label={i18n._(t`Workflow node view modal`)} aria-label={i18n._(t`Workflow node view modal`)}
onClose={() => dispatch({ type: 'SET_NODE_TO_VIEW', value: null })} onClose={() => dispatch({ type: 'SET_NODE_TO_VIEW', value: null })}
actions={[ actions={
<Button readOnly
key="edit" ? []
aria-label={i18n._(t`Edit Node`)} : [
onClick={handleEdit} <Button
> id="node-view-edit-button"
{i18n._(t`Edit`)} key="edit"
</Button>, aria-label={i18n._(t`Edit Node`)}
]} onClick={handleEdit}
>
{i18n._(t`Edit`)}
</Button>,
]
}
> >
{Content} {Content}
</Modal> </Modal>

View File

@@ -168,6 +168,40 @@ describe('NodeViewModal', () => {
wrapper.unmount(); wrapper.unmount();
jest.clearAllMocks(); jest.clearAllMocks();
}); });
test('edit button shoud be shown when readOnly prop is false', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<WorkflowStateContext.Provider value={workflowContext}>
<NodeViewModal />
</WorkflowStateContext.Provider>
</WorkflowDispatchContext.Provider>
);
});
waitForLoaded(wrapper);
expect(wrapper.find('Button#node-view-edit-button').length).toBe(1);
wrapper.unmount();
jest.clearAllMocks();
});
test('edit button shoud be hidden when readOnly prop is true', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<WorkflowStateContext.Provider value={workflowContext}>
<NodeViewModal readOnly />
</WorkflowStateContext.Provider>
</WorkflowDispatchContext.Provider>
);
});
waitForLoaded(wrapper);
expect(wrapper.find('Button#node-view-edit-button').length).toBe(0);
wrapper.unmount();
jest.clearAllMocks();
});
}); });
describe('Project node', () => { describe('Project node', () => {

View File

@@ -460,7 +460,7 @@ function Visualizer({ template, i18n }) {
/> />
)} )}
{showDeleteAllNodesModal && <DeleteAllNodesModal />} {showDeleteAllNodesModal && <DeleteAllNodesModal />}
{nodeToView && <NodeViewModal />} {nodeToView && <NodeViewModal readOnly={readOnly} />}
</WorkflowDispatchContext.Provider> </WorkflowDispatchContext.Provider>
</WorkflowStateContext.Provider> </WorkflowStateContext.Provider>
); );