graceguo-supercat commented on a change in pull request #16992:
URL: https://github.com/apache/superset/pull/16992#discussion_r734092173
##########
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:
my change is for `DashboardPage` as you recommend. It seems it already
used `useTransformedResource`? but json parse exception still breaks page.
what i fixed is part of `transformFn` right?
--
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]