nytai commented on a change in pull request #11206: URL: https://github.com/apache/incubator-superset/pull/11206#discussion_r513065371
########## File path: superset-frontend/src/views/CRUD/chart/ChartCard.tsx ########## @@ -0,0 +1,141 @@ +/** + * 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 React from 'react'; +import { useFavoriteStatus } from 'src/views/CRUD/hooks'; +import { SupersetClient, t } from '@superset-ui/core'; +import ConfirmStatusChange from 'src/components/ConfirmStatusChange'; +import Icon from 'src/components/Icon'; +import Chart from 'src/types/Chart'; + +import ListViewCard from 'src/components/ListViewCard'; +import Label from 'src/components/Label'; +import { Dropdown, Menu } from 'src/common/components'; +import FaveStar from 'src/components/FaveStar'; +import FacePile from 'src/components/FacePile'; + +const FAVESTAR_BASE_URL = '/superset/favstar/slice'; + +interface ChartCardProps { + chart: Chart; + hasPerm: (perm: string) => boolean; + openChartEditModal: (chart: Chart) => void; + bulkSelectEnabled: boolean; + addDangerToast: (msg: string) => void; + addSuccessToast: (msg: string) => void; + refreshData: () => void; + loading: boolean; +} + +export default function ChartCard({ + chart, + hasPerm, + openChartEditModal, + bulkSelectEnabled, + addDangerToast, + addSuccessToast, + refreshData, + loading, +}: ChartCardProps) { + const canEdit = hasPerm('can_edit'); + const canDelete = hasPerm('can_delete'); + const [, fetchFaveStar, saveFaveStar, favoriteStatus] = useFavoriteStatus( + {}, + FAVESTAR_BASE_URL, + addDangerToast, + ); + function handleChartDelete({ id, slice_name: sliceName }: Chart) { + SupersetClient.delete({ + endpoint: `/api/v1/chart/${id}`, + }).then( + () => { + refreshData(); + addSuccessToast(t('Deleted: %s', sliceName)); + }, + () => { + addDangerToast(t('There was an issue deleting: %s', sliceName)); + }, + ); + } Review comment: yup, my comment was mainly around the inconsistency. Ideally, both edit and delete should be treated the same (either delegate to props or define the handlers here). This isn't such a big deal here, as this isn't meant to be a shared lib component, but these inconsistencies can lead to lots of fragmented logic spread across many files. The main issue I see here is the duplication of the useFavortieStatus hook. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
