diff --git a/src/client/actions/index.js b/src/client/actions/index.js index 8e877f2fc626461e62e288f5dd67f80893b674c9..25b6419cf49eee67b6d93e3253e8773267fb3770 100644 --- a/src/client/actions/index.js +++ b/src/client/actions/index.js @@ -160,12 +160,13 @@ export const openFacetDialog = property => ({ export const closeFacetDialog = () => ({ type: CLOSE_FACET_DIALOG, }); -export const fetchFacet = () => ({ +export const fetchFacet = id => ({ type: FETCH_FACET, + id }); -export const updateFacet = ({ facetValues }) => ({ +export const updateFacet = ({ id, facetValues }) => ({ type: UPDATE_FACET, - facetValues + id, facetValues }); export const clearFacet = () => ({ type: CLEAR_FACET, diff --git a/src/client/components/FacetBar.js b/src/client/components/FacetBar.js index c6678eddf9c303e3704950f8b005bc24aca06999..38d5e8831943ad099022acd08731eb096a0375f2 100644 --- a/src/client/components/FacetBar.js +++ b/src/client/components/FacetBar.js @@ -38,7 +38,7 @@ const styles = theme => ({ class FacetBar extends React.Component { componentDidMount = () => { - this.props.fetchFacet(); + //this.props.fetchFacet('source'); } // componentDidUpdate = prevProps => { @@ -50,11 +50,11 @@ class FacetBar extends React.Component { // render() { - const { classes, facet } = this.props; + const { classes, source, productionPlace, lastUpdatedFacet } = this.props; //console.log(facet) return ( <div className={classes.root}> - {this.props.facet.fetchingFacet ? + {this.props.fetchingFacet ? <CircularProgress style={{ color: purple[500] }} thickness={5} /> : <React.Fragment> <Paper className={classes.facetContainer}> @@ -63,9 +63,11 @@ class FacetBar extends React.Component { </Paper> <div className={classes.facetValuesContainerThree}> <Tree + key='source' property='source' - lastUpdatedFacet={facet.lastUpdatedFacet} - data={facet.facetValues.source} + lastUpdatedFacet={lastUpdatedFacet} + data={source} + fetchFacet={this.props.fetchFacet} updateFilter={this.props.updateFilter} /> </div> @@ -89,9 +91,11 @@ class FacetBar extends React.Component { </Paper> <div className={classes.facetValuesContainerTen}> <Tree + key='productionPlace' property='productionPlace' - lastUpdatedFacet={facet.lastUpdatedFacet} - data={facet.facetValues.productionPlace} + lastUpdatedFacet={lastUpdatedFacet} + data={productionPlace} + fetchFacet={this.props.fetchFacet} updateFilter={this.props.updateFilter} /> </div> @@ -111,7 +115,10 @@ class FacetBar extends React.Component { FacetBar.propTypes = { classes: PropTypes.object.isRequired, fetchFacet: PropTypes.func.isRequired, - facet: PropTypes.object.isRequired, + fetchingFacet: PropTypes.bool.isRequired, + lastUpdatedFacet: PropTypes.string.isRequired, + source: PropTypes.array.isRequired, + productionPlace: PropTypes.array.isRequired, updateFilter: PropTypes.func.isRequired, }; diff --git a/src/client/components/Tree.js b/src/client/components/Tree.js index 51acd116b74cce63c31955752335e09dfebac283..0dbcd181b6307a930331f0d1a18a88d3387addc4 100644 --- a/src/client/components/Tree.js +++ b/src/client/components/Tree.js @@ -30,16 +30,20 @@ class Tree extends Component { constructor(props) { super(props); this.state = { - treeData: this.props.data, + treeData: [], searchString: '', searchFocusIndex: 0, searchFoundCount: null, }; } + componentDidMount = () => { + console.log('tree mounted') + //this.props.fetchFacet(this.props.property); + } + // componentDidUpdate = prevProps => { - // console.log(this.props.lastUpdatedFacet); - // //if (prevProps.facetFilters[this.props.property] != this.props.facetFilters ) + // if (prevProps. ) // }; handleCheckboxChange = treeObj => event => { @@ -191,6 +195,7 @@ Tree.propTypes = { property: PropTypes.string.isRequired, lastUpdatedFacet: PropTypes.string.isRequired, data: PropTypes.array.isRequired, + fetchFacet: PropTypes.func.isRequired, updateFilter: PropTypes.func.isRequired, }; diff --git a/src/client/containers/MapApp.js b/src/client/containers/MapApp.js index 400df488dce584773134fe7d3a73e8fba61ecf46..5a35afea42bbf74280cfe7096040f2f772d570bf 100644 --- a/src/client/containers/MapApp.js +++ b/src/client/containers/MapApp.js @@ -92,7 +92,10 @@ let MapApp = (props) => { <React.Fragment> <Grid item sm={12} md={3} className={classes.facetBarContainer}> <FacetBar - facet={props.facet} + fetchingFacet={props.facet.fetchingFacet} + lastUpdatedFacet={props.facet.lastUpdatedFacet} + source={props.facet.source} + productionPlace={props.facet.productionPlace} fetchFacet={props.fetchFacet} updateFilter={props.updateFilter} updatePage={props.updatePage} diff --git a/src/client/epics/index.js b/src/client/epics/index.js index bd3df40772e86f752c8b7cf50448edd6feb7ed0d..e15338f9b0517b9adf185e5981f52f1a073482db 100644 --- a/src/client/epics/index.js +++ b/src/client/epics/index.js @@ -54,7 +54,7 @@ const getPlace = action$ => action$.pipe( const getFacet = (action$, state$) => action$.pipe( ofType(FETCH_FACET), withLatestFrom(state$), - mergeMap(([, state]) => { + mergeMap(([action, state]) => { let params = {}; let filters = {}; let activeFilters = false; @@ -67,10 +67,12 @@ const getFacet = (action$, state$) => action$.pipe( if (activeFilters) { params.filters = JSON.stringify(filters); } - const searchUrl = apiUrl + 'facets'; - const requestUrl = `${searchUrl}?${stringify(params)}`; + const requestUrl = `${apiUrl}facet/${action.id}${stringify(params)}`; return ajax.getJSON(requestUrl).pipe( - map(response => updateFacet({ facetValues: response })) + map(response => updateFacet({ + id: action.id, + facetValues: response, + })) ); }) ); diff --git a/src/client/reducers/facet.js b/src/client/reducers/facet.js index 3e76908878ff38ee5b2a6b98e238190e787d4e9d..eff8054b46d2f0ce6af301000aa291d7699e5207 100644 --- a/src/client/reducers/facet.js +++ b/src/client/reducers/facet.js @@ -7,12 +7,15 @@ import { } from '../actions'; export const INITIAL_STATE = { + source: [], + productionPlace: [], + author: [], facetOptions : { productionPlace: { id: 'productionPlace', label: 'Production place', //predicate: defined in backend - type: 'hierarchical', + values: [] }, author: { id: 'author', @@ -27,11 +30,11 @@ export const INITIAL_STATE = { type: 'checkboxes' } }, - facetValues : { - productionPlace: [], - author: [], - source: [] - }, + // facetValues : { + // productionPlace: [], + // author: [], + // source: [] + // }, facetFilters: { productionPlace: new Set(), author: new Set(), @@ -58,7 +61,7 @@ const facet = (state = INITIAL_STATE, action) => { case UPDATE_FACET: return { ...state, - facetValues: action.facetValues, + [ action.id ]: action.facetValues, fetchingFacet: false }; case UPDATE_FILTER: diff --git a/src/server/index.js b/src/server/index.js index 0af9cbd4caf8bc362be91d783ffb6be681557134..f3b075a3a90f710591b685528db7c43f57969db1 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -5,7 +5,8 @@ import { getManuscripts, getPlaces, getPlace, - getFacets + getFacets, + getFacet } from './sparql/Manuscripts'; const DEFAULT_PORT = 3001; const app = express(); @@ -73,6 +74,18 @@ app.get(`${apiPath}/facets`, (req, res) => { }); }); +app.get(`${apiPath}/facet/:id`, (req, res) => { + const filters = req.query.filters == null ? null : JSON.parse(req.query.filters); + // console.log(filters) + return getFacet(req.params.id, filters).then((data) => { + res.json(data); + }) + .catch((err) => { + console.log(err); + return res.sendStatus(500); + }); +}); + /* Routes are matched to a url in order of their definition Redirect all the the rest for react-router to handle */ app.get('*', function(request, response) { diff --git a/src/server/sparql/Manuscripts.js b/src/server/sparql/Manuscripts.js index 779e65d80244e4d7f73d1296e4484042d99534ac..3c190c926d9e5ee4504d84e285e2edc910f8d652 100644 --- a/src/server/sparql/Manuscripts.js +++ b/src/server/sparql/Manuscripts.js @@ -78,7 +78,7 @@ export const getPlace = id => { }; export const getFacets = filters => { - return Promise.all(Object.values(facetConfigs).map(value => getFacet(value, filters))) + return Promise.all(Object.keys(facetConfigs).map(id => getFacet(id, filters))) .then(data => { let results = {}; let i = 0; @@ -90,9 +90,9 @@ export const getFacets = filters => { }); }; -const getFacet = (facetConfig, filters) => { +export const getFacet = (id, filters) => { let { endpoint, facetQuery } = datasetConfig['mmm']; - //console.log(filters) + const facetConfig = facetConfigs[id]; if (filters == null) { facetQuery = facetQuery.replace('<FILTER>', ''); } else { @@ -113,12 +113,10 @@ const generateFacetFilter = (facetConfig, filters) => { ?id ${facetConfigs[property].predicate} ?${property}Filter . `; } - // console.log(filterStr) return filterStr; }; const generateResultFilter = filters => { - //console.log(filters) let filterStr = ''; for (let property in filters) { filterStr += ` @@ -126,6 +124,5 @@ const generateResultFilter = filters => { ?id ${facetConfigs[property].predicate} ?${property}Filter . `; } - //console.log(filterStr) return filterStr; };