From bc36b60c1165eabb0d8c8b1ad618292575ba5c39 Mon Sep 17 00:00:00 2001 From: Javier Romero Castro Date: Wed, 25 Jan 2023 11:43:46 +0100 Subject: [PATCH] overridable: allow overridable administration views --- .../administration/communities.py | 3 +- .../administration/details.js | 31 +++++++------------ .../administration/search.js | 18 ++++++----- .../administration/community_search.html | 1 + 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/invenio_communities/administration/communities.py b/invenio_communities/administration/communities.py index b08aa9386..572b2cff7 100644 --- a/invenio_communities/administration/communities.py +++ b/invenio_communities/administration/communities.py @@ -28,7 +28,7 @@ class CommunityListView(AdminResourceListView): pid_path = "id" icon = "users" template = "invenio_communities/administration/community_search.html" - + app_id = "InvenioCommunities.AdministrationListView" display_search = True display_delete = False display_create = False @@ -68,6 +68,7 @@ class CommunityDetailView(AdminResourceDetailView): title = "Community" template = "invenio_communities/administration/community_details.html" + app_id = "InvenioCommunities.AdministrationDetailView" display_delete = False display_edit = False diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/details.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/details.js index 65cdbeb04..eea039972 100644 --- a/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/details.js +++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/details.js @@ -8,10 +8,9 @@ import { FeatureModal } from "./FeatureModal"; import React from "react"; import ReactDOM from "react-dom"; import _get from "lodash/get"; -import { OverridableContext, parametrize } from "react-overridable"; +import { OverridableContext, overrideStore } from "react-overridable"; import { FeaturedEntries } from "./featured"; -import { AdminDetailsView, Edit, Delete } from "@js/invenio_administration"; -import { i18next } from "@translations/invenio_communities/i18next"; +import { AdminDetailsView } from "@js/invenio_administration"; const domContainer = document.getElementById("invenio-details-config"); const title = domContainer.dataset.title; @@ -27,28 +26,19 @@ const listUIEndpoint = domContainer.dataset.listEndpoint; const resourceSchema = JSON.parse(domContainer.dataset.resourceSchema); const uiSchema = JSON.parse(domContainer.dataset?.uiConfig); const requestHeaders = JSON.parse(domContainer.dataset?.requestHeaders); +const appName = JSON.parse(domContainer.dataset?.appId); -const createdBySystem = (data) => data?.system_created; - -const overridenComponents = { - "InvenioAdministration.EditAction": parametrize(Edit, { - disable: createdBySystem, - disabledMessage: i18next.t( - "This set is not editable as it was created by the system." - ), - }), - "InvenioAdministration.DeleteAction": parametrize(Delete, { - disable: createdBySystem, - disabledMessage: i18next.t( - "This set is not deletable as it was created by the system." - ), - }), - "InvenioAdministration.ActionModal.layout": FeatureModal, +const defaultComponents = { + [`${appName}.ActionModal.layout`]: FeatureModal, }; +const overriddenComponents = overrideStore.getAll(); + domContainer && ReactDOM.render( - + diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/search.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/search.js index e66ce9029..2bd56a27d 100644 --- a/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/search.js +++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/administration/search.js @@ -7,27 +7,31 @@ import { initDefaultSearchComponents } from "@js/invenio_administration"; import { createSearchAppInit } from "@js/invenio_search_ui"; import { FeatureModal } from "./FeatureModal"; -import { parametrize } from "react-overridable"; +import { parametrize, overrideStore } from "react-overridable"; import { NotificationController, BoolFormatter } from "@js/invenio_administration"; const domContainer = document.getElementById("invenio-search-config"); -const defaultComponents = initDefaultSearchComponents(domContainer); +const appName = "InvenioCommunities.AdministrationListView"; + +const defaultComponents = initDefaultSearchComponents(domContainer, appName); const CustomBoolFormatter = parametrize(BoolFormatter, { icon: "star", color: "yellow", }); -const overridenComponents = { +const overriddenDefaultComponents = { ...defaultComponents, - "InvenioAdministration.BoolFormatter": CustomBoolFormatter, - "InvenioAdministration.ActionModal": FeatureModal, + [`${appName}.BoolFormatter`]: CustomBoolFormatter, + [`${appName}.ActionModal.layout`]: FeatureModal, }; +const overriddenComponents = overrideStore.getAll(); + createSearchAppInit( - overridenComponents, + { ...overriddenDefaultComponents, ...overriddenComponents }, true, "invenio-search-config", - false, + true, NotificationController ); diff --git a/invenio_communities/templates/semantic-ui/invenio_communities/administration/community_search.html b/invenio_communities/templates/semantic-ui/invenio_communities/administration/community_search.html index 39e73de3d..297fe3cad 100644 --- a/invenio_communities/templates/semantic-ui/invenio_communities/administration/community_search.html +++ b/invenio_communities/templates/semantic-ui/invenio_communities/administration/community_search.html @@ -7,5 +7,6 @@ {% extends "invenio_administration/search.html" %} {% block javascript %} + {{ super() }} {{ webpack['invenio-communities-admin-search.js'] }} {% endblock %}