Skip to content

Commit 201dff7

Browse files
authored
Fix unsupported listing on create dataset from connection (#3077)
1 parent c8914df commit 201dff7

File tree

6 files changed

+144
-35
lines changed

6 files changed

+144
-35
lines changed

src/ui/units/datasets/containers/DatasetSources/DatasetSources.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,23 @@ export class DatasetSources extends React.Component {
276276
}
277277
};
278278

279-
retryToGetSources = () => {
279+
retryToGetSources = async () => {
280280
const {
281281
selectedConnection: {entryId} = {},
282282
workbookId,
283283
sourcesPagination,
284-
options,
285-
currentDbName,
284+
resetSourcesPagination,
285+
getSourcesListingOptions,
286286
} = this.props;
287287

288288
if (!entryId) {
289289
return;
290290
}
291-
const {serverPagination, dbNameRequiredForSearch} = getSourceListingValues(
292-
options?.source_listing,
293-
);
291+
292+
resetSourcesPagination();
293+
const {sourceListing, currentDbName} = await getSourcesListingOptions(entryId);
294+
295+
const {serverPagination, dbNameRequiredForSearch} = getSourceListingValues(sourceListing);
294296

295297
this.props.getSources({
296298
connectionId: entryId,
@@ -699,7 +701,9 @@ export class DatasetSources extends React.Component {
699701
>
700702
<SelectSourcePrototypes
701703
sdk={sdk}
702-
isSourcesLoading={ui.isSourcesLoading}
704+
isSourcesLoading={
705+
ui.isSourcesLoading || ui.isSourcesListingOptionsLoading
706+
}
703707
isDisabledAddSource={isUpdating}
704708
isDisabledDropSource={this.isDisabledDropSource}
705709
connections={connections}

src/ui/units/datasets/store/actions/creators/datasetTyped.ts

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
Dataset,
1313
DatasetAvatarRelation,
1414
DatasetField,
15+
DatasetOptions,
1516
DatasetSource,
1617
DatasetSourceAvatar,
1718
WorkbookId,
@@ -491,13 +492,16 @@ export function deleteConnection({
491492
},
492493
} = getState();
493494

495+
getSdk().cancelRequest('getSourceListingOptions');
496+
getSdk().cancelRequest('getDbNames');
494497
getSdk().cancelRequest('getSources');
495498

496499
if (
497500
(sourceLoadingError && sourceLoadingError.connectionId === connectionId) ||
498501
!selectedConnections.length
499502
) {
500503
dispatch(setSourcesLoadingError(null));
504+
dispatch(setSourcesListingOptionsError(null));
501505
}
502506
};
503507
}
@@ -804,6 +808,16 @@ export function toggleSourcesLoader(isSourcesLoading: boolean) {
804808
});
805809
};
806810
}
811+
812+
export function toggleSourcesListingOptionsLoader(isLoading: boolean) {
813+
return (dispatch: DatasetDispatch) => {
814+
dispatch({
815+
type: DATASET_ACTION_TYPES.TOGGLE_SOURCES_LISTING_OPTIONS_LOADER,
816+
payload: {isLoading},
817+
});
818+
};
819+
}
820+
807821
export function setSourcesLoadingError(error: DatasetError) {
808822
return (dispatch: DatasetDispatch) => {
809823
dispatch({
@@ -813,6 +827,15 @@ export function setSourcesLoadingError(error: DatasetError) {
813827
};
814828
}
815829

830+
export function setSourcesListingOptionsError(error: DatasetError) {
831+
return (dispatch: DatasetDispatch) => {
832+
dispatch({
833+
type: DATASET_ACTION_TYPES.SET_SOURCES_LISTING_OPTIONS_ERROR,
834+
payload: {error},
835+
});
836+
};
837+
}
838+
816839
export function setDatasetRevisionMismatch() {
817840
return (dispatch: DatasetDispatch) => {
818841
dispatch({type: DATASET_ACTION_TYPES.SET_DATASET_REVISION_MISMATCH});
@@ -1375,10 +1398,19 @@ export function getSources({
13751398
isSideEffect = false,
13761399
}: GetSourcesProps) {
13771400
return async (dispatch: DatasetDispatch, getState: GetState) => {
1401+
const {
1402+
sourcesPagination,
1403+
errors: {sourceListingOptionsError},
1404+
} = getState().dataset;
1405+
1406+
if (sourceListingOptionsError) {
1407+
dispatch(setSourcesLoadingError(sourceListingOptionsError));
1408+
dispatch(setSourcesListingOptionsError(null));
1409+
return [];
1410+
}
13781411
if (!isSideEffect) {
13791412
dispatch(toggleSourcesLoader(true));
13801413
}
1381-
const {sourcesPagination} = getState().dataset;
13821414
let sources: GetSourceResponse['sources'] = [];
13831415
const currentLimit = limit ? limit + 1 : 10000;
13841416
try {
@@ -1447,27 +1479,28 @@ export function getSources({
14471479

14481480
export function getDbNames(connectionIds: string[]) {
14491481
return async (dispatch: DatasetDispatch, getState: GetState) => {
1450-
dispatch(toggleSourcesLoader(true));
1482+
dispatch(toggleSourcesListingOptionsLoader(true));
14511483
try {
14521484
if (connectionIds.length) {
14531485
const state = getState();
14541486
const {
14551487
options: {source_listing},
14561488
} = state.dataset;
14571489
const currentEntryId = selectedConnectionSelector(state)?.entryId;
1458-
const result = await Promise.allSettled(
1490+
const result = await Promise.all(
14591491
connectionIds.map((id) =>
14601492
getSdk()
1461-
.sdk.bi.getDbNames({connectionId: id})
1493+
.sdk.bi.getDbNames(
1494+
{connectionId: id},
1495+
{concurrentId: 'getDbNames', retries: 2},
1496+
)
14621497
.then((res) => ({id, ...res})),
14631498
),
14641499
);
1465-
const existingDbNames = result
1466-
.filter((item) => item.status === 'fulfilled')
1467-
.reduce<Record<string, string[]>>((acc, item) => {
1468-
acc[item.value.id] = item.value.db_names;
1469-
return acc;
1470-
}, {});
1500+
const existingDbNames = result.reduce<Record<string, string[]>>((acc, item) => {
1501+
acc[item.id] = item.db_names;
1502+
return acc;
1503+
}, {});
14711504

14721505
batch(() => {
14731506
dispatch({
@@ -1481,8 +1514,9 @@ export function getDbNames(connectionIds: string[]) {
14811514
}
14821515
} catch (e) {
14831516
logger.logError('dataset: getDbNames failed', e);
1517+
dispatch(setSourcesListingOptionsError(e));
14841518
} finally {
1485-
dispatch(toggleSourcesLoader(false));
1519+
dispatch(toggleSourcesListingOptionsLoader(false));
14861520
}
14871521
};
14881522
}
@@ -1806,6 +1840,7 @@ export function initializeDataset({connectionId}: {connectionId: string}) {
18061840
return async (dispatch: DatasetDispatch) => {
18071841
if (connectionId) {
18081842
await dispatch(setInitialSources([connectionId]));
1843+
await dispatch(getSourcesListingOptions(connectionId));
18091844
}
18101845

18111846
dispatch(_getSources());
@@ -1963,29 +1998,39 @@ function _getSources() {
19631998

19641999
export function getSourcesListingOptions(connectionId: string) {
19652000
return async (dispatch: DatasetDispatch, getState: GetState) => {
1966-
dispatch(toggleSourcesLoader(true));
1967-
1968-
const result = await (DatasetUtils.isEnabledFeature(Feature.EnableDatasetSourcesPagination)
1969-
? getSdk().sdk.bi.getSourceListingOptions({connectionId})
1970-
: undefined);
1971-
1972-
dispatch({
1973-
type: DATASET_ACTION_TYPES.SET_SOURCES_LISTING_OPTIONS,
1974-
payload: result?.source_listing,
1975-
});
2001+
dispatch(toggleSourcesListingOptionsLoader(true));
2002+
let sourceListing: DatasetOptions['source_listing'] | undefined;
2003+
try {
2004+
const result = await (DatasetUtils.isEnabledFeature(
2005+
Feature.EnableDatasetSourcesPagination,
2006+
)
2007+
? getSdk().sdk.bi.getSourceListingOptions(
2008+
{connectionId},
2009+
{concurrentId: 'getSourceListingOptions', retries: 2},
2010+
)
2011+
: undefined);
2012+
sourceListing = result?.source_listing;
19762013

1977-
const {dbNameRequiredForSearch, supportsDbNameListing} = getSourceListingValues(
1978-
result?.source_listing,
1979-
);
2014+
dispatch({
2015+
type: DATASET_ACTION_TYPES.SET_SOURCES_LISTING_OPTIONS,
2016+
payload: sourceListing,
2017+
});
19802018

1981-
dispatch(toggleSourcesLoader(false));
2019+
const {dbNameRequiredForSearch, supportsDbNameListing} =
2020+
getSourceListingValues(sourceListing);
19822021

1983-
if (dbNameRequiredForSearch || supportsDbNameListing) {
1984-
await dispatch(getDbNames([connectionId]));
2022+
if (dbNameRequiredForSearch || supportsDbNameListing) {
2023+
await dispatch(getDbNames([connectionId]));
2024+
}
2025+
} catch (error) {
2026+
logger.logError('dataset: getSourcesListingOptions failed', error);
2027+
dispatch(setSourcesListingOptionsError(error));
2028+
} finally {
2029+
dispatch(toggleSourcesListingOptionsLoader(false));
19852030
}
19862031

19872032
const currentDbName = getState().dataset.currentDbName;
19882033

1989-
return {sourceListing: result?.source_listing, currentDbName};
2034+
return {sourceListing, currentDbName};
19902035
};
19912036
}

src/ui/units/datasets/store/actions/types/dataset.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ export const TOGGLE_FIELD_EDITOR_MODULE_LOADING = Symbol(
7979
);
8080

8181
export const TOGGLE_SOURCES_LOADER = Symbol('dataset/TOGGLE_SOURCES_LOADER');
82+
export const TOGGLE_SOURCES_LISTING_OPTIONS_LOADER = Symbol(
83+
'dataset/TOGGLE_SOURCES_LISTING_OPTIONS_LOADER',
84+
);
8285
export const SET_SOURCES_LOADING_ERROR = Symbol('dataset/SET_SOURCES_LOADING_ERROR');
8386
export const SET_DATASET_REVISION_MISMATCH = Symbol('dataset/SET_DATASET_REVISION_MISMATCH');
8487

88+
export const SET_SOURCES_LISTING_OPTIONS_ERROR = Symbol(
89+
'dataset/SET_SOURCES_LISTING_OPTIONS_ERROR',
90+
);
91+
8592
export const EDITOR_SET_FILTER = Symbol('dataset/EDITOR_SET_FILTER');
8693
export const EDITOR_SET_ITEMS_TO_DISPLAY = Symbol('dataset/EDITOR_SET_ITEMS_TO_DISPLAY');
8794

src/ui/units/datasets/store/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const initialState: DatasetReduxState = {
6868
savingError: null,
6969
sourceLoadingError: null,
7070
validationError: null,
71+
sourceListingOptionsError: null,
7172
},
7273
validation: {
7374
isLoading: false,
@@ -89,6 +90,7 @@ export const initialState: DatasetReduxState = {
8990
isFieldEditorModuleLoading: false,
9091
isSourcesLoading: false,
9192
isSourcesSearchLoading: false,
93+
isSourcesListingOptionsLoading: false,
9294
},
9395
editor: {
9496
filter: '',

src/ui/units/datasets/store/reducers/dataset.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
SET_LAST_MODIFIED_TAB,
6565
SET_QUEUE_TO_LOAD_PREVIEW,
6666
SET_SOURCES_LISTING_OPTIONS,
67+
SET_SOURCES_LISTING_OPTIONS_ERROR,
6768
SET_SOURCES_LOADING_ERROR,
6869
SET_SOURCES_PAGINATION,
6970
SET_SOURCES_SEARCH_LOADING,
@@ -81,6 +82,7 @@ import {
8182
TOGGLE_FIELD_EDITOR_MODULE_LOADING,
8283
TOGGLE_LOAD_PREVIEW_BY_DEFAULT,
8384
TOGGLE_PREVIEW,
85+
TOGGLE_SOURCES_LISTING_OPTIONS_LOADER,
8486
TOGGLE_SOURCES_LOADER,
8587
TOGGLE_VIEW_PREVIEW,
8688
UPDATE_FIELD,
@@ -1265,9 +1267,16 @@ export default (state: DatasetReduxState = initialState, action: DatasetReduxAct
12651267
...state,
12661268
sourcePrototypes: sourcePrototypesNext,
12671269
selectedConnections: selectedConnectionsNext,
1270+
currentDbName: undefined,
1271+
options: {
1272+
...state.options,
1273+
source_listing: undefined,
1274+
},
12681275
ui: {
12691276
...state.ui,
12701277
selectedConnectionId: selectedConnectionIdNext,
1278+
isSourcesSearchLoading: false,
1279+
isSourcesLoading: false,
12711280
},
12721281
};
12731282
}
@@ -1309,6 +1318,17 @@ export default (state: DatasetReduxState = initialState, action: DatasetReduxAct
13091318
},
13101319
};
13111320
}
1321+
case TOGGLE_SOURCES_LISTING_OPTIONS_LOADER: {
1322+
const {isLoading} = action.payload;
1323+
1324+
return {
1325+
...state,
1326+
ui: {
1327+
...state.ui,
1328+
isSourcesListingOptionsLoading: isLoading,
1329+
},
1330+
};
1331+
}
13121332
case SET_SOURCES_LOADING_ERROR: {
13131333
const {error} = action.payload;
13141334

@@ -1476,6 +1496,17 @@ export default (state: DatasetReduxState = initialState, action: DatasetReduxAct
14761496
},
14771497
};
14781498
}
1499+
case SET_SOURCES_LISTING_OPTIONS_ERROR: {
1500+
const {error} = action.payload;
1501+
1502+
return {
1503+
...state,
1504+
errors: {
1505+
...state.errors,
1506+
sourceListingOptionsError: error,
1507+
},
1508+
};
1509+
}
14791510
default: {
14801511
return state;
14811512
}

0 commit comments

Comments
 (0)