ktmud commented on a change in pull request #10274:
URL: 
https://github.com/apache/incubator-superset/pull/10274#discussion_r452424291



##########
File path: superset-frontend/src/components/ErrorMessage/TimeoutErrorMessage.tsx
##########
@@ -0,0 +1,234 @@
+/**
+ * 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, { useState } from 'react';
+import { Modal } from 'react-bootstrap';
+import { styled, supersetTheme } from '@superset-ui/style';
+import { t, tn } from '@superset-ui/translation';
+
+import { noOp } from 'src/utils/common';
+import Icon from '../Icon';
+import Button from '../../views/datasetList/Button';
+import { SupersetError } from './types';
+import {
+  ERROR_DATASOURCE_TOO_LARGE,
+  ERROR_DATASOURCE_UNDER_LOAD,
+} from './constants';
+import CopyToClipboard from '../CopyToClipboard';
+
+const ErrorAlert = styled.div`
+  align-items: center;
+  background-color: ${({ theme }) => theme.colors.error.light2};
+  border-radius: ${({ theme }) => theme.borderRadius}px;
+  border: 1px solid ${({ theme }) => theme.colors.error.base};
+  color: ${({ theme }) => theme.colors.error.dark2};
+  padding: ${({ theme }) => 2 * theme.gridUnit}px;
+  width: 100%;
+
+  .topRow {
+    display: flex;
+    justify-content: space-between;
+  }
+
+  .errorBody {
+    padding-top: ${({ theme }) => theme.gridUnit}px;
+    padding-left: ${({ theme }) => 8 * theme.gridUnit}px;
+  }
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .link {
+    color: ${({ theme }) => theme.colors.error.dark2};
+    text-decoration: underline;
+  }
+`;
+
+const ErrorModal = styled(Modal)`
+  color: ${({ theme }) => theme.colors.error.dark2};
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .header {
+    align-items: center;
+    background-color: ${({ theme }) => theme.colors.error.light2};
+    display: flex;
+    justify-content: space-between;
+    font-size: ${({ theme }) => theme.typography.sizes.l}px;
+
+    // Remove clearfix hack as Superset is only used on modern browsers
+    ::before,
+    ::after {
+      content: unset;
+    }
+  }
+`;
+
+const LeftSideContent = styled.div`
+  align-items: center;
+  display: flex;
+`;
+
+interface TimeoutErrorExtra {
+  location: 'chart' | 'dashboard' | 'sqllab';
+  owners?: string[];
+  timeout: number;
+}
+
+function TimeoutErrorMessage({
+  error,
+}: {
+  error: SupersetError<TimeoutErrorExtra>;
+}) {
+  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [isMessageExpanded, setIsMessageExpanded] = useState(false);
+  const { extra } = error;
+
+  const title = ['chart', 'dashboard'].includes(extra.location)
+    ? tn(
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      )
+    : tn(
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      );
+
+  const message = (
+    <>
+      <p>
+        {t('This may be triggered by:')}
+        <br />
+        {ERROR_DATASOURCE_TOO_LARGE.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_TOO_LARGE.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+        <br />
+        {ERROR_DATASOURCE_UNDER_LOAD.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_UNDER_LOAD.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+      </p>
+      {['chart', 'dashboard'].includes(extra.location) && extra.owners && (
+        <>
+          <br />
+          <p>{t('Please reach out to the Chart Owner(s) for assistance.')}</p>
+          <p>{t('Chart Owner(s): %s', extra.owners.join(', '))}</p>
+        </>
+      )}
+    </>
+  );
+
+  const copyText = `${title}
+${t('This may be triggered by:')}
+${ERROR_DATASOURCE_TOO_LARGE.message}
+${ERROR_DATASOURCE_UNDER_LOAD.message}`;
+
+  return (
+    <ErrorAlert>
+      <div className="topRow">
+        <LeftSideContent>

Review comment:
       Can this be a simple css class like `.topRow`? I feel we shouldn't 
create new styled components unless they will be reused across components or 
need advanced interactions.
   
   

##########
File path: superset-frontend/src/components/Icon.tsx
##########
@@ -49,7 +52,9 @@ type Icon =
   | 'trash'
   | 'warning';
 
-const iconsRegistry: { [key in Icon]: React.ComponentType } = {
+const iconsRegistry: {
+  [key in Icon]: React.ComponentType<SVGProps<SVGSVGElement>>;
+} = {

Review comment:
       
   ```ts
   type IconName =
     | 'cancel-x'
     | 'checkbox-half'
     ...
   
   const iconsRegistry: Record<IconName, 
React.ComponentType<SVGProps<SVGSVGElement>>>
   ```

##########
File path: superset-frontend/src/components/ErrorMessage/constants.ts
##########
@@ -0,0 +1,31 @@
+/**
+ * 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 { t } from '@superset-ui/translation';
+
+const ROOT_ERROR_REFERENCE_URL =
+  'https://superset.apache.org/error_code_reference.html#';
+
+export const ERROR_DATASOURCE_TOO_LARGE = {
+  message: t('Error 1000 - The datasource is too large to query.'),
+  link: `${ROOT_ERROR_REFERENCE_URL}error-1000`,
+};

Review comment:
       Should this be more structural? I'm imagining a `errors.json` somewhere 
that could potentially be shared by both the frontend and doc generator:
   
   ```
   {
     "1001": {
       "title": "The database is too large to query",
       "description": "It's likely your datasource has grown too large to run 
the current 
       query, and is timing out. You can resolve this by reducing the size of 
your datasource or by modifying your query to only process a subset of your 
data."
     },
     "2001": {
       ....
     }
   }
   ```

##########
File path: superset/utils/core.py
##########
@@ -617,7 +618,14 @@ def handle_timeout(  # pylint: disable=unused-argument
         self, signum: int, frame: Any
     ) -> None:
         logger.error("Process timed out")
-        raise SupersetTimeoutException(self.error_message)
+        raise SupersetTimeoutException(
+            SupersetError(
+                error_type=SupersetErrorType.BACKEND_TIMEOUT_ERROR,
+                message=self.error_message,
+                level=ErrorLevel.ERROR,
+                extra={"timeout": self.seconds,},
+            )

Review comment:
       Using two classes to initialize things is kind of weird to me. Can you 
pass the extras as arguments to `SupersetTimeoutException` and let 
`SupersetTimeoutException` to enforce the structure for `SupersetError`?

##########
File path: superset-frontend/src/components/ErrorMessage/TimeoutErrorMessage.tsx
##########
@@ -0,0 +1,234 @@
+/**
+ * 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, { useState } from 'react';
+import { Modal } from 'react-bootstrap';
+import { styled, supersetTheme } from '@superset-ui/style';
+import { t, tn } from '@superset-ui/translation';
+
+import { noOp } from 'src/utils/common';
+import Icon from '../Icon';
+import Button from '../../views/datasetList/Button';
+import { SupersetError } from './types';
+import {
+  ERROR_DATASOURCE_TOO_LARGE,
+  ERROR_DATASOURCE_UNDER_LOAD,
+} from './constants';
+import CopyToClipboard from '../CopyToClipboard';
+
+const ErrorAlert = styled.div`
+  align-items: center;
+  background-color: ${({ theme }) => theme.colors.error.light2};
+  border-radius: ${({ theme }) => theme.borderRadius}px;
+  border: 1px solid ${({ theme }) => theme.colors.error.base};
+  color: ${({ theme }) => theme.colors.error.dark2};
+  padding: ${({ theme }) => 2 * theme.gridUnit}px;
+  width: 100%;
+
+  .topRow {
+    display: flex;
+    justify-content: space-between;
+  }
+
+  .errorBody {
+    padding-top: ${({ theme }) => theme.gridUnit}px;
+    padding-left: ${({ theme }) => 8 * theme.gridUnit}px;
+  }
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .link {
+    color: ${({ theme }) => theme.colors.error.dark2};
+    text-decoration: underline;
+  }
+`;
+
+const ErrorModal = styled(Modal)`
+  color: ${({ theme }) => theme.colors.error.dark2};
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .header {
+    align-items: center;
+    background-color: ${({ theme }) => theme.colors.error.light2};
+    display: flex;
+    justify-content: space-between;
+    font-size: ${({ theme }) => theme.typography.sizes.l}px;
+
+    // Remove clearfix hack as Superset is only used on modern browsers
+    ::before,
+    ::after {
+      content: unset;
+    }
+  }
+`;
+
+const LeftSideContent = styled.div`
+  align-items: center;
+  display: flex;
+`;
+
+interface TimeoutErrorExtra {
+  location: 'chart' | 'dashboard' | 'sqllab';
+  owners?: string[];
+  timeout: number;
+}
+
+function TimeoutErrorMessage({
+  error,
+}: {
+  error: SupersetError<TimeoutErrorExtra>;
+}) {
+  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [isMessageExpanded, setIsMessageExpanded] = useState(false);
+  const { extra } = error;
+
+  const title = ['chart', 'dashboard'].includes(extra.location)
+    ? tn(
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      )
+    : tn(
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      );
+
+  const message = (
+    <>
+      <p>
+        {t('This may be triggered by:')}
+        <br />
+        {ERROR_DATASOURCE_TOO_LARGE.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_TOO_LARGE.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+        <br />
+        {ERROR_DATASOURCE_UNDER_LOAD.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_UNDER_LOAD.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+      </p>
+      {['chart', 'dashboard'].includes(extra.location) && extra.owners && (
+        <>
+          <br />
+          <p>{t('Please reach out to the Chart Owner(s) for assistance.')}</p>
+          <p>{t('Chart Owner(s): %s', extra.owners.join(', '))}</p>
+        </>
+      )}
+    </>
+  );
+
+  const copyText = `${title}
+${t('This may be triggered by:')}
+${ERROR_DATASOURCE_TOO_LARGE.message}
+${ERROR_DATASOURCE_UNDER_LOAD.message}`;
+
+  return (
+    <ErrorAlert>
+      <div className="topRow">
+        <LeftSideContent>
+          <Icon
+            className="icon"
+            name="error"
+            color={supersetTheme.colors.error.base}
+          />
+          <strong>{t('Timeout Error')}</strong>
+        </LeftSideContent>
+        {extra.location === 'dashboard' && (
+          <>
+            <a className="link" onClick={() => setIsModalOpen(true)}>
+              {t('See More')}
+            </a>
+            <ErrorModal show={isModalOpen} onHide={() => 
setIsModalOpen(false)}>
+              <Modal.Header className="header">
+                <LeftSideContent>
+                  <Icon
+                    className="icon"
+                    name="error"
+                    color={supersetTheme.colors.error.base}
+                  />
+                  <div className="title">{t('Timeout Error')}</div>
+                </LeftSideContent>
+                <span
+                  role="button"
+                  tabIndex={0}
+                  onClick={() => setIsModalOpen(false)}
+                >
+                  <Icon name="close" />
+                </span>
+              </Modal.Header>
+              <Modal.Body>
+                <p>{title}</p>
+                <br />
+                {message}
+              </Modal.Body>
+              <Modal.Footer>
+                <CopyToClipboard
+                  text={copyText}
+                  shouldShowText={false}
+                  wrapped={false}
+                  copyNode={<Button onClick={noOp}>{t('Copy 
Message')}</Button>}
+                />
+                <Button bsStyle="primary" onClick={() => 
setIsModalOpen(false)}>
+                  {t('Close')}
+                </Button>
+              </Modal.Footer>
+            </ErrorModal>
+          </>
+        )}
+      </div>
+      {['chart', 'sqllab'].includes(extra.location) && (
+        <div className="errorBody">
+          <p>{title}</p>
+          {!isMessageExpanded && (
+            <a className="link" onClick={() => setIsMessageExpanded(true)}>
+              {t('See More')}
+            </a>
+          )}
+          {isMessageExpanded && (
+            <>
+              <br />
+              {message}
+              <a className="link" onClick={() => setIsMessageExpanded(false)}>
+                {t('See Less')}
+              </a>
+            </>
+          )}
+        </div>
+      )}

Review comment:
       Instead of two big code chunks, how about creating two separate 
subcomponent `SimpleTimeoutErrorMessage` and `DetailedTimeoutErrorMessage`?

##########
File path: superset-frontend/src/components/ErrorMessage/TimeoutErrorMessage.tsx
##########
@@ -0,0 +1,234 @@
+/**
+ * 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, { useState } from 'react';
+import { Modal } from 'react-bootstrap';
+import { styled, supersetTheme } from '@superset-ui/style';
+import { t, tn } from '@superset-ui/translation';
+
+import { noOp } from 'src/utils/common';
+import Icon from '../Icon';
+import Button from '../../views/datasetList/Button';
+import { SupersetError } from './types';
+import {
+  ERROR_DATASOURCE_TOO_LARGE,
+  ERROR_DATASOURCE_UNDER_LOAD,
+} from './constants';
+import CopyToClipboard from '../CopyToClipboard';
+
+const ErrorAlert = styled.div`
+  align-items: center;
+  background-color: ${({ theme }) => theme.colors.error.light2};
+  border-radius: ${({ theme }) => theme.borderRadius}px;
+  border: 1px solid ${({ theme }) => theme.colors.error.base};
+  color: ${({ theme }) => theme.colors.error.dark2};
+  padding: ${({ theme }) => 2 * theme.gridUnit}px;
+  width: 100%;
+
+  .topRow {
+    display: flex;
+    justify-content: space-between;
+  }
+
+  .errorBody {
+    padding-top: ${({ theme }) => theme.gridUnit}px;
+    padding-left: ${({ theme }) => 8 * theme.gridUnit}px;
+  }
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .link {
+    color: ${({ theme }) => theme.colors.error.dark2};
+    text-decoration: underline;
+  }
+`;
+
+const ErrorModal = styled(Modal)`
+  color: ${({ theme }) => theme.colors.error.dark2};
+
+  .icon {
+    margin-right: ${({ theme }) => 2 * theme.gridUnit}px;
+  }
+
+  .header {
+    align-items: center;
+    background-color: ${({ theme }) => theme.colors.error.light2};
+    display: flex;
+    justify-content: space-between;
+    font-size: ${({ theme }) => theme.typography.sizes.l}px;
+
+    // Remove clearfix hack as Superset is only used on modern browsers
+    ::before,
+    ::after {
+      content: unset;
+    }
+  }
+`;
+
+const LeftSideContent = styled.div`
+  align-items: center;
+  display: flex;
+`;
+
+interface TimeoutErrorExtra {
+  location: 'chart' | 'dashboard' | 'sqllab';
+  owners?: string[];
+  timeout: number;
+}
+
+function TimeoutErrorMessage({
+  error,
+}: {
+  error: SupersetError<TimeoutErrorExtra>;
+}) {
+  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [isMessageExpanded, setIsMessageExpanded] = useState(false);
+  const { extra } = error;
+
+  const title = ['chart', 'dashboard'].includes(extra.location)
+    ? tn(
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading this visualization. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      )
+    : tn(
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s second.',
+        'We’re having trouble loading these results. Queries are set to 
timeout after %s seconds.',
+        extra.timeout,
+        extra.timeout,
+      );
+
+  const message = (
+    <>
+      <p>
+        {t('This may be triggered by:')}
+        <br />
+        {ERROR_DATASOURCE_TOO_LARGE.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_TOO_LARGE.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+        <br />
+        {ERROR_DATASOURCE_UNDER_LOAD.message}{' '}
+        <a
+          href={ERROR_DATASOURCE_UNDER_LOAD.link}
+          rel="noopener noreferrer"
+          target="_blank"
+        >
+          <i className="fa fa-external-link" />
+        </a>
+      </p>
+      {['chart', 'dashboard'].includes(extra.location) && extra.owners && (
+        <>
+          <br />
+          <p>{t('Please reach out to the Chart Owner(s) for assistance.')}</p>

Review comment:
       nit: why is "Chart Owners" in title case?




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to