Skip to content

Commit

Permalink
overridable: enable components to be overriden
Browse files Browse the repository at this point in the history
* namespaces search apps
* closes inveniosoftware/invenio-app-rdm#2018
  • Loading branch information
jrcastro2 authored and kpsherva committed Jan 26, 2023
1 parent dd1f0ae commit 53815c2
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import React from "react";
import ReactDOM from "react-dom";
import CommunitiesCarousel from "./CommunitiesCarousel";
import { OverridableContext } from "react-overridable";
import { overriddenComponents } from "./override";
import { OverridableContext, overrideStore } from "react-overridable";

const communitiesCarouselContainer = document.getElementById("communities-carousel");
const title = communitiesCarouselContainer.dataset.title;
Expand All @@ -18,6 +17,8 @@ const intervalDelay = parseInt(communitiesCarouselContainer.dataset.intervalDela
const animationSpeed = parseInt(communitiesCarouselContainer.dataset.animationSpeed);
const defaultLogo = communitiesCarouselContainer.dataset.defaultLogo;

const overriddenComponents = overrideStore.getAll();

ReactDOM.render(
<OverridableContext.Provider value={overriddenComponents}>
<CommunitiesCarousel
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { i18next } from "@translations/invenio_communities/i18next";
import React from "react";
import { GridResponsiveSidebarColumn } from "react-invenio-forms";
import { parametrize } from "react-overridable";
import { parametrize, overrideStore } from "react-overridable";
import { Count, ResultsList, SearchBar, Sort, withState } from "react-searchkit";
import { Button, Card, Container, Grid, Input, Segment } from "semantic-ui-react";
import { ComputerTabletCommunitiesItem } from "./communities_items/ComputerTabletCommunitiesItem";
Expand All @@ -26,6 +26,8 @@ import {
} from "@js/invenio_search_ui/components";
import PropTypes from "prop-types";

const appName = "InvenioCommunities.Search";

function ResultsGridItemTemplate({ result }) {
return (
<Card fluid href={`/communities/${result.slug}`}>
Expand Down Expand Up @@ -228,10 +230,13 @@ export const CommunitiesSearchLayout = (props) => {
open={sidebarVisible}
onHideClick={() => setSidebarVisible(false)}
// eslint-disable-next-line react/no-children-prop
children={<SearchAppFacets aggs={config.aggs} />}
children={<SearchAppFacets aggs={config.aggs} appName={appName} />}
/>
<Grid.Column mobile={16} tablet={16} computer={12}>
<SearchAppResultsPane layoutOptions={config.layoutOptions} />
<SearchAppResultsPane
layoutOptions={config.layoutOptions}
appName={appName}
/>
</Grid.Column>
</Grid.Row>
</Grid>
Expand All @@ -248,15 +253,22 @@ const ContribSearchAppFacetsWithConfig = parametrize(ContribSearchAppFacets, {
});

const defaultComponents = {
"BucketAggregation.element": RDMBucketAggregationElement,
"BucketAggregationValues.element": ContribBucketAggregationValuesElement,
"SearchApp.facets": ContribSearchAppFacetsWithConfig,
"ResultsList.item": ResultsItemTemplate,
"ResultsGrid.item": ResultsGridItemTemplate,
"SearchApp.layout": CommunitiesSearchLayout,
"SearchBar.element": CommunitiesSearchBarElement,
"SearchApp.results": CommunitiesResults,
[`${appName}.BucketAggregation.element`]: RDMBucketAggregationElement,
[`${appName}.BucketAggregationValues.element`]: ContribBucketAggregationValuesElement,
[`${appName}.SearchApp.facets`]: ContribSearchAppFacetsWithConfig,
[`${appName}.ResultsList.item`]: ResultsItemTemplate,
[`${appName}.ResultsGrid.item`]: ResultsGridItemTemplate,
[`${appName}.SearchApp.layout`]: CommunitiesSearchLayout,
[`${appName}.SearchBar.element`]: CommunitiesSearchBarElement,
[`${appName}.SearchApp.results`]: CommunitiesResults,
};

const overriddenComponents = overrideStore.getAll();

// Auto-initialize search app
createSearchAppInit(defaultComponents);
createSearchAppInit(
{ ...defaultComponents, ...overriddenComponents },
true,
"invenio-search-config",
true
);
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ CommunityRecordResultsGridItem.propTypes = {
result: PropTypes.object.isRequired,
};

export const CommunityRecordSearchAppLayout = ({ config }) => {
export const CommunityRecordSearchAppLayout = ({ config, appName }) => {
const [sidebarVisible, setSidebarVisible] = React.useState(false);

return (
Expand Down Expand Up @@ -174,10 +174,13 @@ export const CommunityRecordSearchAppLayout = ({ config }) => {
open={sidebarVisible}
onHideClick={() => setSidebarVisible(false)}
// eslint-disable-next-line react/no-children-prop
children={<SearchAppFacets aggs={config.aggs} />}
children={<SearchAppFacets aggs={config.aggs} appName={appName} />}
/>
<Grid.Column mobile={16} tablet={16} computer={12}>
<SearchAppResultsPane layoutOptions={config.layoutOptions} />
<SearchAppResultsPane
layoutOptions={config.layoutOptions}
appName={appName}
/>
</Grid.Column>
</Grid.Row>
</Grid>
Expand All @@ -187,6 +190,11 @@ export const CommunityRecordSearchAppLayout = ({ config }) => {

CommunityRecordSearchAppLayout.propTypes = {
config: PropTypes.object.isRequired,
appName: PropTypes.string,
};

CommunityRecordSearchAppLayout.defaultProps = {
appName: "",
};

export const CommunityRecordSingleSearchBarElement = withState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,45 @@ import {
CommunityRecordSearchBarElement,
CommunityToggleComponent,
} from "./components";
import { parametrize } from "react-overridable";
import { parametrize, overrideStore } from "react-overridable";
import {
ContribSearchAppFacets,
ContribBucketAggregationElement,
ContribBucketAggregationValuesElement,
} from "@js/invenio_search_ui/components";

const appName = "InvenioCommunities.DetailsSearch";

const ContribSearchAppFacetsWithConfig = parametrize(ContribSearchAppFacets, {
toogle: true,
});

createSearchAppInit({
"BucketAggregation.element": ContribBucketAggregationElement,
"BucketAggregationValues.element": ContribBucketAggregationValuesElement,
"ResultsGrid.item": CommunityRecordResultsGridItem,
"EmptyResults.element": CommunityEmptyResults,
"ResultsList.item": CommunityRecordResultsListItem,
"SearchApp.facets": ContribSearchAppFacetsWithConfig,
"SearchApp.layout": CommunityRecordSearchAppLayout,
"SearchBar.element": CommunityRecordSearchBarElement,
"Count.element": CommunityCountComponent,
"Error.element": CommunityErrorComponent,
"SearchFilters.Toggle.element": CommunityToggleComponent,
});
const CommunityRecordSearchAppLayoutWAppName = parametrize(
CommunityRecordSearchAppLayout,
{
appName: appName,
}
);

const defaultComponents = {
[`${appName}.BucketAggregation.element`]: ContribBucketAggregationElement,
[`${appName}.BucketAggregationValues.element`]: ContribBucketAggregationValuesElement,
[`${appName}.ResultsGrid.item`]: CommunityRecordResultsGridItem,
[`${appName}.EmptyResults.element`]: CommunityEmptyResults,
[`${appName}.ResultsList.item`]: CommunityRecordResultsListItem,
[`${appName}.SearchApp.facets`]: ContribSearchAppFacetsWithConfig,
[`${appName}.SearchApp.layout`]: CommunityRecordSearchAppLayoutWAppName,
[`${appName}.SearchBar.element`]: CommunityRecordSearchBarElement,
[`${appName}.Count.element`]: CommunityCountComponent,
[`${appName}.Error.element`]: CommunityErrorComponent,
[`${appName}.SearchFilters.Toggle.element`]: CommunityToggleComponent,
};

const overriddenComponents = overrideStore.getAll();

createSearchAppInit(
{ ...defaultComponents, ...overriddenComponents },
true,
"invenio-search-config",
true
);
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SearchResultsBulkActions extends Component {
}));

return (
<Overridable id="SearchResultsBulkActionsManager.layout">
<Overridable id="InvenioCommunities.SearchResultsBulkActionsManager.layout">
<div className="flex">
<Checkbox
className="align-self-center mr-10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SearchResultsBulkActionsManager extends Component {
const { children } = this.props;
const { allSelected, selectedCount } = this.state;
return (
<Overridable id="SearchResultsBulkActionsManager.layout">
<Overridable id="InvenioCommunities.SearchResultsBulkActionsManager.layout">
<BulkActionsContext.Provider
value={{
bulkActionContext: this.selected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ import { SearchFilters } from "@js/invenio_search_ui/components/SearchFilters";

export class InvitationsSearchLayout extends Component {
render() {
const { config, roles, rolesCanInvite, community, communityGroupsEnabled } =
this.props;
const {
config,
roles,
rolesCanInvite,
community,
communityGroupsEnabled,
appName,
} = this.props;

const filtersClass = new Filters(roles);
const customFilters = filtersClass.getInvitationFilters();
Expand Down Expand Up @@ -50,7 +56,7 @@ export class InvitationsSearchLayout extends Component {
<FilterLabels ignoreFilters={["is_open"]} />
</div>

<SearchAppResultsPane layoutOptions={config.layoutOptions} />
<SearchAppResultsPane layoutOptions={config.layoutOptions} appName={appName} />
</>
);
}
Expand All @@ -62,4 +68,9 @@ InvitationsSearchLayout.propTypes = {
rolesCanInvite: PropTypes.object.isRequired,
community: PropTypes.object.isRequired,
communityGroupsEnabled: PropTypes.bool.isRequired,
appName: PropTypes.string,
};

InvitationsSearchLayout.defaultProps = {
appName: "",
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { createSearchAppInit } from "@js/invenio_search_ui";
import { parametrize } from "react-overridable";
import { parametrize, overrideStore } from "react-overridable";
import { DropdownSort } from "@js/invenio_search_ui/components";
import { InvitationsContextProvider as ContextProvider } from "../../api/invitations/InvitationsContextProvider";
import { InvitationResultItem } from "./InvitationResultItem";
Expand All @@ -30,6 +30,8 @@ const communitiesAllRoles = JSON.parse(dataAttr.communitiesAllRoles);
const communitiesRolesCanInvite = JSON.parse(dataAttr.communitiesRolesCanInvite);
const permissions = JSON.parse(dataAttr.permissions);

const appName = "InvenioCommunities.InvitationsSearch";

const communityGroupsEnabled = JSON.parse(dataAttr.communityGroupsEnabled);

const InvitationResultItemWithConfig = parametrize(InvitationResultItem, {
Expand All @@ -43,32 +45,35 @@ const InvitationsSearchLayoutWithConfig = parametrize(InvitationsSearchLayout, {
community: community,
permissions: permissions,
communityGroupsEnabled: communityGroupsEnabled,
appName: appName,
});

const InvitationsContextProvider = parametrize(ContextProvider, {
community: community,
});

const defaultComponents = {
"ResultsList.item": InvitationResultItemWithConfig,
"SearchApp.layout": InvitationsSearchLayoutWithConfig,
"SearchBar.element": InvitationsSearchBarElement,
"SearchApp.results": InvitationsResults,
"ResultsList.container": InvitationsResultsContainer,
"Sort.element": DropdownSort,
"RequestStatus.layout.submitted": SubmitStatus,
"RequestStatus.layout.deleted": DeleteStatus,
"RequestStatus.layout.accepted": AcceptStatus,
"RequestStatus.layout.declined": DeclineStatus,
"RequestStatus.layout.cancelled": CancelStatus,
"RequestStatus.layout.expired": ExpireStatus,
[`${appName}.ResultsList.item`]: InvitationResultItemWithConfig,
[`${appName}.SearchApp.layout`]: InvitationsSearchLayoutWithConfig,
[`${appName}.SearchBar.element`]: InvitationsSearchBarElement,
[`${appName}.SearchApp.results`]: InvitationsResults,
[`${appName}.ResultsList.container`]: InvitationsResultsContainer,
[`${appName}.Sort.element`]: DropdownSort,
[`${appName}.RequestStatus.layout.submitted`]: SubmitStatus,
[`${appName}.RequestStatus.layout.deleted`]: DeleteStatus,
[`${appName}.RequestStatus.layout.accepted`]: AcceptStatus,
[`${appName}.RequestStatus.layout.declined`]: DeclineStatus,
[`${appName}.RequestStatus.layout.cancelled`]: CancelStatus,
[`${appName}.RequestStatus.layout.expired`]: ExpireStatus,
};

const overriddenComponents = overrideStore.getAll();

// Auto-initialize search app
createSearchAppInit(
defaultComponents,
{ ...defaultComponents, ...overriddenComponents },
true,
"invenio-search-config",
false,
true,
InvitationsContextProvider
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import PropTypes from "prop-types";

export class MembersSearchLayout extends Component {
render() {
const { config, roles } = this.props;
const { config, roles, appName } = this.props;
const filtersClass = new Filters(roles);
const customFilters = filtersClass.getMembersFilters();
return (
Expand All @@ -36,7 +36,7 @@ export class MembersSearchLayout extends Component {
<FilterLabels />
</div>

<SearchAppResultsPane layoutOptions={config.layoutOptions} />
<SearchAppResultsPane layoutOptions={config.layoutOptions} appName={appName} />
</>
);
}
Expand All @@ -45,4 +45,9 @@ export class MembersSearchLayout extends Component {
MembersSearchLayout.propTypes = {
config: PropTypes.object.isRequired,
roles: PropTypes.array.isRequired,
appName: PropTypes.string,
};

MembersSearchLayout.defaultProps = {
appName: "",
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { createSearchAppInit } from "@js/invenio_search_ui";
import { parametrize } from "react-overridable";
import { parametrize, overrideStore } from "react-overridable";
import { DropdownSort } from "@js/invenio_search_ui/components";
import { memberVisibilityTypes } from "../";
import { MembersSearchBarElement } from "../../components/MembersSearchBarElement";
Expand All @@ -24,6 +24,8 @@ const communitiesAllRoles = JSON.parse(dataAttr.communitiesAllRoles);
const community = JSON.parse(dataAttr.community);
const permissions = JSON.parse(dataAttr.permissions);

const appName = "InvenioCommunities.ManagerSearch";

const ManagerMembersResultItemWithConfig = parametrize(ManagerMembersResultItem, {
config: {
rolesCanUpdate: communitiesRolesCanUpdate,
Expand All @@ -50,23 +52,26 @@ const MembersSearchAppContext = parametrize(MembersSearchAppContextCmp, {

const MembersSearchLayoutWithConfig = parametrize(MembersSearchLayout, {
roles: communitiesAllRoles,
appName: appName,
});

const defaultComponents = {
"ResultsList.item": ManagerMembersResultItemWithConfig,
"ResultsGrid.item": MembersResultsGridItem,
"SearchApp.layout": MembersSearchLayoutWithConfig,
"SearchBar.element": MembersSearchBarElement,
"SearchApp.results": MembersResults,
"ResultsList.container": ManagerMembersResultContainerWithCommunity,
"Sort.element": DropdownSort,
[`${appName}.ResultsList.item`]: ManagerMembersResultItemWithConfig,
[`${appName}.ResultsGrid.item`]: MembersResultsGridItem,
[`${appName}.SearchApp.layout`]: MembersSearchLayoutWithConfig,
[`${appName}.SearchBar.element`]: MembersSearchBarElement,
[`${appName}.SearchApp.results`]: MembersResults,
[`${appName}.ResultsList.container`]: ManagerMembersResultContainerWithCommunity,
[`${appName}.Sort.element`]: DropdownSort,
};

const overriddenComponents = overrideStore.getAll();

// Auto-initialize search app
createSearchAppInit(
defaultComponents,
{ ...defaultComponents, ...overriddenComponents },
true,
"invenio-search-config",
false,
true,
MembersSearchAppContext
);
Loading

0 comments on commit 53815c2

Please sign in to comment.