etr2460 commented on a change in pull request #16154:
URL: https://github.com/apache/superset/pull/16154#discussion_r722781566
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx
##########
@@ -88,7 +88,6 @@ const addFilterFlow = async () => {
userEvent.click(screen.getByText('Time range'));
userEvent.type(screen.getByTestId(getModalTestId('name-input')),
FILTER_NAME);
userEvent.click(screen.getByText('Save'));
- await screen.findByText('All Filters (1)');
Review comment:
should this be removed?
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTitleContainer.tsx
##########
@@ -0,0 +1,166 @@
+/**
+ * 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 { styled, t } from '@superset-ui/core';
+import Icons from 'src/components/Icons';
+import { FilterRemoval } from './types';
+import DraggableFilter from './DraggableFilter';
+
+const FilterTitle = styled.div`
+ ${({ theme }) => `
+ display: flex;
+ padding: ${theme.gridUnit * 2}px;
+ width: 100%;
+ border-radius: ${theme.borderRadius}px;
+ &.active {
+ color: ${theme.colors.grayscale.dark1};
+ border-radius: ${theme.borderRadius}px;
+ background-color: ${theme.colors.secondary.light4};
+ span, .anticon {
+ color: ${theme.colors.grayscale.dark1};
+ }
+ }
+ &:hover {
+ color: ${theme.colors.primary.light1};
+ span, .anticon {
+ color: ${theme.colors.primary.light1};
+ }
+ }
+`}
+`;
+
+const StyledTrashIcon = styled(Icons.Trash)`
+ color: ${({ theme }) => theme.colors.grayscale.light3};
+`;
+const Container = styled.div`
+ height: 100%;
+ overflow-y: auto;
+`;
+
+interface Props {
+ getFilterTitle: (filterId: string) => string;
+ onChange: (filterId: string) => void;
+ currentFilterId: string;
+ removedFilters: Record<string, FilterRemoval>;
+ onRemove: (id: string) => void;
+ restoreFilter: (id: string) => void;
+ onRearrage: (dragIndex: number, targetIndex: number) => void;
+ filterGroups: string[][];
+}
+
+const FilterTitleContainer: React.FC<Props> = ({
+ getFilterTitle,
+ onChange,
+ currentFilterId,
+ removedFilters,
+ onRemove,
+ restoreFilter,
+ onRearrage,
+ filterGroups,
+}) => {
+ const renderComponent = (id: string) => {
+ const isRemoved = !!removedFilters[id];
+ return (
+ <FilterTitle
+ role="tab"
+ key={`filter-title-tab-${id}`}
+ onClick={() => onChange(id)}
+ className={currentFilterId === id ? 'active' : ''}
+ >
+ <div css={{ display: 'flex', width: '100%' }}>
+ <div>{isRemoved ? t('(Removed)') : getFilterTitle(id)}</div>
+ {isRemoved && (
+ <span
+ css={{ alignSelf: 'flex-end', marginLeft: 'auto' }}
+ role="button"
+ data-test="undo-button"
+ tabIndex={0}
+ onClick={e => {
+ e.preventDefault();
+ restoreFilter(id);
+ }}
+ >
+ {t('Undo?')}
+ </span>
+ )}
+ </div>
+ <div css={{ alignSelf: 'flex-end', marginLeft: 'auto' }}>
+ {isRemoved ? (
+ <></>
Review comment:
why do we need an empty fragment? I assume `null` would be fine?
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTitleContainer.tsx
##########
@@ -0,0 +1,166 @@
+/**
+ * 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 { styled, t } from '@superset-ui/core';
+import Icons from 'src/components/Icons';
+import { FilterRemoval } from './types';
+import DraggableFilter from './DraggableFilter';
+
+const FilterTitle = styled.div`
+ ${({ theme }) => `
+ display: flex;
+ padding: ${theme.gridUnit * 2}px;
+ width: 100%;
+ border-radius: ${theme.borderRadius}px;
+ &.active {
+ color: ${theme.colors.grayscale.dark1};
+ border-radius: ${theme.borderRadius}px;
+ background-color: ${theme.colors.secondary.light4};
+ span, .anticon {
+ color: ${theme.colors.grayscale.dark1};
+ }
+ }
+ &:hover {
+ color: ${theme.colors.primary.light1};
+ span, .anticon {
+ color: ${theme.colors.primary.light1};
+ }
+ }
+`}
+`;
+
+const StyledTrashIcon = styled(Icons.Trash)`
+ color: ${({ theme }) => theme.colors.grayscale.light3};
+`;
+const Container = styled.div`
+ height: 100%;
+ overflow-y: auto;
+`;
+
+interface Props {
+ getFilterTitle: (filterId: string) => string;
+ onChange: (filterId: string) => void;
+ currentFilterId: string;
+ removedFilters: Record<string, FilterRemoval>;
+ onRemove: (id: string) => void;
+ restoreFilter: (id: string) => void;
+ onRearrage: (dragIndex: number, targetIndex: number) => void;
+ filterGroups: string[][];
+}
+
+const FilterTitleContainer: React.FC<Props> = ({
+ getFilterTitle,
+ onChange,
+ currentFilterId,
+ removedFilters,
+ onRemove,
+ restoreFilter,
+ onRearrage,
+ filterGroups,
+}) => {
+ const renderComponent = (id: string) => {
+ const isRemoved = !!removedFilters[id];
+ return (
+ <FilterTitle
+ role="tab"
+ key={`filter-title-tab-${id}`}
+ onClick={() => onChange(id)}
+ className={currentFilterId === id ? 'active' : ''}
+ >
+ <div css={{ display: 'flex', width: '100%' }}>
+ <div>{isRemoved ? t('(Removed)') : getFilterTitle(id)}</div>
+ {isRemoved && (
+ <span
+ css={{ alignSelf: 'flex-end', marginLeft: 'auto' }}
+ role="button"
+ data-test="undo-button"
+ tabIndex={0}
+ onClick={e => {
+ e.preventDefault();
+ restoreFilter(id);
+ }}
+ >
+ {t('Undo?')}
+ </span>
+ )}
+ </div>
+ <div css={{ alignSelf: 'flex-end', marginLeft: 'auto' }}>
+ {isRemoved ? (
+ <></>
+ ) : (
+ <StyledTrashIcon
+ onClick={event => {
+ event.stopPropagation();
+ onRemove(id);
+ }}
+ alt="RemoveFilter"
+ />
+ )}
+ </div>
+ </FilterTitle>
+ );
+ };
+ const recursivelyRender = (
+ elementId: string,
+ nodeList: Array<{ id: string; parentId: string | null }>,
+ rendered: Array<string>,
+ ): React.ReactNode => {
+ const didAlreadyRender = rendered.indexOf(elementId) >= 0;
+ if (didAlreadyRender) {
+ return null;
+ }
+ let parent = null;
+ const element = nodeList.filter(el => el.id === elementId)[0];
+ if (!element) {
+ // eslint-disable-next-line no-console
+ console.warn(`Could not find filter with ID ${elementId}`);
Review comment:
let's clean up the console logs before merging?
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FilterTitlePane.tsx
##########
@@ -0,0 +1,127 @@
+/**
+ * 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 { PlusOutlined } from '@ant-design/icons';
+import { styled, t, useTheme } from '@superset-ui/core';
+import React from 'react';
+import FilterTitleContainer from './FilterTitleContainer';
+import { FilterRemoval } from './types';
+
+interface Props {
+ removedFilters: Record<string, FilterRemoval>;
+ restoreFilter: (id: string) => void;
+ getFilterTitle: (id: string) => string;
+ onRearrage: (dragIndex: number, targetIndex: number) => void;
+ onRemove: (id: string) => void;
+ currentFilterId: string;
+ onChange: (id: string) => void;
+ onEdit: (filterId: string, action: 'add' | 'remove') => void;
+ filterGroups: string[][];
+}
+
+const StyledHeader = styled.div`
+ ${({ theme }) => `
+ color: ${theme.colors.grayscale.dark1};
+ font-size: ${theme.typography.sizes.l}px;
+ padding-top: ${theme.gridUnit * 4}px;
+ padding-right: ${theme.gridUnit * 4}px;
+ padding-left: ${theme.gridUnit * 4}px;
+ padding-bottom: ${theme.gridUnit * 2}px;
+ `}
+`;
+
+const TabsContainer = styled.div`
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+`;
+
+const StyledAddFilterBox = styled.div`
+ color: ${({ theme }) => theme.colors.primary.dark1};
+ padding: ${({ theme }) => theme.gridUnit * 2}px;
+ border-top: 1px solid ${({ theme }) => theme.colors.grayscale.light2};
+ cursor: pointer;
+ margin-top: auto;
+ &:hover {
+ color: ${({ theme }) => theme.colors.primary.base};
+ }
+`;
+
+const FilterTitlePane: React.FC<Props> = ({
+ getFilterTitle,
+ onChange,
+ onEdit,
+ onRemove,
+ onRearrage,
+ restoreFilter,
+ currentFilterId,
+ filterGroups,
+ removedFilters,
+}) => {
+ const theme = useTheme();
+ return (
+ <>
Review comment:
fragment is unneeded
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx
##########
@@ -95,7 +95,13 @@ const FilterControls: FC<FilterControlsProps> = ({
))}
{filtersInScope.map(filter => {
const index = filterValues.findIndex(f => f.id === filter.id);
- return <portals.OutPortal node={portalNodes[index]} inView />;
+ return (
+ <portals.OutPortal
Review comment:
nit, i find it prettier to `import { OutPortal } from 'portals'` and use
it like that in react components
--
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]