fix: Duplicated toast messages (#27135)

This commit is contained in:
Michael S. Molina 2024-02-16 08:13:34 -05:00 committed by GitHub
parent 1ff4f79d5b
commit cf33a6213d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 0 additions and 98 deletions

View File

@ -17,7 +17,6 @@
* under the License.
*/
import { t } from '@superset-ui/core';
import getToastsFromPyFlashMessages from 'src/components/MessageToasts/getToastsFromPyFlashMessages';
import type { BootstrapData } from 'src/types/bootstrapTypes';
import type { InitialState } from 'src/hooks/apiResources/sqlLab';
import {
@ -245,9 +244,6 @@ export default function getInitialState({
queryCostEstimates: {},
unsavedQueryEditor,
},
messageToasts: getToastsFromPyFlashMessages(
(common || {})?.flash_messages || [],
),
localStorageUsageInKilobytes: 0,
common,
...otherBootstrapData,

View File

@ -1,40 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { addToast } from './actions';
import { ToastType } from './types';
export default function toastsFromPyFlashMessages(flashMessages = []) {
const toasts = [];
flashMessages.forEach(([messageType, message]) => {
const toastType =
messageType === 'danger'
? ToastType.Danger
: (messageType === 'success' && ToastType.Success) || ToastType.Info;
const toast = addToast({
text: message,
toastType,
}).payload;
toasts.push(toast);
});
return toasts;
}

View File

@ -1,48 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { ToastType } from 'src/components/MessageToasts/types';
import getToastsFromPyFlashMessages from 'src/components/MessageToasts/getToastsFromPyFlashMessages';
describe('getToastsFromPyFlashMessages', () => {
it('should return an info toast', () => {
const toast = getToastsFromPyFlashMessages([['info', 'info test']])[0];
expect(toast).toMatchObject({
toastType: ToastType.Info,
text: 'info test',
});
});
it('should return a success toast', () => {
const toast = getToastsFromPyFlashMessages([
['success', 'success test'],
])[0];
expect(toast).toMatchObject({
toastType: ToastType.Success,
text: 'success test',
});
});
it('should return a danger toast', () => {
const toast = getToastsFromPyFlashMessages([['danger', 'danger test']])[0];
expect(toast).toMatchObject({
toastType: ToastType.Danger,
text: 'danger test',
});
});
});

View File

@ -59,13 +59,11 @@ const propTypes = {
ownDataCharts: PropTypes.object.isRequired,
layout: PropTypes.object.isRequired,
impressionId: PropTypes.string.isRequired,
initMessages: PropTypes.array,
timeout: PropTypes.number,
userId: PropTypes.string,
};
const defaultProps = {
initMessages: [],
timeout: 60,
userId: '',
};

View File

@ -47,7 +47,6 @@ describe('Dashboard', () => {
triggerQuery() {},
logEvent() {},
},
initMessages: [],
dashboardState,
dashboardInfo,
charts: chartQueries,

View File

@ -50,7 +50,6 @@ const initialState: { dashboardInfo: DashboardInfo } = {
filterBarOrientation: FilterBarOrientation.Vertical,
common: {
conf: {},
flash_messages: [],
},
crossFiltersEnabled: true,
},

View File

@ -48,7 +48,6 @@ function mapStateToProps(state: RootState) {
} = state;
return {
initMessages: dashboardInfo.common?.flash_messages,
timeout: dashboardInfo.common?.conf?.SUPERSET_WEBSERVER_TIMEOUT,
userId: dashboardInfo.userId,
dashboardInfo,

View File

@ -117,7 +117,6 @@ export type DashboardState = {
export type DashboardInfo = {
id: number;
common: {
flash_messages: string[];
conf: JsonObject;
};
userId: string;