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



##########
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:
       Let me look into simplifying this a bit more. I might pull some things 
out into smaller, more reusable components. It's a bit tricky, because 
depending on where the error is being rendered, it's supposed to look different 
(sometimes using a modal, sometimes expanding inline)




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