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 9, 2024
1 parent 4e15331 commit 2fdf543
Show file tree
Hide file tree
Showing 13 changed files with 505 additions and 171 deletions.
21 changes: 20 additions & 1 deletion src/components/Table/ComplexTagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props {
data: ComplexTagResponse[] | undefined;
clickHandler: (identifier: any) => void;
showAccessPanelHandler: (tag: any) => void;
showRemoveAccessPanelHandler: (tag: any) => void;
setShowDeleteTagPanel: (show: boolean) => void;
setSelectedTagToDelete: (tag: TagToDelete) => void;
}
Expand All @@ -24,7 +25,8 @@ const ComplexTagTable = ({
clickHandler,
showAccessPanelHandler,
setShowDeleteTagPanel,
setSelectedTagToDelete
setSelectedTagToDelete,
showRemoveAccessPanelHandler
}: Props) => {
const { keycloak } = useKeycloak();
const isDarkMode = useAppSelector(state => state.darkMode.value);
Expand Down Expand Up @@ -71,6 +73,23 @@ const ComplexTagTable = ({
) : null}
</td>
);
} else if (el.accessor === 'removeAccess') {
return (
<td key={index}>
{dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<Button
variant={'outline-primary'}
onClick={() => {
if (el.accessor) {
showRemoveAccessPanelHandler(dataEl);
}
}}
>
{'Remove Access'}
</Button>
) : null}
</td>
);
} else if (el.accessor === 'delete') {
return (
<td key={index}>
Expand Down
89 changes: 82 additions & 7 deletions src/components/Table/EntityTagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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';
import { EntityTagResponse } from '../../features/planSimulation/providers/types';

interface Props {
columns: { name: string; sortValue?: string; accessor?: string; key?: string }[];
Expand All @@ -17,7 +18,8 @@ interface Props {
clickHandler?: (identifier: any) => void;
clickAccessor?: string;
updateTag: (tag: TagUpdateRequest) => void;
showAccessPanelHandler: (tag: any) => void;
showAccessPanelHandler: (tag: EntityTagResponse) => void;
showRemoveAccessPanelHandler: (tag: any) => void;
setShowDeleteTagPanel: (show: boolean) => void;
setSelectedTagToDelete: (tag: TagToDelete) => void;
}
Expand All @@ -42,12 +44,14 @@ const EntityTagTable = ({
updateTag,
showAccessPanelHandler,
setShowDeleteTagPanel,
setSelectedTagToDelete
setSelectedTagToDelete,
showRemoveAccessPanelHandler
}: 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 @@ -128,14 +132,76 @@ const EntityTagTable = ({
<Button
onClick={() => {
if (el.accessor) {
showAccessPanelHandler(dataEl);
console.log(dataEl);
let entityTag = dataEl as EntityTagResponse;

let entitYobj = new EntityTagResponse(
entityTag.identifier,
entityTag.tag,
entityTag.owner,
entityTag.owners,
entityTag.definition,
entityTag.valueType,
entityTag.aggregate,
entityTag.created,
entityTag.metadataImportId,
entityTag.referencedTag,
entityTag.tagAccGrantsOrganization,
entityTag.tagAccGrantsUser,
entityTag.public,
entityTag.children,
entityTag.selected,
entityTag.resultingOrgs,
entityTag.resultingUsers
);

console.log('is it?', entitYobj instanceof EntityTagResponse);
showAccessPanelHandler(entitYobj);
}
}}
>
{'Grant Access'}
</Button>
</td>
) : null;
} else if (el.name === 'removeAccess') {
return dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
<td key={index}>
<Button
variant={'outline-primary'}
onClick={() => {
if (el.accessor) {
console.log(dataEl);
let entityTag = dataEl as EntityTagResponse;

let entitYobj = new EntityTagResponse(
entityTag.identifier,
entityTag.tag,
entityTag.owner,
entityTag.owners,
entityTag.definition,
entityTag.valueType,
entityTag.aggregate,
entityTag.created,
entityTag.metadataImportId,
entityTag.referencedTag,
entityTag.tagAccGrantsOrganization,
entityTag.tagAccGrantsUser,
entityTag.public,
entityTag.children,
entityTag.selected,
entityTag.resultingOrgs,
entityTag.resultingUsers
);

showRemoveAccessPanelHandler(entitYobj);
}
}}
>
{'Remove Access'}
</Button>
</td>
) : null;
} else if (el.name === 'owners') {
return (
<td key={index}>
Expand All @@ -147,21 +213,30 @@ const EntityTagTable = ({
} else if (el.accessor === 'delete') {
return (
<td key={index}>
{(dataEl['owner'] && !dataEl['aggregate']) || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE) ? (
{(dataEl['owner'] || keycloak.hasRealmRole(TAG_ACCESS_OVERRIDE)) && !dataEl['aggregate'] ? (
<Button
disabled={dataEl['deleting']}
onClick={() => {
if (el.accessor) {
console.log('dataEl', dataEl);

setSelectedTagToDelete({
id: dataEl['identifier'] as string,
type: 'ComplexTag',
tag: dataEl['tag'] as string
type: 'SimpleTag',
tag: dataEl['tag'] as string,
children: (dataEl['children'] as EntityTagResponse[]).map(tag => {
return {
id: tag['identifier'] as string,
type: 'SimpleTag',
tag: tag['tag'] as string
};
})
});
setShowDeleteTagPanel(true);
}
}}
>
{'Delete Tag'}
{dataEl['deleting'] ? 'Deleting Tag' : 'Delete Tag'}
</Button>
) : null}
</td>
Expand Down
55 changes: 50 additions & 5 deletions src/components/Table/MetadataEntityTagTable2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ interface Props {
setMetadataList: (list: MetadataFileImportResponse[]) => void;
metadataList: MetadataFileImportResponse[];
columns: Column<BaseTag>[];
addAccess: boolean;
}

const MetadataEntityTagTable2 = ({ data, setMetadataList, metadataList, columns }: Props) => {
const MetadataEntityTagTable2 = ({ data, setMetadataList, metadataList, columns, addAccess }: Props) => {
const isDarkMode = useAppSelector(state => state.darkMode.value);

const mapRows = useCallback((row: BaseTag): EntityTagResponse[] => {
Expand Down Expand Up @@ -154,22 +155,66 @@ const MetadataEntityTagTable2 = ({ data, setMetadataList, metadataList, columns
</Row>
))}
</td>
) : cell.column.id === 'resultingOrgGrants' ? (
) : cell.column.id === 'resultingOrgGrants' || cell.column.id === 'removeOrgGrants' ? (
<td {...cell.getCellProps()}>
{cellData.resultingOrgs?.map(org => (
<Row>
<Col>
<div>{org.name}</div>
{!addAccess ? (
<div
style={{
color: cellData.tagAccGrantsOrganization?.map(user => user.name).includes(org.name)
? 'red'
: ''
}}
>
{org.name}
</div>
) : (
<div
style={{
color: !cellData.tagAccGrantsOrganization?.map(user => user.name).includes(org.name)
? 'green'
: ''
}}
>
{org.name}
</div>
)}
</Col>
</Row>
))}
</td>
) : cell.column.id === 'resultingUserGrants' ? (
) : cell.column.id === 'resultingUserGrants' || cell.column.id === 'removeUserGrants' ? (
<td {...cell.getCellProps()}>
{cellData.resultingUsers?.map(org => (
<Row>
<Col>
<div>{org.username}</div>
{/*<div>{org.username}</div>*/}

{/*{addAccess ? } */}

{!addAccess ? (
<div
style={{
color: cellData.tagAccGrantsUser?.map(user => user.username).includes(org.username)
? 'red'
: ''
}}
>
{org.username}
</div>
) : (
<div
style={{
color: !cellData.tagAccGrantsUser?.map(user => user.username).includes(org.username)
? 'green'
: ''
}}
>
{org.username}
</div>
)}
</Col>
</Row>
))}
Expand Down
101 changes: 101 additions & 0 deletions src/features/access/RemoveTagAccess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Button, Modal } from 'react-bootstrap';
import React, { useEffect, useState } from 'react';
import { BaseTag, EntityTagResponse } from '../planSimulation/providers/types';
import { removeComplexTagGrants, removeEntityTagGrants } from './api';

import TagAccessOrganization from './components/TagAccessOrganization';

interface Props {
showRemoveAccess: boolean;
setShowRemoveAccess: (val: boolean) => void;
selectedMetadata: BaseTag[];
setTagGrantsUpdated: () => void;
type: 'tag' | 'complexTag';
}

const RemoveTagAccess = ({
showRemoveAccess,
setShowRemoveAccess,
selectedMetadata,
setTagGrantsUpdated,
type
}: Props) => {
const [updatedMetadata, setUpdatedMetadata] = useState<BaseTag[]>([]);

useEffect(() => {
setUpdatedMetadata(selectedMetadata);
}, [selectedMetadata]);

return (
<Modal show={showRemoveAccess} centered size={'xl'} onHide={() => setShowRemoveAccess(false)}>
<Modal.Header closeButton>Remove Access To Tags</Modal.Header>
<Modal.Body>
<TagAccessOrganization
metadata={selectedMetadata}
updatedMetadata={updatedMetadata}
setUpdatedMetadata={setUpdatedMetadata}
addAccess={false}
/>
</Modal.Body>
<Modal.Footer>
<Button
variant="secondary"
onClick={() => {
if (type === 'tag') {
const tags = updatedMetadata.map(meta => {
return {
identifier: meta.identifier,
public: meta.public,
resultingOrgs: meta.resultingOrgs,
resultingUsers: meta.resultingUsers
};
});
updatedMetadata
.filter(
updatedMetadataItem =>
updatedMetadataItem &&
updatedMetadataItem instanceof EntityTagResponse &&
(updatedMetadataItem as EntityTagResponse) &&
(updatedMetadataItem as EntityTagResponse).children
)
.forEach(updatedMetadataItem => {
// @ts-ignore
(updatedMetadataItem as EntityTagResponse).children.forEach(child => {
tags.push({
identifier: child.identifier,
public: child.public,
resultingOrgs: child.resultingOrgs,
resultingUsers: child.resultingUsers
});
});
});

removeEntityTagGrants(tags).then(() => {
setTagGrantsUpdated();
});
} else if (type === 'complexTag') {
removeComplexTagGrants(
updatedMetadata.map(meta => {
return {
id: meta.identifier,
public: meta.public,
resultingOrgs: meta.resultingOrgs,
resultingUsers: meta.resultingUsers
};
})
).then(() => {
setTagGrantsUpdated();
});
}
}}
>
submit
</Button>
<Button id="close-button" variant="secondary" onClick={() => setShowRemoveAccess(false)}>
Close
</Button>
</Modal.Footer>
</Modal>
);
};
export default RemoveTagAccess;
Loading

0 comments on commit 2fdf543

Please sign in to comment.