Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#106 Document group lists filtering and styling #139

Merged
merged 2 commits into from
Feb 4, 2021
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
14 changes: 1 addition & 13 deletions src/components/AnnotationCard/AnnotationCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ function AnnotationCard({
const annotationSaveButton = annotationMatchesCurrentFilters() ? saveButton : (
<OverlayTrigger
overlay={(
<Tooltip id="tooltip-annotation-info">
<Tooltip className="styled-tooltip">
<strong>Note:</strong>
{' '}
Filters applied to this document may exclude
Expand Down Expand Up @@ -735,18 +735,6 @@ function AnnotationCard({
</Card>
<style jsx global>
{`
#tooltip-annotation-info .tooltip-inner {
font-size: 12px;
background-color: #f6f6f6;
color: black;
border: 1px solid rgba(0, 0, 0, 0.125);
}
#tooltip-annotation-info .arrow {
background-color: transparent;
}
#tooltip-annotation-info .arrow::before {
border-top-color: rgba(0, 0, 0, 0.125);
}
.truncated-annotation, .truncated-annotation .text-quote {
overflow: hidden;
text-overflow: ellipsis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import {
Badge, Button, Card, Col, ListGroup, Row, Tab, Tabs,
Badge, Button, Card, Col, ListGroup, OverlayTrigger, Row, Tab, Tabs, Tooltip,
} from 'react-bootstrap';
import { Plus } from 'react-bootstrap-icons';
import { format } from 'date-fns';
import LoadingSpinner from '../../LoadingSpinner';
import { getSharedDocumentsByGroup, getDocumentsByUser } from '../../../utils/docUtil';
import { getGroupNameById } from '../../../utils/groupUtil';
import { getGroupNameById, filterGroupIdsByUser } from '../../../utils/groupUtil';

const DashboardDocumentList = ({
session,
Expand Down Expand Up @@ -98,15 +99,33 @@ const DashboardDocumentList = ({
<Link href={`/documents/${document.slug}`}>{document.title}</Link>
</Col>
<Col className="text-right">
{document.groups && document.groups.length > 0 && (
{session && session.user.groups && document.groups
&& filterGroupIdsByUser(document.groups, session.user.groups).length > 0 && (
<Badge
variant="info"
key={document.groups.sort()[0]}
key={filterGroupIdsByUser(document.groups, session.user.groups).sort()[0]}
className="mr-2"
>
{documentGroupState[document.groups.sort()[0]]}
{documentGroupState[filterGroupIdsByUser(document.groups, session.user.groups)
.sort()[0]]}
</Badge>
)}
{document.groups && session && session.user.groups
&& filterGroupIdsByUser(document.groups, session.user.groups).length > 1 && (
<OverlayTrigger
overlay={(
<Tooltip className="styled-tooltip">
Shared with additional groups
</Tooltip>
)}
placement="top"
>
<Plus
className="mr-1 ml-n1 mb-1"
title="Tooltip on left"
/>
</OverlayTrigger>
)}
<>
{format(new Date(document.createdAt), 'MM/dd/yyyy')}
</>
Expand Down
7 changes: 4 additions & 3 deletions src/components/DocumentList/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'react-bootstrap-icons';
import { format } from 'date-fns';
import LoadingSpinner from '../LoadingSpinner';
import { getGroupNameById } from '../../utils/groupUtil';
import { getGroupNameById, filterGroupIdsByUser } from '../../utils/groupUtil';
import { deleteDocumentById } from '../../utils/docUtil';
import ConfirmationDialog from '../ConfirmationDialog';
import { ucFirst } from '../../utils/stringUtil';
Expand All @@ -27,6 +27,7 @@ const DocumentList = ({
userId,
alerts,
setAlerts,
userGroups,
}) => {
const [groupState, setGroupState] = useState({});
const [showModal, setShowModal] = useState('');
Expand Down Expand Up @@ -114,8 +115,8 @@ const DocumentList = ({
{format(new Date(document.createdAt), 'MM/dd/yyyy')}
</td>
<td>
{(document.groups && document.groups.length > 0)
? document.groups.sort().map((group) => (
{(document.groups && document.groups.length > 0 && userGroups)
? filterGroupIdsByUser(document.groups, userGroups).sort().map((group) => (
<Badge
variant="info"
className="mr-1"
Expand Down
1 change: 1 addition & 0 deletions src/pages/documents/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const DocumentsIndex = ({
setAlerts={setAlerts}
loading={listLoading}
setLoading={setListLoading}
userGroups={session.user.groups}
userId={session.user.id}
/>
)}
Expand Down
15 changes: 15 additions & 0 deletions src/style/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,20 @@ ol.breadcrumb {
}
}

.styled-tooltip {
.tooltip-inner {
font-size: 12px;
background-color: #f6f6f6;
color: black;
border: 1px solid rgba(0, 0, 0, 0.125);
}
.arrow {
background-color: transparent;
}
.arrow::before {
border-top-color: rgba(0, 0, 0, 0.125) !important;
}
}

/* import bootstrap */
@import "~bootstrap/scss/bootstrap";
9 changes: 9 additions & 0 deletions src/utils/groupUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,22 @@ const getGroupById = async (id) => {
return Promise.resolve(res.json());
} return Promise.reject(Error(`Unable to get group ${id}: error ${res.status} received from server`));
};

const filterGroupIdsByUser = (groupIds, userGroups) => {
if (userGroups) {
const filtered = userGroups.filter((grp) => groupIds.includes(grp.id));
return filtered.map((grp) => grp.id);
} return [];
};

export {
addGroupToUser,
addUserToGroup,
changeUserRole,
deleteGroup,
deleteGroupById,
deleteInviteToken,
filterGroupIdsByUser,
generateInviteToken,
getGroupById,
getGroupNameById,
Expand Down