mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
feat: add external dep sorting to moderation queue (#6161)
* feat: add external dep sorting to moderation queue * prepr
This commit is contained in:
@@ -48,6 +48,16 @@
|
|||||||
<span class="text-sm text-secondary">Requesting</span>
|
<span class="text-sm text-secondary">Requesting</span>
|
||||||
<Badge :type="queueEntry.project.requested_status" class="text-sm" />
|
<Badge :type="queueEntry.project.requested_status" class="text-sm" />
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="showExternalDependencies"
|
||||||
|
v-tooltip="'External dependencies'"
|
||||||
|
class="flex items-center gap-1 rounded-full border border-solid border-surface-5 bg-surface-4 px-2.5 py-1"
|
||||||
|
>
|
||||||
|
<FileIcon aria-hidden="true" class="size-4 text-secondary" />
|
||||||
|
<span class="text-sm font-medium text-secondary">
|
||||||
|
{{ queueEntry.external_dependencies_count }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="queueEntry.ownership?.kind === 'user'">
|
<div v-if="queueEntry.ownership?.kind === 'user'">
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
@@ -119,7 +129,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ClipboardCopyIcon, LinkIcon, ScaleIcon } from '@modrinth/assets'
|
import { ClipboardCopyIcon, FileIcon, LinkIcon, ScaleIcon } from '@modrinth/assets'
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Badge,
|
Badge,
|
||||||
@@ -151,6 +161,7 @@ const formatDateTimeFull = useFormatDateTime({
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
queueEntry: ModerationProject
|
queueEntry: ModerationProject
|
||||||
|
showExternalDependencies?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|||||||
@@ -199,17 +199,20 @@ export type ModerationOwnership = ModerationOwnershipUser | ModerationOwnershipO
|
|||||||
|
|
||||||
export interface ProjectWithOwnership {
|
export interface ProjectWithOwnership {
|
||||||
ownership: ModerationOwnership
|
ownership: ModerationOwnership
|
||||||
|
external_dependencies_count: number
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModerationProject {
|
export interface ModerationProject {
|
||||||
project: any
|
project: any
|
||||||
ownership: ModerationOwnership | null
|
ownership: ModerationOwnership | null
|
||||||
|
external_dependencies_count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toModerationProjects(projects: ProjectWithOwnership[]): ModerationProject[] {
|
export function toModerationProjects(projects: ProjectWithOwnership[]): ModerationProject[] {
|
||||||
return projects.map(({ ownership, ...project }) => ({
|
return projects.map(({ ownership, external_dependencies_count, ...project }) => ({
|
||||||
project,
|
project,
|
||||||
ownership: ownership ?? null,
|
ownership: ownership ?? null,
|
||||||
|
external_dependencies_count: external_dependencies_count,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
<Combobox
|
<Combobox
|
||||||
v-model="currentSortType"
|
v-model="currentSortType"
|
||||||
class="!w-full flex-grow sm:!w-[150px] sm:flex-grow-0 lg:!w-[150px]"
|
class="!w-full flex-grow sm:!w-[240px] sm:flex-grow-0"
|
||||||
:options="sortTypes"
|
:options="sortTypes"
|
||||||
:placeholder="formatMessage(commonMessages.sortByLabel)"
|
:placeholder="formatMessage(commonMessages.sortByLabel)"
|
||||||
@select="goToPage(1)"
|
@select="goToPage(1)"
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<template #selected>
|
<template #selected>
|
||||||
<span class="flex flex-row gap-2 align-middle font-semibold">
|
<span class="flex flex-row gap-2 align-middle font-semibold">
|
||||||
<SortAscIcon
|
<SortAscIcon
|
||||||
v-if="currentSortType === 'Oldest'"
|
v-if="currentSortType === 'Oldest' || currentSortType === 'Least external deps'"
|
||||||
class="size-5 flex-shrink-0 text-secondary"
|
class="size-5 flex-shrink-0 text-secondary"
|
||||||
/>
|
/>
|
||||||
<SortDescIcon v-else class="size-5 flex-shrink-0 text-secondary" />
|
<SortDescIcon v-else class="size-5 flex-shrink-0 text-secondary" />
|
||||||
@@ -113,6 +113,7 @@
|
|||||||
v-else
|
v-else
|
||||||
:key="item.project.id"
|
:key="item.project.id"
|
||||||
:queue-entry="item"
|
:queue-entry="item"
|
||||||
|
:show-external-dependencies="currentFilterType === MODPACK_FILTER_TYPE"
|
||||||
@start-from-project="startFromProject"
|
@start-from-project="startFromProject"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -246,12 +247,27 @@ const filterTypes: ComboboxOption<string>[] = [
|
|||||||
const filterTypeValues = filterTypes.map((option) => option.value)
|
const filterTypeValues = filterTypes.map((option) => option.value)
|
||||||
const DEFAULT_FILTER_TYPE = filterTypeValues[0]
|
const DEFAULT_FILTER_TYPE = filterTypeValues[0]
|
||||||
|
|
||||||
const sortTypes: ComboboxOption<string>[] = [
|
const MODPACK_FILTER_TYPE = 'Modpacks'
|
||||||
|
|
||||||
|
const baseSortTypes: ComboboxOption<string>[] = [
|
||||||
{ value: 'Oldest', label: 'Oldest' },
|
{ value: 'Oldest', label: 'Oldest' },
|
||||||
{ value: 'Newest', label: 'Newest' },
|
{ value: 'Newest', label: 'Newest' },
|
||||||
]
|
]
|
||||||
const sortTypeValues = sortTypes.map((option) => option.value)
|
const modpackSortTypes: ComboboxOption<string>[] = [
|
||||||
const DEFAULT_SORT_TYPE = sortTypeValues[0]
|
{ value: 'Most external deps', label: 'Most external deps' },
|
||||||
|
{ value: 'Least external deps', label: 'Least external deps' },
|
||||||
|
]
|
||||||
|
const DEFAULT_SORT_TYPE = baseSortTypes[0].value
|
||||||
|
const modpackSortTypeValues = modpackSortTypes.map((option) => option.value)
|
||||||
|
|
||||||
|
const sortTypes = computed(() => {
|
||||||
|
if (currentFilterType.value === MODPACK_FILTER_TYPE) {
|
||||||
|
return [...baseSortTypes, ...modpackSortTypes]
|
||||||
|
}
|
||||||
|
return baseSortTypes
|
||||||
|
})
|
||||||
|
|
||||||
|
const sortTypeValues = computed(() => sortTypes.value.map((option) => option.value))
|
||||||
|
|
||||||
const itemsPerPageOptions: ComboboxOption<number>[] = [
|
const itemsPerPageOptions: ComboboxOption<number>[] = [
|
||||||
{ value: 20, label: '20' },
|
{ value: 20, label: '20' },
|
||||||
@@ -269,17 +285,31 @@ function parseFilterTypeFromQuery(value: LocationQueryValue | LocationQueryValue
|
|||||||
return filterTypeValues.includes(query) ? query : DEFAULT_FILTER_TYPE
|
return filterTypeValues.includes(query) ? query : DEFAULT_FILTER_TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSortTypeFromQuery(value: LocationQueryValue | LocationQueryValue[]): string {
|
function parseSortTypeFromQuery(
|
||||||
|
value: LocationQueryValue | LocationQueryValue[],
|
||||||
|
filterType: string,
|
||||||
|
): string {
|
||||||
const query = queryAsStringOrEmpty(value)
|
const query = queryAsStringOrEmpty(value)
|
||||||
return sortTypeValues.includes(query) ? query : DEFAULT_SORT_TYPE
|
const validValues = [
|
||||||
|
...baseSortTypes.map((option) => option.value),
|
||||||
|
...(filterType === MODPACK_FILTER_TYPE ? modpackSortTypeValues : []),
|
||||||
|
]
|
||||||
|
return validValues.includes(query) ? query : DEFAULT_SORT_TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentFilterType = ref(parseFilterTypeFromQuery(route.query.filter))
|
const currentFilterType = ref(parseFilterTypeFromQuery(route.query.filter))
|
||||||
const currentSortType = ref(parseSortTypeFromQuery(route.query.sort))
|
const currentSortType = ref(parseSortTypeFromQuery(route.query.sort, currentFilterType.value))
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
currentFilterType,
|
currentFilterType,
|
||||||
(newFilter) => {
|
(newFilter) => {
|
||||||
|
if (
|
||||||
|
newFilter !== MODPACK_FILTER_TYPE &&
|
||||||
|
modpackSortTypeValues.includes(currentSortType.value)
|
||||||
|
) {
|
||||||
|
currentSortType.value = DEFAULT_SORT_TYPE
|
||||||
|
}
|
||||||
|
|
||||||
const currentQuery = { ...route.query }
|
const currentQuery = { ...route.query }
|
||||||
if (newFilter && newFilter !== DEFAULT_FILTER_TYPE) {
|
if (newFilter && newFilter !== DEFAULT_FILTER_TYPE) {
|
||||||
currentQuery.filter = newFilter
|
currentQuery.filter = newFilter
|
||||||
@@ -326,7 +356,7 @@ watch(
|
|||||||
watch(
|
watch(
|
||||||
() => route.query.sort,
|
() => route.query.sort,
|
||||||
(newSortParam) => {
|
(newSortParam) => {
|
||||||
const newValue = parseSortTypeFromQuery(newSortParam)
|
const newValue = parseSortTypeFromQuery(newSortParam, currentFilterType.value)
|
||||||
if (currentSortType.value !== newValue) {
|
if (currentSortType.value !== newValue) {
|
||||||
currentSortType.value = newValue
|
currentSortType.value = newValue
|
||||||
}
|
}
|
||||||
@@ -423,7 +453,11 @@ const typeFiltered = computed(() => {
|
|||||||
const filteredProjects = computed(() => {
|
const filteredProjects = computed(() => {
|
||||||
const filtered = [...typeFiltered.value]
|
const filtered = [...typeFiltered.value]
|
||||||
|
|
||||||
if (currentSortType.value === 'Oldest') {
|
if (currentSortType.value === 'Most external deps') {
|
||||||
|
filtered.sort((a, b) => b.external_dependencies_count - a.external_dependencies_count)
|
||||||
|
} else if (currentSortType.value === 'Least external deps') {
|
||||||
|
filtered.sort((a, b) => a.external_dependencies_count - b.external_dependencies_count)
|
||||||
|
} else if (currentSortType.value === 'Oldest') {
|
||||||
filtered.sort((a, b) => {
|
filtered.sort((a, b) => {
|
||||||
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
||||||
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
||||||
|
|||||||
Reference in New Issue
Block a user