Path: blob/master/src/packages/next/components/account/config/search/entries.ts
1452 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { IconName } from "@cocalc/frontend/components/icon";6import { search_match, search_split } from "@cocalc/util/misc";78interface Info0 {9path: string;10desc: string;11title: string;12icon?: IconName | "ai";13}1415export interface Info extends Info0 {16search: string;17}1819interface Info1 extends Info0 {20search?: string | object;21}2223const searchInfo: { [path: string]: Info } = {};2425export function register(info: Info1) {26const search = (27info.desc +28" " +29info.path +30" " +31info.title +32" " +33JSON.stringify(info.search ?? "")34).toLowerCase();35searchInfo[info.path] = { ...info, search };36}3738export function search(s: string, allowEmpty?: boolean): Info[] {39const v = search_split(s.toLowerCase().trim());40const result: Info[] = [];41if (v.length == 0 && !allowEmpty) return result;42for (const path in searchInfo) {43if (44v.length == 0 ||45(searchInfo[path].search && search_match(searchInfo[path].search, v))46) {47result.push(searchInfo[path]);48}49}50return result;51}525354