Skip to content
Snippets Groups Projects
Commit bba9f2cf authored by esikkala's avatar esikkala
Browse files

Generalize mapStateToProps, clean up reducers

parent 6b0bd025
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
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
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment