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/09 17:32:19 UTC

[GitHub] [superset] lyndsiWilliams commented on a diff in pull request #22043: feat: add tabs to edit dataset page

lyndsiWilliams commented on code in PR #22043:
URL: https://github.com/apache/superset/pull/22043#discussion_r1018217888


##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/index.tsx:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 { styled, SupersetClient, t } from '@superset-ui/core';
+import React, { useEffect, useState } from 'react';
+import Badge from 'src/components/Badge';
+import Tabs from 'src/components/Tabs';
+
+const StyledTabs = styled(Tabs)`
+  margin-top: 34px;
+  padding-left: 16px;
+  // display: inline-block;
+  .ant-tabs-top > .ant-tabs-nav::before,
+  .ant-tabs-top > .ant-tabs-nav::before {
+    width: 200px;
+  }
+  .ant-tabs-nav-list > div:nth-last-child(2) {
+    // margin-right: 0px;
+  }
+`;
+
+const TabStyles = styled.div`
+  .ant-badge {
+    width: 32px;
+    margin-left: 10px;

Review Comment:
   ```suggestion
     margin-top: ${supersetTheme.gridUnit * 8.5}px;
     padding-left: ${supersetTheme.gridUnit * 4}px;
     
     .ant-tabs-top > .ant-tabs-nav::before,
     .ant-tabs-top > .ant-tabs-nav::before {
       width: ${supersetTheme.gridUnit * 50}px;
     }
   `;
   
   const TabStyles = styled.div`
     .ant-badge {
       width: ${supersetTheme.gridUnit * 8}px;
       margin-left: ${supersetTheme.gridUnit * 2.5}px;
   ```
   These values should use the superset theme's gridunit, you can import `supersetTheme` from core-ui to use in this spot. Are these commented bits supposed to be here? I removed them in the code suggestion just in case. Also, I noticed the specificity on lines 28 and 29 look identical (`.ant-tabs-top > .ant-tabs-nav::before`), does this need to be specified twice?



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/index.tsx:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 { styled, SupersetClient, t } from '@superset-ui/core';
+import React, { useEffect, useState } from 'react';
+import Badge from 'src/components/Badge';
+import Tabs from 'src/components/Tabs';
+
+const StyledTabs = styled(Tabs)`
+  margin-top: 34px;
+  padding-left: 16px;
+  // display: inline-block;
+  .ant-tabs-top > .ant-tabs-nav::before,
+  .ant-tabs-top > .ant-tabs-nav::before {
+    width: 200px;
+  }
+  .ant-tabs-nav-list > div:nth-last-child(2) {
+    // margin-right: 0px;
+  }
+`;
+
+const TabStyles = styled.div`
+  .ant-badge {
+    width: 32px;
+    margin-left: 10px;
+  }
+`;
+
+interface EditPageProps {
+  id: string;
+}
+
+const EditPage = ({ id }: EditPageProps) => {
+  const [usageCount, setUsageCount] = useState(0);
+  useEffect(() => {
+    // Todo: this useEffect should be used to call all count methods conncurently
+    // when we populate data for the new tabs. For right separating out this
+    // api call for building the usage page.
+    if (id)
+      SupersetClient.get({
+        endpoint: `/api/v1/dataset/${id}/related_objects`,
+      })
+        .then(({ json = {} }) => {
+          setUsageCount(json.charts.count);
+        })
+        .catch(err => console.log(err));
+  }, [id]);
+
+  const Tab = (
+    <TabStyles>
+      <span>{t('Usage')}</span>
+      <Badge count={usageCount + 1} />
+    </TabStyles>
+  );
+
+  return (
+    <>
+      <StyledTabs moreIcon={null} fullWidth={false}>
+        <Tabs.TabPane tab={t('Columns')} key="1" />
+        <Tabs.TabPane tab={t('Metrics')} key="2" />
+        <Tabs.TabPane tab={Tab} key="3">
+          <div>placeholder</div>

Review Comment:
   Is there text that's supposed to go in place of this placeholder?



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/EditDataset.test.tsx:
##########
@@ -0,0 +1,43 @@
+/**
+ * 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 fetchMock from 'fetch-mock';
+import { render, screen } from 'spec/helpers/testing-library';
+import EditDataset from './index';
+
+const DATASET_ENDPOINT = 'glob:*api/v1/dataset/1/related_objects';
+
+const mockedProps = {
+  id: '1',
+};
+
+fetchMock.get(DATASET_ENDPOINT, { charts: { results: [], count: 2 } });
+
+test('should render edit dataset view with tabs', () => {
+  fetchMock.calls(DATASET_ENDPOINT);
+  render(<EditDataset {...mockedProps} />);
+
+  const columnTab = screen.getByRole('tab', { name: /columns/i });

Review Comment:
   ```suggestion
   test('should render edit dataset view with tabs', async () => {
     fetchMock.calls(DATASET_ENDPOINT);
     render(<EditDataset {...mockedProps} />);
   
     const columnTab = await screen.findByRole('tab', { name: /columns/i });
   ```
   This test has an act error, if you change these lines it will remove the error.



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/index.tsx:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 { styled, SupersetClient, t } from '@superset-ui/core';
+import React, { useEffect, useState } from 'react';
+import Badge from 'src/components/Badge';
+import Tabs from 'src/components/Tabs';
+
+const StyledTabs = styled(Tabs)`
+  margin-top: 34px;
+  padding-left: 16px;
+  // display: inline-block;
+  .ant-tabs-top > .ant-tabs-nav::before,
+  .ant-tabs-top > .ant-tabs-nav::before {
+    width: 200px;
+  }
+  .ant-tabs-nav-list > div:nth-last-child(2) {
+    // margin-right: 0px;
+  }
+`;
+
+const TabStyles = styled.div`
+  .ant-badge {
+    width: 32px;
+    margin-left: 10px;
+  }
+`;
+
+interface EditPageProps {
+  id: string;
+}
+
+const EditPage = ({ id }: EditPageProps) => {
+  const [usageCount, setUsageCount] = useState(0);
+  useEffect(() => {
+    // Todo: this useEffect should be used to call all count methods conncurently
+    // when we populate data for the new tabs. For right separating out this
+    // api call for building the usage page.
+    if (id)
+      SupersetClient.get({
+        endpoint: `/api/v1/dataset/${id}/related_objects`,
+      })
+        .then(({ json = {} }) => {
+          setUsageCount(json.charts.count);
+        })
+        .catch(err => console.log(err));
+  }, [id]);
+
+  const Tab = (
+    <TabStyles>
+      <span>{t('Usage')}</span>
+      <Badge count={usageCount + 1} />
+    </TabStyles>
+  );
+
+  return (
+    <>
+      <StyledTabs moreIcon={null} fullWidth={false}>
+        <Tabs.TabPane tab={t('Columns')} key="1" />
+        <Tabs.TabPane tab={t('Metrics')} key="2" />
+        <Tabs.TabPane tab={Tab} key="3">
+          <div>placeholder</div>
+        </Tabs.TabPane>
+      </StyledTabs>
+    </>

Review Comment:
   ```suggestion
       <StyledTabs moreIcon={null} fullWidth={false}>
         <Tabs.TabPane tab={t('Columns')} key="1" />
         <Tabs.TabPane tab={t('Metrics')} key="2" />
         <Tabs.TabPane tab={Tab} key="3">
           <div>placeholder</div>
         </Tabs.TabPane>
       </StyledTabs>
   ```
   This fragment can be removed since it's all inside of one `StyledTabs` div.



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