michael-s-molina commented on a change in pull request #16992:
URL: https://github.com/apache/superset/pull/16992#discussion_r728120704



##########
File path: superset-frontend/src/dashboard/actions/hydrate.js
##########
@@ -227,19 +231,25 @@ export const hydrateDashboard = (dashboardData, 
chartData) => (
       const componentId = chartIdToLayoutId[key];
       const directPathToFilter = (layout[componentId].parents || []).slice();
       directPathToFilter.push(componentId);
-      dashboardFilters[key] = {
-        ...dashboardFilter,
-        chartId: key,
-        componentId,
-        datasourceId: slice.form_data.datasource,
-        filterName: slice.slice_name,
-        directPathToFilter,
-        columns,
-        labels,
-        scopes: scopesByChartId,
-        isInstantFilter: !!slice.form_data.instant_filtering,
-        isDateFilter: Object.keys(columns).includes(TIME_RANGE),
-      };
+      if (
+        [
+          FILTER_BOX_MIGRATION_STATES.NOOP,
+          FILTER_BOX_MIGRATION_STATES.SNOOZED,
+        ].includes(filterboxMigrationState)
+      ) {
+        dashboardFilters[key] = {

Review comment:
       Currently, `dashboardFilters[key]` is always filled. What's the 
consequence of not setting this information when the migration state is 
CONVERTED, REVIEWING, or UNDECIDED?

##########
File path: superset-frontend/src/common/hooks/apiResources/dashboards.ts
##########
@@ -17,19 +17,33 @@
  * under the License.
  */
 
-import { Dashboard, Datasource } from 'src/dashboard/types';
+import { Dashboard, DashboardMetadata, Datasource } from 'src/dashboard/types';
 import { Chart } from 'src/types/Chart';
 import { useApiV1Resource, useTransformedResource } from './apiResources';
 
 export const useDashboard = (idOrSlug: string | number) =>
   useTransformedResource(
     useApiV1Resource<Dashboard>(`/api/v1/dashboard/${idOrSlug}`),
-    dashboard => ({
-      ...dashboard,
-      metadata: dashboard.json_metadata && JSON.parse(dashboard.json_metadata),
-      position_data:
-        dashboard.position_json && JSON.parse(dashboard.position_json),
-    }),
+    dashboard => {
+      let metadata: DashboardMetadata = {};
+      let position_data = {};
+      try {
+        // need handle data parsing error
+        if (dashboard.json_metadata) {
+          metadata = JSON.parse(dashboard.json_metadata);
+        }
+        if (dashboard.position_json) {
+          position_data = JSON.parse(dashboard.position_json);
+        }
+      } catch (e) {
+        console.error('can not parse dashboard metadata.');

Review comment:
       We should avoid the use of `console` statements. For this case, one 
solution would be to modify `useTransformedResource` to account for 
transformation errors:
   
   ```
   export function useTransformedResource<IN, OUT>(
     resource: Resource<IN>,
     transformFn: (result: IN) => OUT,
   ): Resource<OUT> {
     return useMemo(() => {
       if (resource.status !== ResourceStatus.COMPLETE) {
         // While incomplete, there is no result - no need to transform.
         return resource;
       }
       try {
         return {
           ...resource,
           result: transformFn(resource.result),
         };
       } catch (e) {
         return {
           status: ResourceStatus.ERROR,
           result: null,
           error: e,
         };
       }
     }, [resource, transformFn]);
   }
   ```
   
   You can find one example of a component handling this type of error in 
`DashboardPage`:
   
   ```
   const { result: dashboard, error: dashboardApiError } = useDashboard(
       idOrSlug,
   );
   ```




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