diff --git a/invenio_rdm_records/administration/views/oai.py b/invenio_rdm_records/administration/views/oai.py index e72bdaaee..cc35f3d4b 100644 --- a/invenio_rdm_records/administration/views/oai.py +++ b/invenio_rdm_records/administration/views/oai.py @@ -28,6 +28,7 @@ class OaiPmhListView(AdminResourceListView): pid_path = "id" icon = "exchange" template = "invenio_rdm_records/oai-search.html" + app_id = "InvenioRdmRecords.AdministrationOaipmhListView" display_search = True display_delete = True @@ -58,6 +59,7 @@ class OaiPmhEditView(AdminResourceEditView): pid_path = "id" api_endpoint = "/oaipmh/sets" title = "Edit OAI-PMH set" + app_id = "InvenioRdmRecords.AdministrationOaipmhEditView" list_view_name = "OAI-PMH" @@ -98,6 +100,7 @@ class OaiPmhCreateView(AdminResourceCreateView): pid_path = "id" api_endpoint = "/oaipmh/sets" title = "Create OAI-PMH set" + app_id = "InvenioRdmRecords.AdministrationOaipmhCreateView" list_view_name = "OAI-PMH" @@ -135,7 +138,7 @@ class OaiPmhDetailView(AdminResourceDetailView): name = "OAI-PMH details" resource_config = "oaipmh_server_resource" title = "OAI-PMH Details" - + app_id = "InvenioRdmRecords.AdministrationOaipmhDetailView" template = "invenio_rdm_records/oai-details.html" display_delete = True display_edit = True diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/details/index.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/details/index.js index dd74e92f8..6eaa755e5 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/details/index.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/details/index.js @@ -7,7 +7,7 @@ import React from "react"; import ReactDOM from "react-dom"; import _get from "lodash/get"; -import { OverridableContext, parametrize } from "react-overridable"; +import { OverridableContext, parametrize, overrideStore } from "react-overridable"; import LinksTable from "./LinksTable"; import { AdminDetailsView, Edit, Delete } from "@js/invenio_administration"; import { i18next } from "@translations/invenio_rdm_records/i18next"; @@ -24,17 +24,18 @@ const apiEndpoint = _get(domContainer.dataset, "apiEndpoint"); const idKeyPath = JSON.parse(_get(domContainer.dataset, "pidPath", "pid")); const listUIEndpoint = domContainer.dataset.listEndpoint; const resourceSchema = JSON.parse(domContainer.dataset.resourceSchema); +const appName = JSON.parse(domContainer.dataset.appId); const createdBySystem = (data) => data?.system_created; -const overridenComponents = { - "InvenioAdministration.EditAction": parametrize(Edit, { +const defaultComponents = { + [`${appName}.EditAction`]: parametrize(Edit, { disable: createdBySystem, disabledMessage: i18next.t( "This set is not editable as it was created by the system." ), }), - "InvenioAdministration.DeleteAction": parametrize(Delete, { + [`${appName}.DeleteAction`]: parametrize(Delete, { disable: createdBySystem, disabledMessage: i18next.t( "This set is not deletable as it was created by the system." @@ -42,9 +43,11 @@ const overridenComponents = { }), }; +const overriddenComponents = overrideStore.getAll(); +console.log("asdad appname: ", appName); domContainer && ReactDOM.render( - + diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/SearchResultItem.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/SearchResultItem.js index 4b5116ced..e1df166d7 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/SearchResultItem.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/SearchResultItem.js @@ -10,16 +10,10 @@ import React, { Component } from "react"; import { Table } from "semantic-ui-react"; import isEmpty from "lodash/isEmpty"; import { withState } from "react-searchkit"; -import { Actions, Edit, Delete } from "@js/invenio_administration"; +import { Actions } from "@js/invenio_administration"; import { AdminUIRoutes } from "@js/invenio_administration"; -import { OverridableContext, parametrize } from "react-overridable"; -import { DeleteModal } from "./DeleteModal"; import Formatter from "@js/invenio_administration/src/components/Formatter"; -import { i18next } from "@translations/invenio_rdm_records/i18next"; -const overridenComponents = { - "InvenioAdministration.DeleteModal.layout": DeleteModal, -}; class SearchResultItemComponent extends Component { refreshAfterAction = () => { @@ -62,80 +56,61 @@ class SearchResultItemComponent extends Component { apiEndpoint, idKeyPath, listUIEndpoint, + appName } = this.props; const resourceHasActions = displayEdit || displayDelete || !isEmpty(actions); - overridenComponents["InvenioAdministration.EditAction"] = parametrize( - Edit, - { - disable: () => result.system_created, - disabledMessage: i18next.t( - "This set is not editable as it was created by the system." - ), - } - ); - - overridenComponents["InvenioAdministration.DeleteAction"] = parametrize( - Delete, - { - disable: () => result.system_created, - disabledMessage: i18next.t( - "This set is not deletable as it was created by the system." - ), - } - ); return ( - - - {columns.map(([property, { text, order }], index) => { - return ( - - {index === 0 ? ( - - {this.displayAsPre(result, property)} - - ) : ( - this.displayAsPre(result, property) - )} - - ); - })} - {resourceHasActions && ( - - + + {columns.map(([property, { text, order }], index) => { + return ( + + {index === 0 ? ( + + {this.displayAsPre(result, property)} + + ) : ( + this.displayAsPre(result, property) + )} - )} - - + ); + })} + {resourceHasActions && ( + + + + )} + ); } } @@ -154,6 +129,7 @@ SearchResultItemComponent.propTypes = { idKeyPath: PropTypes.string.isRequired, listUIEndpoint: PropTypes.string.isRequired, resourceSchema: PropTypes.object.isRequired, + appName: PropTypes.string, }; SearchResultItemComponent.defaultProps = { @@ -161,6 +137,7 @@ SearchResultItemComponent.defaultProps = { displayEdit: true, apiEndpoint: undefined, actions: {}, + appName: "", }; export const SearchResultItem = withState(SearchResultItemComponent); diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/index.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/index.js index 2b3601bc9..bb05f05ec 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/index.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/oaipmh/search/index.js @@ -4,15 +4,21 @@ // Invenio RDM 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 { initDefaultSearchComponents } from "@js/invenio_administration"; +import React from "react"; +import { initDefaultSearchComponents, Edit, Delete, DeleteModalTrigger } from "@js/invenio_administration"; import { createSearchAppInit } from "@js/invenio_search_ui"; import { SearchResultItem } from "./SearchResultItem"; -import { parametrize } from "react-overridable"; +import { parametrize, overrideStore } from "react-overridable"; import _get from "lodash/get"; import { NotificationController } from "@js/invenio_administration"; +import { DeleteModal } from "./DeleteModal"; +import { i18next } from "@translations/invenio_rdm_records/i18next"; +import { Popup, Button, Icon } from "semantic-ui-react"; const domContainer = document.getElementById("invenio-search-config"); +const appName = "InvenioRdmRecords.AdministrationOaipmhListView"; + const sortColumns = (columns) => Object.entries(columns).sort((a, b) => a[1].order - b[1].order); const title = JSON.parse(domContainer.dataset.title); @@ -28,7 +34,7 @@ const idKeyPath = JSON.parse(_get(domContainer.dataset, "pidPath", "pid")); const listUIEndpoint = domContainer.dataset.listEndpoint; const resourceSchema = JSON.parse(domContainer.dataset.resourceSchema); -const defaultComponents = initDefaultSearchComponents(domContainer); +const defaultComponents = initDefaultSearchComponents(domContainer, appName); const SearchResultItemWithConfig = parametrize(SearchResultItem, { title: title, resourceName: resourceName, @@ -41,17 +47,113 @@ const SearchResultItemWithConfig = parametrize(SearchResultItem, { idKeyPath: idKeyPath, listUIEndpoint: listUIEndpoint, resourceSchema: resourceSchema, + appName: appName, }); -const overridenComponents = { +const createdBySystem = (data) => data?.system_created; + + +// const EditSet = parametrize( +// Edit, +// { +// disable: createdBySystem, +// disabledMessage: i18next.t( +// "This set is not editable as it was created by the system." +// ), +// // appName: appName, +// } +// ); + +const EditSet = (props) => { + const { display, editUrl, disabled, resource, appName } = props; + const disabledMessage = i18next.t( + "This set is not editable as it was created by the system." + ) + return ( + + + + } + /> + ) +} + +// const DeleteSet = parametrize( +// Delete, +// { +// disable: createdBySystem, +// disabledMessage: i18next.t( +// "This set is not deletable as it was created by the system." +// ), +// appName: appName, +// } +// ); + +const DeleteSet = (props) => { + const { + disable, + title, + resourceName, + successCallback, + idKeyPath, + resource, + appName + } = props + const disabledMessage = i18next.t( + "This set is not deletable as it was created by the system." + ) + return ( + + + + } + /> + ) + +} + + +const overriddenDefaultComponents = { ...defaultComponents, - "ResultsList.item": SearchResultItemWithConfig, + [`${appName}.ResultsList.item`]: SearchResultItemWithConfig, + [`${appName}.EditAction.layout`]: EditSet, + [`${appName}.DeleteAction.layout`]: DeleteSet, + [`${appName}.DeleteModal.layout`]: DeleteModal, }; +const overriddenComponents = overrideStore.getAll(); + createSearchAppInit( - overridenComponents, + { ...overriddenDefaultComponents, ...overriddenComponents }, true, "invenio-search-config", - false, + true, NotificationController );