;
+}
+
+export type Dashboard = {
+ dttm: number;
+ id: number;
+ url: string;
+ title: string;
+ creator?: string;
+ creator_url?: string;
+};
diff --git a/superset-frontend/src/welcome/App.jsx b/superset-frontend/src/welcome/App.tsx
similarity index 97%
rename from superset-frontend/src/welcome/App.jsx
rename to superset-frontend/src/welcome/App.tsx
index 42e3f29bb55..267dd5a0f67 100644
--- a/superset-frontend/src/welcome/App.jsx
+++ b/superset-frontend/src/welcome/App.tsx
@@ -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 };
diff --git a/superset-frontend/src/welcome/DashboardTable.jsx b/superset-frontend/src/welcome/DashboardTable.tsx
similarity index 80%
rename from superset-frontend/src/welcome/DashboardTable.jsx
rename to superset-frontend/src/welcome/DashboardTable.tsx
index 6399064b540..704cdc30208 100644
--- a/superset-frontend/src/welcome/DashboardTable.jsx
+++ b/superset-frontend/src/welcome/DashboardTable.tsx
@@ -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: [],
});
}
}
@@ -58,6 +68,13 @@ class DashboardTable extends React.PureComponent {
row: {
original: { url, dashboard_title: dashboardTitle },
},
+ }: {
+ row: {
+ original: {
+ url: string;
+ dashboard_title: string;
+ };
+ };
}) => {dashboardTitle},
},
{
@@ -67,6 +84,13 @@ class DashboardTable extends React.PureComponent {
row: {
original: { changed_by_name: changedByName, changedByUrl },
},
+ }: {
+ row: {
+ original: {
+ changed_by_name: string;
+ changedByUrl: string;
+ };
+ };
}) => {changedByName},
},
{
@@ -76,13 +100,19 @@ class DashboardTable extends React.PureComponent {
row: {
original: { changed_on: changedOn },
},
+ }: {
+ row: {
+ original: {
+ changed_on: string;
+ };
+ };
}) => {moment(changedOn).fromNow()},
},
];
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 => ({
diff --git a/superset-frontend/src/welcome/Welcome.jsx b/superset-frontend/src/welcome/Welcome.tsx
similarity index 83%
rename from superset-frontend/src/welcome/Welcome.jsx
rename to superset-frontend/src/welcome/Welcome.tsx
index 97d17f91deb..3ec66e1d34b 100644
--- a/superset-frontend/src/welcome/Welcome.jsx
+++ b/superset-frontend/src/welcome/Welcome.tsx
@@ -17,23 +17,30 @@
* under the License.
*/
import React, { useState } from 'react';
-import PropTypes from 'prop-types';
import { Panel, Row, Col, Tabs, Tab, FormControl } from 'react-bootstrap';
import { t } from '@superset-ui/translation';
-import { useQueryParam, StringParam } from 'use-query-params';
+import { useQueryParam, StringParam, QueryParamConfig } from 'use-query-params';
+import { User } from 'src/types/bootstrapTypes';
import RecentActivity from '../profile/components/RecentActivity';
import Favorites from '../profile/components/Favorites';
import DashboardTable from './DashboardTable';
-const propTypes = {
- user: PropTypes.object.isRequired,
-};
+interface WelcomeProps {
+ user: User;
+}
-function useSyncQueryState(queryParam, queryParamType, defaultState) {
+function useSyncQueryState(
+ queryParam: string,
+ queryParamType: QueryParamConfig<
+ string | null | undefined,
+ string | undefined
+ >,
+ defaultState: string,
+): [string, (val: string) => void] {
const [queryState, setQueryState] = useQueryParam(queryParam, queryParamType);
const [state, setState] = useState(queryState || defaultState);
- const setQueryStateAndState = val => {
+ const setQueryStateAndState = (val: string) => {
setQueryState(val);
setState(val);
};
@@ -41,7 +48,7 @@ function useSyncQueryState(queryParam, queryParamType, defaultState) {
return [state, setQueryStateAndState];
}
-export default function Welcome({ user }) {
+export default function Welcome({ user }: WelcomeProps) {
const [activeTab, setActiveTab] = useSyncQueryState(
'activeTab',
StringParam,
@@ -58,6 +65,7 @@ export default function Welcome({ user }) {
@@ -75,6 +83,7 @@ export default function Welcome({ user }) {
style={{ marginTop: '25px' }}
placeholder="Search"
value={searchQuery}
+ // @ts-ignore React bootstrap types aren't quite right here
onChange={e => setSearchQuery(e.currentTarget.value)}
/>
@@ -114,5 +123,3 @@ export default function Welcome({ user }) {
);
}
-
-Welcome.propTypes = propTypes;
diff --git a/superset-frontend/src/welcome/index.jsx b/superset-frontend/src/welcome/index.tsx
similarity index 100%
rename from superset-frontend/src/welcome/index.jsx
rename to superset-frontend/src/welcome/index.tsx
diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js
index 2d3545b81c9..d6295d3f3ed 100644
--- a/superset-frontend/webpack.config.js
+++ b/superset-frontend/webpack.config.js
@@ -181,7 +181,7 @@ const config = {
explore: addPreamble('/src/explore/index.jsx'),
dashboard: addPreamble('/src/dashboard/index.jsx'),
sqllab: addPreamble('/src/SqlLab/index.tsx'),
- welcome: addPreamble('/src/welcome/index.jsx'),
+ welcome: addPreamble('/src/welcome/index.tsx'),
profile: addPreamble('/src/profile/index.tsx'),
showSavedQuery: [path.join(APP_DIR, '/src/showSavedQuery/index.jsx')],
},