bito-code-review[bot] commented on code in PR #37107: URL: https://github.com/apache/superset/pull/37107#discussion_r2687795915
########## superset-frontend/src/features/reports/ReportModal/actions.ts: ########## @@ -0,0 +1,243 @@ +/** + * 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. + */ +/* eslint camelcase: 0 */ +import { SupersetClient } from '@superset-ui/core'; +import { t } from '@apache-superset/core/ui'; +import rison from 'rison'; +import { + addDangerToast, + addSuccessToast, +} from 'src/components/MessageToasts/actions'; +import { isEmpty } from 'lodash'; +import { Dispatch, AnyAction } from 'redux'; +import { ReportObject, ReportCreationMethod } from 'src/features/reports/types'; +import { DashboardInfo, ChartsState } from 'src/dashboard/types'; +import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes'; +import { ExplorePageState } from 'src/explore/types'; + +// Type definitions for report-related state +interface ReportApiResponse { + result?: ReportObject[]; +} + +interface ReportApiJsonResponse { + result: Partial<ReportObject>; + id: number; +} + +interface ReportRootState { + user: UserWithPermissionsAndRoles; + dashboardInfo: DashboardInfo; + charts: ChartsState; + explore: ExplorePageState['explore'] & { + user?: UserWithPermissionsAndRoles; + }; +} + +type ReportFilterField = 'dashboard_id' | 'chart_id'; + +export const SET_REPORT = 'SET_REPORT' as const; + +export interface SetReportAction { + type: typeof SET_REPORT; + report: ReportApiResponse; + resourceId: number; + creationMethod: ReportCreationMethod; + filterField: ReportFilterField; +} + +export function setReport( + report: ReportApiResponse, + resourceId: number, + creationMethod: ReportCreationMethod, + filterField: ReportFilterField, +): SetReportAction { + return { type: SET_REPORT, report, resourceId, creationMethod, filterField }; +} + +interface FetchUISpecificReportParams { + userId: number | undefined; + filterField: ReportFilterField; + creationMethod: ReportCreationMethod; + resourceId: number; +} + +export function fetchUISpecificReport({ + userId, + filterField, + creationMethod, + resourceId, +}: FetchUISpecificReportParams) { + const queryParams = rison.encode({ + filters: [ + { + col: filterField, + opr: 'eq', + value: resourceId, + }, + { + col: 'creation_method', + opr: 'eq', + value: creationMethod, + }, + { + col: 'created_by', + opr: 'rel_o_m', + value: userId, + }, + ], + }); + return function fetchUISpecificReportThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.get({ + endpoint: `/api/v1/report/?q=${queryParams}`, + }) + .then(({ json }) => { + dispatch( + setReport( + json as ReportApiResponse, + resourceId, + creationMethod, + filterField, + ), + ); + }) + .catch(() => + dispatch( + addDangerToast( + t( + 'There was an issue fetching reports attached to this dashboard.', + ), + ), + ), + ); + }; +} + +const structureFetchAction = ( + dispatch: Dispatch<AnyAction>, + getState: () => ReportRootState, +) => { + const state = getState(); + const { user, dashboardInfo, charts, explore } = state; + if (!isEmpty(dashboardInfo)) { + dispatch( + fetchUISpecificReport({ + userId: user.userId, + filterField: 'dashboard_id', + creationMethod: 'dashboards', + resourceId: dashboardInfo.id, + }), + ); + } else { + const [chartArr] = Object.keys(charts); + dispatch( + fetchUISpecificReport({ + userId: explore.user?.userId || user?.userId, + filterField: 'chart_id', + creationMethod: 'charts', + resourceId: charts[chartArr].id, + }), + ); + } +}; + +export const ADD_REPORT = 'ADD_REPORT' as const; + +export interface AddReportAction { + type: typeof ADD_REPORT; + json: ReportApiJsonResponse; +} + +export const addReport = + (report: Partial<ReportObject>) => (dispatch: Dispatch<AnyAction>) => + SupersetClient.post({ + endpoint: `/api/v1/report/`, + jsonPayload: report, + }).then(({ json }) => { + dispatch({ type: ADD_REPORT, json } as AddReportAction); + dispatch(addSuccessToast(t('The report has been created'))); + }); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing Error Handling</b></div> <div id="fix"> addReport lacks error handling, unlike toggleActive and deleteActiveReport, potentially leading to silent failures. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` - export const addReport = - (report: Partial<ReportObject>) => (dispatch: Dispatch<AnyAction>) => - SupersetClient.post({ - endpoint: `/api/v1/report/`, - jsonPayload: report, - }).then(({ json }) => { - dispatch({ type: ADD_REPORT, json } as AddReportAction); - dispatch(addSuccessToast(t('The report has been created'))); - }); + export const addReport = + (report: Partial<ReportObject>) => (dispatch: Dispatch<AnyAction>) => - SupersetClient.post({ - endpoint: `/api/v1/report/`, - jsonPayload: report, - }).then(({ json }) => { - dispatch({ type: ADD_REPORT, json } as AddReportAction); - dispatch(addSuccessToast(t('The report has been created'))); - }).catch(() => { - dispatch(addDangerToast(t('Failed to create report'))); - }); ``` </div> </details> </div> <small><i>Code Review Run #55969a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/src/features/reports/ReportModal/reducer.ts: ########## @@ -0,0 +1,147 @@ +/** + * 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. + */ +/* eslint-disable camelcase */ +import { omit } from 'lodash'; +import { + SET_REPORT, + ADD_REPORT, + EDIT_REPORT, + DELETE_REPORT, + ReportAction, + SetReportAction, + AddReportAction, + EditReportAction, + DeleteReportAction, +} from './actions'; +import { ReportObject, ReportCreationMethod } from 'src/features/reports/types'; + +// State structure: { dashboards: { [id]: ReportObject }, charts: { [id]: ReportObject } } +export interface ReportsState { + dashboards?: Record<number, ReportObject>; + charts?: Record<number, ReportObject>; + alerts_reports?: Record<number, ReportObject>; +} + +type ActionHandlers = { + [key: string]: () => ReportsState; +}; + +export default function reportsReducer( + state: ReportsState = {}, + action: ReportAction, +): ReportsState { + const actionHandlers: ActionHandlers = { + [SET_REPORT]() { + const { report, resourceId, creationMethod, filterField } = + action as SetReportAction; + // For now report count should only be one, but we are checking in case + // functionality changes. + const reportObject = report.result?.find( + (r: ReportObject) => + (r as Record<string, number>)[filterField] === resourceId, + ); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Type mismatch in report filtering</b></div> <div id="fix"> The SET_REPORT handler currently indexes the report object using filterField ('dashboard_id'|'chart_id'), but ReportObject uses 'dashboard'/'chart'. We need to map filterField to the correct property name (e.g., strip '_id') before comparing to resourceId. </div> </div> <small><i>Code Review Run #55969a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/src/features/reports/ReportModal/actions.ts: ########## @@ -0,0 +1,243 @@ +/** + * 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. + */ +/* eslint camelcase: 0 */ +import { SupersetClient } from '@superset-ui/core'; +import { t } from '@apache-superset/core/ui'; +import rison from 'rison'; +import { + addDangerToast, + addSuccessToast, +} from 'src/components/MessageToasts/actions'; +import { isEmpty } from 'lodash'; +import { Dispatch, AnyAction } from 'redux'; +import { ReportObject, ReportCreationMethod } from 'src/features/reports/types'; +import { DashboardInfo, ChartsState } from 'src/dashboard/types'; +import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes'; +import { ExplorePageState } from 'src/explore/types'; + +// Type definitions for report-related state +interface ReportApiResponse { + result?: ReportObject[]; +} + +interface ReportApiJsonResponse { + result: Partial<ReportObject>; + id: number; +} + +interface ReportRootState { + user: UserWithPermissionsAndRoles; + dashboardInfo: DashboardInfo; + charts: ChartsState; + explore: ExplorePageState['explore'] & { + user?: UserWithPermissionsAndRoles; + }; +} + +type ReportFilterField = 'dashboard_id' | 'chart_id'; + +export const SET_REPORT = 'SET_REPORT' as const; + +export interface SetReportAction { + type: typeof SET_REPORT; + report: ReportApiResponse; + resourceId: number; + creationMethod: ReportCreationMethod; + filterField: ReportFilterField; +} + +export function setReport( + report: ReportApiResponse, + resourceId: number, + creationMethod: ReportCreationMethod, + filterField: ReportFilterField, +): SetReportAction { + return { type: SET_REPORT, report, resourceId, creationMethod, filterField }; +} + +interface FetchUISpecificReportParams { + userId: number | undefined; + filterField: ReportFilterField; + creationMethod: ReportCreationMethod; + resourceId: number; +} + +export function fetchUISpecificReport({ + userId, + filterField, + creationMethod, + resourceId, +}: FetchUISpecificReportParams) { + const queryParams = rison.encode({ + filters: [ + { + col: filterField, + opr: 'eq', + value: resourceId, + }, + { + col: 'creation_method', + opr: 'eq', + value: creationMethod, + }, + { + col: 'created_by', + opr: 'rel_o_m', + value: userId, + }, + ], + }); + return function fetchUISpecificReportThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.get({ + endpoint: `/api/v1/report/?q=${queryParams}`, + }) + .then(({ json }) => { + dispatch( + setReport( + json as ReportApiResponse, + resourceId, + creationMethod, + filterField, + ), + ); + }) + .catch(() => + dispatch( + addDangerToast( + t( + 'There was an issue fetching reports attached to this dashboard.', + ), + ), + ), + ); + }; +} + +const structureFetchAction = ( + dispatch: Dispatch<AnyAction>, + getState: () => ReportRootState, +) => { + const state = getState(); + const { user, dashboardInfo, charts, explore } = state; + if (!isEmpty(dashboardInfo)) { + dispatch( + fetchUISpecificReport({ + userId: user.userId, + filterField: 'dashboard_id', + creationMethod: 'dashboards', + resourceId: dashboardInfo.id, + }), + ); + } else { + const [chartArr] = Object.keys(charts); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Potential Runtime Error</b></div> <div id="fix"> Wrap the `Object.keys(charts)` access in an `if (!isEmpty(charts))` check before destructuring to avoid runtime errors when `charts` is empty. </div> </div> <small><i>Code Review Run #55969a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/src/features/reports/ReportModal/actions.ts: ########## @@ -0,0 +1,243 @@ +/** + * 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. + */ +/* eslint camelcase: 0 */ +import { SupersetClient } from '@superset-ui/core'; +import { t } from '@apache-superset/core/ui'; +import rison from 'rison'; +import { + addDangerToast, + addSuccessToast, +} from 'src/components/MessageToasts/actions'; +import { isEmpty } from 'lodash'; +import { Dispatch, AnyAction } from 'redux'; +import { ReportObject, ReportCreationMethod } from 'src/features/reports/types'; +import { DashboardInfo, ChartsState } from 'src/dashboard/types'; +import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes'; +import { ExplorePageState } from 'src/explore/types'; + +// Type definitions for report-related state +interface ReportApiResponse { + result?: ReportObject[]; +} + +interface ReportApiJsonResponse { + result: Partial<ReportObject>; + id: number; +} + +interface ReportRootState { + user: UserWithPermissionsAndRoles; + dashboardInfo: DashboardInfo; + charts: ChartsState; + explore: ExplorePageState['explore'] & { + user?: UserWithPermissionsAndRoles; + }; +} + +type ReportFilterField = 'dashboard_id' | 'chart_id'; + +export const SET_REPORT = 'SET_REPORT' as const; + +export interface SetReportAction { + type: typeof SET_REPORT; + report: ReportApiResponse; + resourceId: number; + creationMethod: ReportCreationMethod; + filterField: ReportFilterField; +} + +export function setReport( + report: ReportApiResponse, + resourceId: number, + creationMethod: ReportCreationMethod, + filterField: ReportFilterField, +): SetReportAction { + return { type: SET_REPORT, report, resourceId, creationMethod, filterField }; +} + +interface FetchUISpecificReportParams { + userId: number | undefined; + filterField: ReportFilterField; + creationMethod: ReportCreationMethod; + resourceId: number; +} + +export function fetchUISpecificReport({ + userId, + filterField, + creationMethod, + resourceId, +}: FetchUISpecificReportParams) { + const queryParams = rison.encode({ + filters: [ + { + col: filterField, + opr: 'eq', + value: resourceId, + }, + { + col: 'creation_method', + opr: 'eq', + value: creationMethod, + }, + { + col: 'created_by', + opr: 'rel_o_m', + value: userId, + }, + ], + }); + return function fetchUISpecificReportThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.get({ + endpoint: `/api/v1/report/?q=${queryParams}`, + }) + .then(({ json }) => { + dispatch( + setReport( + json as ReportApiResponse, + resourceId, + creationMethod, + filterField, + ), + ); + }) + .catch(() => + dispatch( + addDangerToast( + t( + 'There was an issue fetching reports attached to this dashboard.', + ), + ), + ), + ); + }; +} + +const structureFetchAction = ( + dispatch: Dispatch<AnyAction>, + getState: () => ReportRootState, +) => { + const state = getState(); + const { user, dashboardInfo, charts, explore } = state; + if (!isEmpty(dashboardInfo)) { + dispatch( + fetchUISpecificReport({ + userId: user.userId, + filterField: 'dashboard_id', + creationMethod: 'dashboards', + resourceId: dashboardInfo.id, + }), + ); + } else { + const [chartArr] = Object.keys(charts); + dispatch( + fetchUISpecificReport({ + userId: explore.user?.userId || user?.userId, + filterField: 'chart_id', + creationMethod: 'charts', + resourceId: charts[chartArr].id, + }), + ); + } +}; + +export const ADD_REPORT = 'ADD_REPORT' as const; + +export interface AddReportAction { + type: typeof ADD_REPORT; + json: ReportApiJsonResponse; +} + +export const addReport = + (report: Partial<ReportObject>) => (dispatch: Dispatch<AnyAction>) => + SupersetClient.post({ + endpoint: `/api/v1/report/`, + jsonPayload: report, + }).then(({ json }) => { + dispatch({ type: ADD_REPORT, json } as AddReportAction); + dispatch(addSuccessToast(t('The report has been created'))); + }); + +export const EDIT_REPORT = 'EDIT_REPORT' as const; + +export interface EditReportAction { + type: typeof EDIT_REPORT; + json: ReportApiJsonResponse; +} + +export const editReport = + (id: number, report: Partial<ReportObject>) => + (dispatch: Dispatch<AnyAction>) => + SupersetClient.put({ + endpoint: `/api/v1/report/${id}`, + jsonPayload: report, + }).then(({ json }) => { + dispatch({ type: EDIT_REPORT, json } as EditReportAction); + dispatch(addSuccessToast(t('Report updated'))); + }); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing Error Handling</b></div> <div id="fix"> editReport lacks error handling, unlike toggleActive and deleteActiveReport, potentially leading to silent failures. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` - }).then(({ json }) => { - dispatch({ type: EDIT_REPORT, json } as EditReportAction); - dispatch(addSuccessToast(t('Report updated'))); - }); + }).then(({ json }) => { - dispatch({ type: EDIT_REPORT, json } as EditReportAction); - dispatch(addSuccessToast(t('Report updated'))); - }).catch(() => - dispatch(addDangerToast(t('Failed to update report'))) - ); ``` </div> </details> </div> <small><i>Code Review Run #55969a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/src/features/reports/ReportModal/actions.ts: ########## @@ -0,0 +1,243 @@ +/** + * 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. + */ +/* eslint camelcase: 0 */ +import { SupersetClient } from '@superset-ui/core'; +import { t } from '@apache-superset/core/ui'; +import rison from 'rison'; +import { + addDangerToast, + addSuccessToast, +} from 'src/components/MessageToasts/actions'; +import { isEmpty } from 'lodash'; +import { Dispatch, AnyAction } from 'redux'; +import { ReportObject, ReportCreationMethod } from 'src/features/reports/types'; +import { DashboardInfo, ChartsState } from 'src/dashboard/types'; +import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes'; +import { ExplorePageState } from 'src/explore/types'; + +// Type definitions for report-related state +interface ReportApiResponse { + result?: ReportObject[]; +} + +interface ReportApiJsonResponse { + result: Partial<ReportObject>; + id: number; +} + +interface ReportRootState { + user: UserWithPermissionsAndRoles; + dashboardInfo: DashboardInfo; + charts: ChartsState; + explore: ExplorePageState['explore'] & { + user?: UserWithPermissionsAndRoles; + }; +} + +type ReportFilterField = 'dashboard_id' | 'chart_id'; + +export const SET_REPORT = 'SET_REPORT' as const; + +export interface SetReportAction { + type: typeof SET_REPORT; + report: ReportApiResponse; + resourceId: number; + creationMethod: ReportCreationMethod; + filterField: ReportFilterField; +} + +export function setReport( + report: ReportApiResponse, + resourceId: number, + creationMethod: ReportCreationMethod, + filterField: ReportFilterField, +): SetReportAction { + return { type: SET_REPORT, report, resourceId, creationMethod, filterField }; +} + +interface FetchUISpecificReportParams { + userId: number | undefined; + filterField: ReportFilterField; + creationMethod: ReportCreationMethod; + resourceId: number; +} + +export function fetchUISpecificReport({ + userId, + filterField, + creationMethod, + resourceId, +}: FetchUISpecificReportParams) { + const queryParams = rison.encode({ + filters: [ + { + col: filterField, + opr: 'eq', + value: resourceId, + }, + { + col: 'creation_method', + opr: 'eq', + value: creationMethod, + }, + { + col: 'created_by', + opr: 'rel_o_m', + value: userId, + }, + ], + }); + return function fetchUISpecificReportThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.get({ + endpoint: `/api/v1/report/?q=${queryParams}`, + }) + .then(({ json }) => { + dispatch( + setReport( + json as ReportApiResponse, + resourceId, + creationMethod, + filterField, + ), + ); + }) + .catch(() => + dispatch( + addDangerToast( + t( + 'There was an issue fetching reports attached to this dashboard.', + ), + ), + ), + ); + }; +} + +const structureFetchAction = ( + dispatch: Dispatch<AnyAction>, + getState: () => ReportRootState, +) => { + const state = getState(); + const { user, dashboardInfo, charts, explore } = state; + if (!isEmpty(dashboardInfo)) { + dispatch( + fetchUISpecificReport({ + userId: user.userId, + filterField: 'dashboard_id', + creationMethod: 'dashboards', + resourceId: dashboardInfo.id, + }), + ); + } else { + const [chartArr] = Object.keys(charts); + dispatch( + fetchUISpecificReport({ + userId: explore.user?.userId || user?.userId, + filterField: 'chart_id', + creationMethod: 'charts', + resourceId: charts[chartArr].id, + }), + ); + } +}; + +export const ADD_REPORT = 'ADD_REPORT' as const; + +export interface AddReportAction { + type: typeof ADD_REPORT; + json: ReportApiJsonResponse; +} + +export const addReport = + (report: Partial<ReportObject>) => (dispatch: Dispatch<AnyAction>) => + SupersetClient.post({ + endpoint: `/api/v1/report/`, + jsonPayload: report, + }).then(({ json }) => { + dispatch({ type: ADD_REPORT, json } as AddReportAction); + dispatch(addSuccessToast(t('The report has been created'))); + }); + +export const EDIT_REPORT = 'EDIT_REPORT' as const; + +export interface EditReportAction { + type: typeof EDIT_REPORT; + json: ReportApiJsonResponse; +} + +export const editReport = + (id: number, report: Partial<ReportObject>) => + (dispatch: Dispatch<AnyAction>) => + SupersetClient.put({ + endpoint: `/api/v1/report/${id}`, + jsonPayload: report, + }).then(({ json }) => { + dispatch({ type: EDIT_REPORT, json } as EditReportAction); + dispatch(addSuccessToast(t('Report updated'))); + }); + +export function toggleActive(report: ReportObject, isActive: boolean) { + return function toggleActiveThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.put({ + endpoint: encodeURI(`/api/v1/report/${report.id}`), + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + active: isActive, + }), + }) + .catch(() => { + dispatch( + addDangerToast( + t('We were unable to active or deactivate this report.'), + ), + ); + }) + .finally(() => { + dispatch(structureFetchAction); + }); + }; +} + +export const DELETE_REPORT = 'DELETE_REPORT' as const; + +export interface DeleteReportAction { + type: typeof DELETE_REPORT; + report: ReportObject; +} + +export function deleteActiveReport(report: ReportObject) { + return function deleteActiveReportThunk(dispatch: Dispatch<AnyAction>) { + return SupersetClient.delete({ + endpoint: encodeURI(`/api/v1/report/${report.id}`), + }) + .catch(() => { + dispatch(addDangerToast(t('Your report could not be deleted'))); + }) + .finally(() => { + dispatch({ type: DELETE_REPORT, report } as DeleteReportAction); + dispatch(addSuccessToast(t('Deleted: %s', report.name))); + }); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Success Feedback on Failure</b></div> <div id="fix"> The success toast and action dispatch are in finally, so they run even on error, misleading the user that deletion succeeded when it failed. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion .then(() => { dispatch({ type: DELETE_REPORT, report } as DeleteReportAction); dispatch(addSuccessToast(t('Deleted: %s', report.name))); }) .catch(() => { dispatch(addDangerToast(t('Your report could not be deleted'))); }); ```` </div> </details> </div> <small><i>Code Review Run #55969a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
