console: allow skipping notification display while adding datasource

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6121
GitOrigin-RevId: 3291185ee74502364a0452c8eaf0c9db3e03709e
This commit is contained in:
Rishichandra Wawhal 2022-09-29 20:40:03 +05:30 committed by hasura-bot
parent e04a82a613
commit 2b21e6bb14
3 changed files with 72 additions and 60 deletions

View File

@ -780,7 +780,8 @@ const makeMigrationCall = (
shouldSkipSchemaReload,
skipExecution = false,
isRetry = false,
source = getState().tables.currentDataSource
source = getState().tables.currentDataSource,
shouldShowNotifications = true
) => {
const { resourceVersion } = getState().metadata;
const upQuery = {
@ -837,7 +838,7 @@ const makeMigrationCall = (
}
dispatch(updateSchemaInfo());
}
if (successMsg) {
if (successMsg && shouldShowNotifications) {
dispatch(showSuccessNotification(successMsg));
}
customOnSuccess(data, globals.consoleMode, currMigrationMode);
@ -846,44 +847,46 @@ const makeMigrationCall = (
const errorDetails = getErrorMessage('', err);
const errorDetailsLines = errorDetails.split('\n');
dispatch(
showNotification(
{
title: errMsg,
level: 'error',
message: (
<p>
{errorDetailsLines.map((m, i) => (
<div key={i}>{m}</div>
))}
<br />
Do you want to drop the dependent items as well?
</p>
),
autoDismiss: 0,
action: {
label: 'Continue',
callback: () =>
makeMigrationCall(
dispatch,
getState,
cascadeUpQueries(upQueries, isPgCascade), // cascaded new up queries
downQueries,
migrationName,
customOnSuccess,
customOnError,
requestMsg,
successMsg,
errorMsg,
shouldSkipSchemaReload,
false,
true // prevent further retry
),
if (shouldShowNotifications) {
dispatch(
showNotification(
{
title: errMsg,
level: 'error',
message: (
<p>
{errorDetailsLines.map((m, i) => (
<div key={i}>{m}</div>
))}
<br />
Do you want to drop the dependent items as well?
</p>
),
autoDismiss: 0,
action: {
label: 'Continue',
callback: () =>
makeMigrationCall(
dispatch,
getState,
cascadeUpQueries(upQueries, isPgCascade), // cascaded new up queries
downQueries,
migrationName,
customOnSuccess,
customOnError,
requestMsg,
successMsg,
errorMsg,
shouldSkipSchemaReload,
false,
true // prevent further retry
),
},
},
},
'error'
)
);
'error'
)
);
}
};
const onError = err => {
@ -904,7 +907,10 @@ const makeMigrationCall = (
};
dispatch({ type: MAKE_REQUEST });
dispatch(showSuccessNotification(requestMsg));
if (shouldShowNotifications) {
dispatch(showSuccessNotification(requestMsg));
}
return dispatch(
requestAction(url, options, REQUEST_SUCCESS, REQUEST_ERROR)
).then(onSuccess, onError);

View File

@ -138,7 +138,8 @@ export const connectDataSource = (
>[],
isEditState = false,
isRenameSource = false,
currentName = ''
currentName = '',
shouldShowNotification = true
) => {
let connectionParams: ConnectionParams | undefined;
let databaseURL: string | { from_env: string } =
@ -220,7 +221,8 @@ export const connectDataSource = (
)
);
}
return dispatch(addDataSource(data, cb, replicas));
return dispatch(addDataSource(data, cb, replicas, shouldShowNotification));
};
export const removeEmptyValues = (obj: any) =>

View File

@ -281,7 +281,8 @@ export const addDataSource =
| 'use_prepared_statements'
| 'ssl_configuration'
| 'isolation_level'
>[]
>[],
shouldShowNotifications = true
): Thunk<Promise<void | ReduxState>, MetadataActions> =>
(dispatch, getState) => {
const upQuery = addSource(data.driver, data.payload, replicas);
@ -306,23 +307,25 @@ export const addDataSource =
};
return dispatch(exportMetadata()).then(() => {
dispatch(fetchDataInit(data.payload.name, data.driver));
dispatch(
showNotification(
{
title: `Data source ${
!isEdit ? 'added' : 'updated'
} successfully!`,
level: 'success',
autoDismiss: 0,
alternateActionButtonProps: {
label: 'View Database',
onClick: onButtonClick,
trackId: 'data-tab-view-database-notification-button-add-db',
if (shouldShowNotifications) {
dispatch(
showNotification(
{
title: `Data source ${
!isEdit ? 'added' : 'updated'
} successfully!`,
level: 'success',
autoDismiss: 0,
alternateActionButtonProps: {
label: 'View Database',
onClick: onButtonClick,
trackId: 'data-tab-view-database-notification-button-add-db',
},
},
},
'success'
)
);
'success'
)
);
}
if (successCb) successCb();
return getState();
});
@ -350,7 +353,8 @@ export const addDataSource =
false,
false,
false,
data.payload.name
data.payload.name,
shouldShowNotifications
);
};