From 38095c18894ab18e4d3d378f8017b9e9689c3571 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 1 Apr 2023 21:42:12 -0800 Subject: [PATCH] fix recently added on homescreen --- backend/app/api/handlers/v1/v1_ctrl_items.go | 1 + backend/internal/data/repo/repo_items.go | 27 ++++++++++++++------ frontend/components/Item/View/Table.vue | 6 ++++- frontend/lib/api/classes/items.ts | 1 + frontend/pages/home/table.ts | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index 062fbad..7e7600c 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -58,6 +58,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc { LabelIDs: queryUUIDList(params, "labels"), IncludeArchived: queryBool(params.Get("includeArchived")), Fields: filterFieldItems(params["fields"]), + OrderBy: params.Get("orderBy"), } if strings.HasPrefix(v.Search, "#") { diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 103c3e9..8e4bf55 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -29,13 +29,14 @@ type ( ItemQuery struct { Page int PageSize int - Search string `json:"search"` - AssetID AssetID `json:"assetId"` - LocationIDs []uuid.UUID `json:"locationIds"` - LabelIDs []uuid.UUID `json:"labelIds"` - SortBy string `json:"sortBy"` - IncludeArchived bool `json:"includeArchived"` - Fields []FieldQuery + Search string `json:"search"` + AssetID AssetID `json:"assetId"` + LocationIDs []uuid.UUID `json:"locationIds"` + LabelIDs []uuid.UUID `json:"labelIds"` + SortBy string `json:"sortBy"` + IncludeArchived bool `json:"includeArchived"` + Fields []FieldQuery `json:"fields"` + OrderBy string `json:"orderBy"` } ItemField struct { @@ -385,7 +386,17 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite return PaginationResult[ItemSummary]{}, err } - qb = qb.Order(ent.Asc(item.FieldName)). + // Order + switch q.OrderBy { + case "createdAt": + qb = qb.Order(ent.Desc(item.FieldCreatedAt)) + case "updatedAt": + qb = qb.Order(ent.Desc(item.FieldUpdatedAt)) + default: // "name" + qb = qb.Order(ent.Asc(item.FieldName)) + } + + qb = qb. WithLabel(). WithLocation() diff --git a/frontend/components/Item/View/Table.vue b/frontend/components/Item/View/Table.vue index b9b7196..f6c3cf1 100644 --- a/frontend/components/Item/View/Table.vue +++ b/frontend/components/Item/View/Table.vue @@ -79,7 +79,7 @@ }; const props = defineProps(); - const sortByProperty = ref("name"); + const sortByProperty = ref(""); const headers = computed(() => { return [ @@ -136,6 +136,10 @@ } function itemSort(a: ItemSummary, b: ItemSummary) { + if (!sortByProperty.value) { + return 0; + } + const aLower = extractSortable(a, sortByProperty.value); const bLower = extractSortable(b, sortByProperty.value); diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts index 29403a2..b7cc17d 100644 --- a/frontend/lib/api/classes/items.ts +++ b/frontend/lib/api/classes/items.ts @@ -15,6 +15,7 @@ import { AttachmentTypes, PaginationResult } from "../types/non-generated"; import { Requests } from "~~/lib/requests"; export type ItemsQuery = { + orderBy?: string; includeArchived?: boolean; page?: number; pageSize?: number; diff --git a/frontend/pages/home/table.ts b/frontend/pages/home/table.ts index 127ecbb..7c38d6a 100644 --- a/frontend/pages/home/table.ts +++ b/frontend/pages/home/table.ts @@ -5,6 +5,7 @@ export function itemsTable(api: UserClient) { const { data } = await api.items.getAll({ page: 1, pageSize: 5, + orderBy: "createdAt", }); return data.items; });