Skip to content

Commit

Permalink
chore: type welcome (apache#10317)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Ritter authored and auxten committed Nov 20, 2020
1 parent 7876fbd commit ee2980e
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 57 deletions.
29 changes: 29 additions & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@
"@superset-ui/validator": "^0.14.9",
"@types/classnames": "^2.2.9",
"@types/enzyme": "^3.10.5",
"@types/fetch-mock": "^7.3.2",
"@types/react-bootstrap": "^0.32.21",
"@types/react-gravatar": "^2.6.8",
"@types/react-json-tree": "^0.6.11",
"@types/react-router-dom": "^5.1.5",
"@types/react-select": "^3.0.12",
"@types/react-virtualized": "^9.21.10",
"@types/react-window": "^1.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('DashboardTable', () => {
expect(fetchMock.calls(dashboardsEndpoint)).toHaveLength(1);
// there's a delay between response and updating state, so manually set it
// rather than adding a timeout which could introduce flakiness
wrapper.setState({ dashaboards: mockDashboards });
wrapper.setState({ dashboards: mockDashboards });
expect(wrapper.find(ListView)).toHaveLength(1);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ import { shallow } from 'enzyme';
import Welcome from 'src/welcome/Welcome';

describe('Welcome', () => {
const mockedProps = {};
const mockedProps = {
user: {
username: 'alpha',
firstName: 'alpha',
lastName: 'alpha',
createdOn: '2016-11-11T12:34:17',
userId: 5,
email: 'alpha@alpha.com',
isActive: true,
},
};
it('is valid', () => {
expect(React.isValidElement(<Welcome {...mockedProps} />)).toBe(true);
});
it('renders 4 Tab, Panel, and Row components', () => {
it('renders 3 Tab, Panel, and Row components', () => {
const wrapper = shallow(<Welcome {...mockedProps} />);
expect(wrapper.find(Tab)).toHaveLength(3);
expect(wrapper.find(Panel)).toHaveLength(3);
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/profile/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import UserInfo from './UserInfo';
import Security from './Security';
import RecentActivity from './RecentActivity';
import CreatedContent from './CreatedContent';
import { User } from '../types';
import { UserWithPermissionsAndRoles } from '../../types/bootstrapTypes';

interface AppProps {
user: User;
user: UserWithPermissionsAndRoles;
}

export default function App({ user }: AppProps) {
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/profile/components/CreatedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import moment from 'moment';
import { t } from '@superset-ui/translation';

import TableLoader from '../../components/TableLoader';
import { User, Dashboard, Slice } from '../types';
import { Slice } from '../types';
import { User, Dashboard } from '../../types/bootstrapTypes';

interface CreatedContentProps {
user: User;
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/profile/components/Favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import moment from 'moment';
import { t } from '@superset-ui/translation';

import TableLoader from '../../components/TableLoader';
import { User, Dashboard, Slice } from '../types';
import { Slice } from '../types';
import { User, Dashboard } from '../../types/bootstrapTypes';

interface FavoritesProps {
user: User;
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/profile/components/RecentActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import React from 'react';
import moment from 'moment';

import TableLoader from '../../components/TableLoader';
import { User, Activity } from '../types';
import { Activity } from '../types';
import { User } from '../../types/bootstrapTypes';

interface RecentActivityProps {
user: User;
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/profile/components/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import React from 'react';
import { Badge, Label } from 'react-bootstrap';
import { t } from '@superset-ui/translation';
import { User } from '../types';
import { UserWithPermissionsAndRoles } from '../../types/bootstrapTypes';

interface SecurityProps {
user: User;
user: UserWithPermissionsAndRoles;
}

export default function Security({ user }: SecurityProps) {
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/profile/components/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import Gravatar from 'react-gravatar';
import moment from 'moment';
import { Panel } from 'react-bootstrap';
import { t } from '@superset-ui/translation';
import { User } from '../types';
import { UserWithPermissionsAndRoles } from '../../types/bootstrapTypes';

interface UserInfoProps {
user: User;
user: UserWithPermissionsAndRoles;
}

export default function UserInfo({ user }: UserInfoProps) {
Expand Down
24 changes: 0 additions & 24 deletions superset-frontend/src/profile/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
export type User = {
createdOn: string;
email: string;
firstName: string;
isActive: boolean;
lastName: string;
permissions: {
database_access?: string[];
datasource_access?: string[];
};
roles: Record<string, any>;
userId: number;
username: string;
};

export type Slice = {
dttm: number;
id: number;
Expand All @@ -41,15 +26,6 @@ export type Slice = {
viz_type: string;
};

export type Dashboard = {
dttm: number;
id: number;
url: string;
title: string;
creator?: string;
creator_url?: string;
};

export type Activity = {
action: string;
item_title: string;
Expand Down
44 changes: 44 additions & 0 deletions superset-frontend/src/types/bootstrapTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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.
*/
export type User = {
createdOn: string;
email: string;
firstName: string;
isActive: boolean;
lastName: string;
userId: number;
username: string;
};

export interface UserWithPermissionsAndRoles extends User {
permissions: {
database_access?: string[];
datasource_access?: string[];
};
roles: Record<string, string[][]>;
}

export type Dashboard = {
dttm: number;
id: number;
url: string;
title: string;
creator?: string;
creator_url?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ setupApp();
setupPlugins();

const container = document.getElementById('app');
const bootstrap = JSON.parse(container.getAttribute('data-bootstrap'));
const bootstrap = JSON.parse(container?.getAttribute('data-bootstrap') ?? '{}');
const user = { ...bootstrap.user };
const menu = { ...bootstrap.common.menu_data };
const common = { ...bootstrap.common };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,45 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { t } from '@superset-ui/translation';
import { SupersetClient } from '@superset-ui/connection';
import moment from 'moment';
import { debounce } from 'lodash';
import ListView from 'src/components/ListView/ListView';
import withToasts from 'src/messageToasts/enhancers/withToasts';
import { Dashboard } from 'src/types/bootstrapTypes';
import { FetchDataConfig } from 'src/components/ListView/types';

const PAGE_SIZE = 25;

class DashboardTable extends React.PureComponent {
static propTypes = {
addDangerToast: PropTypes.func.isRequired,
search: PropTypes.string,
};
interface DashboardTableProps {
addDangerToast: (message: string) => void;
search?: string;
}

interface DashboardTableState {
dashboards: Dashboard[];
dashboard_count: number;
loading: boolean;
}

class DashboardTable extends React.PureComponent<
DashboardTableProps,
DashboardTableState
> {
state = {
dashboards: [],
dashboard_count: 0,
loading: false,
};

componentDidUpdate(prevProps) {
componentDidUpdate(prevProps: DashboardTableProps) {
if (prevProps.search !== this.props.search) {
this.fetchDataDebounced({
pageSize: PAGE_SIZE,
pageIndex: 0,
sortBy: this.initialSort,
filters: {},
filters: [],
});
}
}
Expand All @@ -58,6 +68,13 @@ class DashboardTable extends React.PureComponent {
row: {
original: { url, dashboard_title: dashboardTitle },
},
}: {
row: {
original: {
url: string;
dashboard_title: string;
};
};
}) => <a href={url}>{dashboardTitle}</a>,
},
{
Expand All @@ -67,6 +84,13 @@ class DashboardTable extends React.PureComponent {
row: {
original: { changed_by_name: changedByName, changedByUrl },
},
}: {
row: {
original: {
changed_by_name: string;
changedByUrl: string;
};
};
}) => <a href={changedByUrl}>{changedByName}</a>,
},
{
Expand All @@ -76,13 +100,19 @@ class DashboardTable extends React.PureComponent {
row: {
original: { changed_on: changedOn },
},
}: {
row: {
original: {
changed_on: string;
};
};
}) => <span className="no-wrap">{moment(changedOn).fromNow()}</span>,
},
];

initialSort = [{ id: 'changed_on', desc: true }];

fetchData = ({ pageIndex, pageSize, sortBy, filters }) => {
fetchData = ({ pageIndex, pageSize, sortBy, filters }: FetchDataConfig) => {
this.setState({ loading: true });
const filterExps = Object.keys(filters)
.map(fk => ({
Expand Down
Loading

0 comments on commit ee2980e

Please sign in to comment.