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/01 09:02:45 UTC

[GitHub] [superset] geido commented on a diff in pull request #21970: feat: Update native filter dividers to support horizontal display

geido commented on code in PR #21970:
URL: https://github.com/apache/superset/pull/21970#discussion_r1010224848


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterDivider.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useEffect, useRef, useState } from 'react';
+import Icons from 'src/components/Icons';
+import { Tooltip } from 'src/components/Tooltip';
+
+export interface FilterDividerProps {
+  title: string;
+  description: string;
+  horizontal?: boolean;
+  horizontalOverflow?: boolean;
+}
+
+const useIsTruncated = <T extends HTMLElement>(
+  text: string,
+): [React.RefObject<T>, boolean] => {
+  const ref = useRef<T>(null);
+  const [isTruncated, setIsTruncated] = useState(true);
+  useEffect(() => {
+    if (ref.current) {
+      setIsTruncated(ref.current.offsetWidth < ref.current.scrollWidth);
+    }
+  }, [text]);
+
+  return [ref, isTruncated];
+};
+
+const VerticalDivider = ({ title, description }: FilterDividerProps) => (
+  <div>
+    <h3>{title}</h3>
+    {description ? <p data-test="divider-description">{description}</p> : null}
+  </div>
+);
+
+const HorizontalDivider = ({ title, description }: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const tooltipOverlay = (
+    <>
+      {titleIsTruncated ? (
+        <div>
+          <strong>{title}</strong>
+        </div>
+      ) : null}
+      {description ? <div>{description}</div> : null}
+    </>
+  );
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        display: flex;
+        align-items: center;
+        height: ${8 * theme.gridUnit}px;
+        border-left: 1px solid ${theme.colors.grayscale.light2};
+        padding-left: ${4 * theme.gridUnit}px;
+        margin-right: ${4 * theme.gridUnit}px;
+      `}
+    >
+      <h3
+        ref={titleRef}
+        css={(theme: SupersetTheme) => css`
+          max-width: 130px;
+          white-space: nowrap;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          font-size: 14px;
+          font-weight: normal;
+          margin: 0;
+          color: ${theme.colors.grayscale.dark1};
+        `}
+      >
+        {title}
+      </h3>
+      {titleIsTruncated || description ? (
+        <Tooltip overlay={tooltipOverlay}>
+          <Icons.BookOutlined
+            data-test="divider-description-icon"
+            css={(theme: SupersetTheme) => css`
+              color: ${theme.colors.grayscale.base};
+              font-size: 16px;
+              margin: 0 ${theme.gridUnit * 1.5}px;
+              vertical-align: unset;
+              line-height: unset;
+            `}
+          />
+        </Tooltip>
+      ) : null}
+    </div>
+  );
+};
+
+const HorizontalOverflowDivider = ({
+  title,
+  description,
+}: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const [descriptionRef, descriptionIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(description);
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        border-top: 1px solid ${theme.colors.grayscale.light2};
+        padding-top: ${theme.gridUnit * 4}px;
+        &:not(&:last-child) {
+          margin-bottom: ${theme.gridUnit * 4}px;
+        }
+      `}
+    >
+      <Tooltip overlay={titleIsTruncated ? <strong>{title}</strong> : null}>
+        <h3
+          ref={titleRef}
+          css={(theme: SupersetTheme) => css`
+            display: block;
+            white-space: nowrap;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            color: ${theme.colors.grayscale.dark1};
+            font-weight: normal;
+            font-size: 14px;

Review Comment:
   Same comment about font-size as above



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterDivider.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useEffect, useRef, useState } from 'react';
+import Icons from 'src/components/Icons';
+import { Tooltip } from 'src/components/Tooltip';
+
+export interface FilterDividerProps {
+  title: string;
+  description: string;
+  horizontal?: boolean;
+  horizontalOverflow?: boolean;
+}
+
+const useIsTruncated = <T extends HTMLElement>(
+  text: string,
+): [React.RefObject<T>, boolean] => {
+  const ref = useRef<T>(null);
+  const [isTruncated, setIsTruncated] = useState(true);
+  useEffect(() => {
+    if (ref.current) {
+      setIsTruncated(ref.current.offsetWidth < ref.current.scrollWidth);
+    }
+  }, [text]);
+
+  return [ref, isTruncated];
+};
+
+const VerticalDivider = ({ title, description }: FilterDividerProps) => (
+  <div>
+    <h3>{title}</h3>
+    {description ? <p data-test="divider-description">{description}</p> : null}
+  </div>
+);
+
+const HorizontalDivider = ({ title, description }: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const tooltipOverlay = (
+    <>
+      {titleIsTruncated ? (
+        <div>
+          <strong>{title}</strong>
+        </div>
+      ) : null}
+      {description ? <div>{description}</div> : null}
+    </>
+  );
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        display: flex;
+        align-items: center;
+        height: ${8 * theme.gridUnit}px;
+        border-left: 1px solid ${theme.colors.grayscale.light2};
+        padding-left: ${4 * theme.gridUnit}px;
+        margin-right: ${4 * theme.gridUnit}px;
+      `}
+    >
+      <h3
+        ref={titleRef}
+        css={(theme: SupersetTheme) => css`
+          max-width: 130px;
+          white-space: nowrap;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          font-size: 14px;
+          font-weight: normal;
+          margin: 0;
+          color: ${theme.colors.grayscale.dark1};
+        `}
+      >
+        {title}
+      </h3>
+      {titleIsTruncated || description ? (
+        <Tooltip overlay={tooltipOverlay}>
+          <Icons.BookOutlined
+            data-test="divider-description-icon"
+            css={(theme: SupersetTheme) => css`
+              color: ${theme.colors.grayscale.base};
+              font-size: 16px;
+              margin: 0 ${theme.gridUnit * 1.5}px;
+              vertical-align: unset;
+              line-height: unset;
+            `}
+          />
+        </Tooltip>
+      ) : null}
+    </div>
+  );
+};
+
+const HorizontalOverflowDivider = ({
+  title,
+  description,
+}: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const [descriptionRef, descriptionIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(description);
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        border-top: 1px solid ${theme.colors.grayscale.light2};
+        padding-top: ${theme.gridUnit * 4}px;
+        &:not(&:last-child) {
+          margin-bottom: ${theme.gridUnit * 4}px;
+        }
+      `}
+    >
+      <Tooltip overlay={titleIsTruncated ? <strong>{title}</strong> : null}>
+        <h3
+          ref={titleRef}
+          css={(theme: SupersetTheme) => css`
+            display: block;
+            white-space: nowrap;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            color: ${theme.colors.grayscale.dark1};
+            font-weight: normal;
+            font-size: 14px;
+            margin: 0 0 ${theme.gridUnit}px 0;
+          `}
+        >
+          {title}
+        </h3>
+      </Tooltip>
+      {description ? (
+        <Tooltip overlay={descriptionIsTruncated ? description : null}>
+          <p
+            ref={descriptionRef}
+            data-test="divider-description"
+            css={(theme: SupersetTheme) => css`
+              display: block;
+              white-space: nowrap;
+              overflow: hidden;
+              text-overflow: ellipsis;
+              font-size: 12px;

Review Comment:
   This too



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterDivider.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useEffect, useRef, useState } from 'react';
+import Icons from 'src/components/Icons';
+import { Tooltip } from 'src/components/Tooltip';
+
+export interface FilterDividerProps {
+  title: string;
+  description: string;
+  horizontal?: boolean;
+  horizontalOverflow?: boolean;
+}
+
+const useIsTruncated = <T extends HTMLElement>(

Review Comment:
   I saw this hook being used in at least 3 more places in the app. We should move this to the common hooks if possible. In a separate PR we can then go back and replace it everywhere else



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterDivider.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useEffect, useRef, useState } from 'react';
+import Icons from 'src/components/Icons';
+import { Tooltip } from 'src/components/Tooltip';
+
+export interface FilterDividerProps {
+  title: string;
+  description: string;
+  horizontal?: boolean;
+  horizontalOverflow?: boolean;
+}
+
+const useIsTruncated = <T extends HTMLElement>(
+  text: string,
+): [React.RefObject<T>, boolean] => {
+  const ref = useRef<T>(null);
+  const [isTruncated, setIsTruncated] = useState(true);
+  useEffect(() => {
+    if (ref.current) {
+      setIsTruncated(ref.current.offsetWidth < ref.current.scrollWidth);
+    }
+  }, [text]);
+
+  return [ref, isTruncated];
+};
+
+const VerticalDivider = ({ title, description }: FilterDividerProps) => (
+  <div>
+    <h3>{title}</h3>
+    {description ? <p data-test="divider-description">{description}</p> : null}
+  </div>
+);
+
+const HorizontalDivider = ({ title, description }: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const tooltipOverlay = (
+    <>
+      {titleIsTruncated ? (
+        <div>
+          <strong>{title}</strong>
+        </div>
+      ) : null}
+      {description ? <div>{description}</div> : null}
+    </>
+  );
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        display: flex;
+        align-items: center;
+        height: ${8 * theme.gridUnit}px;
+        border-left: 1px solid ${theme.colors.grayscale.light2};
+        padding-left: ${4 * theme.gridUnit}px;
+        margin-right: ${4 * theme.gridUnit}px;
+      `}
+    >
+      <h3
+        ref={titleRef}
+        css={(theme: SupersetTheme) => css`
+          max-width: 130px;
+          white-space: nowrap;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          font-size: 14px;

Review Comment:
   We should use the provided typography settings in the `theme`



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterDivider.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { css, SupersetTheme } from '@superset-ui/core';
+import React, { useEffect, useRef, useState } from 'react';
+import Icons from 'src/components/Icons';
+import { Tooltip } from 'src/components/Tooltip';
+
+export interface FilterDividerProps {
+  title: string;
+  description: string;
+  horizontal?: boolean;
+  horizontalOverflow?: boolean;
+}
+
+const useIsTruncated = <T extends HTMLElement>(
+  text: string,
+): [React.RefObject<T>, boolean] => {
+  const ref = useRef<T>(null);
+  const [isTruncated, setIsTruncated] = useState(true);
+  useEffect(() => {
+    if (ref.current) {
+      setIsTruncated(ref.current.offsetWidth < ref.current.scrollWidth);
+    }
+  }, [text]);
+
+  return [ref, isTruncated];
+};
+
+const VerticalDivider = ({ title, description }: FilterDividerProps) => (
+  <div>
+    <h3>{title}</h3>
+    {description ? <p data-test="divider-description">{description}</p> : null}
+  </div>
+);
+
+const HorizontalDivider = ({ title, description }: FilterDividerProps) => {
+  const [titleRef, titleIsTruncated] =
+    useIsTruncated<HTMLHeadingElement>(title);
+
+  const tooltipOverlay = (
+    <>
+      {titleIsTruncated ? (
+        <div>
+          <strong>{title}</strong>
+        </div>
+      ) : null}
+      {description ? <div>{description}</div> : null}
+    </>
+  );
+
+  return (
+    <div
+      css={(theme: SupersetTheme) => css`
+        display: flex;
+        align-items: center;
+        height: ${8 * theme.gridUnit}px;
+        border-left: 1px solid ${theme.colors.grayscale.light2};
+        padding-left: ${4 * theme.gridUnit}px;
+        margin-right: ${4 * theme.gridUnit}px;
+      `}
+    >
+      <h3
+        ref={titleRef}
+        css={(theme: SupersetTheme) => css`
+          max-width: 130px;
+          white-space: nowrap;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          font-size: 14px;
+          font-weight: normal;
+          margin: 0;
+          color: ${theme.colors.grayscale.dark1};
+        `}
+      >
+        {title}
+      </h3>
+      {titleIsTruncated || description ? (
+        <Tooltip overlay={tooltipOverlay}>
+          <Icons.BookOutlined
+            data-test="divider-description-icon"
+            css={(theme: SupersetTheme) => css`
+              color: ${theme.colors.grayscale.base};
+              font-size: 16px;

Review Comment:
   Icons have a property `iconSize` with predefined sizes. We should stick to those whenever possible.



-- 
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