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

Update map component, provide both hierarchical and flat facet values

parent 39b0b50f
No related branches found
No related tags found
No related merge requests found
...@@ -62,9 +62,9 @@ export const fetchFacetFailed = error => ({ ...@@ -62,9 +62,9 @@ export const fetchFacetFailed = error => ({
type: FETCH_FACET_FAILED, type: FETCH_FACET_FAILED,
error error
}); });
export const updateFacet = ({ id, distinctValueCount, values, sortBy, sortDirection }) => ({ export const updateFacet = ({ id, distinctValueCount, values, flatValues, sortBy, sortDirection }) => ({
type: UPDATE_FACET, type: UPDATE_FACET,
id, distinctValueCount, values, sortBy, sortDirection id, distinctValueCount, values, flatValues, sortBy, sortDirection
}); });
export const updateFilter = filter => ({ export const updateFilter = filter => ({
type: UPDATE_FILTER, type: UPDATE_FILTER,
......
...@@ -70,7 +70,8 @@ const ColorIcon = L.Icon.extend({ ...@@ -70,7 +70,8 @@ const ColorIcon = L.Icon.extend({
class LeafletMap extends React.Component { class LeafletMap extends React.Component {
componentDidMount() { componentDidMount() {
this.props.fetchPlaces(this.props.variant);
//this.props.fetchPlaces(this.props.variant);
// Base layers // Base layers
// const OSMBaseLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { // const OSMBaseLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
...@@ -140,20 +141,21 @@ class LeafletMap extends React.Component { ...@@ -140,20 +141,21 @@ class LeafletMap extends React.Component {
} }
componentDidUpdate({ results, place, mapMode }) { componentDidUpdate({ results, instance, mapMode }) {
// check if results data or mapMode have changed // check if results data or mapMode have changed
if (this.props.results !== results || this.props.mapMode !== mapMode) { if (this.props.results !== results || this.props.mapMode !== mapMode) {
if (this.props.mapMode === 'cluster') { if (this.props.mapMode === 'cluster') {
console.log(this.props.results)
this.updateMarkersAndCluster(this.props.results); this.updateMarkersAndCluster(this.props.results);
} else { } else {
this.updateMarkers(this.props.results); this.updateMarkers(this.props.results);
} }
} }
if (this.props.place !== place) { if (this.props.instance !== instance) {
this.markers[this.props.place.id] this.markers[this.props.instance.id]
.bindPopup(this.createPopUpContent(this.props.place), { .bindPopup(this.createPopUpContent(this.props.instance), {
maxHeight: 300, maxHeight: 300,
maxWidth: 400, maxWidth: 400,
minWidth: 400, minWidth: 400,
...@@ -165,7 +167,7 @@ class LeafletMap extends React.Component { ...@@ -165,7 +167,7 @@ class LeafletMap extends React.Component {
} }
renderSpinner() { renderSpinner() {
if(this.props.fetchingPlaces) { if(this.props.fetching) {
return ( return (
<div className={this.props.classes.spinner}> <div className={this.props.classes.spinner}>
<CircularProgress style={{ color: purple[500] }} thickness={5} /> <CircularProgress style={{ color: purple[500] }} thickness={5} />
...@@ -286,7 +288,7 @@ class LeafletMap extends React.Component { ...@@ -286,7 +288,7 @@ class LeafletMap extends React.Component {
} }
markerOnClick = event => { markerOnClick = event => {
this.props.fetchPlace(event.target.options.id); this.props.fetchByURI(event.target.options.id);
}; };
createPopUpContent(result) { createPopUpContent(result) {
...@@ -351,13 +353,12 @@ class LeafletMap extends React.Component { ...@@ -351,13 +353,12 @@ class LeafletMap extends React.Component {
LeafletMap.propTypes = { LeafletMap.propTypes = {
classes: PropTypes.object.isRequired, classes: PropTypes.object.isRequired,
fetchPlaces: PropTypes.func.isRequired,
fetchingPlaces: PropTypes.bool.isRequired,
fetchPlace: PropTypes.func.isRequired,
results: PropTypes.array.isRequired, results: PropTypes.array.isRequired,
instance: PropTypes.object.isRequired,
fetchResults: PropTypes.func,
fetchByURI: PropTypes.func.isRequired,
fetching: PropTypes.bool.isRequired,
mapMode: PropTypes.string.isRequired, mapMode: PropTypes.string.isRequired,
variant: PropTypes.string.isRequired,
place: PropTypes.object.isRequired,
}; };
export default withStyles(styles)(LeafletMap); export default withStyles(styles)(LeafletMap);
...@@ -4,7 +4,7 @@ import { Route, Redirect } from 'react-router-dom'; ...@@ -4,7 +4,7 @@ import { Route, Redirect } from 'react-router-dom';
import ViewTabs from './ViewTabs'; import ViewTabs from './ViewTabs';
import ResultTable from './ResultTable'; import ResultTable from './ResultTable';
import LeafletMap from './LeafletMap'; import LeafletMap from './LeafletMap';
import Deck from './Deck'; //import Deck from './Deck';
let Manuscripts = props => { let Manuscripts = props => {
return ( return (
...@@ -38,7 +38,7 @@ let Manuscripts = props => { ...@@ -38,7 +38,7 @@ let Manuscripts = props => {
render={routeProps => render={routeProps =>
<ResultTable <ResultTable
data={props.manuscripts} data={props.manuscripts}
filters={props.facets.filters} filters={props.facetData.filters}
resultClass='manuscripts' resultClass='manuscripts'
fetchResults={props.fetchResults} fetchResults={props.fetchResults}
updatePage={props.updatePage} updatePage={props.updatePage}
...@@ -51,16 +51,14 @@ let Manuscripts = props => { ...@@ -51,16 +51,14 @@ let Manuscripts = props => {
path={'/manuscripts/production_places'} path={'/manuscripts/production_places'}
render={() => render={() =>
<LeafletMap <LeafletMap
fetchPlaces={props.fetchPlaces} results={props.facetData.facets.productionPlace.flatValues}
fetchingPlaces={props.search.fetchingPlaces} instance={props.manuscripts.instance}
fetchPlace={props.fetchPlace} fetchByURI={props.fetchByURI}
results={props.search.places} fetching={props.facetData.fetching}
place={props.search.place} mapMode={'cluster'}
mapMode='cluster'
variant='productionPlaces'
/>} />}
/> />
<Route {/*<Route
path={'/manuscripts/migrations'} path={'/manuscripts/migrations'}
render={() => render={() =>
<Deck <Deck
...@@ -68,14 +66,14 @@ let Manuscripts = props => { ...@@ -68,14 +66,14 @@ let Manuscripts = props => {
fetchingPlaces={props.search.fetchingPlaces} fetchingPlaces={props.search.fetchingPlaces}
data={props.search.places} data={props.search.places}
/>} />}
/> /> */}
</React.Fragment> </React.Fragment>
); );
}; };
Manuscripts.propTypes = { Manuscripts.propTypes = {
manuscripts: PropTypes.object.isRequired, manuscripts: PropTypes.object.isRequired,
facets: PropTypes.object.isRequired, facetData: PropTypes.object.isRequired,
fetchResults: PropTypes.func.isRequired, fetchResults: PropTypes.func.isRequired,
fetchByURI: PropTypes.func.isRequired, fetchByURI: PropTypes.func.isRequired,
updatePage: PropTypes.func.isRequired, updatePage: PropTypes.func.isRequired,
......
...@@ -90,7 +90,7 @@ class ResultTable extends React.Component { ...@@ -90,7 +90,7 @@ class ResultTable extends React.Component {
handleOnChangeRowsPerPage = (event, rowsPerPage) => { handleOnChangeRowsPerPage = (event, rowsPerPage) => {
if (event != null) { if (event != null) {
console.log(rowsPerPage) return rowsPerPage;
} }
} }
......
...@@ -88,7 +88,7 @@ class Tree extends Component { ...@@ -88,7 +88,7 @@ class Tree extends Component {
} }
if (this.props.updatedFacet !== '' && this.props.updatedFacet !== this.props.property && prevProps.facetFilters != this.props.facetFilters) { if (this.props.updatedFacet !== '' && this.props.updatedFacet !== this.props.property && prevProps.facetFilters != this.props.facetFilters) {
// console.log(`fetching new values for ${this.props.property}`) // console.log(`fetching new values for ${this.props.property}`)
this.props.fetchFacet(this.props.property, this.props.sortBy, this.props.sortDirection); this.props.fetchFacet(this.props.resultClass, this.props.property, this.props.sortBy, this.props.sortDirection);
} }
} }
......
...@@ -100,7 +100,7 @@ let MapApp = (props) => { ...@@ -100,7 +100,7 @@ let MapApp = (props) => {
<Paper className={classes.resultsContainerPaper}> <Paper className={classes.resultsContainerPaper}>
<Manuscripts <Manuscripts
manuscripts={props.manuscripts} manuscripts={props.manuscripts}
facets={props.manuscriptsFacets} facetData={props.manuscriptsFacets}
fetchResults={props.fetchResults} fetchResults={props.fetchResults}
fetchByURI={props.fetchByURI} fetchByURI={props.fetchByURI}
updatePage={props.updatePage} updatePage={props.updatePage}
......
...@@ -76,6 +76,7 @@ const fetchFacetEpic = (action$, state$) => action$.pipe( ...@@ -76,6 +76,7 @@ const fetchFacetEpic = (action$, state$) => action$.pipe(
id: action.id, id: action.id,
distinctValueCount: res.distinctValueCount, distinctValueCount: res.distinctValueCount,
values: res.values, values: res.values,
flatValues: res.flatValues,
sortBy: action.sortBy, sortBy: action.sortBy,
sortDirection: action.sortDirection sortDirection: action.sortDirection
})) }))
......
...@@ -15,6 +15,7 @@ export const INITIAL_STATE = { ...@@ -15,6 +15,7 @@ export const INITIAL_STATE = {
// predicate: defined in backend // predicate: defined in backend
distinctValueCount: 0, distinctValueCount: 0,
values: [], values: [],
flatValues: [],
sortBy: 'instanceCount', sortBy: 'instanceCount',
sortDirection: 'desc', sortDirection: 'desc',
isFetching: false, isFetching: false,
...@@ -25,6 +26,7 @@ export const INITIAL_STATE = { ...@@ -25,6 +26,7 @@ export const INITIAL_STATE = {
//predicate: defined in backend //predicate: defined in backend
distinctValueCount: 0, distinctValueCount: 0,
values: [], values: [],
flatValues: [],
sortBy: 'prefLabel', sortBy: 'prefLabel',
sortDirection: 'asc', sortDirection: 'asc',
isFetching: false, isFetching: false,
...@@ -35,6 +37,7 @@ export const INITIAL_STATE = { ...@@ -35,6 +37,7 @@ export const INITIAL_STATE = {
// predicate: defined in backend // predicate: defined in backend
distinctValueCount: 0, distinctValueCount: 0,
values: [], values: [],
flatValues: [],
sortBy: 'prefLabel', sortBy: 'prefLabel',
sortDirection: 'asc', sortDirection: 'asc',
isFetching: false, isFetching: false,
...@@ -56,7 +59,8 @@ export const INITIAL_STATE = { ...@@ -56,7 +59,8 @@ export const INITIAL_STATE = {
source: new Set(), source: new Set(),
language: new Set(), language: new Set(),
}, },
updatedFacet: '' updatedFacet: '',
fetching: false
}; };
const manuscriptsFacets = (state = INITIAL_STATE, action) => { const manuscriptsFacets = (state = INITIAL_STATE, action) => {
...@@ -72,12 +76,14 @@ const manuscriptsFacets = (state = INITIAL_STATE, action) => { ...@@ -72,12 +76,14 @@ const manuscriptsFacets = (state = INITIAL_STATE, action) => {
case FETCH_FACET: case FETCH_FACET:
return { return {
...state, ...state,
fetching: true,
facets: { facets: {
...state.facets, ...state.facets,
[ action.id ]: { [ action.id ]: {
...state.facets[action.id], ...state.facets[action.id],
distinctValueCount: 0, distinctValueCount: 0,
values: [], values: [],
flatValues: [],
sortBy: action.sortBy, sortBy: action.sortBy,
sortDirection: action.sortDirection, sortDirection: action.sortDirection,
isFetching: true isFetching: true
...@@ -87,12 +93,14 @@ const manuscriptsFacets = (state = INITIAL_STATE, action) => { ...@@ -87,12 +93,14 @@ const manuscriptsFacets = (state = INITIAL_STATE, action) => {
case UPDATE_FACET: case UPDATE_FACET:
return { return {
...state, ...state,
fetching: false,
facets: { facets: {
...state.facets, ...state.facets,
[ action.id ]: { [ action.id ]: {
...state.facets[action.id], ...state.facets[action.id],
distinctValueCount: action.distinctValueCount, distinctValueCount: action.distinctValueCount,
values: action.values, values: action.values,
flatValues: action.flatValues || [],
sortBy: action.sortBy, sortBy: action.sortBy,
sortDirection: action.sortDirection, sortDirection: action.sortDirection,
isFetching: false isFetching: false
......
...@@ -72,6 +72,7 @@ export const mapHierarchicalFacet = sparqlBindings => { ...@@ -72,6 +72,7 @@ export const mapHierarchicalFacet = sparqlBindings => {
treeData.forEach(node => sumUp(node)); treeData.forEach(node => sumUp(node));
return { return {
distinctValueCount: results.length, distinctValueCount: results.length,
flatValues: results,
values: treeData values: treeData
}; };
}; };
......
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