Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Paginated rows don't consistently have the same sort order #3581

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ export const CallsTable: FC<{
new Set<string>().add('inputs.example')
);

// Keep track of the display sort model separately from the actual sort model
const [displaySortModel, setDisplaySortModel] = useState<GridSortModel>([]);

// Helpers to handle expansion
const onExpand = (col: string) => {
setExpandedRefCols(prevState => new Set(prevState).add(col));
Expand Down Expand Up @@ -708,18 +711,37 @@ export const CallsTable: FC<{
}

// handle feedback conversion from weave summary to backend filter
for (const sort of newModel) {
const processedModel = newModel.map(sort => {
if (sort.field.startsWith('summary.weave.feedback')) {
const parsed = parseFeedbackType(sort.field);
if (parsed) {
const backendFilter = convertFeedbackFieldToBackendFilter(
parsed.field
);
sort.field = backendFilter;
return {
...sort,
field: convertFeedbackFieldToBackendFilter(parsed.field),
};
}
}
return sort;
});

// Update the display sort model
setDisplaySortModel(processedModel);

// If there's no sort specified, use started_at desc only
if (processedModel.length === 0) {
setSortModel([{field: 'started_at', sort: 'desc'}]);
return;
}

// Only append started_at as secondary sort if it's not already present
const hasStartedAt = processedModel.some(
sort => sort.field === 'started_at'
);
if (!hasStartedAt) {
setSortModel([...processedModel, {field: 'started_at', sort: 'desc'}]);
} else {
setSortModel(processedModel);
}
setSortModel(newModel);
},
[callsLoading, setSortModel, muiColumns]
);
Expand Down Expand Up @@ -932,7 +954,7 @@ export const CallsTable: FC<{
columnVisibilityModel={columnVisibilityModel}
// SORT SECTION START
sortingMode="server"
sortModel={sortModel}
sortModel={displaySortModel}
onSortModelChange={onSortModelChange}
// SORT SECTION END
// PAGINATION SECTION START
Expand Down