ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(palette): Favorites + Recent entity visits sections
Juan Denisfd775fc62909
diff --git a/frontend/src/components/CommandPalette.jsx b/frontend/src/components/CommandPalette.jsxindex 5edf4217..fdd36ec4 100644--- a/frontend/src/components/CommandPalette.jsx+++ b/frontend/src/components/CommandPalette.jsx@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, useMemo } from 'react';import { useNavigate } from 'react-router-dom';import {History, SlidersHorizontal, LayoutGrid, Zap, Server, Globe,- Database, Boxes, Puzzle, BookOpen, KeyRound, Clock, ExternalLink,+ Database, Boxes, Puzzle, BookOpen, KeyRound, Clock, ExternalLink, Star,} from 'lucide-react';import api from '../services/api';import {@@ -23,14 +23,16 @@ import { COMMAND_ACTIONS } from '../data/commandActions';import { DOCS_LINKS } from '../utils/docsLinks';import { scoreItem } from '../utils/paletteScore';import { frecencyScore, recordUse, recentIds } from '../utils/paletteFrecency';+import { getFavorites, getRecents } from '../utils/recents';// Group order in the list, plus a per-category icon and a scoring weight so the// headline categories (Settings, Pages, Actions) outrank raw entity hits on ties.const GROUP_ORDER = [- 'Recently used', 'Settings', 'Pages', 'Actions', 'Services', 'Servers',+ 'Favorites', 'Recently used', 'Settings', 'Pages', 'Actions', 'Services', 'Servers','Domains', 'Databases', 'Sites', 'Cron Jobs', 'Vaults', 'Extensions', 'Docs',];const CATEGORY_ICONS = {+ Favorites: Star,'Recently used': History,Settings: SlidersHorizontal,Pages: LayoutGrid,@@ -46,6 +48,7 @@ const CATEGORY_ICONS = {Docs: BookOpen,};const CATEGORY_WEIGHT = {+ Favorites: 5,Settings: 6, Pages: 4, Actions: 4, Services: 2, Servers: 2, Domains: 2,Databases: 2, Sites: 2, 'Cron Jobs': 1, Vaults: 1, Extensions: 1, Docs: 0,};@@ -55,6 +58,11 @@ const ENTITY_CATEGORY = {database: 'Databases', site: 'Sites', cron: 'Cron Jobs',extension: 'Extensions', plugin: 'Extensions', vault: 'Vaults',};+// Visit/favorite entry `type` -> human sublabel.+const TYPE_LABEL = {+ service: 'Service', server: 'Server', monitor: 'Monitor',+ workspace: 'Workspace', project: 'Project', domain: 'Domain',+};// Docs entries derived from the single docsLinks map (plan 40). Hidden under// White Label since they point at the public serverkit.ai docs.@@ -168,6 +176,31 @@ const CommandPalette = ({ open, onClose }) => {}));}, [whiteLabel]);+ // --- Favorites + visited entities (localStorage, refreshed per open) -----+ const favoriteItems = useMemo(+ () => (open ? getFavorites() : []).map((e) => ({+ id: `fav:${e.type}:${e.id}`,+ label: e.label,+ sublabel: TYPE_LABEL[e.type] || e.type,+ keywords: `${e.type} favorite starred`,+ path: e.path,+ category: 'Favorites',+ })),+ [open],+ );++ const visitItems = useMemo(+ () => (open ? getRecents(6) : []).map((e) => ({+ id: `visit:${e.type}:${e.id}`,+ label: e.label,+ sublabel: TYPE_LABEL[e.type] || e.type,+ keywords: `${e.type} recent visited`,+ path: e.path,+ category: 'Recently used',+ })),+ [open],+ );+// --- Async entity provider (backend /search), debounced 200ms ------------useEffect(() => {if (!open) return undefined;@@ -200,8 +233,8 @@ const CommandPalette = ({ open, onClose }) => {const results = useMemo(() => {const t = term.trim();- // Empty query: recently used + suggestions (bare), or the full small set- // for a prefix mode.+ // Empty query: favorites + recent visits + frecency recents + suggested+ // actions (bare), or the full small set for a prefix mode.if (!t) {if (mode === 'actions') return capGroups(actionItems);if (mode === 'docs') return capGroups(docItems);@@ -215,14 +248,20 @@ const CommandPalette = ({ open, onClose }) => {? recents: pageItems.slice(0, 6).map((i) => ({ ...i, category: 'Recently used' }));const suggestions = actionItems.filter((a) => a.suggested).slice(0, 4);- return capGroups([...base, ...suggestions], 8, OVERALL_CAP);+ return capGroups([+ ...favoriteItems.slice(0, 4),+ ...visitItems,+ ...base,+ ...suggestions,+ ], 8, OVERALL_CAP);}const syncPool = mode === 'actions'? actionItems: mode === 'docs'? docItems- : [...settingsItems, ...pageItems, ...actionItems, ...pluginItems, ...docItems];+ : [...settingsItems, ...pageItems, ...actionItems, ...pluginItems, ...docItems,+ ...favoriteItems, ...visitItems];const scored = [];for (const item of syncPool) {diff --git a/frontend/src/hooks/useRecordVisit.js b/frontend/src/hooks/useRecordVisit.jsnew file mode 100644index 00000000..1a33972c--- /dev/null+++ b/frontend/src/hooks/useRecordVisit.js@@ -0,0 +1,18 @@+import { useEffect } from 'react';+import { recordVisit } from '@/utils/recents';++// Records a detail-page visit for the command palette's Recent section.+// Call once per detail page with the entity's stable identity:+//+// useRecordVisit(service && { type: 'service', id: service.id, path: `/services/${service.id}`, label: service.name });+//+// Pass null while the entity is still loading — the visit is recorded once+// the label is known.+export function useRecordVisit(entry) {+ useEffect(() => {+ if (entry) recordVisit(entry);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [entry?.type, entry?.id, entry?.label]);+}++export default useRecordVisit;diff --git a/frontend/src/utils/recents.js b/frontend/src/utils/recents.jsnew file mode 100644index 00000000..6bb3e217--- /dev/null+++ b/frontend/src/utils/recents.js@@ -0,0 +1,66 @@+// Recently visited entities + pinned favorites, kept in localStorage so the+// command palette (and later the sidebar) can surface them. Client-only —+// same stance as paletteFrecency: cross-device sync is out of scope.+//+// An entry is { type, id, path, label, at } — e.g.+// { type: 'service', id: 12, path: '/services/12', label: 'shop-api', at: 1733… }++const RECENTS_KEY = 'serverkit:recents';+const FAVORITES_KEY = 'serverkit:favorites';+const MAX_RECENTS = 10;++function load(key) {+ try {+ const raw = localStorage.getItem(key);+ const parsed = raw ? JSON.parse(raw) : null;+ return Array.isArray(parsed) ? parsed : [];+ } catch {+ return [];+ }+}++function save(key, entries) {+ try {+ localStorage.setItem(key, JSON.stringify(entries));+ } catch {+ /* storage full / disabled — a nicety, never fatal */+ }+}++const sameEntry = (a, b) => a.type === b.type && String(a.id) === String(b.id);++/** Record a detail-page visit. Most recent first, deduped by type+id. */+export function recordVisit({ type, id, path, label }) {+ if (!type || id == null || !path) return;+ const entry = { type, id, path, label: label || String(id), at: Date.now() };+ const rest = load(RECENTS_KEY).filter((e) => !sameEntry(e, entry));+ save(RECENTS_KEY, [entry, ...rest].slice(0, MAX_RECENTS));+ // Keep the label fresh if this entity is a favorite.+ const favorites = load(FAVORITES_KEY);+ if (favorites.some((e) => sameEntry(e, entry))) {+ save(FAVORITES_KEY, favorites.map((e) => (sameEntry(e, entry) ? { ...e, label: entry.label, path } : e)));+ }+}++export function getRecents(limit = MAX_RECENTS) {+ return load(RECENTS_KEY).slice(0, limit);+}++export function getFavorites() {+ return load(FAVORITES_KEY);+}++export function isFavorite(type, id) {+ return load(FAVORITES_KEY).some((e) => e.type === type && String(e.id) === String(id));+}++/** Toggle a favorite; returns the new state (true = now a favorite). */+export function toggleFavorite({ type, id, path, label }) {+ const entry = { type, id, path, label: label || String(id), at: Date.now() };+ const favorites = load(FAVORITES_KEY);+ const exists = favorites.some((e) => sameEntry(e, entry));+ save(FAVORITES_KEY, exists+ ? favorites.filter((e) => !sameEntry(e, entry))+ : [entry, ...favorites]);+ return !exists;+}