Skip to content

Commit

Permalink
LDAT-64 Get share permissions and show / hide share types
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Jones committed Nov 21, 2024
1 parent 3e91b66 commit 3c671c0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 43 deletions.
98 changes: 57 additions & 41 deletions src/components/NoteShareType/NoteShareTypeDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import ShareTypes from 'constants/shareTypes';
import DataElementWrapper from 'components/DataElementWrapper';
import ShareTypeIcon from '../NoteShareType/ShareTypeIcon';

import { getSharePermissions } from 'helpers/annotationShareType';

import './NoteShareType.scss';

const propTypes = {
Expand All @@ -21,6 +23,8 @@ const NoteShareTypeDialog = forwardRef(({ onClose, onSelect, positionStyle, sele

const preventAutoClose = (e) => e.stopPropagation();

const sharePermissions = getSharePermissions();

return (
<dialog
ref={dialogRef}
Expand All @@ -33,49 +37,61 @@ const NoteShareTypeDialog = forwardRef(({ onClose, onSelect, positionStyle, sele
}}
>
<div className="note-share-type-popup" onClick={preventAutoClose}>
<DataElementWrapper
tabbable
dataElement="notePopupStateAssessor"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ASSESSORS })}
onClick={() => onSelect(ShareTypes.ASSESSORS)}
>
<ShareTypeIcon shareType={ShareTypes.ASSESSORS} />
{t('option.state.assessors')}
</DataElementWrapper>
{/* Assessors */}
{sharePermissions.includes('ASSESSORS') && (
<DataElementWrapper
tabbable
dataElement="notePopupStateAssessor"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ASSESSORS })}
onClick={() => onSelect(ShareTypes.ASSESSORS)}
>
<ShareTypeIcon shareType={ShareTypes.ASSESSORS} />
{t('option.state.assessors')}
</DataElementWrapper>
)}

<DataElementWrapper
tabbable
dataElement="notePopupStateParticipants"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.PARTICIPANTS })}
onClick={() => onSelect(ShareTypes.PARTICIPANTS)}
>
<ShareTypeIcon shareType={ShareTypes.PARTICIPANTS} />
{t('option.state.participants')}
</DataElementWrapper>
{/* Participants */}
{sharePermissions.includes('PARTICIPANTS') && (
<DataElementWrapper
tabbable
dataElement="notePopupStateParticipants"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.PARTICIPANTS })}
onClick={() => onSelect(ShareTypes.PARTICIPANTS)}
>
<ShareTypeIcon shareType={ShareTypes.PARTICIPANTS} />
{t('option.state.participants')}
</DataElementWrapper>
)}

<DataElementWrapper
tabbable
dataElement="notePopupStateAll"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ALL })}
onClick={() => onSelect(ShareTypes.ALL)}
>
<ShareTypeIcon shareType={ShareTypes.ALL} />
{t('option.state.all')}
</DataElementWrapper>
{/* All */}
{sharePermissions.includes('ALL') && (
<DataElementWrapper
tabbable
dataElement="notePopupStateAll"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ALL })}
onClick={() => onSelect(ShareTypes.ALL)}
>
<ShareTypeIcon shareType={ShareTypes.ALL} />
{t('option.state.all')}
</DataElementWrapper>
)}

<DataElementWrapper
tabbable
dataElement="notePopupStateAssessors"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.NONE })}
onClick={() => onSelect(ShareTypes.NONE)}
>
<ShareTypeIcon shareType={ShareTypes.NONE} />
{t('option.state.none')}
</DataElementWrapper>
{/* None */}
{sharePermissions.includes('NONE') && (
<DataElementWrapper
tabbable
dataElement="notePopupStateAssessors"
type="button"
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.NONE })}
onClick={() => onSelect(ShareTypes.NONE)}
>
<ShareTypeIcon shareType={ShareTypes.NONE} />
{t('option.state.none')}
</DataElementWrapper>
)}
</div>
</dialog>
);
Expand All @@ -84,4 +100,4 @@ const NoteShareTypeDialog = forwardRef(({ onClose, onSelect, positionStyle, sele
NoteShareTypeDialog.displayName = 'NoteShareTypeDialog';
NoteShareTypeDialog.propTypes = propTypes;

export default NoteShareTypeDialog;
export default NoteShareTypeDialog;
12 changes: 11 additions & 1 deletion src/helpers/annotationShareType.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ const setAnnotationShareType = (annot, shareType) => {
return annot;
};

export { getAnnotationShareType, setAnnotationShareType };
/**
* Get share permissions
* @returns {string[]} sharingPermissions
*/

const getSharePermissions = () => {
const { sharingPermissions } = getWiseflowCustomValues();
return sharingPermissions;
};

export { getAnnotationShareType, setAnnotationShareType, getSharePermissions };
4 changes: 3 additions & 1 deletion src/helpers/getWiseflowCustomValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import ShareTypes from 'src/constants/shareTypes';
* @returns {WiseflowCustomValues}
* @returns {string} defaultShareType (default: ShareTypes.NONE)
* @returns {boolean} showShareType (default: true)
* @returns {string[]} sharingPermissions (default: [])
*/
const getWiseflowCustomValues = () => {
return {
// Defaults
defaultShareType: ShareTypes.NONE,
showShareType: true,
...JSON.parse(getCustomData())
sharingPermissions: ['NONE', 'PARTICIPANTS', 'ASSESSORS', 'ALL'],
...JSON.parse(getCustomData()),
};
};

Expand Down

0 comments on commit 3c671c0

Please sign in to comment.