fix recently added on homescreen

This commit is contained in:
Hayden 2023-04-01 21:42:12 -08:00
parent 84bdb8c9a5
commit 38095c1889
No known key found for this signature in database
GPG key ID: 17CF79474E257545
5 changed files with 27 additions and 9 deletions

View file

@ -58,6 +58,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
LabelIDs: queryUUIDList(params, "labels"), LabelIDs: queryUUIDList(params, "labels"),
IncludeArchived: queryBool(params.Get("includeArchived")), IncludeArchived: queryBool(params.Get("includeArchived")),
Fields: filterFieldItems(params["fields"]), Fields: filterFieldItems(params["fields"]),
OrderBy: params.Get("orderBy"),
} }
if strings.HasPrefix(v.Search, "#") { if strings.HasPrefix(v.Search, "#") {

View file

@ -35,7 +35,8 @@ type (
LabelIDs []uuid.UUID `json:"labelIds"` LabelIDs []uuid.UUID `json:"labelIds"`
SortBy string `json:"sortBy"` SortBy string `json:"sortBy"`
IncludeArchived bool `json:"includeArchived"` IncludeArchived bool `json:"includeArchived"`
Fields []FieldQuery Fields []FieldQuery `json:"fields"`
OrderBy string `json:"orderBy"`
} }
ItemField struct { ItemField struct {
@ -385,7 +386,17 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
return PaginationResult[ItemSummary]{}, err 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(). WithLabel().
WithLocation() WithLocation()

View file

@ -79,7 +79,7 @@
}; };
const props = defineProps<Props>(); const props = defineProps<Props>();
const sortByProperty = ref<keyof ItemSummary>("name"); const sortByProperty = ref<keyof ItemSummary | "">("");
const headers = computed<TableHeader[]>(() => { const headers = computed<TableHeader[]>(() => {
return [ return [
@ -136,6 +136,10 @@
} }
function itemSort(a: ItemSummary, b: ItemSummary) { function itemSort(a: ItemSummary, b: ItemSummary) {
if (!sortByProperty.value) {
return 0;
}
const aLower = extractSortable(a, sortByProperty.value); const aLower = extractSortable(a, sortByProperty.value);
const bLower = extractSortable(b, sortByProperty.value); const bLower = extractSortable(b, sortByProperty.value);

View file

@ -15,6 +15,7 @@ import { AttachmentTypes, PaginationResult } from "../types/non-generated";
import { Requests } from "~~/lib/requests"; import { Requests } from "~~/lib/requests";
export type ItemsQuery = { export type ItemsQuery = {
orderBy?: string;
includeArchived?: boolean; includeArchived?: boolean;
page?: number; page?: number;
pageSize?: number; pageSize?: number;

View file

@ -5,6 +5,7 @@ export function itemsTable(api: UserClient) {
const { data } = await api.items.getAll({ const { data } = await api.items.getAll({
page: 1, page: 1,
pageSize: 5, pageSize: 5,
orderBy: "createdAt",
}); });
return data.items; return data.items;
}); });