mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
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:
@@ -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>
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user