mirror of
https://github.com/ansible/awx.git
synced 2026-01-24 16:01:20 -03: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:
parent
945dfbb648
commit
19886f7ec3
@ -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>
|
||||
|
||||
@ -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', () => {
|
||||
|
||||
@ -460,7 +460,7 @@ function Visualizer({ template, i18n }) {
|
||||
/>
|
||||
)}
|
||||
{showDeleteAllNodesModal && <DeleteAllNodesModal />}
|
||||
{nodeToView && <NodeViewModal />}
|
||||
{nodeToView && <NodeViewModal readOnly={readOnly} />}
|
||||
</WorkflowDispatchContext.Provider>
|
||||
</WorkflowStateContext.Provider>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user