Skip to content

Commit

Permalink
Administration: make main components overridable
Browse files Browse the repository at this point in the history
* remove unused components
* add missing translations
* closes: inveniosoftware#102
  • Loading branch information
Pineirin committed Sep 27, 2022
1 parent e62286c commit 4509ee0
Show file tree
Hide file tree
Showing 35 changed files with 652 additions and 661 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// This file is part of InvenioAdministration
// Copyright (C) 2022 CERN.
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";
import isEmpty from "lodash/isEmpty";
import { ResourceActions } from "./ResourceActions";
import { ActionsDropdown } from "./ActionsDropdown";
import { ResourceActions } from ".";
import { ActionsDropdown } from ".";
import { Button, Icon, Popup } from "semantic-ui-react";
import { AdminUIRoutes } from "../routes";
import { DeleteModalTrigger } from "./DeleteModalTrigger";
import { DeleteModalTrigger } from ".";
import { i18next } from "@translations/invenio_administration/i18next";
import Overridable from "react-overridable";

export class Actions extends Component {
class Actions extends Component {
render() {
const {
title,
Expand All @@ -35,86 +42,86 @@ export class Actions extends Component {
const displayAsDropdown =
displayEdit && displayDelete && Object.keys(actions).length > 1;

if (displayAsDropdown) {
return (
<ActionsDropdown
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
displayEdit={displayEdit}
displayDelete={displayDelete}
/>
);
} else {
return (
<Button.Group size="tiny" className="relaxed">
{!isEmpty(actions) && (
<ResourceActions
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
apiEndpoint={apiEndpoint}
/>
)}
{displayEdit && (
<Popup
content={
disabledEditMessage
? disabledEditMessage
: i18next.t("Resource is not editable.")
}
disabled={!disableEdit}
trigger={
<span className="mr-5">
<Button
as="a"
disabled={disableEdit}
href={AdminUIRoutes.editView(listUIEndpoint, resource, idKeyPath)}
icon
labelPosition="left"
title={disabledEditMessage ? disabledEditMessage : ""}
>
<Icon name="pencil" />
{i18next.t("Edit")}
</Button>
</span>
}
/>
)}
{displayDelete && (
<Popup
content={
disabledDeleteMessage
? disabledDeleteMessage
: i18next.t("Resource is not deletable.")
}
disabled={!disableDelete}
trigger={
<span>
<DeleteModalTrigger
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
disabled={disableDelete}
disabledDeleteMessage={
disabledEditMessage ? disabledEditMessage : ""
}
/>
</span>
}
/>
)}
</Button.Group>
);
}
return (
<Overridable id="Actions.layout">
{displayAsDropdown ? (
<ActionsDropdown
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
displayEdit={displayEdit}
displayDelete={displayDelete}
/>
) : (
<Button.Group size="tiny" className="relaxed">
{!isEmpty(actions) && (
<ResourceActions
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
apiEndpoint={apiEndpoint}
/>
)}
{displayEdit && (
<Popup
content={
disabledEditMessage
? disabledEditMessage
: i18next.t("Resource is not editable.")
}
disabled={!disableEdit}
trigger={
<span className="mr-5">
<Button
as="a"
disabled={disableEdit}
href={AdminUIRoutes.editView(listUIEndpoint, resource, idKeyPath)}
icon
labelPosition="left"
title={disabledEditMessage ? disabledEditMessage : ""}
>
<Icon name="pencil" />
{i18next.t("Edit")}
</Button>
</span>
}
/>
)}
{displayDelete && (
<Popup
content={
disabledDeleteMessage
? disabledDeleteMessage
: i18next.t("Resource is not deletable.")
}
disabled={!disableDelete}
trigger={
<span>
<DeleteModalTrigger
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
disabled={disableDelete}
disabledDeleteMessage={
disabledEditMessage ? disabledEditMessage : ""
}
/>
</span>
}
/>
)}
</Button.Group>
)}
</Overridable>
);
}
}

Expand Down Expand Up @@ -153,3 +160,5 @@ Actions.defaultProps = {
apiEndpoint: undefined,
idKeyPath: "pid",
};

export default Overridable.component("Actions", Actions);
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// This file is part of InvenioAdministration
// Copyright (C) 2022 CERN.
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";
import { Dropdown, Button } from "semantic-ui-react";
import { ResourceActions } from "./ResourceActions";
import { ResourceActions } from ".";
import isEmpty from "lodash/isEmpty";
import { i18next } from "@translations/invenio_administration/i18next";
import { DeleteModalTrigger } from "./DeleteModalTrigger";
import { DeleteModalTrigger } from ".";
import Overridable from "react-overridable";

export class ActionsDropdown extends Component {
class ActionsDropdown extends Component {
render() {
const {
title,
Expand All @@ -20,38 +27,40 @@ export class ActionsDropdown extends Component {
actions,
} = this.props;
return (
<Dropdown>
{!isEmpty(actions) && (
<ResourceActions
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
apiEndpoint={apiEndpoint}
Element={Dropdown.Item}
trigger={
<Button
icon="cog"
size="tiny"
className="transparent rel-ml-1"
aria-label={i18next.t("Open list of actions")}
/>
}
/>
)}
{displayEdit && <Dropdown.Item>Edit</Dropdown.Item>}
{displayDelete && (
<DeleteModalTrigger
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
Element={Dropdown.Item}
/>
)}
</Dropdown>
<Overridable id="ActionsDropdown.layout">
<Dropdown>
{!isEmpty(actions) && (
<ResourceActions
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
actions={actions}
apiEndpoint={apiEndpoint}
Element={Dropdown.Item}
trigger={
<Button
icon="cog"
size="tiny"
className="transparent rel-ml-1"
aria-label={i18next.t("Open list of actions")}
/>
}
/>
)}
{displayEdit && <Dropdown.Item>Edit</Dropdown.Item>}
{displayDelete && (
<DeleteModalTrigger
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
resource={resource}
successCallback={successCallback}
idKeyPath={idKeyPath}
Element={Dropdown.Item}
/>
)}
</Dropdown>
</Overridable>
);
}
}
Expand All @@ -72,3 +81,5 @@ ActionsDropdown.defaultProps = {
displayDelete: true,
displayEdit: true,
};

export default Overridable.component("ActionsDropdown", ActionsDropdown);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { NotificationContext } from "../ui_messages/context";
import Overridable from "react-overridable";
import { InvenioAdministrationActionsApi } from "../api/actions";

export class DeleteModal extends Component {
class DeleteModal extends Component {
constructor(props) {
super(props);
this.state = { loading: false, error: undefined };
Expand Down
Loading

0 comments on commit 4509ee0

Please sign in to comment.