From d1684cb18e7c12f4e85f12b5e47de9e4f91edef7 Mon Sep 17 00:00:00 2001 From: Abbey Reisle Date: Wed, 2 Feb 2022 13:28:08 -0800 Subject: [PATCH] fix: allow readonly user to swap to graph view closes #28 --- .../RecordForm/__tests__/index.test.js | 2 +- src/components/RecordForm/index.js | 3 +++ .../__tests__/index.test.js | 1 + src/components/RecordFormStateToggle/index.js | 18 ++++++++++++------ .../StatementForm/__tests__/index.test.js | 2 +- src/components/StatementForm/index.js | 1 + src/views/RecordView/index.js | 14 ++------------ 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/RecordForm/__tests__/index.test.js b/src/components/RecordForm/__tests__/index.test.js index ea802a73c..1bbb9acfd 100644 --- a/src/components/RecordForm/__tests__/index.test.js +++ b/src/components/RecordForm/__tests__/index.test.js @@ -9,7 +9,7 @@ import * as api from '@/services/api'; import RecordForm from '..'; -const auth = { user: { '@rid': '23:9' } }; +const auth = { user: { '@rid': '23:9' }, hasWriteAccess: true }; jest.mock('@/services/api', () => { const mockRequest = () => ({ diff --git a/src/components/RecordForm/index.js b/src/components/RecordForm/index.js index 173ac04dc..213052136 100644 --- a/src/components/RecordForm/index.js +++ b/src/components/RecordForm/index.js @@ -21,6 +21,7 @@ import { cleanPayload, FORM_VARIANT } from '@/components/util'; import api from '@/services/api'; import schema from '@/services/schema'; +import { useAuth } from '../Auth'; import EdgeTable from './EdgeTable'; import RelatedStatementsTable from './RelatedStatementsTable'; import RelatedVariantsTable from './RelatedVariantsTable'; @@ -49,6 +50,7 @@ const RecordForm = ({ ...rest }) => { const snackbar = useSnackbar(); + const auth = useAuth(); const [actionInProgress, setActionInProgress] = useState(false); const controllers = useRef([]); @@ -199,6 +201,7 @@ const RecordForm = ({
{onTopClick && (variant === FORM_VARIANT.VIEW || variant === FORM_VARIANT.EDIT) && ( { beforeEach(() => { ({ getByText } = render(( View - - Edit - + {allowEdit && ( + + Edit + + )} {requireConfirm && ( {}, + allowEdit: false, requireConfirm: false, message: 'Are you sure?', value: 'view', diff --git a/src/components/StatementForm/__tests__/index.test.js b/src/components/StatementForm/__tests__/index.test.js index a1ac8dcbc..a0f74358f 100644 --- a/src/components/StatementForm/__tests__/index.test.js +++ b/src/components/StatementForm/__tests__/index.test.js @@ -9,7 +9,7 @@ import { AuthContext } from '@/components/Auth'; import StatementForm from '..'; -const auth = { user: { '@rid': '23:9' } }; +const auth = { user: { '@rid': '23:9' }, hasWriteAccess: true }; jest.mock('@/services/api', () => { const mockRequest = () => ({ diff --git a/src/components/StatementForm/index.js b/src/components/StatementForm/index.js index e9e8dfca3..559c9c6ff 100644 --- a/src/components/StatementForm/index.js +++ b/src/components/StatementForm/index.js @@ -314,6 +314,7 @@ const StatementForm = ({ {civicEvidenceId && } {onTopClick && (variant === FORM_VARIANT.VIEW || variant === FORM_VARIANT.EDIT) && ( { const { history, match: { path, params: { rid, modelName: modelNameParam, variant } } } = props; - const auth = useAuth(); const [recordContent, setRecordContent] = useState({}); const [modelName, setModelName] = useState(modelNameParam || ''); @@ -164,11 +162,7 @@ const RecordView = (props) => { navigateToGraph={navigateToGraphView} onError={handleError} onSubmit={handleSubmit} - onTopClick={ - auth.hasWriteAccess - ? onTopClick - : null - } + onTopClick={onTopClick} rid={rid} title={DEFAULT_TITLES[variant].replace(':modelName', 'Statement')} value={recordContent} @@ -182,11 +176,7 @@ const RecordView = (props) => { navigateToGraph={navigateToGraphView} onError={handleError} onSubmit={handleSubmit} - onTopClick={ - auth.hasWriteAccess - ? onTopClick - : null - } + onTopClick={onTopClick} rid={rid} title={DEFAULT_TITLES[variant].replace(':modelName', modelName)} value={recordContent}