suddjian commented on a change in pull request #10936: URL: https://github.com/apache/incubator-superset/pull/10936#discussion_r496093405
########## File path: superset-frontend/src/dashboard/components/FiltersBadge/index.tsx ########## @@ -0,0 +1,119 @@ +/** + * 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 { connect, Dispatch } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { WarningFilled } from '@ant-design/icons'; +import { useTheme } from '@superset-ui/core'; +import { ReactComponent as FilterIcon } from 'images/icons/filter.svg'; +import { Popover, Icon } from 'src/common/components'; +import DetailsPanel, { Indicator } from './DetailsPanel'; +import S from './Styles'; +import { setDirectPathToChild } from '../../actions/dashboardState'; +import { + selectIndicatorsForChart, + INCOMPATIBLE, + APPLIED, + UNSET, +} from './selectors'; + +const mapDispatchToProps = (dispatch: Dispatch<any>) => { + return bindActionCreators( + { + onHighlightFilterSource: setDirectPathToChild, + }, + dispatch, + ); +}; + +interface FiltersBadgeProps { + chartId: number; +} + +const mapStateToProps = ( + { datasources, dashboardFilters, charts }: any, + { chartId }: FiltersBadgeProps, +) => { + const indicators = selectIndicatorsForChart( + chartId, + dashboardFilters, + datasources, + charts, + ); + + return { + chartId, + indicators, + }; +}; + +const FiltersBadge = ({ + indicators, + onHighlightFilterSource, +}: { + indicators: Indicator[]; + onHighlightFilterSource: (path: string) => void; +}) => { + const theme = useTheme(); + const appliedIndicators = indicators.filter( + indicator => indicator.status === APPLIED, + ); + const unsetIndicators = indicators.filter( + indicator => indicator.status === UNSET, + ); + const incompatibleIndicators = indicators.filter( + indicator => indicator.status === INCOMPATIBLE, + ); + + if (!appliedIndicators.length && !incompatibleIndicators.length) { + return null; + } + + return ( + <span> + <Popover + content={ + <DetailsPanel + appliedIndicators={appliedIndicators} + unsetIndicators={unsetIndicators} + incompatibleIndicators={incompatibleIndicators} + onHighlightFilterSource={onHighlightFilterSource} + /> + } + placement="bottomRight" + trigger="click" + > + <S.Pill> + <Icon component={FilterIcon} />{' '} + <span className="indicator-count"> + {appliedIndicators.length + incompatibleIndicators.length} + </span> + {incompatibleIndicators.length ? ( + <span className="rejected-indicators"> Review comment: I used them for some styling during development that isn't there anymore. No longer used. ########## File path: superset-frontend/src/dashboard/components/FiltersBadge/index.tsx ########## @@ -0,0 +1,119 @@ +/** + * 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 { connect, Dispatch } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { WarningFilled } from '@ant-design/icons'; +import { useTheme } from '@superset-ui/core'; +import { ReactComponent as FilterIcon } from 'images/icons/filter.svg'; +import { Popover, Icon } from 'src/common/components'; +import DetailsPanel, { Indicator } from './DetailsPanel'; +import S from './Styles'; +import { setDirectPathToChild } from '../../actions/dashboardState'; +import { + selectIndicatorsForChart, + INCOMPATIBLE, + APPLIED, + UNSET, +} from './selectors'; + +const mapDispatchToProps = (dispatch: Dispatch<any>) => { + return bindActionCreators( + { + onHighlightFilterSource: setDirectPathToChild, + }, + dispatch, + ); +}; + +interface FiltersBadgeProps { + chartId: number; +} + +const mapStateToProps = ( + { datasources, dashboardFilters, charts }: any, + { chartId }: FiltersBadgeProps, +) => { + const indicators = selectIndicatorsForChart( + chartId, + dashboardFilters, + datasources, + charts, + ); + + return { + chartId, + indicators, + }; +}; + +const FiltersBadge = ({ + indicators, + onHighlightFilterSource, +}: { + indicators: Indicator[]; + onHighlightFilterSource: (path: string) => void; +}) => { + const theme = useTheme(); + const appliedIndicators = indicators.filter( + indicator => indicator.status === APPLIED, + ); + const unsetIndicators = indicators.filter( + indicator => indicator.status === UNSET, + ); + const incompatibleIndicators = indicators.filter( + indicator => indicator.status === INCOMPATIBLE, + ); + + if (!appliedIndicators.length && !incompatibleIndicators.length) { + return null; + } + + return ( + <span> + <Popover + content={ + <DetailsPanel + appliedIndicators={appliedIndicators} + unsetIndicators={unsetIndicators} + incompatibleIndicators={incompatibleIndicators} + onHighlightFilterSource={onHighlightFilterSource} + /> + } + placement="bottomRight" + trigger="click" + > + <S.Pill> + <Icon component={FilterIcon} />{' '} + <span className="indicator-count"> + {appliedIndicators.length + incompatibleIndicators.length} + </span> + {incompatibleIndicators.length ? ( + <span className="rejected-indicators"> Review comment: I used them for some styling during development that isn't there anymore. No longer used outside of tests. ---------------------------------------------------------------- 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]
