From f86d60b1df48a5a866e18a0c336f6132f2f1fe62 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Tue, 21 Jul 2020 18:24:04 +0100 Subject: [PATCH 1/6] fix(datasets): sort and humanized modified by --- .../src/views/datasetList/DatasetList.tsx | 34 +++++-------------- superset/datasets/api.py | 12 +++++-- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/superset-frontend/src/views/datasetList/DatasetList.tsx b/superset-frontend/src/views/datasetList/DatasetList.tsx index a144c2004b076..6ae6b8523fb91 100644 --- a/superset-frontend/src/views/datasetList/DatasetList.tsx +++ b/superset-frontend/src/views/datasetList/DatasetList.tsx @@ -18,7 +18,6 @@ */ import { SupersetClient } from '@superset-ui/connection'; import { t } from '@superset-ui/translation'; -import moment from 'moment'; import React, { FunctionComponent, useCallback, @@ -26,7 +25,6 @@ import React, { useState, } from 'react'; import rison from 'rison'; -import { SHORT_DATE, SHORT_TIME } from 'src/utils/common'; import ConfirmStatusChange from 'src/components/ConfirmStatusChange'; import DeleteModal from 'src/components/DeleteModal'; import ListView, { ListViewProps } from 'src/components/ListView/ListView'; @@ -55,8 +53,8 @@ type Dataset = { changed_by_name: string; changed_by_url: string; changed_by: string; - changed_on: string; - databse_name: string; + changed_on_delta_humanized: string; + database_name: string; explore_url: string; id: number; owners: Array; @@ -195,7 +193,7 @@ const DatasetList: FunctionComponent = ({ const canDelete = hasPerm('can_delete'); const canCreate = hasPerm('can_add'); - const initialSort = [{ id: 'changed_on', desc: true }]; + const initialSort = [{ id: 'changed_on_delta_humanized', desc: true }]; const handleDatasetEdit = ({ id }: { id: number }) => { window.location.assign(`/tablemodelview/edit/${id}`); @@ -277,31 +275,16 @@ const DatasetList: FunctionComponent = ({ { Header: t('Schema'), accessor: 'schema', - disableSortBy: true, size: 'lg', }, { Cell: ({ row: { - original: { changed_on: changedOn }, + original: { changed_on_delta_humanized: changedOn }, }, - }: any) => { - const momentTime = moment(changedOn); - const time = momentTime.format(SHORT_DATE); - const date = momentTime.format(SHORT_TIME); - return ( - - {date} - - ); - }, - Header: t('Last Modified'), - accessor: 'changed_on', - size: 'xl', + }: any) => {changedOn}, + Header: t('Modified'), + accessor: 'changed_on_delta_humanized', }, { Cell: ({ @@ -310,8 +293,7 @@ const DatasetList: FunctionComponent = ({ }, }: any) => changedByName, Header: t('Modified By'), - accessor: 'changed_by_fk', - disableSortBy: true, + accessor: 'changed_by.first_name', size: 'xl', }, { diff --git a/superset/datasets/api.py b/superset/datasets/api.py index c6ed752b02b5a..34d08d5fe77dc 100644 --- a/superset/datasets/api.py +++ b/superset/datasets/api.py @@ -74,11 +74,12 @@ class DatasetRestApi(BaseSupersetModelRestApi): "id", "database_id", "database_name", - "changed_by_fk", "changed_by_name", "changed_by_url", + "changed_by.first_name", "changed_by.username", - "changed_on", + "changed_on_utc", + "changed_on_delta_humanized", "default_endpoint", "explore_url", "kind", @@ -90,6 +91,13 @@ class DatasetRestApi(BaseSupersetModelRestApi): "sql", "table_name", ] + list_select_columns = list_columns + ["changed_on", "changed_by_fk"] + order_columns = [ + "table_name", + "schema", + "changed_by.first_name", + "changed_on_delta_humanized", + ] show_columns = [ "database.database_name", "database.id", From 99982079c44072c8c759a07eb935d1b3aa797e0d Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Tue, 21 Jul 2020 21:20:13 +0100 Subject: [PATCH 2/6] size xl on changed_on_delta_humanized --- superset-frontend/src/views/datasetList/DatasetList.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/superset-frontend/src/views/datasetList/DatasetList.tsx b/superset-frontend/src/views/datasetList/DatasetList.tsx index 6ae6b8523fb91..aebd465aaf2e5 100644 --- a/superset-frontend/src/views/datasetList/DatasetList.tsx +++ b/superset-frontend/src/views/datasetList/DatasetList.tsx @@ -285,6 +285,7 @@ const DatasetList: FunctionComponent = ({ }: any) => {changedOn}, Header: t('Modified'), accessor: 'changed_on_delta_humanized', + size: 'xl', }, { Cell: ({ From 4ecb16adedb6907cc0f440a671792e9684f8e458 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 22 Jul 2020 08:57:01 +0100 Subject: [PATCH 3/6] Fix, tests --- tests/datasets/api_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/datasets/api_tests.py b/tests/datasets/api_tests.py index bd634eaa18c73..6d3c94a98b686 100644 --- a/tests/datasets/api_tests.py +++ b/tests/datasets/api_tests.py @@ -88,10 +88,10 @@ def test_get_dataset_list(self): self.assertEqual(response["count"], 1) expected_columns = [ "changed_by", - "changed_by_fk", "changed_by_name", "changed_by_url", - "changed_on", + "changed_on_utc", + "changed_on_delta_humanized", "database_id", "database_name", "default_endpoint", From f92dd3c47b0fa7fb9a79c6047fd5a19f17274a76 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 22 Jul 2020 09:44:26 +0100 Subject: [PATCH 4/6] Fix, tests --- tests/datasets/api_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/datasets/api_tests.py b/tests/datasets/api_tests.py index 6d3c94a98b686..bf0342f89cd35 100644 --- a/tests/datasets/api_tests.py +++ b/tests/datasets/api_tests.py @@ -81,6 +81,7 @@ def test_get_dataset_list(self): {"col": "table_name", "opr": "eq", "value": f"birth_names"}, ] } + self.maxDiff = None uri = f"api/v1/dataset/?q={prison.dumps(arguments)}" rv = self.get_assert_metric(uri, "get_list") self.assertEqual(rv.status_code, 200) @@ -90,8 +91,8 @@ def test_get_dataset_list(self): "changed_by", "changed_by_name", "changed_by_url", - "changed_on_utc", "changed_on_delta_humanized", + "changed_on_utc", "database_id", "database_name", "default_endpoint", From d241819fb6579d09adb09bcc589bb9ab33faf263 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 22 Jul 2020 10:11:34 +0100 Subject: [PATCH 5/6] Fix, frontend tests --- .../spec/javascripts/views/datasetList/DatasetList_spec.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/spec/javascripts/views/datasetList/DatasetList_spec.jsx b/superset-frontend/spec/javascripts/views/datasetList/DatasetList_spec.jsx index 1ceb5272d7ec5..58b5ef0f574c6 100644 --- a/superset-frontend/spec/javascripts/views/datasetList/DatasetList_spec.jsx +++ b/superset-frontend/spec/javascripts/views/datasetList/DatasetList_spec.jsx @@ -114,7 +114,7 @@ describe('DatasetList', () => { const callsD = fetchMock.calls(/dataset\/\?q/); expect(callsD).toHaveLength(1); expect(callsD[0][0]).toMatchInlineSnapshot( - `"http://localhost/api/v1/dataset/?q=(order_column:changed_on,order_direction:desc,page:0,page_size:25)"`, + `"http://localhost/api/v1/dataset/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`, ); }); From 049a875e105479b4852ad5a5bea46cf386feadd5 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 22 Jul 2020 11:00:28 +0100 Subject: [PATCH 6/6] remove debug flag --- tests/datasets/api_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/datasets/api_tests.py b/tests/datasets/api_tests.py index bf0342f89cd35..d5bf9b043e480 100644 --- a/tests/datasets/api_tests.py +++ b/tests/datasets/api_tests.py @@ -81,7 +81,6 @@ def test_get_dataset_list(self): {"col": "table_name", "opr": "eq", "value": f"birth_names"}, ] } - self.maxDiff = None uri = f"api/v1/dataset/?q={prison.dumps(arguments)}" rv = self.get_assert_metric(uri, "get_list") self.assertEqual(rv.status_code, 200)