Skip to content

Commit

Permalink
enhancements nih tag access
Browse files Browse the repository at this point in the history
  • Loading branch information
trevlenb2 committed Jun 7, 2024
1 parent c65e6e9 commit 4e15331
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 114 deletions.
70 changes: 58 additions & 12 deletions src/components/Table/ComplexTagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ import { Button, Table } from 'react-bootstrap';
import { useAppSelector } from '../../store/hooks';
import { t } from 'i18next';
import { ComplexTagResponse } from '../../features/planSimulation/providers/types';
import { TagToDelete } from '../../features/tagging/components/ComplexTagging';
import { useKeycloak } from '@react-keycloak/web';
import { TAG_ACCESS_OVERRIDE } from '../../constants';

interface Props {
columns: { name: string; sortValue?: string; accessor: string; key: string }[];
data: ComplexTagResponse[] | undefined;
clickHandler: (identifier: any) => void;
showAccessPanelHandler: (tag: any) => void;
setShowDeleteTagPanel: (show: boolean) => void;
setSelectedTagToDelete: (tag: TagToDelete) => void;
}

//TODO: Complete sorting
const ComplexTagTable = ({ columns, data, clickHandler, showAccessPanelHandler }: Props) => {
const ComplexTagTable = ({
columns,
data,
clickHandler,
showAccessPanelHandler,
setShowDeleteTagPanel,
setSelectedTagToDelete
}: Props) => {
const { keycloak } = useKeycloak();
const isDarkMode = useAppSelector(state => state.darkMode.value);

return (
Expand All @@ -36,7 +49,7 @@ const ComplexTagTable = ({ columns, data, clickHandler, showAccessPanelHandler }
if (el.accessor) {
let val = dataEl[el.accessor];

if (Array.isArray(val) && val.length) {
if (el.accessor === 'complexTagVariables') {
return (
<td key={index}>
<Button onClick={() => clickHandler(dataEl)}>{'View Variables'}</Button>
Expand All @@ -45,19 +58,52 @@ const ComplexTagTable = ({ columns, data, clickHandler, showAccessPanelHandler }
} else if (el.accessor === 'access') {
return (
<td key={index}>
<Button
onClick={() => {
if (el.accessor) {
showAccessPanelHandler(dataEl);
}
}}
>
{'Grant Access'}
</Button>
{dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<Button
onClick={() => {
if (el.accessor) {
showAccessPanelHandler(dataEl);
}
}}
>
{'Grant Access'}
</Button>
) : null}
</td>
);
} else if (el.accessor === 'delete') {
return (
<td key={index}>
{dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<Button
onClick={() => {
if (el.accessor) {
console.log('dataEl', dataEl);
setSelectedTagToDelete({
id: dataEl['id'] as string,
type: 'ComplexTag',
tag: dataEl['tagName'] as string
});
setShowDeleteTagPanel(true);
}
}}
>
{'Delete Tag'}
</Button>
) : null}
</td>
);
}
if (el.accessor === 'owners') {
return (
<td key={index}>
{dataEl['owners'].map((owner: any) => (
<p>{owner.username}</p>
))}
</td>
);
} else {
return <td key={index}>{val.toString()}</td>;
return <td key={index}>{val?.toString()}</td>;
}
}
return null;
Expand Down
43 changes: 40 additions & 3 deletions src/components/Table/EntityTagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { useAppSelector } from '../../store/hooks';
import { formatDate } from '../../utils';
import { t } from 'i18next';
import { TagUpdateRequest } from '../../features/tagging/providers/types';
import { TagToDelete } from '../../features/tagging/components/ComplexTagging';
import { TAG_ACCESS_OVERRIDE } from '../../constants';
import { useKeycloak } from '@react-keycloak/web';

interface Props {
columns: { name: string; sortValue?: string; accessor?: string; key?: string }[];
Expand All @@ -15,6 +18,8 @@ interface Props {
clickAccessor?: string;
updateTag: (tag: TagUpdateRequest) => void;
showAccessPanelHandler: (tag: any) => void;
setShowDeleteTagPanel: (show: boolean) => void;
setSelectedTagToDelete: (tag: TagToDelete) => void;
}

const DATE_FORMATS = [
Expand All @@ -35,12 +40,14 @@ const EntityTagTable = ({
clickHandler,
clickAccessor,
updateTag,
showAccessPanelHandler
showAccessPanelHandler,
setShowDeleteTagPanel,
setSelectedTagToDelete
}: Props) => {
const [sortDirection, setSortDirection] = useState(false);
const [activeSortField, setActiveSortField] = useState('');
const isDarkMode = useAppSelector(state => state.darkMode.value);

const { keycloak } = useKeycloak();
return (
<Table bordered responsive hover variant={isDarkMode ? 'dark' : 'white'}>
<thead className="border border-2">
Expand Down Expand Up @@ -116,7 +123,7 @@ const EntityTagTable = ({
</td>
);
} else if (el.name === 'access') {
return dataEl['aggregate'] ? (
return dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<td key={index}>
<Button
onClick={() => {
Expand All @@ -129,6 +136,36 @@ const EntityTagTable = ({
</Button>
</td>
) : null;
} else if (el.name === 'owners') {
return (
<td key={index}>
{dataEl['owners'].map((owner: any) => (
<p>{owner.username}</p>
))}
</td>
);
} else if (el.accessor === 'delete') {
return (
<td key={index}>
{(dataEl['owner'] && !dataEl['aggregate']) || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<Button
onClick={() => {
if (el.accessor) {
console.log('dataEl', dataEl);
setSelectedTagToDelete({
id: dataEl['identifier'] as string,
type: 'ComplexTag',
tag: dataEl['tag'] as string
});
setShowDeleteTagPanel(true);
}
}}
>
{'Delete Tag'}
</Button>
) : null}
</td>
);
} else {
return <td key={index}>{dataEl[el.accessor]?.toString()}</td>;
}
Expand Down
31 changes: 22 additions & 9 deletions src/components/Table/MetadataEntityTagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const MetadataEntityTagTable = ({ data, setMetadataList, metadataList, columns }
tagAccGrantsUser: entityTag.tagAccGrantsUser,
tagAccGrantsOrganization: entityTag.tagAccGrantsOrganization,
public: entityTag.public,
owners: entityTag.owners,
owner: entityTag.owner,
children: entityTag.children?.map(child => {
return {
tag: child.tag,
Expand All @@ -74,7 +76,9 @@ const MetadataEntityTagTable = ({ data, setMetadataList, metadataList, columns }
created: child.created,
tagAccGrantsUser: child.tagAccGrantsUser,
tagAccGrantsOrganization: child.tagAccGrantsOrganization,
public: child.public
public: child.public,
owners: child.owners,
owner: child.owner
};
})
});
Expand All @@ -95,7 +99,7 @@ const MetadataEntityTagTable = ({ data, setMetadataList, metadataList, columns }
<Table bordered responsive hover {...getTableProps()} variant={isDarkMode ? 'dark' : 'white'}>
<thead className="border border-2">
{headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
<tr {...headerGroup.getHeaderGroupProps()} style={{ backgroundColor: '#edf4fc' }}>
{headerGroup.headers.map(column => {
return (
<th
Expand All @@ -116,17 +120,18 @@ const MetadataEntityTagTable = ({ data, setMetadataList, metadataList, columns }
{rows.map(row => {
prepareRow(row);
return (
<tr {...row.getRowProps()}>
<tr {...row.getRowProps()} style={{ backgroundColor: '#edf4fc' }}>
{row.cells.map(cell => {
const cellData = cell.row.original;
return cell.column.id === 'selected' ? (
<td {...cell.getCellProps()}>
{' '}
<FormCheck
checked={cellData.selected}
disabled={cellData.aggregate}
onChange={evt => setSelected(evt, row.original.identifier)}
/>
{cellData.owner ? (
<FormCheck
checked={cellData.selected}
disabled={cellData.aggregate}
onChange={evt => setSelected(evt, row.original.identifier)}
/>
) : null}
</td>
) : cell.column.id === 'orgGrants' ? (
<td {...cell.getCellProps()}>
Expand Down Expand Up @@ -172,6 +177,14 @@ const MetadataEntityTagTable = ({ data, setMetadataList, metadataList, columns }
<td {...cell.getCellProps()}>{cellData.public ? 'true' : 'false'}</td>
) : cell.column.id === 'aggregate' ? (
<td {...cell.getCellProps()}>{cellData.aggregate ? 'true' : 'false'}</td>
) : cell.column.id === 'owner' ? (
<td {...cell.getCellProps()}>{cellData.owner ? 'true' : 'false'}</td>
) : cell.column.id === 'owners' ? (
<td {...cell.getCellProps()}>
{cellData.owners.map(owner => (
<p>{owner.username}</p>
))}
</td>
) : (
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/Table/MetadataEntityTagTable2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const MetadataEntityTagTable2 = ({ data, setMetadataList, metadataList, columns
tagAccGrantsUser: entityTag.tagAccGrantsUser,
tagAccGrantsOrganization: entityTag.tagAccGrantsOrganization,
public: entityTag.public,
owners: entityTag.owners,
owner: entityTag.owner,
children: entityTag.children?.map(child => {
return {
tag: child.tag,
Expand All @@ -76,7 +78,9 @@ const MetadataEntityTagTable2 = ({ data, setMetadataList, metadataList, columns
created: child.created,
tagAccGrantsUser: child.tagAccGrantsUser,
tagAccGrantsOrganization: child.tagAccGrantsOrganization,
public: child.public
public: child.public,
owners: child.owners,
owner: child.owner
};
})
});
Expand Down
55 changes: 41 additions & 14 deletions src/components/Table/MetadataImportTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Column, Row, useExpanded, useTable } from 'react-table';
import { MetadataFileImportResponse } from '../../features/metaDataImport/type';
import MetadataEntityTagTable from './MetadataEntityTagTable';
import { EntityTagResponse } from '../../features/planSimulation/providers/types';
import { TAG_ACCESS_OVERRIDE } from '../../constants';
import { useKeycloak } from '@react-keycloak/web';

interface Props {
data: MetadataFileImportResponse[];
Expand All @@ -18,7 +20,7 @@ interface Props {

const MetadataImportTable = ({ data, setMetadataList }: Props) => {
const isDarkMode = useAppSelector(state => state.darkMode.value);

const { keycloak } = useKeycloak();
const columnsForMetadataTables = React.useMemo<Column<EntityTagResponse>[]>(
() => [
{
Expand Down Expand Up @@ -54,7 +56,8 @@ const MetadataImportTable = ({ data, setMetadataList }: Props) => {
{ Header: 'tag', accessor: 'tag' },
{ Header: 'type', accessor: 'valueType' },
{ Header: 'aggregate', accessor: 'aggregate' },

{ Header: 'owner', accessor: 'owner' },
{ Header: 'owners', accessor: 'owners' },
{ Header: 'isPublic', accessor: 'public' },
{ Header: 'orgGrants' },
{ Header: 'userGrants' },
Expand Down Expand Up @@ -114,6 +117,8 @@ const MetadataImportTable = ({ data, setMetadataList }: Props) => {
{ Header: 'uploadDate', accessor: 'uploadDatetime' },
{ Header: 'status', accessor: 'status' },
{ Header: 'uploadedBy', accessor: 'uploadedBy' },
{ Header: 'owner', accessor: 'owner' },
{ Header: 'owners', accessor: 'owners' },
{ Header: 'selected', accessor: 'selected' }
],
[]
Expand Down Expand Up @@ -152,6 +157,8 @@ const MetadataImportTable = ({ data, setMetadataList }: Props) => {
tagAccGrantsUser: entityTag.tagAccGrantsUser,
tagAccGrantsOrganization: entityTag.tagAccGrantsOrganization,
public: entityTag.public,
owners: entityTag.owners,
owner: entityTag.owner,
children: entityTag.children?.map(child => {
return {
tag: child.tag,
Expand All @@ -166,7 +173,9 @@ const MetadataImportTable = ({ data, setMetadataList }: Props) => {
created: child.created,
tagAccGrantsUser: child.tagAccGrantsUser,
tagAccGrantsOrganization: child.tagAccGrantsOrganization,
public: child.public
public: child.public,
owners: child.owners,
owner: child.owner
};
})
});
Expand Down Expand Up @@ -210,22 +219,40 @@ const MetadataImportTable = ({ data, setMetadataList }: Props) => {
<>
<tr {...row.getRowProps()}>
{row.cells.map(cell => {
return cell.column.id === 'selected' ? (
<td {...cell.getCellProps()}>
<FormCheck
checked={cell.row.original.selected}
onChange={evt => setSelected(evt, row.original.identifier)}
/>
</td>
) : (
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
);
if (cell.column.id === 'selected') {
return (
<td {...cell.getCellProps()}>
{cell.row.original.owner || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<FormCheck
checked={cell.row.original.selected}
onChange={evt => setSelected(evt, row.original.identifier)}
/>
) : (
''
)}
</td>
);
} else if (cell.column.id === 'owner') {
return <td {...cell.getCellProps()}>{cell.row.original.owner ? 'true' : 'false'}</td>;
} else if (cell.column.id === 'owners') {
return (
<td {...cell.getCellProps()}>
{cell.row.original.owners.map(owner => (
<p>{owner.username}</p>
))}
</td>
);
} else {
return <td {...cell.getCellProps()}>{cell.render('Cell')}</td>;
}
})}
</tr>

{(row as any).isExpanded ? (
<tr>
<td colSpan={row.cells?.length}>{renderRowSubComponent(row)}</td>
<td colSpan={row.cells?.length} style={{ backgroundColor: '#f3f8fc' }}>
{renderRowSubComponent(row)}
</td>
</tr>
) : (
''
Expand Down
3 changes: 3 additions & 0 deletions src/constants/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ export const REVEAL_SIMULATION_EDIT = 'reveal_simulation_edit';

//METADATA IMPORT
export const METADATA_FILE_IMPORT = 'metadata_file_import';

//METADATA IMPORT
export const TAG_ACCESS_OVERRIDE = 'tag_access_override';
Loading

0 comments on commit 4e15331

Please sign in to comment.