Skip to content

Commit

Permalink
add isUniqueValuesLoading to dataset header column
Browse files Browse the repository at this point in the history
  • Loading branch information
zegonz committed Apr 9, 2020
1 parent f954013 commit bdbb3a1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/lib/dataset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type ColumnTypeMapping = {
export type DataSetColumn = {
name: string;
type?: DataSetColumnType;
isUniqueValueLoading?: boolean; //It will be updated by backendify function
};

/**
Expand Down
44 changes: 33 additions & 11 deletions src/store/backend-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import { Store } from 'vuex';

import { BackendResponse } from '@/lib/backend-response';
import { BackendError, BackendResponse } from '@/lib/backend-response';
import { DataSet } from '@/lib/dataset';
import { pageOffset } from '@/lib/dataset/pagination';
import { Pipeline } from '@/lib/steps';
Expand Down Expand Up @@ -114,32 +114,54 @@ function _preparePipeline(pipeline: Pipeline, store: Store<any>) {
* - logs the error in the store if any,
* - sets the `loading: false` property on the store at the end.
*/
export function backendify(target: Function) {
export function backendify(
target: Function,
callFront?: Function,
callBack?: Function,
reject?: Function,
) {
return async function(this: BackendService | void, store: Store<any>, ...args: any[]) {
try {
store.commit(VQBnamespace('setLoading'), { isLoading: true });
if (callFront) {
callFront();
}
const response = await target.bind(this)(store, ...args);
if (response.error) {
store.commit(VQBnamespace('logBackendError'), {
backendError: response.error,
});
if (reject) {
reject(response.error);
}
}
return response;
} catch (error) {
const response = { error: { type: 'error', message: error.toString() } };
store.commit(VQBnamespace('logBackendError'), {
backendError: response.error,
});
if (reject) {
reject(response.error);
}
return response;
} finally {
store.commit(VQBnamespace('setLoading'), { isLoading: false });
if (callBack) {
callBack();
}
}
};
}

async function _updateDataset(store: Store<any>, service: BackendService, pipeline: Pipeline) {
pipeline = _preparePipeline(pipeline, store);
const response = await backendify(service.executePipeline).bind(service)(
const response = await backendify(
service.executePipeline,
() => {
store.commit(VQBnamespace('setLoading'), { isLoading: true });
},
() => {
store.commit(VQBnamespace('setLoading'), { isLoading: false });
},
(error: BackendError) => {
store.commit(VQBnamespace('logBackendError'), {
backendError: error,
});
},
).bind(service)(
store,
pipeline,
store.state[VQB_MODULE_NAME].pagesize,
Expand Down
6 changes: 6 additions & 0 deletions src/store/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ const getters: GetterTree<VQBState, any> = {
*/
pageno: (state: VQBState) =>
state.dataset.paginationContext ? state.dataset.paginationContext.pageno : 1,
/**
* helper that is True if unique values are loading
*/
isUniqueValuesLoading: (state: VQBState) => (column: string) =>
state.dataset.headers[state.dataset.headers.map(col => col.name).indexOf(column)]
.isUniqueValueLoading,
/**
* Return current edited pipeline
*/
Expand Down
12 changes: 12 additions & 0 deletions src/store/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ class Mutations {
state.isLoading = isLoading;
}

/**
* Set unique values loading
*/
setUniqueValuesLoading(
state: VQBState,
{ isLoading, column }: { isLoading: boolean; column: string },
) {
state.dataset.headers[
state.dataset.headers.map(col => col.name).indexOf(column)
].isUniqueValueLoading = isLoading;
}

/**
* Update translator.
*/
Expand Down

0 comments on commit bdbb3a1

Please sign in to comment.