-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[F] Add bulk delete UI to users; wire up for users/rgs/annotations
- Loading branch information
Showing
7 changed files
with
238 additions
and
99 deletions.
There are no files selected for viewing
120 changes: 54 additions & 66 deletions
120
client/src/backend/components/list/EntitiesList/Entity/UserRow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.