bito-code-review[bot] commented on code in PR #39795:
URL: https://github.com/apache/superset/pull/39795#discussion_r3308582539
##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Horizontal.tsx:
##########
@@ -94,9 +138,71 @@ const HorizontalFilterBar: FC<HorizontalBarProps> = ({
[chartIds, chartLayoutItems, dataMask, verboseMaps],
);
+ const [activeUrlFilters, setActiveUrlFilters] = useState<
+ UrlFilterIndicator[]
+ >(() => getUrlFilterIndicators());
+
+ // Re-read chips whenever the URL changes (back/forward navigation, or a
+ // programmatic history.replace).
+ useEffect(() => {
+ setActiveUrlFilters(getUrlFilterIndicators());
+ }, [location.search]);
+
+ const handleRemoveUrlFilter = useCallback(
+ (filterToRemove: UrlFilterIndicator) => {
+ const risonParam = getRisonFilterParam();
+ if (!risonParam) return;
+
+ const removeId = getUrlFilterIdentity(filterToRemove.filter);
+ const currentFilters = parseRisonFilters(risonParam);
+ const remaining = currentFilters.filter(
+ f => getUrlFilterIdentity(f) !== removeId,
+ );
+ updateUrlWithUnmatchedFilters(remaining, history);
+ setActiveUrlFilters(prev =>
+ prev.filter(f => getUrlFilterIdentity(f.filter) !== removeId),
+ );
+
+ if (remaining.length === 0) {
+ dispatch(removeDataMask(RISON_UNMATCHED_DATAMASK_ID));
+ } else {
+ const extraFormDataFilters: QueryObjectFilterClause[] =
+ risonFiltersToExtraFormDataFilters(remaining);
+ dispatch(
+ updateDataMask(RISON_UNMATCHED_DATAMASK_ID, {
+ extraFormData: { filters: extraFormDataFilters },
+ }),
+ );
+ }
+ },
+ [dispatch, history],
+ );
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing URL filter dispatch tests</b></div>
<div id="fix">
The new `handleRemoveUrlFilter` logic (lines 151-176) lacks test coverage.
`HorizontalFilterBar.test.tsx` only tests basic rendering — it doesn't verify
that removing the last URL filter dispatches `removeDataMask` or that removing
a filter with others remaining dispatches `updateDataMask` with
`RISON_UNMATCHED_DATAMASK_ID`. This mirrors the covered behavior in
`Vertical.test.tsx` (lines 81-121). Without assertions on dispatch calls,
regressions in the data mask logic will go undetected.
</div>
</div>
<small><i>Code Review Run #23d385</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/dashboard/components/nativeFilters/FilterBar/UrlFilters/Vertical.tsx:
##########
@@ -0,0 +1,96 @@
+/**
+ * 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 { useCallback, useEffect, useState } from 'react';
+import { useDispatch } from 'react-redux';
+import { useHistory, useLocation } from 'react-router-dom';
+import { QueryObjectFilterClause } from '@superset-ui/core';
+import { removeDataMask, updateDataMask } from 'src/dataMask/actions';
+import {
+ getRisonFilterParam,
+ parseRisonFilters,
+ RISON_UNMATCHED_DATAMASK_ID,
+ risonFiltersToExtraFormDataFilters,
+ updateUrlWithUnmatchedFilters,
+} from 'src/dashboard/util/risonFilters';
+import {
+ getUrlFilterIdentity,
+ getUrlFilterIndicators,
+ UrlFilterIndicator,
+} from './urlFilterUtils';
+import UrlFiltersVerticalCollapse from './VerticalCollapse';
+
+const UrlFiltersVertical = () => {
+ const dispatch = useDispatch();
+ const history = useHistory();
+ const location = useLocation();
+ const [urlFilters, setUrlFilters] = useState<UrlFilterIndicator[]>(() =>
+ getUrlFilterIndicators(),
+ );
+
+ // Re-read chips whenever the URL changes (back/forward navigation, or a
+ // programmatic history.replace).
+ useEffect(() => {
+ setUrlFilters(getUrlFilterIndicators());
+ }, [location.search]);
+
+ const handleRemoveFilter = useCallback(
+ (filterToRemove: UrlFilterIndicator) => {
+ const risonParam = getRisonFilterParam();
+ if (!risonParam) return;
+
+ const removeId = getUrlFilterIdentity(filterToRemove.filter);
+ const currentFilters = parseRisonFilters(risonParam);
+ const remaining = currentFilters.filter(
+ f => getUrlFilterIdentity(f) !== removeId,
+ );
+
+ updateUrlWithUnmatchedFilters(remaining, history);
+ setUrlFilters(prev =>
+ prev.filter(f => getUrlFilterIdentity(f.filter) !== removeId),
+ );
+
+ if (remaining.length === 0) {
+ dispatch(removeDataMask(RISON_UNMATCHED_DATAMASK_ID));
+ } else {
+ const extraFormDataFilters: QueryObjectFilterClause[] =
+ risonFiltersToExtraFormDataFilters(remaining);
+ dispatch(
+ updateDataMask(RISON_UNMATCHED_DATAMASK_ID, {
+ extraFormData: { filters: extraFormDataFilters },
+ }),
+ );
+ }
+ },
+ [dispatch, history],
+ );
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Duplicated filter removal logic</b></div>
<div id="fix">
The `handleRemoveFilter` logic (lines 53-82) is semantically identical to
`handleRemoveUrlFilter` in `Horizontal.tsx` (lines 151-179). Both implement the
same pattern: get Rison param, parse, filter out removed, update URL, dispatch
dataMask action. This duplication creates maintenance risk where fixes in one
file may be missed in the other.
</div>
</div>
<small><i>Code Review Run #23d385</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]