Skip to content

Commit

Permalink
[front] - feat(assistants): sort by date (#6558)
Browse files Browse the repository at this point in the history
* [front/components/assistant] - feature: add 'Edited at' sorting option for search

 - Extend the SearchOrder to include an 'edited_at' option for sorting search results
 - Implement the logic for sorting based on the 'edited_at' timestamp
 - Update SearchOrderDropdown to display a human-friendly label for the 'edited_at' sort option
 - Introduce a mapping object to convert search order keys to their pretty-printed equivalents for UI display

* [front] - fix: update label for 'edited_at' in SearchOrderDropdown

 - Changed the 'edited_at' label to 'Last edited at' for clarity

---------

Co-authored-by: Jules <[email protected]>
  • Loading branch information
JulesBelveze and Jules authored Jul 29, 2024
1 parent 95d7be8 commit 1b0e776
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions front/components/assistant/SearchOrderDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Button, DropdownMenu } from "@dust-tt/sparkle";

export const SearchOrder = ["name", "usage"] as const;
export const SearchOrder = ["name", "usage", "edited_at"] as const;
export type SearchOrderType = (typeof SearchOrder)[number];

const prettyfiedSearchOrder: { [key in SearchOrderType]: string } = {
name: "Name",
usage: "Usage",
edited_at: "Last edited at",
};

// Headless UI does not inherently handle Portal-based rendering,
// leading to dropdown menus being hidden by parent divs with overflow settings.
// Adapts layout for smaller screens.
Expand All @@ -21,7 +27,7 @@ export function SearchOrderDropdown({
<Button
type="select"
labelVisible={true}
label={`Order by: ${orderBy}`}
label={`Order by: ${prettyfiedSearchOrder[orderBy]}`}
variant="tertiary"
hasMagnifying={false}
size="sm"
Expand All @@ -32,7 +38,7 @@ export function SearchOrderDropdown({
{SearchOrder.map((order) => (
<DropdownMenu.Item
key={order}
label={order}
label={prettyfiedSearchOrder[order]}
onClick={() => setOrderBy(order)}
/>
))}
Expand Down
11 changes: 11 additions & 0 deletions front/pages/w/[wId]/builder/assistants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ export default function WorkspaceAssistants({
});
break;
}
case "edited_at":
filteredAgents.sort((a, b) => {
const dateA = a.versionCreatedAt
? new Date(a.versionCreatedAt).getTime()
: -Infinity;
const dateB = b.versionCreatedAt
? new Date(b.versionCreatedAt).getTime()
: -Infinity;
return dateB - dateA;
});
break;
default:
assertNever(orderBy);
}
Expand Down

0 comments on commit 1b0e776

Please sign in to comment.