bito-code-review[bot] commented on code in PR #44276:
URL: https://github.com/apache/superset/pull/44276#discussion_r4140955711


##########
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:
   <!-- Bito Reply -->
   Returning a detached snapshot is a robust approach to prevent accidental 
mutation of Redux-owned state. By performing a deep clone of the layout object 
before returning it, you ensure that any modifications made by callers remain 
isolated from the store's `present` state, effectively decoupling the API's 
output from the underlying Redux data structure.
   
   **superset-frontend/src/core/dashboard/index.ts**
   ```
   import cloneDeep from 'lodash/cloneDeep';
   
   const getLayout: typeof dashboardApi.getLayout = () =>
     isDashboardActive() ? cloneDeep(getState().dashboardLayout.present) : {};
   ```



-- 
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]

Reply via email to