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/05/26 09:26:36 UTC

[GitHub] [superset] villebro commented on a diff in pull request #20109: refactor: decouple DataTablesPane

villebro commented on code in PR #20109:
URL: https://github.com/apache/superset/pull/20109#discussion_r882481533


##########
superset-frontend/src/explore/components/DataTablesPane/components/ResultsPane.tsx:
##########
@@ -0,0 +1,173 @@
+/**
+ * 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, useEffect } from 'react';
+import { ensureIsArray, GenericDataType, styled, t } from '@superset-ui/core';
+import Loading from 'src/components/Loading';
+import { EmptyStateMedium } from 'src/components/EmptyState';
+import TableView, { EmptyWrapperType } from 'src/components/TableView';
+import {
+  useFilteredTableData,
+  useTableColumns,
+} from 'src/explore/components/DataTableControl';
+import { useOriginalFormattedTimeColumns } from 'src/explore/components/useOriginalFormattedTimeColumns';
+import { getChartDataRequest } from 'src/components/Chart/chartAction';
+import { getClientErrorObject } from 'src/utils/getClientErrorObject';
+import { TableControls } from './DataTableControls';
+import { ResultsPaneProps } from '../types';
+
+const Error = styled.pre`
+  margin-top: ${({ theme }) => `${theme.gridUnit * 4}px`};
+`;
+
+const cache = new WeakSet();
+
+export const ResultsPane = ({
+  isRequest,
+  queryFormData,
+  queryForce,
+  ownState,
+  errorMessage,
+  actions,
+  dataSize = 50,
+}: ResultsPaneProps) => {
+  const [filterText, setFilterText] = useState('');
+  const [data, setData] = useState<Record<string, any>[][]>([]);
+  const [colnames, setColnames] = useState<string[]>([]);
+  const [coltypes, setColtypes] = useState<GenericDataType[]>([]);
+  const [isLoading, setIsLoading] = useState<boolean>(false);
+  const [responseError, setResponseError] = useState<string>('');
+
+  useEffect(() => {
+    // it's an invalid formData when gets a errorMessage
+    if (errorMessage) return;
+    if (isRequest && !cache.has(queryFormData)) {
+      setIsLoading(true);
+      getChartDataRequest({
+        formData: queryFormData,
+        force: queryForce,
+        resultFormat: 'json',
+        resultType: 'results',
+        ownState,
+      })
+        .then(({ json }) => {
+          const { colnames, coltypes } = json.result[0];
+          // Only displaying the first query is currently supported

Review Comment:
   Idea for follow-up: Now it should be fairly simple to add support for displaying the other queries data, too. We could have a dropdown next to the search field where you could choose the query if there are more than one available.



##########
superset-frontend/src/explore/components/DataTablesPane/DataTablesPane.tsx:
##########
@@ -0,0 +1,214 @@
+/**
+ * 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, {
+  useCallback,
+  useEffect,
+  useMemo,
+  useState,
+  MouseEvent,
+} from 'react';
+import { styled, t, useTheme } from '@superset-ui/core';
+import Icons from 'src/components/Icons';
+import Tabs from 'src/components/Tabs';
+import {
+  getItem,
+  setItem,
+  LocalStorageKeys,
+} from 'src/utils/localStorageHelpers';
+import { ResultsPane, SamplesPane, TableControlsWrapper } from './components';
+import { DataTablesPaneProps } from './types';
+
+enum ResultTypes {
+  results = 'results',
+  samples = 'samples',

Review Comment:
   nit, I believe this is the convention:
   ```suggestion
     Results = 'results',
     Samples = 'samples',
   ```



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