From 089682c08d40dbd527a1cbb1a18b8c277209534a Mon Sep 17 00:00:00 2001 From: samunohito <46447427+samunohito@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:10:42 +0900 Subject: [PATCH] support sort --- .../backend/src/core/CustomEmojiService.ts | 4 +- .../api/endpoints/admin/emoji/v2/list.ts | 6 +- .../frontend/src/components/MkTagItem.vue | 20 ++++-- .../admin/custom-emojis-grid.local.list.vue | 64 +++++++++++++++---- packages/misskey-js/src/autogen/types.ts | 2 +- 5 files changed, 71 insertions(+), 25 deletions(-) diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index c0444055c1..193bb4831d 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -64,7 +64,7 @@ export type FetchEmojisParams = { page?: number; sort?: { key : FetchEmojisSortKeys; - order : 'ASC' | 'DESC'; + direction : 'ASC' | 'DESC'; }[] } @@ -508,7 +508,7 @@ export class CustomEmojiService implements OnApplicationShutdown { if (params?.sort) { for (const sort of params.sort) { - builder.addOrderBy(`emoji.${sort.key}`, sort.order); + builder.addOrderBy(`emoji.${sort.key}`, sort.direction); } } else { builder.addOrderBy('emoji.id', 'DESC'); diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/v2/list.ts b/packages/backend/src/server/api/endpoints/admin/emoji/v2/list.ts index d7c3dc0057..c2139c37de 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/v2/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/v2/list.ts @@ -82,13 +82,13 @@ export const paramDef = { ], default: 'id', }, - order: { + direction: { type: 'string', enum: ['ASC', 'DESC'], default: 'DESC', }, }, - required: ['key', 'order'], + required: ['key', 'direction'], }, }, }, @@ -128,7 +128,7 @@ export default class extends Endpoint { // eslint- params.page = ps.page; params.sort = ps.sort?.map(it => ({ key: it.key, - order: it.order, + direction: it.direction, })); const result = await this.customEmojiService.fetchEmojis(params); diff --git a/packages/frontend/src/components/MkTagItem.vue b/packages/frontend/src/components/MkTagItem.vue index 52e4b0b034..da2152b959 100644 --- a/packages/frontend/src/components/MkTagItem.vue +++ b/packages/frontend/src/components/MkTagItem.vue @@ -3,7 +3,7 @@ {{ content }} - + @@ -24,15 +24,15 @@ defineProps<{ diff --git a/packages/frontend/src/pages/admin/custom-emojis-grid.local.list.vue b/packages/frontend/src/pages/admin/custom-emojis-grid.local.list.vue index 36ba429ab6..010c0559c7 100644 --- a/packages/frontend/src/pages/admin/custom-emojis-grid.local.list.vue +++ b/packages/frontend/src/pages/admin/custom-emojis-grid.local.list.vue @@ -65,13 +65,15 @@
- + @@ -152,6 +154,7 @@ import MkSelect from '@/components/MkSelect.vue'; import { deviceKind } from '@/scripts/device-kind.js'; import { GridSetting } from '@/components/grid/grid.js'; import MkTagItem from '@/components/MkTagItem.vue'; +import { MenuItem } from '@/types/menu.js'; type GridItem = { checked: boolean; @@ -171,18 +174,20 @@ type GridItem = { originalUrl?: string | null; } -type GridSortOrderKey = - 'name' | - 'category' | - 'aliases' | - 'type' | - 'license' | - 'isSensitive' | - 'localOnly' | - 'updatedAt'; +const gridSortOrderKeys = [ + 'name', + 'category', + 'aliases', + 'type', + 'license', + 'isSensitive', + 'localOnly', + 'updatedAt', +]; +type GridSortOrderKey = typeof gridSortOrderKeys[number]; type GridSortOrder = { - column: GridSortOrderKey; + key: GridSortOrderKey; direction: 'ASC' | 'DESC'; } @@ -237,7 +242,6 @@ const querySensitive = ref(null); const queryLocalOnly = ref(null); const previousQuery = ref(undefined); const sortOrders = ref([]); -sortOrders.value.push({ column: 'updatedAt', direction: 'DESC' }, { column: 'name', direction: 'ASC' }); const requestLogs = ref([]); const gridItems = ref([]); @@ -352,6 +356,36 @@ function onGridResetButtonClicked() { refreshGridItems(); } +function onToggleSortOrderButtonClicked(order: GridSortOrder) { + console.log(order); + switch (order.direction) { + case 'ASC': + order.direction = 'DESC'; + break; + case 'DESC': + order.direction = 'ASC'; + break; + } +} + +function onRemoveSortOrderButtonClicked(key: GridSortOrderKey) { + sortOrders.value = sortOrders.value.filter(it => it.key !== key); +} + +function onAddSortOrderButtonClicked(ev: MouseEvent) { + const menuItems: MenuItem[] = gridSortOrderKeys + .filter(key => !sortOrders.value.map(it => it.key).includes(key)) + .map(it => { + return { + text: it, + action: () => { + sortOrders.value.push({ key: it, direction: 'ASC' }); + }, + }; + }); + os.contextMenu(menuItems, ev); +} + async function onSearchButtonClicked() { await refreshCustomEmojis(); } @@ -529,6 +563,7 @@ async function refreshCustomEmojis() { query: query, limit: limit, page: currentPage.value, + sort: sortOrders.value.map(({ key, direction }) => ({ key: key as any, direction })), }), () => { }, @@ -654,6 +689,7 @@ onMounted(async () => { flex-direction: row; align-items: flex-start; justify-content: flex-start; + flex-wrap: wrap; gap: 8px; } diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index f0ce974443..4698f98121 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -6981,7 +6981,7 @@ export type operations = { * @default DESC * @enum {string} */ - order: 'ASC' | 'DESC'; + direction: 'ASC' | 'DESC'; })[]; }; };