diff --git a/static/app/views/dashboards/manage/dashboardGrid.tsx b/static/app/views/dashboards/manage/dashboardGrid.tsx index e488bf45d69527..1b2443431eb666 100644 --- a/static/app/views/dashboards/manage/dashboardGrid.tsx +++ b/static/app/views/dashboards/manage/dashboardGrid.tsx @@ -10,6 +10,7 @@ import { } from 'sentry/actionCreators/dashboards'; import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator'; import type {Client} from 'sentry/api'; +import Feature from 'sentry/components/acl/feature'; import {Button} from 'sentry/components/button'; import {openConfirmModal} from 'sentry/components/confirm'; import type {MenuItemProps} from 'sentry/components/dropdownMenu'; @@ -101,6 +102,11 @@ function DashboardGrid({ } } + // function handleFavorite() { + // // call api + // onDashboardsChange(); + // } + function renderDropdownMenu(dashboard: DashboardListItem) { const menuItems: MenuItemProps[] = [ { @@ -164,6 +170,27 @@ function DashboardGrid({ : {}), }; + function renderDashboardCard(dashboard: DashboardListItem, index: number) { + return ( + : undefined + } + createdBy={dashboard.createdBy} + renderWidgets={() => renderGridPreview(dashboard)} + renderContextMenu={() => renderDropdownMenu(dashboard)} + // pass handleFavourite + /> + ); + } + function renderMiniDashboards() { // on pagination, render no dashboards to show placeholders while loading if ( @@ -174,23 +201,23 @@ function DashboardGrid({ } return currentDashboards?.slice(0, rowCount * columnCount).map((dashboard, index) => { - return ( - : undefined - } - createdBy={dashboard.createdBy} - renderWidgets={() => renderGridPreview(dashboard)} - renderContextMenu={() => renderDropdownMenu(dashboard)} - /> - ); + return renderDashboardCard(dashboard, index); + }); + } + + function renderFavoriteDashboards() { + if ( + rowCount * columnCount === currentDashboards?.length && + !isEqual(currentDashboards, dashboards) + ) { + return []; + } + + const favoriteDashboardsRows = Math.ceil(5 / columnCount); + rowCount -= favoriteDashboardsRows; + + return currentDashboards?.slice(0, 5).map((dashboard, index) => { + return renderDashboardCard(dashboard, index); }); } @@ -210,19 +237,43 @@ function DashboardGrid({ ? currentDashboards?.length ?? 0 : dashboards?.length ?? 0; + const isFirstPage = location.query.cursor === undefined; + return ( - - {renderMiniDashboards()} - {isLoading && - rowCount * columnCount > numDashboards && - new Array(rowCount * columnCount - numDashboards) - .fill(0) - .map((_, index) => )} - + + {isFirstPage && ( + +
+
{t('My Favourites')}
+ + {renderFavoriteDashboards()} + {isLoading && + rowCount * columnCount > numDashboards && + new Array(rowCount * columnCount - numDashboards) + .fill(0) + .map((_, index) => )} + +
+
+ )} + {isFirstPage &&
{t('All Dashboards')}
} + + {renderMiniDashboards()} + {isLoading && + rowCount * columnCount > numDashboards && + new Array(rowCount * columnCount - numDashboards) + .fill(0) + .map((_, index) => )} + +
); } @@ -239,6 +290,14 @@ const DashboardGridContainer = styled('div')<{columns: number; rows: number}>` gap: ${DASHBOARD_CARD_GRID_PADDING}px; `; +const DashboardGridWrapper = styled('div')` + h5 { + border-bottom: 1px solid ${p => p.theme.border}; + padding-bottom: ${space(1)}; + margin-bottom: ${space(2)}; + } +`; + const DropdownTrigger = styled(Button)` transform: translateX(${space(1)}); `; diff --git a/static/app/views/dashboards/manage/index.tsx b/static/app/views/dashboards/manage/index.tsx index f34d53614be4a6..fbc7ea4cecccc4 100644 --- a/static/app/views/dashboards/manage/index.tsx +++ b/static/app/views/dashboards/manage/index.tsx @@ -37,6 +37,7 @@ import {useLocalStorageState} from 'sentry/utils/useLocalStorageState'; import {useLocation} from 'sentry/utils/useLocation'; import {useNavigate} from 'sentry/utils/useNavigate'; import useOrganization from 'sentry/utils/useOrganization'; +import DashboardGrid from 'sentry/views/dashboards/manage/dashboardGrid'; import {DashboardImportButton} from 'sentry/views/dashboards/manage/dashboardImport'; import DashboardTable from 'sentry/views/dashboards/manage/dashboardTable'; import {MetricsRemovedAlertsWidgetsAlert} from 'sentry/views/metrics/metricsRemovedAlertsWidgetsAlert'; @@ -46,7 +47,6 @@ import {getDashboardTemplates} from '../data'; import {assignDefaultLayout, getInitialColumnDepths} from '../layoutUtils'; import type {DashboardDetails, DashboardListItem} from '../types'; -import DashboardGrid from './dashboardGrid'; import { DASHBOARD_CARD_GRID_PADDING, DASHBOARD_GRID_DEFAULT_NUM_CARDS, @@ -115,11 +115,13 @@ function ManageDashboards() { refetch: refetchDashboards, } = useApiQuery( [ + // here `/organizations/${organization.slug}/dashboards/`, { query: { ...pick(location.query, ['cursor', 'query']), sort: getActiveSort().value, + filter: 'onlyFavorites', per_page: dashboardsLayout === GRID ? rowCount * columnCount : DASHBOARD_TABLE_NUM_ROWS, },