Skip to content

Commit

Permalink
Merge pull request #253 from EmmanuelDemey/master
Browse files Browse the repository at this point in the history
feat: order element case insensitive
  • Loading branch information
BulotF authored Feb 2, 2022
2 parents 002c625 + f35f9a4 commit 2d78e73
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 134 deletions.
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 app/src/js/applications/collections/visualization/home-container.js
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;
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class SimsCreation extends React.Component {
label: op.labelLg1,
value: op.idSims,
})
);
).sort((o1, o2) => o1.label.toLowerCase().localeCompare(o2.label.toLowerCase()));
function MSDInformations(msd, handleChange, firstLevel = false) {
return (
<React.Fragment key={msd.idMas}>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"react-redux": "7.2.0",
"react-router-dom": "5.2.0",
"redux": "4.0.5",
"rollup": "^2.53.2"
"rollup": "^2.66.1"
},
"husky": {
"hooks": {
Expand Down

0 comments on commit 2d78e73

Please sign in to comment.