Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions specifyweb/frontend/js_src/lib/components/Forms/DataTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { useSearchParameter } from '../../hooks/navigation';
import { RA } from '../../utils/types';
import { State } from 'typesafe-reducer';
import { LoadingContext } from '../Core/Contexts';
import { useCachedState } from '../../hooks/useCachedState';
import { Dialog } from '../Molecules/Dialog';
import { commonText } from '../../localization/common';
import { userText } from '../../localization/user';

export function ViewRecordSet(): JSX.Element {
const { id, index } = useParams();
Expand Down Expand Up @@ -80,9 +84,17 @@ function DisplayRecordSet({
}: {
readonly recordSet: SpecifyResource<RecordSet>;
readonly resourceIndex: number;
}): null {
}): null | JSX.Element {
const [recordToOpen] = usePref('form', 'recordSet', 'recordToOpen');
const navigate = useNavigate();

const [isReadOnly = false] = useCachedState(
'forms',
'readOnlyMode'
);

const [readOnlyState, setReadOnlyState] = React.useState(false);

useAsyncState(
React.useCallback(
async () =>
Expand All @@ -92,6 +104,7 @@ function DisplayRecordSet({
orderBy: recordToOpen === 'first' ? 'id' : '-id',
limit: 1,
}).then(({ records }) =>
isReadOnly === true && records.length === 0 ? setReadOnlyState(true) :
navigate(
formatUrl(
getResourceViewUrl(
Expand All @@ -104,12 +117,20 @@ function DisplayRecordSet({
replace: true,
}
)

),
[recordSet, resourceIndex, recordToOpen]
),
true
);
return null;
return readOnlyState ?
<>
<Dialog
buttons={commonText.close()}
header={userText.permissionDeniedError()}
onClose={(): void => navigate('/specify/')}
>{userText.emptyRecordSetsReadOnly()}</Dialog>
</> : null;
}

/** Begins the process of creating a new resource */
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/frontend/js_src/lib/localization/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ export const resourcesText = createDictionary({
selectResourceType: {
'en-us': 'Select Resource Type',
'ru-ru': 'Выберите тип ресурса',
},
}
} as const);
3 changes: 3 additions & 0 deletions specifyweb/frontend/js_src/lib/localization/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ export const userText = createDictionary({
следующих действий:
`,
},
emptyRecordSetsReadOnly: {
'en-us': `Cannot open empty Record Set when in Read-Only mode`
},
permissionDeniedForUrl: {
'en-us': 'Permission denied when accessing <url />',
'ru-ru': 'Разрешение не было дано при доступе к <url />',
Expand Down