You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/11/09 17:58:55 UTC

[GitHub] [superset] michael-s-molina commented on a diff in pull request #22064: feat: Horizontal filter bar states

michael-s-molina commented on code in PR #22064:
URL: https://github.com/apache/superset/pull/22064#discussion_r1018207395


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx:
##########
@@ -37,38 +38,15 @@ interface ActionButtonsProps {
   dataMaskSelected: DataMaskState;
   dataMaskApplied: DataMaskStateWithId;
   isApplyDisabled: boolean;
+  orientation?: FilterBarLocation;

Review Comment:
   Can we rename it to `FilterBarOrientation`?



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx:
##########
@@ -37,38 +38,15 @@ interface ActionButtonsProps {
   dataMaskSelected: DataMaskState;
   dataMaskApplied: DataMaskStateWithId;
   isApplyDisabled: boolean;
+  orientation?: FilterBarLocation;
 }
 
-const ActionButtonsContainer = styled.div<{ width: number }>`
-  ${({ theme, width }) => css`
+const ActionButtonsContainer = styled.div<{

Review Comment:
   Totally optional, but for these cases, I like to use [Emotion's Composition](https://emotion.sh/docs/composition).
   
   You can write the individual styles:
   
   ```
   const containerStyle = (theme: SupersetTheme) => css`
     display: flex;
   
     && > .filter-clear-all-button {
       color: ${theme.colors.grayscale.base};
       margin-left: 0;
       &:hover {
         color: ${theme.colors.primary.dark1};
       }
   
       &[disabled],
       &[disabled]:hover {
         color: ${theme.colors.grayscale.light1};
       }
     }
   `;
   
   const verticalStyle = (theme: SupersetTheme, width: number) => css`
     flex-direction: column;
     align-items: center;
     pointer-events: none;
     position: fixed;
     z-index: 100;
   
     // filter bar width minus 1px for border
     width: ${width - 1}px;
     bottom: 0;
   
     padding: ${theme.gridUnit * 4}px;
     padding-top: ${theme.gridUnit * 6}px;
   
     background: linear-gradient(
       ${rgba(theme.colors.grayscale.light5, 0)},
       ${theme.colors.grayscale.light5} ${theme.opacity.mediumLight}
     );
   
     & > button {
       pointer-events: auto;
     }
   
     & > .filter-apply-button {
       margin-bottom: ${theme.gridUnit * 3}px;
     }
   `;
   
   const horizontalStyle = (theme: SupersetTheme) => css`
     margin: 0 ${theme.gridUnit * 2}px;
     && > .filter-clear-all-button {
       text-transform: capitalize;
       font-weight: ${theme.typography.weights.normal};
     }
     & > .filter-apply-button {
       &[disabled],
       &[disabled]:hover {
         color: ${theme.colors.grayscale.light1};
         background: ${theme.colors.grayscale.light3};
       }
     }
   `;
   ```
   
   And apply them conditionally:
   
   ```
   return (
       <div
         data-test="filterbar-action-buttons"
         css={(theme: SupersetTheme) => [
           containerStyle(theme),
           isVertical ? verticalStyle(theme, width) : horizontalStyle(theme),
         ]}
       >
         ...
       </div>
     );
   };
   ```



##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx:
##########
@@ -354,6 +361,14 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
     ({ dropIndicatorProps }: { dropIndicatorProps: JsonObject }) => (
       <div>
         {!hideDashboardHeader && <DashboardHeader />}
+        {nativeFiltersEnabled &&

Review Comment:
   Can you extract `nativeFiltersEnabled && !editMode` to a const called `showFilterBar` to be used in both places?



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx:
##########
@@ -58,6 +58,10 @@ const HeaderButton = styled(Button)`
 const Wrapper = styled.div`
   padding: ${({ theme }) => theme.gridUnit}px
     ${({ theme }) => theme.gridUnit * 2}px;
+
+  .ant-dropdown-trigger span {
+    padding-right: ${({ theme }) => theme.gridUnit * 2}px;
+  }
 `;

Review Comment:
   ```suggestion
   const Wrapper = styled.div`
     ${({ theme }) => `
       padding: ${theme.gridUnit}px ${theme.gridUnit * 2}px;
   
       .ant-dropdown-trigger span {
         padding-right: ${theme.gridUnit * 2}px;
       }
     `}
   `;
   ```



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/HorizontalFilterBar.test.tsx:
##########
@@ -0,0 +1,107 @@
+/**
+ * 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 { NativeFilterType } from '@superset-ui/core';
+import React from 'react';
+import { render, screen, waitFor } from 'spec/helpers/testing-library';
+import HorizontalBar from './Horizontal';
+
+describe('HorizontalFilterBar', () => {

Review Comment:
   [Avoid nesting when you're testing](https://github.com/apache/superset/wiki/Testing-Guidelines-and-Best-Practices#avoid-nesting-when-youre-testing) 😉 



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Horizontal.tsx:
##########
@@ -0,0 +1,130 @@
+/**
+ * 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 Loading from 'src/components/Loading';
+import FilterControls from './FilterControls/FilterControls';
+import { getFilterBarTestId, HorizontalBarProps } from './utils';
+import FilterBarLocationSelect from './FilterBarLocationSelect';
+import FilterConfigurationLink from './FilterConfigurationLink';
+
+const HorizontalBar = styled.div`
+  ${({ theme }) => `
+  padding: ${theme.gridUnit * 2}px ${theme.gridUnit * 2}px;
+  background: ${theme.colors.grayscale.light5};
+  box-shadow: inset 0px -2px 2px -1px ${theme.colors.grayscale.light2};
+`}
+`;
+
+const HorizontalBarContent = styled.div`
+  ${({ theme }) => `
+  display: flex;
+  flex-direction: row;
+  flex-wrap: nowrap;
+  align-items: center;
+  justify-content: flex-start;
+  padding: 0 ${theme.gridUnit * 2}px;
+
+  .loading {
+    margin: ${theme.gridUnit * 2}px auto ${theme.gridUnit * 2}px;
+    padding: 0;
+  }
+`}
+`;
+
+const FilterBarEmptyStateContainer = styled.div`
+  ${({ theme }) => `
+  margin: 0 ${theme.gridUnit * 2}px;
+  font-weight: ${theme.typography.weights.bold};
+`}
+`;
+
+const FiltersLinkContainer = styled.div<{ hasFilters: boolean }>`
+  ${({ theme, hasFilters }) => `
+  padding: 0 ${theme.gridUnit * 2}px;
+  border-right: ${
+    hasFilters ? `1px solid ${theme.colors.grayscale.light2}` : 0
+  };
+
+  button {
+    display: flex;
+    align-items: center;
+    text-transform: capitalize;
+    font-weight: ${theme.typography.weights.normal};
+    color: ${theme.colors.primary.base};
+    > .anticon + span, > .anticon {
+        margin-right: 0;
+        margin-left: 0;
+      }
+  }
+`}
+`;

Review Comment:
   ```suggestion
   const HorizontalBar = styled.div`
     ${({ theme }) => `
       padding: ${theme.gridUnit * 2}px ${theme.gridUnit * 2}px;
       background: ${theme.colors.grayscale.light5};
       box-shadow: inset 0px -2px 2px -1px ${theme.colors.grayscale.light2};
     `}
   `;
   
   const HorizontalBarContent = styled.div`
     ${({ theme }) => `
       display: flex;
       flex-direction: row;
       flex-wrap: nowrap;
       align-items: center;
       justify-content: flex-start;
       padding: 0 ${theme.gridUnit * 2}px;
   
       .loading {
         margin: ${theme.gridUnit * 2}px auto ${theme.gridUnit * 2}px;
         padding: 0;
       }
     `}
   `;
   
   const FilterBarEmptyStateContainer = styled.div`
     ${({ theme }) => `
       margin: 0 ${theme.gridUnit * 2}px;
       font-weight: ${theme.typography.weights.bold};
     `}
   `;
   
   const FiltersLinkContainer = styled.div<{ hasFilters: boolean }>`
     ${({ theme, hasFilters }) => `
       padding: 0 ${theme.gridUnit * 2}px;
       border-right: ${
         hasFilters ? `1px solid ${theme.colors.grayscale.light2}` : 0
       };
   
       button {
         display: flex;
         align-items: center;
         text-transform: capitalize;
         font-weight: ${theme.typography.weights.normal};
         color: ${theme.colors.primary.base};
         > .anticon + span, > .anticon {
             margin-right: 0;
             margin-left: 0;
           }
       }
     `}
   `;
   ```



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org