Skip to content

Commit

Permalink
Add golden dashboards to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
kgopal492 committed Nov 17, 2024
1 parent 1c1a9cd commit e96ac1c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 17 deletions.
17 changes: 15 additions & 2 deletions superset-frontend/src/features/home/DashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function DashboardTable({
addDangerToast,
addSuccessToast,
mine,
golden,
showThumbnails,
otherTabData,
otherTabFilters,
Expand All @@ -58,7 +59,7 @@ function DashboardTable({
const history = useHistory();
const defaultTab = getItem(
LocalStorageKeys.HomepageDashboardFilter,
TableTab.Other,
TableTab.Golden,
);

const filteredOtherTabData = filter(
Expand All @@ -77,7 +78,11 @@ function DashboardTable({
t('dashboard'),
addDangerToast,
true,
defaultTab === TableTab.Mine ? mine : filteredOtherTabData,
defaultTab === TableTab.Mine
? mine
: defaultTab === TableTab.Golden
? golden
: filteredOtherTabData,
[],
false,
);
Expand Down Expand Up @@ -151,6 +156,14 @@ function DashboardTable({
);

const menuTabs = [
{
name: TableTab.Golden,
label: t('Golden'),
onClick: () => {
setActiveTab(TableTab.Golden);
setItem(LocalStorageKeys.HomepageDashboardFilter, TableTab.Golden);
},
},
{
name: TableTab.Favorite,
label: t('Favorite'),
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/features/home/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export default function EmptyState({
if (
tab === TableTab.Mine ||
tableName === WelcomeTable.Recents ||
tab === TableTab.Other
tab === TableTab.Other ||
tab === TableTab.Golden
) {
return (
<EmptyContainer>
Expand Down
44 changes: 30 additions & 14 deletions superset-frontend/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import withToasts from 'src/components/MessageToasts/withToasts';
import {
CardContainer,
createErrorHandler,
getGoldenDashboards,
getRecentActivityObjs,
getUserOwnedObjects,
loadingCardCount,
Expand Down Expand Up @@ -176,6 +177,8 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
const [dashboardData, setDashboardData] = useState<Array<object> | null>(
null,
);
const [goldenDashboardData, setGoldenDashboardData] =
useState<Array<object> | null>(null);
const [isFetchingActivityData, setIsFetchingActivityData] = useState(true);

const collapseState = getItem(LocalStorageKeys.HomepageCollapseState, []);
Expand Down Expand Up @@ -298,6 +301,18 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
]).then(() => {
setIsFetchingActivityData(false);
});
getGoldenDashboards()
.then(r => {
setGoldenDashboardData(r);
return Promise.resolve();
})
.catch((err: unknown) => {
setGoldenDashboardData([]);
addDangerToast(
t('There was an issue fetching golden dashboards: %s', err),
);
return Promise.resolve();
});
}, [otherTabFilters]);

const handleToggle = () => {
Expand Down Expand Up @@ -365,6 +380,21 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
ghost
bigger
>
<Collapse.Panel header={t('Dashboards')} key="2">
{!dashboardData || isRecentActivityLoading ? (
<LoadingCards cover={checked} />
) : (
<DashboardTable
user={user}
mine={dashboardData}
golden={goldenDashboardData}
showThumbnails={checked}
otherTabData={activityData?.[TableTab.Other]}
otherTabFilters={otherTabFilters}
otherTabTitle={otherTabTitle}
/>
)}
</Collapse.Panel>
<Collapse.Panel header={t('Recents')} key="1">
{activityData &&
(activityData[TableTab.Viewed] ||
Expand All @@ -382,20 +412,6 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
<LoadingCards />
)}
</Collapse.Panel>
<Collapse.Panel header={t('Dashboards')} key="2">
{!dashboardData || isRecentActivityLoading ? (
<LoadingCards cover={checked} />
) : (
<DashboardTable
user={user}
mine={dashboardData}
showThumbnails={checked}
otherTabData={activityData?.[TableTab.Other]}
otherTabFilters={otherTabFilters}
otherTabTitle={otherTabTitle}
/>
)}
</Collapse.Panel>
<Collapse.Panel header={t('Charts')} key="3">
{!chartData || isRecentActivityLoading ? (
<LoadingCards cover={checked} />
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/views/CRUD/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum TableTab {
Viewed = 'Viewed',
Created = 'Created',
Edited = 'Edited',
Golden = 'Golden',
}

export type Filter = {
Expand All @@ -45,6 +46,7 @@ export interface DashboardTableProps {
addSuccessToast: (message: string) => void;
user?: User;
mine: Array<Dashboard>;
golden: Array<Dashboard>;
showThumbnails?: boolean;
otherTabData: Array<Dashboard>;
otherTabFilters: Filter[];
Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ export const getEditedObjects = (userId: string | number) => {
.catch(err => err);
};

export const getGoldenDashboards = (
filters: Filter[] = [
{
col: 'tags',
opr: 'dashboard_tags',
value: 'Golden',
},
],
) =>
SupersetClient.get({
endpoint: `/api/v1/dashboard/?q=${getParams(filters)}`,
}).then(res => res.json?.result);

export const getUserOwnedObjects = (
userId: string | number,
resource: string,
Expand Down

0 comments on commit e96ac1c

Please sign in to comment.