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

View File

@ -168,6 +168,40 @@ describe('NodeViewModal', () => {
wrapper.unmount();
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', () => {

View File

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