Commit 1ba480bc authored by Matija Obreza's avatar Matija Obreza

Merge branch 'genesys-ui-96-unnecessary-api-calls' into 'master'

Unnecessary API calls

See merge request !320
parents 1e3fe909 366f0c11
Pipeline #7448 passed with stages
in 8 minutes and 32 seconds
......@@ -5,6 +5,7 @@ import { clearCookies, saveCookies } from 'utilities';
import { ROLE_CLIENT } from 'constants/userRoles';
import { log } from 'utilities/debug';
import { configureBackendApi } from 'utilities/requestUtils';
import {receiveUserProfile} from './userProfile';
export function checkAccessTokens(dispatch) {
const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token');
......@@ -123,6 +124,7 @@ export const logoutRequest = () => (dispatch, getState) => {
return LoginService.logout(token)
.then(() => {
clearCookies();
dispatch(receiveUserProfile(null));
return dispatch(logout());
});
};
......@@ -7,7 +7,7 @@ import { RECEIVE_USER_PROFILE } from 'constants/userProfile';
import User from 'model/user/User';
import { IReducerAction } from 'model/common.model';
const receiveUserProfile = (user: User): IReducerAction => ({
export const receiveUserProfile = (user: User): IReducerAction => ({
type: RECEIVE_USER_PROFILE, payload: user,
});
......
......@@ -96,22 +96,29 @@ function deleteDataset(dataset: Dataset) {
// Review step exports
export { rejectDataset, approveDataset, publishDataset, deleteDataset };
export const clearAccessionRefs = (dataset: Dataset) => (dispatch) => {
return DatasetService.upsertAccessions(dataset.uuid, dataset.version, [])
.then((saved) => {
dispatch(receiveDataset(saved));
return saved;
}).catch((error) => {
log('Publish error', error);
return Promise.reject(error);
});
};
// Accession identifiers step
function updateDatasetAccessionRefs(dataset: Dataset, accessionRefs: AccessionRef[]) {
return (dispatch, getState) => {
return DatasetService.upsertAccessions(dataset.uuid, dataset.version, accessionRefs)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Publish error', error);
});
};
}
export const updateDatasetAccessionRefs = (dataset: Dataset, accessionRefs: AccessionRef[]) => (dispatch) => {
// Accession identifiers step exports
export { updateDatasetAccessionRefs };
return DatasetService.upsertAccessions(dataset.uuid, dataset.version, accessionRefs)
.then((saved) => {
dispatch(receiveDataset(saved));
return saved;
}).catch((error) => {
log('Publish error', error);
return Promise.reject(error);
});
};
// Descriptors step
......@@ -238,8 +245,10 @@ function updateCreatorRequest(uuid: string, creator: DatasetCreator) {
return (dispatch, getState) => {
return DatasetService.updateDatasetCreator(uuid, creator)
.then((obj) => {
dispatch(updateCreator(obj));
.then((saved) => {
if (saved.version !== creator.version) {
dispatch(updateCreator(saved));
}
}).catch((error) => {
log('Update creator error', error);
});
......@@ -313,7 +322,9 @@ function updateLocationRequest(datasetUUID: string, location: DatasetLocation) {
return DatasetService.updateLocation(datasetUUID, location)
.then((saved) => {
dispatch(receiveLocation(saved));
if (saved.version !== location.version) {
dispatch(receiveLocation(saved));
}
dispatch(receiveDataset(refreshStartEndDates(getState().datasets.dashboard.dataset)));
}).catch((error) => {
log('Save error', error);
......@@ -340,15 +351,16 @@ export { createLocationRequest, updateLocationRequest, deleteLocationRequest, re
// Common actions
function loadDataset(uuid: string) {
return (dispatch, getState) => {
return (dispatch): Promise<Dataset> => {
return DatasetService.getDataset(uuid)
.then((dataset) => {
dispatch(receiveDataset(dataset));
return dataset;
})
.catch((error) => {
log('Error', error);
return null;
});
};
}
......@@ -365,11 +377,12 @@ const saveDataset = (dataset: Dataset) => (dispatch, getState) => {
// remove normalized data here
const data: Dataset = {
...dataset,
repositoryFiles: [],
creators: [],
locations: [],
descriptors: [],
...dataset,
accessionRefs: [],
};
return saveOrUpdate(data)
......
......@@ -101,7 +101,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
log('Payload ADD_CREATOR_TO_DATASET', action);
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
return update(state, {
dataset: { creators: { $push: [action.payload.creator] } },
dataset: {
version: { $set: state.dataset.version + 1 },
creators: { $push: [action.payload.creator] },
},
});
} else {
return state;
......@@ -112,7 +115,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
log('Payload REMOVE_CREATOR_FROM_DATASET', action);
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
return update(state, {
dataset: { creators: { $apply: (creators) => creators.filter((creator) => creator.uuid !== action.payload.creator.uuid) } },
dataset: {
version: { $set: state.dataset.version + 1 },
creators: { $apply: (creators) => creators.filter((creator) => creator.uuid !== action.payload.creator.uuid) },
},
});
} else {
return state;
......@@ -124,7 +130,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
const index = state.dataset.creators.findIndex((creator) => creator.uuid === action.payload.creator.uuid);
return update(state, {
dataset: { creators: { [index]: { $set: action.payload.creator } } },
dataset: {
version: { $set: state.dataset.version + 1 },
creators: { [index]: { $set: action.payload.creator } },
},
});
} else {
return state;
......@@ -136,7 +145,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
log('Payload ADD_LOCATION', action);
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
return update(state, {
dataset: { locations: { $push: [action.payload.location] } },
dataset: {
version: { $set: state.dataset.version + 1 },
locations: { $push: [action.payload.location] },
},
});
} else {
return state;
......@@ -147,7 +159,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
log('Payload REMOVE_LOCATION', action);
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
return update(state, {
dataset: { locations: { $apply: (locations) => locations.filter((location) => location.uuid !== action.payload.location.uuid) } },
dataset: {
version: { $set: state.dataset.version + 1 },
locations: { $apply: (locations) => locations.filter((location) => location.uuid !== action.payload.location.uuid) },
},
});
} else {
return state;
......@@ -159,7 +174,10 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
if (state.dataset) { // && action.payload.datasetUUID === state.dataset.uuid) {
const index = state.dataset.locations.findIndex((location) => location.uuid === action.payload.location.uuid);
return update(state, {
dataset: { locations: { [index]: { $set: action.payload.location } } },
dataset: {
version: { $set: state.dataset.version + 1 },
locations: { [index]: { $set: action.payload.location } },
},
});
} else {
return state;
......
......@@ -161,7 +161,7 @@ const mapStateToProps = (state, ownProps) => ({
sort: parse(ownProps.location.search).s, // page sorts
dir: parse(ownProps.location.search).d, // page sort directions
filter: state.filterCode.filters && parse(ownProps.location.search).filter && state.filterCode.filters[parse(ownProps.location.search).filter] || null,
filterCode: parse(ownProps.location.search).filter,
filterCode: parse(ownProps.location.search).filter || '',
}),
paged: state.datasets.public.paged,
});
......
......@@ -10,10 +10,12 @@ import AccessionRef from 'model/accession/AccessionRef';
import AccessionRefsTable from 'ui/catalog/accession/AccessionRefsTable';
import { CSV, ICsvConfiguration } from 'utilities/CSV';
import CSVConfiguration, { CSVConfig } from 'ui/common/csv-configuration/CSVConfiguration';
import Dataset from 'model/catalog/Dataset';
import Loading from 'ui/common/Loading';
interface IListOfAccession extends React.ClassAttributes<any> {
classes: any;
onAccessionsUpdated: (accessionRefs: AccessionRef[]) => void;
onAccessionsUpdated: (accessionRefs: AccessionRef[]) => Promise<Dataset>;
accessionRefs: AccessionRef[];
}
......@@ -43,14 +45,19 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
quote: '"',
autodetect: false,
},
uploading: false,
};
}
public dataPasted = (e) => {
e.preventDefault();
this.setState({ ...this.state, uploading: true, uploadText: 'Parsing' });
console.log('Pasted', e.clipboardData);
// console.log(e.clipboardData.getData('text/plain'));
this.parseCsv(e.clipboardData.getData('text/plain'));
// Delay parsing a little bit for UI to update
const data = e.clipboardData.getData('text/plain');
setTimeout(() => this.parseCsv(data), 10);
}
public textBlurred = (e) => {
......@@ -64,6 +71,7 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
private parseCsv(csvText: string) {
// log('CSV text', csvText);
if (! csvText) {
this.setState({ ...this.state, uploading: false, uploadText: undefined });
return;
}
......@@ -78,16 +86,25 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
.on('json', (jsonObj) => {
const aid: AccessionRef = jsonObj as AccessionRef;
newIdentifiers.push(aid);
log(aid);
// log(aid);
}).on('end', () => {
log('All CSV parsed');
this.props.onAccessionsUpdated(newIdentifiers);
this.setState({ ...this.state, uploading: true, uploadText: 'Uploading to server' });
log('All CSV parsed');
this.props.onAccessionsUpdated(newIdentifiers)
.then((dataset) => {
console.log('Done', dataset);
this.setState({ ...this.state, uploading: false });
}).catch((err) => {
this.setState({ ...this.state, uploading: false });
console.log('Error uploading', err);
});
});
}
public render() {
const {classes, accessionRefs} = this.props;
const { uploading, uploadText } = this.state;
return (
<div className={ `${ classes.root } m-20 p-20 even-row` }>
......@@ -111,9 +128,10 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
<Input multiline placeholder="Paste accessions data here (comma separated)" onPaste={ this.dataPasted } onBlur={ this.textBlurred }/>
</FormControl>
</form>
</div>
{ uploading && <Loading message={ uploadText } /> }
<h3>Accession list: { accessionRefs ? accessionRefs.length : 0 } rows</h3>
<AccessionRefsTable accessionRefs={ accessionRefs } />
</div>
......
......@@ -33,7 +33,9 @@ interface IDatasetProps extends React.ClassAttributes<any> {
class BasicInfoStep extends React.Component<IDatasetProps, any> {
protected static needs = [];
protected static needs = [
() => loadMyPartners(),
];
public componentWillMount() {
const {myPartners, loadMyPartners} = this.props;
......@@ -68,6 +70,7 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
const mapStateToProps = (state, ownProps) => ({
dataset: state.datasets.dashboard.dataset,
myPartners: state.partner.dashboard.myPartners,
stillLoading: ownProps.stillLoading,
location: ownProps.location,
onDelete: ownProps.onDelete,
......
......@@ -168,7 +168,7 @@ const mapStateToProps = (state, ownProps) => ({
sort: parse(ownProps.location.search).s, // page sorts
dir: parse(ownProps.location.search).d, // page sort directions
filter: state.filterCode.filters && parse(ownProps.location.search).filter && state.filterCode.filters[parse(ownProps.location.search).filter] || null,
filterCode: parse(ownProps.location.search).filter,
filterCode: parse(ownProps.location.search).filter || '',
}),
paged: state.descriptorList.public.paged,
loading: state.descriptorList.loading,
......
......@@ -45,9 +45,9 @@ class DescriptorListPage extends React.Component<IDescriptorListPageProps, any>
];
public componentWillMount() {
const {uuid, loading, loadDescriptorList} = this.props;
const {uuid, loadDescriptorList, descriptorList} = this.props;
if (uuid && (! loading || loading.uuid !== uuid)) {
if (uuid && (! descriptorList || descriptorList.uuid !== uuid)) {
loadDescriptorList(uuid);
}
}
......
......@@ -13,8 +13,6 @@ import BottomSection from 'ui/common/stepper/BottomSection';
import DescriptorList from 'model/catalog/DescriptorList';
import renderRoutes from 'ui/renderRoutes';
import {loadMyPartners} from 'partners/actions/dashboard';
import Partner from 'model/genesys/Partner';
import steps from './steps';
import PageLayout from 'ui/layout/PageLayout';
......@@ -30,8 +28,6 @@ interface IDescriptorListProps extends React.ClassAttributes<any> {
navigateTo: (path: string) => void;
setPageTitle: (title: string) => void;
loadMyPartners: any;
myPartners: Partner[];
publishDescriptorList: (descriptorList: DescriptorList, showDescriptorList: boolean) => void;
deleteDescriptorList: (descriptorList: DescriptorList) => Promise<DescriptorList>;
}
......@@ -52,11 +48,7 @@ class DescriptorListStepper extends React.Component<IDescriptorListProps, any> {
}
public componentWillMount() {
const {uuid, descriptorList, loadDescriptorList, myPartners, loadMyPartners} = this.props;
if (!myPartners) {
loadMyPartners();
}
const {uuid, descriptorList, loadDescriptorList} = this.props;
if (uuid && ! descriptorList) {
loadDescriptorList(uuid);
......@@ -128,7 +120,6 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadDescriptorList,
deleteDescriptorList,
loadMyPartners,
publishDescriptorList,
setPageTitle,
navigateTo,
......
......@@ -164,7 +164,7 @@ const mapStateToProps = (state, ownProps) => ({
sort: parse(ownProps.location.search).s, // page sorts
dir: parse(ownProps.location.search).d, // page sort directions
filter: state.filterCode.filters && parse(ownProps.location.search).filter && state.filterCode.filters[parse(ownProps.location.search).filter] || null,
filterCode: parse(ownProps.location.search).filter,
filterCode: parse(ownProps.location.search).filter || '',
}),
paged: state.partner.public.paged,
loading: state.partner.public.loading,
......
......@@ -21,13 +21,19 @@ interface IProfilePageProps extends React.ClassAttributes<any> {
class ProfilePage extends React.Component<IProfilePageProps, any> {
protected static needs = [
() => loadUserProfile(),
];
constructor(props) {
super(props);
}
public componentWillMount() {
const { loadUserProfile } = this.props;
loadUserProfile();
const { loadUserProfile, userProfile } = this.props;
if (! userProfile) {
loadUserProfile();
}
}
private onChangePassword = (values) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment