Skip to content

Commit

Permalink
Merge pull request #3110 from kobotoolbox/3109-custom-export-settings…
Browse files Browse the repository at this point in the history
…-save-bug-fix

Project downloads settings not saving properly bug fix
  • Loading branch information
jnm committed Mar 26, 2021
2 parents d56621b + 86f9ce4 commit 27cff69
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions jsapp/js/components/library/myLibraryStore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const myLibraryStore = Reflux.createStore({
PAGE_SIZE: 100,
DEFAULT_ORDER_COLUMN: ASSETS_TABLE_COLUMNS['date-modified'],

isVirgin: true,
isInitialised: false,

data: {
isFetchingData: false,
Expand Down Expand Up @@ -69,7 +69,7 @@ const myLibraryStore = Reflux.createStore({
* otherwise wait until route changes to a library (see `onRouteChange`)
*/
startupStore() {
if (this.isVirgin && isOnLibraryRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnLibraryRoute() && !this.data.isFetchingData) {
this.fetchData(true);
}
},
Expand Down Expand Up @@ -133,7 +133,7 @@ const myLibraryStore = Reflux.createStore({
},

onRouteChange(data) {
if (this.isVirgin && isOnLibraryRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnLibraryRoute() && !this.data.isFetchingData) {
this.fetchData(true);
} else if (
(
Expand Down Expand Up @@ -186,7 +186,7 @@ const myLibraryStore = Reflux.createStore({
this.data.totalUserAssets = this.data.totalSearchAssets;
}
this.data.isFetchingData = false;
this.isVirgin = false;
this.isInitialised = true;
this.trigger(this.data);
},

Expand Down
6 changes: 3 additions & 3 deletions jsapp/js/components/library/ownedCollectionsStore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {isOnLibraryRoute} from './libraryUtils';
import {ASSET_TYPES} from 'js/constants';

const ownedCollectionsStore = Reflux.createStore({
isVirgin: true,
isInitialised: false,

data: {
isFetchingData: false,
Expand All @@ -33,7 +33,7 @@ const ownedCollectionsStore = Reflux.createStore({

startupStore() {
if (
this.isVirgin &&
!this.isInitialised &&
isOnLibraryRoute() &&
stores.session.currentAccount !== undefined &&
!this.data.isFetchingData
Expand All @@ -47,7 +47,7 @@ const ownedCollectionsStore = Reflux.createStore({
onGetCollectionsCompleted(response) {
this.data.collections = response.results;
this.data.isFetchingData = false;
this.isVirgin = false;
this.isInitialised = true;
this.trigger(this.data);
},

Expand Down
8 changes: 4 additions & 4 deletions jsapp/js/components/library/publicCollectionsStore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const publicCollectionsStore = Reflux.createStore({
PAGE_SIZE: 100,
DEFAULT_ORDER_COLUMN: ASSETS_TABLE_COLUMNS['date-modified'],

isVirgin: true,
isInitialised: false,

data: {
isFetchingData: false,
Expand Down Expand Up @@ -66,7 +66,7 @@ const publicCollectionsStore = Reflux.createStore({
* otherwise wait until route changes to a library (see `onRouteChange`)
*/
startupStore() {
if (this.isVirgin && isOnPublicCollectionsRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnPublicCollectionsRoute() && !this.data.isFetchingData) {
this.fetchData(true);
}
},
Expand Down Expand Up @@ -129,7 +129,7 @@ const publicCollectionsStore = Reflux.createStore({
},

onRouteChange(data) {
if (this.isVirgin && isOnPublicCollectionsRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnPublicCollectionsRoute() && !this.data.isFetchingData) {
this.fetchData(true);
} else if (
this.previousPath.startsWith(ROUTES.PUBLIC_COLLECTIONS) === false &&
Expand Down Expand Up @@ -172,7 +172,7 @@ const publicCollectionsStore = Reflux.createStore({
}
this.data.totalSearchAssets = response.count;
this.data.isFetchingData = false;
this.isVirgin = false;
this.isInitialised = true;
this.trigger(this.data);
},

Expand Down
8 changes: 4 additions & 4 deletions jsapp/js/components/library/singleCollectionStore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const singleCollectionStore = Reflux.createStore({
PAGE_SIZE: 100,
DEFAULT_ORDER_COLUMN: ASSETS_TABLE_COLUMNS['date-modified'],

isVirgin: true,
isInitialised: false,

data: {
isFetchingData: false,
Expand Down Expand Up @@ -65,7 +65,7 @@ const singleCollectionStore = Reflux.createStore({
* otherwise wait until route changes to a library (see `onRouteChange`)
*/
startupStore() {
if (this.isVirgin && isOnLibraryAssetRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnLibraryAssetRoute() && !this.data.isFetchingData) {
this.fetchData(true);
}
},
Expand Down Expand Up @@ -134,7 +134,7 @@ const singleCollectionStore = Reflux.createStore({
},

onRouteChange(data) {
if (this.isVirgin && isOnLibraryAssetRoute() && !this.data.isFetchingData) {
if (!this.isInitialised && isOnLibraryAssetRoute() && !this.data.isFetchingData) {
this.fetchData(true);
} else if (
(
Expand Down Expand Up @@ -173,7 +173,7 @@ const singleCollectionStore = Reflux.createStore({
this.data.totalUserAssets = this.data.totalSearchAssets;
}
this.data.isFetchingData = false;
this.isVirgin = false;
this.isInitialised = true;
this.trigger(this.data);
},

Expand Down
18 changes: 14 additions & 4 deletions jsapp/js/components/projectDownloads/projectExportsCreator.es6
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ export default class ProjectExportsCreator extends React.Component {
}

onAnyInputChange(statePropName, newValue) {
this.clearSelectedDefinedExport();
const newStateObj = {};
newStateObj[statePropName] = newValue;
this.setState(newStateObj);
this.clearSelectedDefinedExport();
}

onSelectedExportTypeChange(newValue) {
Expand All @@ -290,6 +290,7 @@ export default class ProjectExportsCreator extends React.Component {
}

onSelectedRowsChange(newRowsArray) {
this.clearSelectedDefinedExport();
const newSelectedRows = new Set();
newRowsArray.forEach((item) => {
if (item.checked) {
Expand All @@ -301,11 +302,13 @@ export default class ProjectExportsCreator extends React.Component {

selectAllRows(evt) {
evt.preventDefault();
this.clearSelectedDefinedExport();
this.setState({selectedRows: new Set(this.getAllSelectableRows())});
}

clearSelectedRows(evt) {
evt.preventDefault();
this.clearSelectedDefinedExport();
this.setState({selectedRows: new Set()});
}

Expand Down Expand Up @@ -392,7 +395,8 @@ export default class ProjectExportsCreator extends React.Component {
payload.name = this.state.customExportName || this.generateExportName();
}

// unless custom selection is enabled, we send empty fields (it means "all fields" for backend)
// unless custom selection is enabled, we send empty fields (it means "all
// fields" for backend); otherwise we send the selected rows
if (this.state.isCustomSelectionEnabled) {
payload.export_settings.fields = Array.from(this.state.selectedRows);
}
Expand Down Expand Up @@ -603,7 +607,10 @@ export default class ProjectExportsCreator extends React.Component {
/>

<bem.ProjectDownloads__textButton
disabled={!this.state.isCustomSelectionEnabled}
disabled={(
!this.state.isCustomSelectionEnabled ||
this.state.selectedRows.size === this.state.selectableRowsCount
)}
onClick={this.selectAllRows}
>
{t('Select all')}
Expand All @@ -612,7 +619,10 @@ export default class ProjectExportsCreator extends React.Component {
<span className='project-downloads__vr'/>

<bem.ProjectDownloads__textButton
disabled={!this.state.isCustomSelectionEnabled}
disabled={(
!this.state.isCustomSelectionEnabled ||
this.state.selectedRows.size === 0
)}
onClick={this.clearSelectedRows}
>
{t('Deselect all')}
Expand Down

0 comments on commit 27cff69

Please sign in to comment.