Skip to content
Open
Changes from 1 commit
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 @@ -95,7 +95,9 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
this.pageSize,
this.currentPage - 1
);
this.objects = result.objects;
this.objects = ECCClientGa4ghDrsObjects.sortObjectsByLastUpdated(
result.objects
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect as the sorting should be handled on the backend.


// Update total objects and pages from API response
if (result.pagination?.total !== undefined) {
Expand Down Expand Up @@ -166,6 +168,17 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
this.loadData();
}

private static sortObjectsByLastUpdated(objects: DrsObject[]): DrsObject[] {
return [...objects].sort((a, b) => {
// Use updated_time if available, otherwise fall back to created_time
const aTime = a.updated_time || a.created_time;
const bTime = b.updated_time || b.created_time;

// Sort in reverse chronological order (most recent first)
return new Date(bTime).getTime() - new Date(aTime).getTime();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Consider handling missing/invalid timestamps more defensively in the sort comparator.

If updated_time/created_time is missing or not a valid date, new Date(...).getTime() returns NaN, and comparisons with NaN can produce non‑deterministic ordering. Consider explicitly handling falsy/invalid timestamps (e.g., normalizing them to a sentinel like 0/-Infinity or special‑casing when aTime/bTime is invalid) so those entries are consistently placed at the start or end of the list.

});
}

private renderPagination() {
return html`
<ecc-utils-design-pagination>
Expand Down Expand Up @@ -299,7 +312,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
.map(
() => html`
<ecc-utils-design-table-row>
<ecc-utils-design-table-cell class="w-6/12">
<ecc-utils-design-table-cell class="w-5/12">
<div class="flex flex-col w-full gap-2">
<ecc-utils-design-skeleton
class="part:h-5 part:w-40"
Expand All @@ -317,14 +330,14 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
class="part:h-4 part:w-20"
></ecc-utils-design-skeleton>
</ecc-utils-design-table-cell>
<ecc-utils-design-table-cell class="w-2/12">
<ecc-utils-design-table-cell class="w-2.5/12">
<ecc-utils-design-skeleton
class="part:h-4 part:w-24"
></ecc-utils-design-skeleton>
</ecc-utils-design-table-cell>
<ecc-utils-design-table-cell class="w-2/12">
<ecc-utils-design-table-cell class="w-2.5/12">
<ecc-utils-design-skeleton
class="part:h-8 part:w-8 part:rounded"
class="part:h-4 part:w-24"
></ecc-utils-design-skeleton>
</ecc-utils-design-table-cell>
</ecc-utils-design-table-row>
Expand All @@ -341,9 +354,17 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
return `${parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
}

private static formatDate(dateString: string): string {
private static formatDateTime(dateString: string): string {
try {
return new Date(dateString).toLocaleDateString();
return new Date(dateString).toLocaleString("en-US", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
});
} catch {
return dateString;
}
Expand Down Expand Up @@ -403,18 +424,18 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
<ecc-utils-design-table>
<ecc-utils-design-table-header>
<ecc-utils-design-table-row>
<ecc-utils-design-table-head class="w-6/12"
<ecc-utils-design-table-head class="w-5/12"
>Object Info</ecc-utils-design-table-head
>
<ecc-utils-design-table-head class="w-2/12"
>Size</ecc-utils-design-table-head
>
<ecc-utils-design-table-head class="w-2/12"
<ecc-utils-design-table-head class="w-2.5/12"
>Created</ecc-utils-design-table-head
>
<ecc-utils-design-table-head
class="w-2/12"
></ecc-utils-design-table-head>
<ecc-utils-design-table-head class="w-2.5/12"
>Last Updated</ecc-utils-design-table-head
>
</ecc-utils-design-table-row>
</ecc-utils-design-table-header>
<ecc-utils-design-table-body>
Expand All @@ -426,7 +447,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
return html`
<ecc-utils-design-table-row>
<ecc-utils-design-table-cell
colspan="5"
colspan="4"
class="part:text-center part:py-8 part:text-muted-foreground"
>
No objects found
Expand All @@ -437,7 +458,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
return this.objects.map(
(object) => html`
<ecc-utils-design-table-row>
<ecc-utils-design-table-cell class="w-6/12">
<ecc-utils-design-table-cell class="w-5/12">
<div class="flex flex-col w-full">
<ecc-utils-design-button
class="part:font-medium part:text-primary part:w-fit part:cursor-pointer part:p-0"
Expand Down Expand Up @@ -467,22 +488,19 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
)}</span
>
</ecc-utils-design-table-cell>
<ecc-utils-design-table-cell class="w-2/12">
<ecc-utils-design-table-cell class="w-2.5/12">
<span class="text-sm"
>${ECCClientGa4ghDrsObjects.formatDate(
>${ECCClientGa4ghDrsObjects.formatDateTime(
object.created_time
)}</span
>
</ecc-utils-design-table-cell>
<ecc-utils-design-table-cell class="w-2/12">
<slot name=${`actions-${object.id}`}>
<ecc-utils-design-button
size="sm"
@click=${() => this.handleObjectSelect(object.id)}
>
View Details
</ecc-utils-design-button>
</slot>
<ecc-utils-design-table-cell class="w-2.5/12">
<span class="text-sm"
>${ECCClientGa4ghDrsObjects.formatDateTime(
object.updated_time || object.created_time
)}</span
>
</ecc-utils-design-table-cell>
</ecc-utils-design-table-row>
`
Expand Down
Loading