Skip to content

Commit

Permalink
fix(datasets): sort and humanized modified by (apache#10380)
Browse files Browse the repository at this point in the history
* fix(datasets): sort and humanized modified by

* size xl on changed_on_delta_humanized

* Fix, tests

* Fix, tests

* Fix, frontend tests

* remove debug flag
  • Loading branch information
dpgaspar authored and auxten committed Nov 20, 2020
1 parent 496a523 commit f4ebcda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`,
);
});

Expand Down
33 changes: 8 additions & 25 deletions superset-frontend/src/views/datasetList/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
*/
import { SupersetClient } from '@superset-ui/connection';
import { t } from '@superset-ui/translation';
import moment from 'moment';
import React, {
FunctionComponent,
useCallback,
useEffect,
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';
Expand Down Expand Up @@ -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<Owner>;
Expand Down Expand Up @@ -195,7 +193,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
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}`);
Expand Down Expand Up @@ -277,30 +275,16 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
{
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 (
<TooltipWrapper
label="last-modified"
tooltip={time}
placement="right"
>
<span>{date}</span>
</TooltipWrapper>
);
},
Header: t('Last Modified'),
accessor: 'changed_on',
}: any) => <span className="no-wrap">{changedOn}</span>,
Header: t('Modified'),
accessor: 'changed_on_delta_humanized',
size: 'xl',
},
{
Expand All @@ -310,8 +294,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
},
}: any) => changedByName,
Header: t('Modified By'),
accessor: 'changed_by_fk',
disableSortBy: true,
accessor: 'changed_by.first_name',
size: 'xl',
},
{
Expand Down
12 changes: 10 additions & 2 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/datasets/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_delta_humanized",
"changed_on_utc",
"database_id",
"database_name",
"default_endpoint",
Expand Down

0 comments on commit f4ebcda

Please sign in to comment.