-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from EmmanuelDemey/master
feat: order element case insensitive
- Loading branch information
Showing
4 changed files
with
98 additions
and
134 deletions.
There are no files selected for viewing
76 changes: 42 additions & 34 deletions
76
app/src/js/applications/administration/dashboard/concepts/home-container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,49 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Loading } from '@inseefr/wilco'; | ||
import * as select from 'js/reducers'; | ||
import Dashboard from './home'; | ||
import loadConceptSearchList from 'js/actions/concepts/search-list'; | ||
import loadCollectionDashboardList from 'js/actions/dashboard/collections'; | ||
import api from '../../../../remote-api/concepts-api'; | ||
import { ArrayUtils } from 'bauhaus-utilities'; | ||
|
||
class DashboardContainer extends Component { | ||
componentWillMount() { | ||
const { conceptSearchList, collectionDashboardList } = this.props; | ||
if (!conceptSearchList) this.props.loadConceptSearchList(); | ||
if (!collectionDashboardList) this.props.loadCollectionDashboardList(); | ||
} | ||
const emptyItem = { | ||
id: '', | ||
label: '', | ||
created: '', | ||
modified: '', | ||
disseminationStatus: '', | ||
validationStatus: '', | ||
definition: '', | ||
creator: '', | ||
isTopConceptOf: '', | ||
valid: '', | ||
}; | ||
|
||
render() { | ||
const { conceptSearchList, collectionDashboardList } = this.props; | ||
if (!conceptSearchList || !collectionDashboardList) return <Loading />; | ||
const DashboardContainer = () => { | ||
const [loading, setLoading] = useState(true); | ||
const [concepts, setConcepts] = useState([]); | ||
const [collections, setCollections] = useState([]); | ||
|
||
return ( | ||
<Dashboard | ||
conceptsData={conceptSearchList} | ||
collectionsData={collectionDashboardList} | ||
/> | ||
); | ||
} | ||
} | ||
useEffect(() => { | ||
Promise.all([ | ||
api.getConceptSearchList(), | ||
api.getCollectionDashboardList() | ||
]).then(([ conceptsList, collectionsList ]) => { | ||
|
||
const mapStateToProps = state => ({ | ||
conceptSearchList: select.getConceptSearchList(state), | ||
collectionDashboardList: select.getCollectionDashboardList(state), | ||
}); | ||
const mapDispatchToProps = { | ||
loadConceptSearchList, | ||
loadCollectionDashboardList, | ||
}; | ||
setConcepts(ArrayUtils.sortArrayByLabel(conceptsList).map(concept => | ||
Object.assign({}, emptyItem, concept) | ||
)) | ||
|
||
setCollections(ArrayUtils.sortArrayByLabel(collectionsList)); | ||
}).finally(() => setLoading(false)) | ||
}, []) | ||
if(loading){ | ||
return <Loading />; | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(DashboardContainer); | ||
return ( | ||
<Dashboard | ||
conceptsData={concepts} | ||
collectionsData={collections} | ||
/> | ||
); | ||
} | ||
export default DashboardContainer; |
152 changes: 54 additions & 98 deletions
152
app/src/js/applications/collections/visualization/home-container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,66 @@ | ||
import React, { Component } from 'react'; | ||
import { PropTypes } from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { VALIDATE_COLLECTION_LIST } from 'js/actions/constants'; | ||
import validateCollection from 'js/actions/collections/validate'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import * as select from 'js/reducers'; | ||
import loadCollections from 'js/actions/collections/collection'; | ||
import loadStampList from 'js/actions/stamp'; | ||
import { Loading, buildExtract } from '@inseefr/wilco'; | ||
import { Loading } from '@inseefr/wilco'; | ||
import CollectionVisualization from './home'; | ||
import { OK } from 'js/constants'; | ||
import { Auth, Stores } from 'bauhaus-utilities'; | ||
import { useParams } from 'react-router-dom'; | ||
import api from '../../../remote-api/concepts-api'; | ||
import globalApi from '../../../remote-api/api'; | ||
|
||
const extractId = buildExtract('id'); | ||
const CollectionVisualizationContainer = () => { | ||
const { id } = useParams(); | ||
const [collection, setCollection] = useState(); | ||
const [loading, setLoading] = useState(true); | ||
const [saving, setSaving] = useState(false); | ||
const [stamps, setStamps] = useState(); | ||
|
||
class CollectionVisualizationContainer extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
validationRequested: false, | ||
}; | ||
this.handleCollectionValidation = (id) => { | ||
this.props.validateCollection(id); | ||
this.setState({ | ||
validationRequested: true, | ||
}); | ||
}; | ||
} | ||
componentWillMount() { | ||
const { id, collection, stampList } = this.props; | ||
if (!collection) this.props.loadCollections(id); | ||
if (stampList.length === 0) this.props.loadStampList(); | ||
} | ||
|
||
componentWillReceiveProps({ id, validationStatus }) { | ||
if (id !== this.props.id) { | ||
this.props.loadCollections(id); | ||
} | ||
if (this.state.validationRequested && validationStatus === OK) { | ||
//validation has been processed successfully, we can show the | ||
//component again | ||
this.setState({ | ||
validationRequested: false, | ||
}); | ||
//we need to load the collection again | ||
this.props.loadCollections(id); | ||
} | ||
} | ||
render() { | ||
const { validationRequested } = this.state; | ||
const { validationStatus, langs } = this.props; | ||
if (validationRequested && validationStatus !== OK) { | ||
//if validation is OK: nothing to do. We stay on this page and the collection will | ||
//be loaded automatically (since the entries for the given collection in the store will | ||
//be deleted). | ||
if (validationStatus !== OK) return <Loading textType="validating" />; | ||
} | ||
const { id, permission, collection, stampList, secondLang } = this.props; | ||
if (collection && stampList) { | ||
const { general, members } = collection; | ||
return ( | ||
<CollectionVisualization | ||
id={id} | ||
permission={permission} | ||
general={general} | ||
members={members} | ||
stampList={stampList} | ||
validateCollection={this.handleCollectionValidation} | ||
validationStatus={validationStatus} | ||
secondLang={secondLang} | ||
langs={langs} | ||
/> | ||
); | ||
} | ||
return <Loading />; | ||
const permission = useSelector(state => Auth.getPermission(state)); | ||
const secondLang = useSelector(state => Stores.SecondLang.getSecondLang(state)); | ||
const langs = useSelector(state => select.getLangs(state)) | ||
|
||
const fetchData = () => { | ||
Promise.all([ | ||
api.getCollectionGeneral(id), | ||
api.getCollectionMembersList(id), | ||
globalApi.getStampList() | ||
]).then(([general, members, stamps]) => { | ||
setCollection({ general, members}); | ||
setStamps(stamps); | ||
}).finally(() => setLoading(false)) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state, ownProps) => { | ||
const id = extractId(ownProps); | ||
return { | ||
id, | ||
permission: Auth.getPermission(state), | ||
secondLang: Stores.SecondLang.getSecondLang(state), | ||
collection: select.getCollection(state, id), | ||
stampList: Stores.Stamps.getStampList(state), | ||
validationStatus: select.getStatus(state, VALIDATE_COLLECTION_LIST), | ||
langs: select.getLangs(state), | ||
}; | ||
}; | ||
useEffect(() => { | ||
fetchData(); | ||
}, []) | ||
|
||
const mapDispatchToProps = { | ||
loadCollections, | ||
loadStampList, | ||
validateCollection: (id) => validateCollection([id]), | ||
}; | ||
const handleCollectionValidation = (id) => { | ||
setSaving(true) | ||
api.putCollectionValidList([id]) | ||
.then(() => fetchData()) | ||
.finally(() => setSaving(false)); | ||
} | ||
if(loading){ | ||
return <Loading /> | ||
} | ||
|
||
CollectionVisualizationContainer = connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(CollectionVisualizationContainer); | ||
if(saving){ | ||
return <Loading textType="validating" /> | ||
} | ||
const { general, members } = collection; | ||
|
||
CollectionVisualizationContainer.propTypes = { | ||
match: PropTypes.shape({ | ||
params: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
}), | ||
}), | ||
}; | ||
return ( | ||
<CollectionVisualization | ||
id={id} | ||
permission={permission} | ||
general={general} | ||
members={members} | ||
stampList={stamps} | ||
validateCollection={handleCollectionValidation} | ||
secondLang={secondLang} | ||
langs={langs} | ||
/> | ||
); | ||
} | ||
export default CollectionVisualizationContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters