Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions static/app/utils/dashboards/dashboardsApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import {apiOptions} from 'sentry/utils/api/apiOptions';
import type {QueryParamValue} from 'sentry/utils/useLocation';
import type {DashboardListItem} from 'sentry/views/dashboards/types';

export function starredDashboardsApiOptions(organization: Organization) {
return apiOptions.as<DashboardListItem[]>()(
'/organizations/$organizationIdOrSlug/dashboards/starred/',
{
path: {organizationIdOrSlug: organization.slug},
staleTime: Infinity,
}
);
}

export function dashboardsApiOptions(
organization: Organization,
options?: {
Expand Down
20 changes: 4 additions & 16 deletions static/app/views/dashboards/hooks/useGetStarredDashboards.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {useQuery} from '@tanstack/react-query';

import type {Organization} from 'sentry/types/organization';
import {
dashboardsApiOptions,
starredDashboardsApiOptions,
} from 'sentry/utils/dashboards/dashboardsApiOptions';
import {dashboardsApiOptions} from 'sentry/utils/dashboards/dashboardsApiOptions';
import {useHasProjectAccess} from 'sentry/utils/useHasProjectAccess';
import {useOrganization} from 'sentry/utils/useOrganization';

export function getStarredDashboardsQueryKey(organization: Organization) {
if (organization.features.includes('dashboards-starred-reordering')) {
return starredDashboardsApiOptions(organization).queryKey;
}
return dashboardsApiOptions(organization, {
query: {filter: 'onlyFavorites'},
}).queryKey;
Expand All @@ -21,16 +15,10 @@ export function useGetStarredDashboards() {
const organization = useOrganization();
const {hasProjectAccess, projectsLoaded} = useHasProjectAccess();

const usesStarredEndpoint = organization.features.includes(
'dashboards-starred-reordering'
);

return useQuery({
...(usesStarredEndpoint
? starredDashboardsApiOptions(organization)
: dashboardsApiOptions(organization, {
query: {filter: 'onlyFavorites'},
})),
...dashboardsApiOptions(organization, {
query: {filter: 'onlyFavorites'},
}),
staleTime: Infinity,
enabled: hasProjectAccess || !projectsLoaded,
});
Expand Down
33 changes: 0 additions & 33 deletions static/app/views/dashboards/hooks/useOwnedDashboards.tsx

This file was deleted.

84 changes: 1 addition & 83 deletions static/app/views/dashboards/manage/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {LocationFixture} from 'sentry-fixture/locationFixture';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {ProjectFixture} from 'sentry-fixture/project';

import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
import {selectEvent} from 'sentry-test/selectEvent';

import {ProjectsStore} from 'sentry/stores/projectsStore';
Expand Down Expand Up @@ -285,86 +285,4 @@ describe('Dashboards > Detail', () => {

expect(await screen.findByTestId('dashboard-grid')).toBeInTheDocument();
});

it('uses recently viewed sort by default on table view', async () => {
const org = OrganizationFixture({
features: [...FEATURES, 'dashboards-starred-reordering'],
});
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);

// mock the view type to table
localStorageWrapper.setItem(LAYOUT_KEY, '"table"');

render(<ManageDashboards />, {
organization: org,
});

const sortBy = await screen.findByTestId('sort-by-select');
expect(sortBy).toBeInTheDocument();
// The prefix and the selection are concatenated when using text content
expect(sortBy).toHaveTextContent('Sort ByRecently Viewed');
});

it('does not show My Dashboards as a sort option in table view', async () => {
const org = OrganizationFixture({
features: [...FEATURES, 'dashboards-starred-reordering'],
});
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);

// mock the view type to table
localStorageWrapper.setItem(LAYOUT_KEY, '"table"');

render(<ManageDashboards />, {
organization: org,
});

const sortBy = await screen.findByTestId('sort-by-select');
expect(sortBy).toBeInTheDocument();
// The prefix and the selection are concatenated when using text content
expect(sortBy).toHaveTextContent('Sort ByRecently Viewed');
expect(screen.queryByText('My Dashboards')).not.toBeInTheDocument();
});

it('redirects the URL to the default sort option when the sort option is not valid', async () => {
const org = OrganizationFixture({
features: [...FEATURES, 'dashboards-starred-reordering'],
});
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);
mockUseLocation.mockReturnValue(LocationFixture({query: {sort: 'invalid'}}));

localStorageWrapper.setItem(LAYOUT_KEY, '"grid"');

render(<ManageDashboards />, {
organization: org,
});

expect(await screen.findByText('My Dashboards')).toBeInTheDocument();
await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith(
expect.objectContaining({query: {sort: 'mydashboards'}})
);
});
});

it('shows the most favorited sort option for the %s view type', async () => {
const org = OrganizationFixture({
features: [...FEATURES, 'dashboards-starred-reordering'],
});
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);

render(<ManageDashboards />, {
organization: org,
});

await selectEvent.openMenu(await screen.findByRole('button', {name: /sort by/i}));
await userEvent.click(await screen.findByRole('option', {name: 'Most Starred'}));

expect(mockNavigate).toHaveBeenCalledWith(
expect.objectContaining({query: {sort: 'mostFavorited'}})
);
});
});
94 changes: 10 additions & 84 deletions static/app/views/dashboards/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {SearchBar} from 'sentry/components/searchBar';
import {SentryDocumentTitle} from 'sentry/components/sentryDocumentTitle';
import {IconAdd, IconGrid, IconList} from 'sentry/icons';
import {t} from 'sentry/locale';
import type {Organization} from 'sentry/types/organization';
import {trackAnalytics} from 'sentry/utils/analytics';
import {selectJsonWithHeaders} from 'sentry/utils/api/apiOptions';
import {dashboardsApiOptions} from 'sentry/utils/dashboards/dashboardsApiOptions';
Expand All @@ -43,12 +42,7 @@ import {useLocation} from 'sentry/utils/useLocation';
import {useNavigate} from 'sentry/utils/useNavigate';
import {useOrganization} from 'sentry/utils/useOrganization';
import {DashboardCreateLimitWrapper} from 'sentry/views/dashboards/createLimitWrapper';
import {useOwnedDashboards} from 'sentry/views/dashboards/hooks/useOwnedDashboards';
import DashboardTable from 'sentry/views/dashboards/manage/dashboardTable';
import {
OWNED_CURSOR_KEY,
OwnedDashboardsTable,
} from 'sentry/views/dashboards/manage/tableView/ownedDashboardsTable';
import type {DashboardsLayout} from 'sentry/views/dashboards/manage/types';
import {DashboardFilter, PREBUILT_DASHBOARD_LABEL} from 'sentry/views/dashboards/types';
import {PREBUILT_DASHBOARDS} from 'sentry/views/dashboards/utils/prebuiltConfigs';
Expand Down Expand Up @@ -86,22 +80,10 @@ function getDashboardsOverviewLayout(): DashboardsLayout {
: TABLE;
}

function getSortOptions({
organization,
dashboardsLayout,
isOnlyPrebuilt,
}: {
dashboardsLayout: DashboardsLayout;
isOnlyPrebuilt: boolean;
organization: Organization;
}) {
function getSortOptions({isOnlyPrebuilt}: {isOnlyPrebuilt: boolean}) {
const options = [];

if (
!isOnlyPrebuilt &&
(!organization.features.includes('dashboards-starred-reordering') ||
dashboardsLayout === GRID)
) {
if (!isOnlyPrebuilt) {
options.push({label: t('My Dashboards'), value: 'mydashboards'});
}

Expand All @@ -110,38 +92,18 @@ function getSortOptions({
{label: t('Dashboard Name (Z-A)'), value: '-title'},
{label: t('Date Created (Newest)'), value: '-dateCreated'},
{label: t('Date Created (Oldest)'), value: 'dateCreated'},
{label: t('Most Popular'), value: 'mostPopular'}
{label: t('Most Popular'), value: 'mostPopular'},
{label: t('Recently Viewed'), value: 'recentlyViewed'}
);

if (organization.features.includes('dashboards-starred-reordering')) {
options.push({label: t('Most Starred'), value: 'mostFavorited'});
}

options.push({label: t('Recently Viewed'), value: 'recentlyViewed'});

return options;
}

function getDefaultSort({
organization,
dashboardsLayout,
isOnlyPrebuilt,
}: {
dashboardsLayout: DashboardsLayout;
isOnlyPrebuilt: boolean;
organization: Organization;
}) {
function getDefaultSort({isOnlyPrebuilt}: {isOnlyPrebuilt: boolean}) {
if (isOnlyPrebuilt) {
return DEFAULT_PREBUILT_SORT;
}

if (
organization.features.includes('dashboards-starred-reordering') &&
dashboardsLayout === TABLE
) {
return 'recentlyViewed';
}

return 'mydashboards';
}

Expand Down Expand Up @@ -173,11 +135,7 @@ function ManageDashboards() {

const {hasProjectAccess, projectsLoaded} = useHasProjectAccess();

const sortOptions = getSortOptions({
organization,
dashboardsLayout,
isOnlyPrebuilt,
});
const sortOptions = getSortOptions({isOnlyPrebuilt});

const {
data: dashboardsResponse,
Expand All @@ -199,12 +157,7 @@ function ManageDashboards() {
},
}),
select: selectJsonWithHeaders,
enabled:
(hasProjectAccess || !projectsLoaded) &&
!(
organization.features.includes('dashboards-starred-reordering') &&
dashboardsLayout === TABLE
),
enabled: hasProjectAccess || !projectsLoaded,
});
const dashboardsWithoutPrebuiltConfigs = dashboardsResponse?.json;

Expand All @@ -231,16 +184,6 @@ function ManageDashboards() {
[dashboardsWithoutPrebuiltConfigs]
);

const ownedDashboards = useOwnedDashboards({
query: decodeScalar(location.query.query, ''),
cursor: decodeScalar(location.query[OWNED_CURSOR_KEY], ''),
sort: getActiveSort()!.value,
enabled:
(hasProjectAccess || !projectsLoaded) &&
organization.features.includes('dashboards-starred-reordering') &&
dashboardsLayout === TABLE,
});

const dashboardsPageLinks = dashboardsResponse?.headers.Link ?? '';

function setRowsAndColumns(containerWidth: number) {
Expand Down Expand Up @@ -311,11 +254,7 @@ function ManageDashboards() {

useEffect(() => {
const urlSort = decodeScalar(location.query.sort);
const defaultSort = getDefaultSort({
organization,
dashboardsLayout,
isOnlyPrebuilt,
});
const defaultSort = getDefaultSort({isOnlyPrebuilt});
if (urlSort && !sortOptions.some(option => option.value === urlSort)) {
// The sort option is not valid, so we need to set the default sort
// in the URL
Expand All @@ -335,11 +274,7 @@ function ManageDashboards() {
]);

function getActiveSort() {
const defaultSort = getDefaultSort({
organization,
dashboardsLayout,
isOnlyPrebuilt,
});
const defaultSort = getDefaultSort({isOnlyPrebuilt});
const urlSort = decodeScalar(location.query.sort, defaultSort);

if (urlSort) {
Expand Down Expand Up @@ -533,12 +468,6 @@ function ManageDashboards() {
rowCount={rowCount}
columnCount={columnCount}
/>
) : organization.features.includes('dashboards-starred-reordering') ? (
<OwnedDashboardsTable
dashboards={ownedDashboards.data?.json ?? []}
isLoading={ownedDashboards.isLoading}
pageLinks={ownedDashboards.data?.headers.Link}
/>
) : (
<DashboardTable
api={api}
Expand Down Expand Up @@ -770,10 +699,7 @@ function ManageDashboards() {
<div ref={dashboardGridRef} id="dashboard-list-container">
{renderDashboards()}
</div>
{!(
organization.features.includes('dashboards-starred-reordering') &&
dashboardsLayout === TABLE
) && renderPagination()}
{renderPagination()}
</Layout.Main>
</Layout.Body>
</NoProjectMessage>
Expand Down

This file was deleted.

Loading
Loading