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/01/27 16:49:04 UTC

[GitHub] [superset] etr2460 commented on a change in pull request #18188: refactor: upgrade ControlHeader to TSX & FC and add storybook

etr2460 commented on a change in pull request #18188:
URL: https://github.com/apache/superset/pull/18188#discussion_r793801636



##########
File path: superset-frontend/src/explore/components/ControlHeader.stories.tsx
##########
@@ -0,0 +1,79 @@
+/**
+ * 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 ControlHeader, { ControlHeaderProps } from './ControlHeader';
+
+export default {
+  title: 'ControlHeader',
+  component: ControlHeader,
+};
+
+const options: {
+  [key: string]: ControlHeaderProps;
+} = {
+  label: {
+    label: 'Control label',
+  },
+  warning: {
+    label: 'Control warning',
+    warning: 'Example of warning message',
+  },
+  error: {
+    label: 'Control error',
+    validationErrors: ['Something is wrong'],
+  },
+};
+
+export const ControlHeaderGallery = () => (
+  <>
+    {Object.entries(options).map(([name, props]) => (
+      <>
+        <h4>{name}</h4>
+        <ControlHeader {...props} />
+      </>
+    ))}
+  </>
+);
+
+export const InteractiveControlHeader = (props: ControlHeaderProps) => (
+  <>
+    <ControlHeader {...props} />
+  </>

Review comment:
       no fragment needed

##########
File path: superset-frontend/src/explore/components/ControlHeader.stories.tsx
##########
@@ -0,0 +1,79 @@
+/**

Review comment:
       love the stories, thanks!

##########
File path: superset-frontend/src/explore/components/ControlHeader.tsx
##########
@@ -0,0 +1,154 @@
+/**
+ * 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, { FC, ReactNode } from 'react';
+import { t, css, useTheme, JsonObject } from '@superset-ui/core';
+import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
+import { Tooltip } from 'src/components/Tooltip';
+import { FormLabel } from 'src/components/Form';
+import Icons from 'src/components/Icons';
+
+export type ControlHeaderProps = {
+  name?: string;
+  label?: ReactNode;
+  description?: ReactNode;
+  validationErrors?: JsonObject | null;

Review comment:
       validation errors was an array before, and now you've set it to a json object. Was that intended? seems like it can always be an `any[]`, and maybe even a `string[]`

##########
File path: superset-frontend/src/explore/components/ControlHeader.tsx
##########
@@ -0,0 +1,154 @@
+/**
+ * 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, { FC, ReactNode } from 'react';
+import { t, css, useTheme, JsonObject } from '@superset-ui/core';
+import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
+import { Tooltip } from 'src/components/Tooltip';
+import { FormLabel } from 'src/components/Form';
+import Icons from 'src/components/Icons';
+
+export type ControlHeaderProps = {
+  name?: string;
+  label?: ReactNode;
+  description?: ReactNode;
+  validationErrors?: JsonObject | null;
+  renderTrigger?: boolean;
+  rightNode?: ReactNode;
+  leftNode?: ReactNode;
+  onClick?: () => {};
+  hovered?: boolean;
+  tooltipOnClick?: () => {};

Review comment:
       ```suggestion
     tooltipOnClick?: () => void;
   ```

##########
File path: superset-frontend/src/explore/components/ControlHeader.tsx
##########
@@ -0,0 +1,154 @@
+/**
+ * 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, { FC, ReactNode } from 'react';
+import { t, css, useTheme, JsonObject } from '@superset-ui/core';
+import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
+import { Tooltip } from 'src/components/Tooltip';
+import { FormLabel } from 'src/components/Form';
+import Icons from 'src/components/Icons';
+
+export type ControlHeaderProps = {
+  name?: string;
+  label?: ReactNode;
+  description?: ReactNode;
+  validationErrors?: JsonObject | null;
+  renderTrigger?: boolean;
+  rightNode?: ReactNode;
+  leftNode?: ReactNode;
+  onClick?: () => {};

Review comment:
       ```suggestion
     onClick?: () => void;
   ```
   
   I think this is what you want, unless onClick actually returns an empty object

##########
File path: superset-frontend/src/explore/components/ControlHeader.tsx
##########
@@ -0,0 +1,154 @@
+/**
+ * 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, { FC, ReactNode } from 'react';
+import { t, css, useTheme, JsonObject } from '@superset-ui/core';
+import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
+import { Tooltip } from 'src/components/Tooltip';
+import { FormLabel } from 'src/components/Form';
+import Icons from 'src/components/Icons';
+
+export type ControlHeaderProps = {
+  name?: string;
+  label?: ReactNode;
+  description?: ReactNode;
+  validationErrors?: JsonObject | null;
+  renderTrigger?: boolean;
+  rightNode?: ReactNode;
+  leftNode?: ReactNode;
+  onClick?: () => {};
+  hovered?: boolean;
+  tooltipOnClick?: () => {};
+  warning?: string;
+  danger?: string;
+};
+
+const ControlHeader: FC<ControlHeaderProps> = ({
+  name,
+  label,
+  description,
+  validationErrors = [],
+  renderTrigger = false,
+  rightNode,
+  leftNode,
+  onClick,
+  hovered = false,
+  tooltipOnClick = () => {},
+  warning,
+  danger,
+}) => {
+  const { gridUnit, colors } = useTheme();
+
+  const renderOptionalIcons = () => {
+    if (!hovered) {
+      return null;
+    }
+
+    return (
+      <span
+        css={() => css`
+          position: absolute;
+          top: 50%;
+          right: 0;
+          padding-left: ${gridUnit}px;
+          transform: translate(100%, -50%);
+          white-space: nowrap;
+        `}
+      >
+        {description && (
+          <span>
+            <InfoTooltipWithTrigger
+              label={t('description')}
+              tooltip={description}
+              placement="top"
+              onClick={tooltipOnClick}
+            />{' '}
+          </span>
+        )}
+        {renderTrigger && (
+          <span>
+            <InfoTooltipWithTrigger
+              label={t('bolt')}
+              tooltip={t('Changing this control takes effect instantly')}
+              placement="top"
+              icon="bolt"
+            />{' '}
+          </span>
+        )}
+      </span>
+    );
+  };
+  if (!label) {
+    return null;
+  }

Review comment:
       maybe this should be before the `renderOptionalIcons` function def so that we can return early?




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