mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
fix: disable sort on item page
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
items: ItemSummary[];
|
items: ItemSummary[];
|
||||||
locationFlatTree?: FlatTreeItem[];
|
locationFlatTree?: FlatTreeItem[];
|
||||||
pagination?: Pagination;
|
pagination?: Pagination;
|
||||||
|
disableSort?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -27,8 +28,10 @@
|
|||||||
const preferences = useViewPreferences();
|
const preferences = useViewPreferences();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const columns = computed(() =>
|
const columns = computed(() =>
|
||||||
makeColumns(t, () => {
|
makeColumns({
|
||||||
emit("refresh");
|
t,
|
||||||
|
refresh: () => emit("refresh"),
|
||||||
|
disableSort: props.disableSort,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,30 @@ import { cn } from "~/lib/utils";
|
|||||||
* Create columns with i18n support.
|
* Create columns with i18n support.
|
||||||
* Pass `t` from useI18n() when creating the columns in your component.
|
* Pass `t` from useI18n() when creating the columns in your component.
|
||||||
*/
|
*/
|
||||||
export function makeColumns(t: (key: string) => string, refresh?: () => void): ColumnDef<ItemSummary>[] {
|
export function makeColumns({
|
||||||
|
t,
|
||||||
|
refresh,
|
||||||
|
disableSort,
|
||||||
|
}: {
|
||||||
|
t: (key: string) => string;
|
||||||
|
refresh?: () => void;
|
||||||
|
disableSort?: boolean;
|
||||||
|
}): ColumnDef<ItemSummary>[] {
|
||||||
const sortable = (column: Column<ItemSummary, unknown>, key: string) => {
|
const sortable = (column: Column<ItemSummary, unknown>, key: string) => {
|
||||||
const sortState = column.getIsSorted(); // 'asc' | 'desc' | false
|
const sortState = column.getIsSorted(); // 'asc' | 'desc' | false
|
||||||
if (!sortState) {
|
if (!sortState) {
|
||||||
// show the neutral up/down icon when not sorted
|
// show the neutral up/down icon when not sorted
|
||||||
return [t(key), h(ArrowUpDown, { class: "ml-2 h-4 w-4 opacity-40" })];
|
return [t(key), h(ArrowUpDown, { class: cn(["ml-2 h-4 w-4 opacity-40", disableSort && "opacity-0"]) })];
|
||||||
}
|
}
|
||||||
// show a single arrow that points up for asc (rotate-180) and down for desc
|
// show a single arrow that points up for asc (rotate-180) and down for desc
|
||||||
return [
|
return [
|
||||||
t(key),
|
t(key),
|
||||||
h(ArrowDown, {
|
h(ArrowDown, {
|
||||||
class: cn(["ml-2 h-4 w-4 transition-transform opacity-100", sortState === "asc" ? "rotate-180" : ""]),
|
class: cn([
|
||||||
|
"ml-2 h-4 w-4 transition-transform opacity-100",
|
||||||
|
sortState === "asc" ? "rotate-180" : "",
|
||||||
|
disableSort && "opacity-0",
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -58,7 +70,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.asset_id")
|
() => sortable(column, "items.asset_id")
|
||||||
),
|
),
|
||||||
@@ -72,7 +84,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.name")
|
() => sortable(column, "items.name")
|
||||||
),
|
),
|
||||||
@@ -86,7 +98,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.quantity")
|
() => sortable(column, "items.quantity")
|
||||||
),
|
),
|
||||||
@@ -100,7 +112,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.insured")
|
() => sortable(column, "items.insured")
|
||||||
),
|
),
|
||||||
@@ -121,7 +133,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.purchase_price")
|
() => sortable(column, "items.purchase_price")
|
||||||
),
|
),
|
||||||
@@ -136,14 +148,14 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.location")
|
() => sortable(column, "items.location")
|
||||||
),
|
),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const loc = (row.original as ItemSummary).location as { id: string; name: string } | null;
|
const loc = (row.original as ItemSummary).location as { id: string; name: string } | null;
|
||||||
if (loc) {
|
if (loc) {
|
||||||
return h("NuxtLink", { to: `/location/${loc.id}`, class: "hover:underline text-sm" }, () => loc.name);
|
return h("a", { href: `/location/${loc.id}`, class: "hover:underline text-sm" }, loc.name);
|
||||||
}
|
}
|
||||||
return h("div", { class: "text-sm text-muted-foreground" }, "");
|
return h("div", { class: "text-sm text-muted-foreground" }, "");
|
||||||
},
|
},
|
||||||
@@ -156,7 +168,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.archived")
|
() => sortable(column, "items.archived")
|
||||||
),
|
),
|
||||||
@@ -177,7 +189,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.created_at")
|
() => sortable(column, "items.created_at")
|
||||||
),
|
),
|
||||||
@@ -196,7 +208,7 @@ export function makeColumns(t: (key: string) => string, refresh?: () => void): C
|
|||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
variant: "ghost",
|
variant: "ghost",
|
||||||
onClick: () => column.toggleSorting(column.getIsSorted() === "asc"),
|
onClick: () => !disableSort && column.toggleSorting(column.getIsSorted() === "asc"),
|
||||||
},
|
},
|
||||||
() => sortable(column, "items.updated_at")
|
() => sortable(column, "items.updated_at")
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -46,7 +46,9 @@
|
|||||||
v-for="cell in row.getVisibleCells()"
|
v-for="cell in row.getVisibleCells()"
|
||||||
:key="cell.id"
|
:key="cell.id"
|
||||||
:href="
|
:href="
|
||||||
cell.column.id !== 'select' && cell.column.id !== 'actions' ? `/item/${row.original.id}` : undefined
|
cell.column.id !== 'select' && cell.column.id !== 'actions' && cell.column.id !== 'location'
|
||||||
|
? `/item/${row.original.id}`
|
||||||
|
: undefined
|
||||||
"
|
"
|
||||||
:class="cell.column.id === 'select' || cell.column.id === 'actions' ? 'w-10 px-3' : ''"
|
:class="cell.column.id === 'select' || cell.column.id === 'actions' ? 'w-10 px-3' : ''"
|
||||||
:compact="cell.column.id === 'select' || cell.column.id === 'actions'"
|
:compact="cell.column.id === 'select' || cell.column.id === 'actions'"
|
||||||
|
|||||||
@@ -437,6 +437,7 @@
|
|||||||
<SelectValue :placeholder="$t('items.order_by')" />
|
<SelectValue :placeholder="$t('items.order_by')" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
|
<SelectItem value="name"> {{ $t("items.name") }} </SelectItem>
|
||||||
<SelectItem value="createdAt"> {{ $t("items.created_at") }} </SelectItem>
|
<SelectItem value="createdAt"> {{ $t("items.created_at") }} </SelectItem>
|
||||||
<SelectItem value="updatedAt"> {{ $t("items.updated_at") }} </SelectItem>
|
<SelectItem value="updatedAt"> {{ $t("items.updated_at") }} </SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@@ -509,6 +510,7 @@
|
|||||||
:items="items"
|
:items="items"
|
||||||
:location-flat-tree="locationFlatTree"
|
:location-flat-tree="locationFlatTree"
|
||||||
:pagination="pagination"
|
:pagination="pagination"
|
||||||
|
disable-sort
|
||||||
@refresh="async () => search()"
|
@refresh="async () => search()"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in New Issue
Block a user