From bba9f2cfb4904180917b1256a8d0df0ef9a4075c Mon Sep 17 00:00:00 2001 From: esikkala <esko.ikkala@aalto.fi> Date: Sun, 5 Dec 2021 11:13:04 +0200 Subject: [PATCH] Generalize mapStateToProps, clean up reducers --- src/client/configs/sampo/PerspectiveConfig.js | 151 ------------------ src/client/containers/SemanticPortal.js | 132 +++++---------- src/client/reducers/index.js | 6 - src/client/reducers/sampo/emloActors.js | 150 ----------------- src/client/reducers/sampo/emloActorsFacets.js | 110 ------------- .../sampo/emloActorsFacetsConstrainSelf.js | 110 ------------- 6 files changed, 40 insertions(+), 619 deletions(-) delete mode 100644 src/client/reducers/sampo/emloActors.js delete mode 100644 src/client/reducers/sampo/emloActorsFacets.js delete mode 100644 src/client/reducers/sampo/emloActorsFacetsConstrainSelf.js diff --git a/src/client/configs/sampo/PerspectiveConfig.js b/src/client/configs/sampo/PerspectiveConfig.js index 04cb345e..0d1d12a9 100644 --- a/src/client/configs/sampo/PerspectiveConfig.js +++ b/src/client/configs/sampo/PerspectiveConfig.js @@ -192,157 +192,6 @@ export const perspectiveConfig = [ } ] }, - { - id: 'emloActors', - isHidden: true, - frontPageImage: null, - - defaultActiveFacets: new Set(['prefLabel']), - tabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'map', - value: 1, - icon: <AddLocationIcon /> - }, - { - id: 'export', - value: 2, - icon: <CloudDownloadIcon /> - } - ], - instancePageTabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'emloLetterNetwork', - value: 1, - icon: <BubbleChartIcon /> - }, - { - id: 'emloSentReceived', - value: 2, - icon: <LineChartIcon /> - }, - { - id: 'export', - value: 3, - icon: <CloudDownloadIcon /> - } - ] - }, - { - id: 'emloLetters', - isHidden: true, - frontPageImage: null, - defaultActiveFacets: new Set(['prefLabel']), - tabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'migrations', - value: 1, - icon: <RedoIcon /> - }, - { - id: 'by_year', - value: 2, - icon: <LineChartIcon /> - }, - { - id: 'export', - value: 3, - icon: <CloudDownloadIcon /> - } - ], - instancePageTabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'export', - value: 1, - icon: <CloudDownloadIcon /> - } - ] - }, - { - id: 'emloPlaces', - isHidden: true, - frontPageImage: null, - defaultActiveFacets: new Set(['prefLabel']), - tabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'export', - value: 1, - icon: <CloudDownloadIcon /> - } - ], - instancePageTabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'export', - value: 1, - icon: <CloudDownloadIcon /> - } - ] - }, - { - id: 'hellerau', - isHidden: true, - frontPageImage: null, - defaultActiveFacets: new Set(['prefLabel']), - tabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'migrations', - value: 1, - icon: <RedoIcon /> - }, - { - id: 'export', - value: 2, - icon: <CloudDownloadIcon /> - } - ], - instancePageTabs: [ - { - id: 'table', - value: 0, - icon: <CalendarViewDayIcon /> - }, - { - id: 'export', - value: 1, - icon: <CloudDownloadIcon /> - } - ] - }, { id: 'clientFSPlaces', frontPageImage: placesImage, diff --git a/src/client/containers/SemanticPortal.js b/src/client/containers/SemanticPortal.js index 3f9c4513..a9d0a6fa 100644 --- a/src/client/containers/SemanticPortal.js +++ b/src/client/containers/SemanticPortal.js @@ -52,10 +52,6 @@ import { perspectiveConfigOnlyInfoPages } from '../configs/sampo/PerspectiveConf import { rootUrl, layoutConfig } from '../configs/sampo/GeneralConfig' // ** General components ** -// import InfoHeader from '../components/main_layout/InfoHeader' -// import TextPage from '../components/main_layout/TextPage' -// import Message from '../components/main_layout/Message' -// import FacetBar from '../components/facet_bar/FacetBar' const InfoHeader = lazy(() => import('../components/main_layout/InfoHeader')) const TextPage = lazy(() => import('../components/main_layout/TextPage')) const Message = lazy(() => import('../components/main_layout/Message')) @@ -63,15 +59,6 @@ const FacetBar = lazy(() => import('../components/facet_bar/FacetBar')) // ** General components end ** // ** Portal specific components and configs ** -// import TopBar from '../components/perspectives/sampo/TopBar' -// import FacetedSearchPerspective from '../components/perspectives/sampo/FacetedSearchPerspective' -// import Main from '../components/perspectives/sampo/Main' -// import FullTextSearch from '../components/perspectives/sampo/FullTextSearch' -// import ClientFSPerspective from '../components/perspectives/sampo/client_fs/ClientFSPerspective' -// import ClientFSMain from '../components/perspectives/sampo/client_fs/ClientFSMain' -// import InstanceHomePage from '../components/perspectives/sampo/InstanceHomePage' -// import Footer from '../components/perspectives/sampo/Footer' -// import KnowledgeGraphMetadataTable from '../components/perspectives/sampo/KnowledgeGraphMetadataTable' const portalID = 'sampo' const TopBar = lazy(() => import('../components/perspectives/' + portalID + '/TopBar')) const Main = lazy(() => import('../components/perspectives/' + portalID + '/Main')) @@ -252,7 +239,7 @@ const SemanticPortal = props => { if (lgScreen) { screenSize = 'lg' } if (xlScreen) { screenSize = 'xl' } const rootUrlWithLang = `${rootUrl}/${props.options.currentLocale}` - const noClientFSResults = props.clientFSState.results == null + const noClientFSResults = props.clientFSState && props.clientFSState.results === null useEffect(() => { document.title = intl.get('html.title') @@ -622,39 +609,32 @@ const SemanticPortal = props => { } const mapStateToProps = state => { - const { clientFSResults, clientFSFacetValues } = filterResults(state.clientSideFacetedSearch) - return { - perspective1: state.perspective1, - perspective1Facets: state.perspective1Facets, - perspective1FacetsConstrainSelf: state.perspective1FacetsConstrainSelf, - perspective2: state.perspective2, - perspective2Facets: state.perspective2Facets, - perspective2FacetsConstrainSelf: state.perspective2FacetsConstrainSelf, - perspective3: state.perspective3, - perspective3Facets: state.perspective3Facets, - perspective3FacetsConstrainSelf: state.perspective3FacetsConstrainSelf, - manuscripts: state.manuscripts, - works: state.works, - events: state.events, - actors: state.actors, - expressions: state.expressions, - collections: state.collections, - places: state.places, - finds: state.finds, - findsFacets: state.findsFacets, - findsFacetsConstrainSelf: state.findsFacetsConstrainSelf, - emloActors: state.emloActors, - emloActorsFacets: state.emloActorsFacets, - emloActorsFacetsConstrainSelf: state.emloActorsFacetsConstrainSelf, - leafletMap: state.leafletMap, - fullTextSearch: state.fullTextSearch, - clientFSState: state.clientSideFacetedSearch, - clientFSResults, - clientFSFacetValues, - animationValue: state.animation.value, - options: state.options, - error: state.error - } + const stateToProps = {} + perspectiveConfig.forEach(perspective => { + const { id, searchMode } = perspective + if (searchMode && searchMode === 'federated-search') { + const { clientFSResults, clientFSFacetValues } = filterResults(state.clientSideFacetedSearch) + stateToProps.clientFSState = state.clientSideFacetedSearch + stateToProps.clientFSResults = clientFSResults + stateToProps.clientFSFacetValues = clientFSFacetValues + } else { + stateToProps[id] = state[id] + stateToProps[`${id}Facets`] = state[`${id}Facets`] + if (has(state, `${id}FacetsConstrainSelf`)) { + stateToProps[`${id}FacetsConstrainSelf`] = state[`${id}FacetsConstrainSelf`] + } + } + }) + perspectiveConfigOnlyInfoPages.forEach(perspective => { + const { id } = perspective + stateToProps[id] = state[id] + }) + stateToProps.leafletMap = state.leafletMap + stateToProps.fullTextSearch = state.fullTextSearch + stateToProps.animationValue = state.animation.value + stateToProps.options = state.options + stateToProps.error = state.error + return stateToProps } const mapDispatchToProps = ({ @@ -700,46 +680,14 @@ SemanticPortal.propTypes = { * Errors shown with react-redux-toastr. */ error: PropTypes.object.isRequired, - /** - * Faceted search configs and results of 'Perspective 1'. - */ - perspective1: PropTypes.object.isRequired, - /** - * Facet configs and values of 'Perspective 1'. - */ - perspective1Facets: PropTypes.object.isRequired, - /** - * Facet configs and values for facets that restrict themselves of 'Perspective 1'. - */ - perspective1FacetsConstrainSelf: PropTypes.object.isRequired, - /** - * Faceted search configs and results of 'Perspective 2'. - */ - perspective2: PropTypes.object.isRequired, - /** - * Facet configs and values of 'Perspective 2'. - */ - perspective2Facets: PropTypes.object.isRequired, - /** - * Faceted search configs and results of 'Perspective 3'. - */ - perspective3: PropTypes.object.isRequired, - /** - * Facet configs and values of 'Perspective 3'. - */ - perspective3Facets: PropTypes.object.isRequired, - /** - * Faceted search configs and results of 'Places'. - */ - places: PropTypes.object.isRequired, /** * Leaflet map config and external layers. */ - leafletMap: PropTypes.object.isRequired, + leafletMap: PropTypes.object, /** * State of the animation, used by TemporalMap. */ - animationValue: PropTypes.array.isRequired, + animationValue: PropTypes.array, /** * Redux action for fetching all faceted search results. */ @@ -751,7 +699,7 @@ SemanticPortal.propTypes = { /** * Redux action for full text search results. */ - fetchFullTextResults: PropTypes.func.isRequired, + fetchFullTextResults: PropTypes.func, /** * Redux action for fetching paginated faceted search results. */ @@ -763,16 +711,16 @@ SemanticPortal.propTypes = { /** * Redux action for loading external GeoJSON layers. */ - fetchGeoJSONLayers: PropTypes.func.isRequired, + fetchGeoJSONLayers: PropTypes.func, /** * Redux action for clearing external GeoJSON layers. */ - clearGeoJSONLayers: PropTypes.func.isRequired, + clearGeoJSONLayers: PropTypes.func, /** * Redux action for loading external GeoJSON layers via the backend. * Useful when the API or similar needs to be hidden. */ - fetchGeoJSONLayersBackend: PropTypes.func.isRequired, + fetchGeoJSONLayersBackend: PropTypes.func, /** * Redux action for sorting the paginated results. */ @@ -820,7 +768,7 @@ SemanticPortal.propTypes = { /** * Redux action for animating TemporalMap. */ - animateMap: PropTypes.func.isRequired, + animateMap: PropTypes.func, /** * State for client-side faceted search. */ @@ -828,27 +776,27 @@ SemanticPortal.propTypes = { /** * Redux action for updating the dataset selections in client-side faceted search. */ - clientFSToggleDataset: PropTypes.func.isRequired, + clientFSToggleDataset: PropTypes.func, /** * Redux action for the fetching the initial result set in client-side faceted search. */ - clientFSFetchResults: PropTypes.func.isRequired, + clientFSFetchResults: PropTypes.func, /** * Redux action for the clearing the initial result set in client-side faceted search. */ - clientFSClearResults: PropTypes.func.isRequired, + clientFSClearResults: PropTypes.func, /** * Redux action for sorting results in client-side faceted search. */ - clientFSSortResults: PropTypes.func.isRequired, + clientFSSortResults: PropTypes.func, /** * Redux action for updating the initial query in client-side faceted search. */ - clientFSUpdateQuery: PropTypes.func.isRequired, + clientFSUpdateQuery: PropTypes.func, /** * Redux action for updating a facet in client-side faceted search. */ - clientFSUpdateFacet: PropTypes.func.isRequired + clientFSUpdateFacet: PropTypes.func } export const SemanticPortalComponent = SemanticPortal diff --git a/src/client/reducers/index.js b/src/client/reducers/index.js index 1ccf6bde..a0d8ef15 100644 --- a/src/client/reducers/index.js +++ b/src/client/reducers/index.js @@ -20,9 +20,6 @@ import expressions from './sampo/expressions' import collections from './sampo/collections' import finds from './sampo/finds' import findsFacets from './sampo/findsFacets' -import emloActors from './sampo/emloActors' -import emloActorsFacets from './sampo/emloActorsFacets' -import emloActorsFacetsConstrainSelf from './sampo/emloActorsFacetsConstrainSelf' import findsFacetsConstrainSelf from './sampo/findsFacetsConstrainSelf' import perspective1Facets from './sampo/perspective1Facets' import perspective1FacetsConstrainSelf from './sampo/perspective1FacetsConstrainSelf' @@ -51,9 +48,6 @@ const reducer = combineReducers({ finds, findsFacets, findsFacetsConstrainSelf, - emloActors, - emloActorsFacets, - emloActorsFacetsConstrainSelf, leafletMap, animation, options, diff --git a/src/client/reducers/sampo/emloActors.js b/src/client/reducers/sampo/emloActors.js deleted file mode 100644 index 08627549..00000000 --- a/src/client/reducers/sampo/emloActors.js +++ /dev/null @@ -1,150 +0,0 @@ -import { handleDataFetchingAction } from '../general/results' - -export const INITIAL_STATE = { - results: null, - resultUpdateID: 0, - resultsSparqlQuery: null, - paginatedResults: [], - paginatedResultsSparqlQuery: null, - resultCount: 0, - page: -1, - pagesize: 10, - sortBy: null, - sortDirection: null, - fetching: false, - fetchingResultCount: false, - facetedSearchHeaderExpanded: false, - instancePageHeaderExpanded: false, - instanceTableData: null, - instanceTableExternalData: null, - instanceAnalysisData: null, - instanceAnalysisDataUpdateID: 0, - instanceSparqlQuery: null, - properties: [ - { - id: 'uri', - valueType: 'object', - makeLink: true, - externalLink: true, - sortValues: true, - numberedList: false, - onlyOnInstancePage: true - }, - { - id: 'prefLabel', - valueType: 'object', - makeLink: true, - externalLink: false, - sortValues: true, - numberedList: false, - minWidth: 250 - }, - { - id: 'gender', - valueType: 'object', - makeLink: false, - externalLink: false, - sortValues: true, - numberedList: false, - minWidth: 90, - priority: 5 - }, - { - id: 'type', - valueType: 'object', - makeLink: true, - externalLink: false, - sortValues: true, - numberedList: false, - minWidth: 90, - priority: 5 - }, - { - id: 'related', - valueType: 'object', - makeLink: true, - externalLink: true, - sortValues: true, - numberedList: false, - minWidth: 250, - priority: 8, - onlyOnInstancePage: true - }, - { - id: 'birthDateTimespan', - valueType: 'object', - makeLink: false, - externalLink: false, - sortValues: true, - numberedList: false, - showSource: true, - sourceExternalLink: true, - minWidth: 250 - }, - { - id: 'deathDateTimespan', - valueType: 'object', - makeLink: false, - externalLink: false, - sortValues: true, - numberedList: false, - showSource: true, - sourceExternalLink: true, - minWidth: 250 - }, - { - id: 'altLabel', - valueType: 'string', - renderAsHTML: false, - makeLink: false, - externalLink: false, - sortValues: false, - numberedList: false, - minWidth: 150, - collapsedMaxWords: 12, - onlyOnInstancePage: true - }, - { - id: 'rel', - valueType: 'object', - makeLink: true, - externalLink: false, - sortValues: false, - numberedList: false, - minWidth: 220, - onlyOnInstancePage: true - }, - { - id: 'cor', - valueType: 'object', - makeLink: true, - externalLink: false, - sortValues: false, - numberedList: false, - minWidth: 220, - onlyOnInstancePage: true - }, - { - id: 'knownLocation', - valueType: 'object', - makeLink: true, - externalLink: false, - sortValues: true, - numberedList: false, - minWidth: 220, - onlyOnInstancePage: true - } - ] -} - -const resultClasses = new Set([ - 'emloActors', 'emloLetterNetwork', 'emloSentReceived' -]) - -const emloActors = (state = INITIAL_STATE, action) => { - if (resultClasses.has(action.resultClass)) { - return handleDataFetchingAction(state, action) - } else return state -} - -export default emloActors diff --git a/src/client/reducers/sampo/emloActorsFacets.js b/src/client/reducers/sampo/emloActorsFacets.js deleted file mode 100644 index 0f5cee84..00000000 --- a/src/client/reducers/sampo/emloActorsFacets.js +++ /dev/null @@ -1,110 +0,0 @@ -import { handleFacetAction } from '../general/facets' - -export const INITIAL_STATE = { - updatedFacet: null, - facetUpdateID: 0, - updatedFilter: null, - facets: { - prefLabel: { - id: 'prefLabel', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'one', - filterType: 'textFilter', - textFilter: null, - priority: 1 - }, - gender: { - id: 'gender', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: 'instanceCount', - sortDirection: 'desc', - sortButton: false, - spatialFilterButton: false, - chartButton: true, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'uriFilter', - uriFilter: null, - priority: 9 - }, - type: { - id: 'type', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: 'instanceCount', - sortDirection: 'desc', - sortButton: false, - spatialFilterButton: false, - chartButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'uriFilter', - uriFilter: null, - priority: 9 - }, - birthDateTimespan: { - id: 'birthDateTimespan', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'timespanFilter', - min: null, - max: null, - timespanFilter: null, - type: 'timespan', - priority: 8 - }, - deathDateTimespan: { - id: 'deathDateTimespan', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'timespanFilter', - min: null, - max: null, - timespanFilter: null, - type: 'timespan', - priority: 8 - } - } -} - -const actorsFacets = (state = INITIAL_STATE, action) => { - if (action.facetClass === 'emloActors') { - return handleFacetAction(state, action, INITIAL_STATE) - } else return state -} - -export default actorsFacets diff --git a/src/client/reducers/sampo/emloActorsFacetsConstrainSelf.js b/src/client/reducers/sampo/emloActorsFacetsConstrainSelf.js deleted file mode 100644 index bfd1b8d3..00000000 --- a/src/client/reducers/sampo/emloActorsFacetsConstrainSelf.js +++ /dev/null @@ -1,110 +0,0 @@ -import { handleFacetConstrainSelfAction } from '../general/facetsConstrainSelf' - -export const INITIAL_STATE = { - updatedFacet: null, - facetUpdateID: 0, - updatedFilter: null, - facets: { - prefLabel: { - id: 'prefLabel', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'one', - filterType: 'textFilter', - textFilter: null, - priority: 1 - }, - gender: { - id: 'gender', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: 'instanceCount', - sortDirection: 'desc', - sortButton: false, - spatialFilterButton: false, - chartButton: true, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'uriFilter', - uriFilter: null, - priority: 9 - }, - type: { - id: 'type', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: 'instanceCount', - sortDirection: 'desc', - sortButton: false, - spatialFilterButton: false, - chartButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'uriFilter', - uriFilter: null, - priority: 9 - }, - birthDateTimespan: { - id: 'birthDateTimespan', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'timespanFilter', - min: null, - max: null, - timespanFilter: null, - type: 'timespan', - priority: 8 - }, - deathDateTimespan: { - id: 'deathDateTimespan', - // predicate: defined in backend - distinctValueCount: 0, - values: [], - flatValues: [], - sortBy: null, - sortDirection: null, - sortButton: false, - spatialFilterButton: false, - isFetching: false, - searchField: false, - containerClass: 'three', - filterType: 'timespanFilter', - min: null, - max: null, - timespanFilter: null, - type: 'timespan', - priority: 8 - } - } -} - -const perspective1FacetsConstrainself = (state = INITIAL_STATE, action) => { - if (action.facetClass === 'emloActors') { - return handleFacetConstrainSelfAction(state, action) - } else return state -} - -export default perspective1FacetsConstrainself -- GitLab