Skip to content

Commit

Permalink
[F] Add bulk delete UI to users; wire up for users/rgs/annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
1aurend committed Dec 12, 2024
1 parent 11ebf48 commit 2fe11c7
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 99 deletions.
120 changes: 54 additions & 66 deletions client/src/backend/components/list/EntitiesList/Entity/UserRow.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,63 @@
import React, { PureComponent } from "react";
import React from "react";
import PropTypes from "prop-types";
import { withTranslation } from "react-i18next";
import { useTranslation } from "react-i18next";
import lh from "helpers/linkHandler";
import EntityThumbnail from "global/components/entity-thumbnail";
import EntityRow from "./Row";

class UserRow extends PureComponent {
static displayName = "EntitiesList.Entity.UserRow";

static propTypes = {
entity: PropTypes.object,
currentUserId: PropTypes.string,
active: PropTypes.string,
t: PropTypes.func
import Checkbox from "../List/bulkActions/Checkbox";
import { useCurrentUser } from "hooks";

function UserRow({
entity,
bulkActionsActive,
bulkSelection,
addItem,
removeItem,
...props
}) {
const { t } = useTranslation();
const currentUser = useCurrentUser();

const { id, attributes } = entity;

const isSelected =
!!bulkSelection?.filters || bulkSelection?.ids?.includes(id);

const additionalProps = {
title: `${attributes.firstName} ${attributes.lastName}`,
figure: <EntityThumbnail.User entity={entity} />,
figureSize: "small",
figureShape: "circle",
label: [
{ text: t(`records.users.role_options.${attributes.role}`), level: "" },
...(id === currentUser.id
? [
{
text: t("common.you"),
level: "notice"
}
]
: [])
],
onRowClick: lh.link("backendRecordsUser", id),
rowClickMode: "block",
prepend: bulkActionsActive && (
<Checkbox
checked={isSelected}
onSelect={() => addItem(id)}
onClear={() => removeItem(id)}
/>
)
};

get entity() {
return this.props.entity;
}

get attributes() {
return this.entity.attributes;
}

get role() {
return (
<>
{this.isCurrentUser(this.id)}
{this.attributes.role
? this.props.t(`records.users.role_options.${this.attributes.role}`)
: null}
</>
);
}

get name() {
const { firstName, lastName } = this.attributes;
return `${firstName} ${lastName}`;
}

get id() {
return this.entity.id;
}

get active() {
return this.props.active === this.id;
}
return <EntityRow {...props} {...additionalProps} />;
}

isCurrentUser(id) {
let output = "";
if (this.props.currentUserId === id) {
output = <span className="specifier">{this.props.t("common.you")}</span>;
}
return output;
}
UserRow.displayName = "EntitiesList.Entity.UserRow";

render() {
return (
<EntityRow
{...this.props}
onRowClick={lh.link("backendRecordsUser", this.id)}
rowClickMode="block"
title={this.name}
figure={<EntityThumbnail.User entity={this.entity} />}
figureSize={"small"}
figureShape={"circle"}
label={this.role}
active={this.active}
/>
);
}
}
UserRow.propTypes = {
entity: PropTypes.object,
currentUserId: PropTypes.string
};

export default withTranslation()(UserRow);
export default UserRow;
30 changes: 24 additions & 6 deletions client/src/backend/containers/annotations/List.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from "react";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { annotationsAPI } from "api";
import { annotationsAPI, bulkDeleteAPI } from "api";
import EntitiesList, {
Search,
AnnotationRow
} from "backend/components/list/EntitiesList";
import { useFetch, useApiCallback, useListQueryParams } from "hooks";
import {
useFetch,
useApiCallback,
useListQueryParams,
useNotification
} from "hooks";
import withFilteredLists, { annotationFilters } from "hoc/withFilteredLists";
import withConfirmation from "hoc/withConfirmation";
import PageHeader from "backend/components/layout/PageHeader";
Expand Down Expand Up @@ -59,12 +64,23 @@ function AnnotationsList({
bulkSelectionEmpty
);

const bulkDelete = useApiCallback(annotationsAPI.bulkDelete);
const bulkDelete = useApiCallback(bulkDeleteAPI.annotations);

const unit = t("glossary.annotation", {
count: meta?.pagination?.totalCount
});

const notifyBulkDelete = useNotification(count => ({
level: 0,
id: "BULK_DELETE_SUCCESS",
heading: t("notifications.bulk_delete_success"),
body: t("notifications.bulk_delete_success_body", {
count,
entity: t("glossary.annotation", { count })
}),
expiration: 5000
}));

const onBulkDelete = () => {
const count = bulkSelection.filters
? meta?.pagination?.totalCount
Expand All @@ -74,10 +90,12 @@ function AnnotationsList({
if (confirm)
confirm(heading, message, async () => {
const params = bulkSelection.filters
? { filters: bulkSelection.filters }
: { annotationIds: bulkSelection.ids };
await bulkDelete(params);
? { filters: bulkSelection.filters, ids: [] }
: { filters: {}, ids: bulkSelection.ids };
const res = await bulkDelete(params);
notifyBulkDelete(res.bulk_deletions.total);
refresh();
resetBulkSelection();
});
};

Expand Down
29 changes: 24 additions & 5 deletions client/src/backend/containers/reading-group/Annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import lh from "helpers/linkHandler";
import { childRoutes } from "helpers/router";
import { readingGroupsAPI, annotationsAPI } from "api";
import { readingGroupsAPI, bulkDeleteAPI } from "api";
import { withRouter } from "react-router-dom";
import { useFetch, useApiCallback, useListQueryParams } from "hooks";
import {
useFetch,
useApiCallback,
useListQueryParams,
useNotification
} from "hooks";
import EntitiesList, {
Search,
AnnotationRow
Expand Down Expand Up @@ -66,12 +71,23 @@ function ReadingGroupAnnotationsContainer({
bulkSelectionEmpty
);

const bulkDelete = useApiCallback(annotationsAPI.bulkDelete);
const bulkDelete = useApiCallback(bulkDeleteAPI.annotations);

const unit = t("glossary.annotation", {
count: meta?.pagination?.totalCount
});

const notifyBulkDelete = useNotification(count => ({
level: 0,
id: "BULK_DELETE_SUCCESS",
heading: t("notifications.bulk_delete_success"),
body: t("notifications.bulk_delete_success_body", {
count,
entity: t("glossary.annotation", { count })
}),
expiration: 5000
}));

const onBulkDelete = () => {
const count = bulkSelection.filters
? meta?.pagination?.totalCount
Expand All @@ -81,10 +97,13 @@ function ReadingGroupAnnotationsContainer({
if (confirm)
confirm(heading, message, async () => {
const params = bulkSelection.filters
? { filters: bulkSelection.filters }
: { annotationIds: bulkSelection.ids };
? { filters: bulkSelection.filters, ids: [] }
: { filters: {}, ids: bulkSelection.ids };
await bulkDelete(params);
const res = await bulkDelete(params);
notifyBulkDelete(res.bulk_deletions.total);
refresh();
resetBulkSelection();
});
};

Expand Down
30 changes: 24 additions & 6 deletions client/src/backend/containers/reading-groups/List.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from "react";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { readingGroupsAPI } from "api";
import { readingGroupsAPI, bulkDeleteAPI } from "api";
import EntitiesList, {
Search,
ReadingGroupRow
} from "backend/components/list/EntitiesList";
import { useFetch, useApiCallback, useListQueryParams } from "hooks";
import {
useFetch,
useApiCallback,
useListQueryParams,
useNotification
} from "hooks";
import withFilteredLists, { readingGroupFilters } from "hoc/withFilteredLists";
import withConfirmation from "hoc/withConfirmation";
import {
Expand Down Expand Up @@ -67,7 +72,18 @@ function ReadingGroupsList({
});
};

const bulkDelete = useApiCallback(readingGroupsAPI.bulkDelete);
const bulkDelete = useApiCallback(bulkDeleteAPI.readingGroups);

const notifyBulkDelete = useNotification(count => ({
level: 0,
id: "BULK_DELETE_SUCCESS",
heading: t("notifications.bulk_delete_success"),
body: t("notifications.bulk_delete_success_body", {
count,
entity: t("glossary.reading_group", { count })
}),
expiration: 5000
}));

const unit = t("glossary.reading_group", {
count: meta?.pagination?.totalCount
Expand All @@ -82,10 +98,12 @@ function ReadingGroupsList({
if (confirm)
confirm(heading, message, async () => {
const params = bulkSelection.filters
? { filters: bulkSelection.filters }
: { annotationIds: bulkSelection.ids };
await bulkDelete(params);
? { filters: bulkSelection.filters, ids: [] }
: { filters: {}, ids: bulkSelection.ids };
const res = await bulkDelete(params);
notifyBulkDelete(res.bulk_deletions.total);
refresh();
resetBulkSelection();
});
};

Expand Down
Loading

0 comments on commit 2fe11c7

Please sign in to comment.