sadpandajoe commented on code in PR #44276: URL: https://github.com/apache/superset/pull/44276#discussion_r4140954458
########## superset-frontend/src/core/dashboard/index.ts: ########## @@ -0,0 +1,105 @@ +/** + * 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 { dashboard as dashboardApi } from '@apache-superset/core'; +import { isNativeFilter } from '@superset-ui/core'; +import type { Divider, Filter } from '@superset-ui/core'; +import { updateComponents } from 'src/dashboard/actions/dashboardLayout'; +import { dashboardInfoChanged } from 'src/dashboard/actions/dashboardInfo'; +import { updateDataMask } from 'src/dataMask/actions'; +import { store, RootState } from 'src/views/store'; + +const getState = () => store.getState() as RootState; + +const requireDashboardId = (): number => { + const { id } = getState().dashboardInfo; Review Comment: Thanks—this fixes the Dashboard-to-Explore case, but the same-surface transition is still unsafe: `navigation.getPage()` becomes `dashboard` before dashboard B hydrates while the Redux slices still contain A. An extension call in that window can mutate A, and a pending `saveFilters()` response can then apply A's filters to B. Could this gate on the routed dashboard being fully hydrated rather than only the page name? ########## superset-frontend/src/core/dashboard/index.ts: ########## @@ -0,0 +1,210 @@ +/** + * 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 { dashboard as dashboardApi } from '@apache-superset/core'; +import { isNativeFilter, makeApi, SupersetClient } from '@superset-ui/core'; +import type { + DataMask, + Divider, + Filter, + JsonObject, + QueryFormData, +} from '@superset-ui/core'; +import { updateComponents } from 'src/dashboard/actions/dashboardLayout'; +import { dashboardInfoChanged } from 'src/dashboard/actions/dashboardInfo'; +import { applySavedFilterChanges } from 'src/dashboard/actions/nativeFilters'; +import type { SaveFilterChangesType } from 'src/dashboard/components/nativeFilters/FiltersConfigModal/types'; +import { updateDataMask } from 'src/dataMask/actions'; +import { + setChartFormData, + triggerQuery, +} from 'src/components/Chart/chartAction'; +import { applyDefaultFormData } from 'src/explore/store'; +import extractUrlParams from 'src/dashboard/util/extractUrlParams'; +import { store, RootState } from 'src/views/store'; +import { navigation } from '../navigation'; + +const getState = () => store.getState() as RootState; + +// The Redux slices below are retained across an in-SPA navigation, so +// checking them alone can't tell a still-active dashboard from a stale one +// left over from before the user navigated to another page. +const isDashboardActive = (): boolean => navigation.getPage() === 'dashboard'; + +const requireDashboardId = (): number => { + const { id } = getState().dashboardInfo; + if (!isDashboardActive() || id == null) { + throw new Error('No dashboard is currently active'); + } + return id; +}; + +const getDashboardId: typeof dashboardApi.getDashboardId = () => + isDashboardActive() ? (getState().dashboardInfo.id ?? undefined) : undefined; + +const getLayout: typeof dashboardApi.getLayout = () => + isDashboardActive() ? { ...getState().dashboardLayout.present } : {}; Review Comment: Agreed—mutating a node returned by `getLayout()` changes Redux-owned layout state outside reducers, so rendering and undo state can diverge. Could this return a detached snapshot or make the nested objects immutable? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
