Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overridable: allow overridable administration views #872

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion invenio_communities/administration/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
<OverridableContext.Provider value={overridenComponents}>
<OverridableContext.Provider
value={{ ...defaultComponents, ...overriddenComponents }}
>
<AdminDetailsView
title={title}
actions={actions}
Expand All @@ -63,6 +53,7 @@ domContainer &&
resourceSchema={resourceSchema}
requestHeaders={requestHeaders}
uiSchema={uiSchema}
appName={appName}
>
<FeaturedEntries />
</AdminDetailsView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
{% extends "invenio_administration/search.html" %}

{% block javascript %}
{{ super() }}
{{ webpack['invenio-communities-admin-search.js'] }}
{% endblock %}