From 221f6f200208e796f64487bb2abd77fa49903780 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+SamTV12345@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:32:40 +0200 Subject: [PATCH] Added sorting for plugins (#6580) --- admin/src/index.css | 9 +++++ admin/src/pages/HomePage.tsx | 76 ++++++++++++++++++++++++++++++------ admin/src/pages/PadPage.tsx | 4 +- admin/src/pages/Plugin.ts | 2 +- 4 files changed, 75 insertions(+), 16 deletions(-) diff --git a/admin/src/index.css b/admin/src/index.css index a038888d7..99a406ee7 100644 --- a/admin/src/index.css +++ b/admin/src/index.css @@ -802,3 +802,12 @@ input, button, select, optgroup, textarea { background-color: var(--etherpad-color); color: white } + +.search-pads{ + text-align: center; +} + +.search-pads-body tr td:last-child { + display: flex; + justify-content: center; +} diff --git a/admin/src/pages/HomePage.tsx b/admin/src/pages/HomePage.tsx index c96b03424..c0d5913ee 100644 --- a/admin/src/pages/HomePage.tsx +++ b/admin/src/pages/HomePage.tsx @@ -6,14 +6,51 @@ import {Trans, useTranslation} from "react-i18next"; import {SearchField} from "../components/SearchField.tsx"; import {Download, Trash} from "lucide-react"; import {IconButton} from "../components/IconButton.tsx"; +import {determineSorting} from "../utils/sorting.ts"; export const HomePage = () => { const pluginsSocket = useStore(state=>state.pluginsSocket) const [plugins,setPlugins] = useState([]) const [installedPlugins, setInstalledPlugins] = useState([]) + const [searchParams, setSearchParams] = useState({ + offset: 0, + limit: 99999, + sortBy: 'name', + sortDir: 'asc', + searchTerm: '' + }) + + const filteredInstallablePlugins = useMemo(()=>{ + return plugins.sort((a, b)=>{ + if(searchParams.sortBy === "version"){ + if(searchParams.sortDir === "asc"){ + return a.version.localeCompare(b.version) + } + return b.version.localeCompare(a.version) + } + + if(searchParams.sortBy === "last-updated"){ + if(searchParams.sortDir === "asc"){ + return a.time.localeCompare(b.time) + } + return b.time.localeCompare(a.time) + } + + + if (searchParams.sortBy === "name") { + if(searchParams.sortDir === "asc"){ + return a.name.localeCompare(b.name) + } + return b.name.localeCompare(a.name) + } + return 0 + }) + }, [plugins, searchParams]) + const sortedInstalledPlugins = useMemo(()=>{ return installedPlugins.sort((a, b)=>{ + if(a.name < b.name){ return -1 } @@ -23,14 +60,8 @@ export const HomePage = () => { return 0 }) - } ,[installedPlugins]) - const [searchParams, setSearchParams] = useState({ - offset: 0, - limit: 99999, - sortBy: 'name', - sortDir: 'asc', - searchTerm: '' - }) + } ,[installedPlugins, searchParams]) + const [searchTerm, setSearchTerm] = useState('') const {t} = useTranslation() @@ -165,16 +196,35 @@ export const HomePage = () => { - + - - + + - {(plugins.length > 0) ? - plugins.map((plugin) => { + {(filteredInstallablePlugins.length > 0) ? + filteredInstallablePlugins.map((plugin) => { return diff --git a/admin/src/pages/PadPage.tsx b/admin/src/pages/PadPage.tsx index 2de3ba5f9..e663603cd 100644 --- a/admin/src/pages/PadPage.tsx +++ b/admin/src/pages/PadPage.tsx @@ -104,7 +104,7 @@ export const PadPage = ()=>{ setSearchTerm(v.target.value)} placeholder={t('ep_admin_pads:ep_adminpads2_search-heading')}/>
{ + setSearchParams({ + ...searchParams, + sortBy: 'name', + sortDir: searchParams.sortDir === "asc"? "desc": "asc" + }) + }}> + { + setSearchParams({ + ...searchParams, + sortBy: 'version', + sortDir: searchParams.sortDir === "asc"? "desc": "asc" + }) + }}>{ + setSearchParams({ + ...searchParams, + sortBy: 'last-updated', + sortDir: searchParams.sortDir === "asc"? "desc": "asc" + }) + }}>
{plugin.name} {plugin.description}
- + - + { pads?.results?.map((pad)=>{ return diff --git a/admin/src/pages/Plugin.ts b/admin/src/pages/Plugin.ts index 3188c247f..f5563863b 100644 --- a/admin/src/pages/Plugin.ts +++ b/admin/src/pages/Plugin.ts @@ -20,7 +20,7 @@ export type SearchParams = { searchTerm: string, offset: number, limit: number, - sortBy: 'name'|'version', + sortBy: 'name'|'version'|'last-updated', sortDir: 'asc'|'desc' }
{ setSearchParams({ ...searchParams, @@ -136,7 +136,7 @@ export const PadPage = ()=>{