Skip to content
Merged
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
20 changes: 14 additions & 6 deletions static/app/views/explore/logs/tables/logsAggregateTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ export function LogsAggregateTable({
canSort
direction={direction}
generateSortLink={() => {
const nextSort = (() => {
switch (direction) {
case 'asc':
return {
field: visualizes[0]?.yAxis ?? allFields[0]!,
kind: 'desc' as const,
};
case 'desc':
return {field: column.key, kind: 'asc' as const};
default:
return {field: column.key, kind: 'desc' as const};
}
})();
return getTargetWithReadableQueryParams(location, {
aggregateSortBys: [
{
field: column.key,
kind: direction === 'desc' ? 'asc' : 'desc',
},
],
aggregateSortBys: [nextSort],
});
}}
title={title}
Expand Down
45 changes: 43 additions & 2 deletions static/app/views/explore/logs/tables/logsInfiniteTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
userEvent,
waitFor,
within,
type RenderOptions,
} from 'sentry-test/reactTestingLibrary';

import {PageFiltersStore} from 'sentry/components/pageFilters/store';
Expand Down Expand Up @@ -194,8 +195,8 @@ describe('LogsInfiniteTable', () => {
});
});

const renderWithProviders = (children: React.ReactNode) => {
return render(
function Wrapper({children}: {children: React.ReactNode}) {
return (
<OrganizationContext.Provider value={organization}>
<LogsQueryParamsProvider
analyticsPageSource={LogsAnalyticsPageSource.EXPLORE_LOGS}
Expand All @@ -205,6 +206,10 @@ describe('LogsInfiniteTable', () => {
</LogsQueryParamsProvider>
</OrganizationContext.Provider>
);
}

const renderWithProviders = (children: React.ReactElement, options?: RenderOptions) => {
return render(children, {additionalWrapper: Wrapper, ...options});
};

it('should render the table component', async () => {
Expand Down Expand Up @@ -472,4 +477,40 @@ describe('LogsInfiniteTable', () => {
await screen.findByText('abc123de');
await screen.findByText('abc123ee');
});

it('cycles column sort: unsorted → desc → asc → reset to default timestamp desc', async () => {
// Start with severity sorted ascending (second click has already happened)
mockUseLocation.mockReturnValue(
LocationFixture({
pathname: `/organizations/${organization.slug}/explore/logs/`,
query: {
[LOGS_FIELDS_KEY]: visibleColumnFields,
[LOGS_SORT_BYS_KEY]: 'severity',
},
})
);

const {router} = renderWithProviders(
<LogsInfiniteTable analyticsPageSource={LogsAnalyticsPageSource.EXPLORE_LOGS} />,
{
initialRouterConfig: {
location: {
pathname: `/organizations/${organization.slug}/explore/logs/`,
query: {
[LOGS_FIELDS_KEY]: visibleColumnFields,
[LOGS_SORT_BYS_KEY]: 'severity',
},
},
},
organization,
}
);

// Wait for table headers to be rendered (empty while pending)
const severityHeader = await screen.findByText('Severity');

// Third click (asc → reset): should navigate to default timestamp desc sort
await userEvent.click(severityHeader);
expect(router.location.query[LOGS_SORT_BYS_KEY]).toBe('-timestamp');
});
});
13 changes: 11 additions & 2 deletions static/app/views/explore/logs/tables/logsInfiniteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
} from 'sentry/views/explore/components/table';
import {useLogsAutoRefreshEnabled} from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext';
import {useLogsPageDataQueryResult} from 'sentry/views/explore/contexts/logs/logsPageData';
import {logsTimestampDescendingSortBy} from 'sentry/views/explore/contexts/logs/sortBys';
import {
MINIMUM_INFINITE_SCROLL_FETCH_COOLDOWN_MS,
QUANTIZE_MINUTES,
Expand Down Expand Up @@ -658,8 +659,16 @@ function LogsTableHeader({
isFrozen
? undefined
: () => {
const kind = direction === 'desc' ? 'asc' : 'desc';
setSortBys([{field, kind}]);
switch (direction) {
case 'asc':
setSortBys([logsTimestampDescendingSortBy]);
break;
case 'desc':
setSortBys([{field, kind: 'asc'}]);
break;
default:
setSortBys([{field, kind: 'desc'}]);
}
}
}
isFrozen={isFrozen}
Expand Down
2 changes: 1 addition & 1 deletion tests/js/sentry-test/reactTestingLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface RouterConfig {
routes?: string[];
}

interface RenderOptions extends rtl.RenderOptions, ProviderOptions {
export interface RenderOptions extends rtl.RenderOptions, ProviderOptions {
initialRouterConfig?: RouterConfig;
outletContext?: Record<string, unknown>;
}
Expand Down
Loading