CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/account/config/search/entries.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { IconName } from "@cocalc/frontend/components/icon";
7
import { search_match, search_split } from "@cocalc/util/misc";
8
9
interface Info0 {
10
path: string;
11
desc: string;
12
title: string;
13
icon?: IconName | "ai";
14
}
15
16
export interface Info extends Info0 {
17
search: string;
18
}
19
20
interface Info1 extends Info0 {
21
search?: string | object;
22
}
23
24
const searchInfo: { [path: string]: Info } = {};
25
26
export function register(info: Info1) {
27
const search = (
28
info.desc +
29
" " +
30
info.path +
31
" " +
32
info.title +
33
" " +
34
JSON.stringify(info.search ?? "")
35
).toLowerCase();
36
searchInfo[info.path] = { ...info, search };
37
}
38
39
export function search(s: string, allowEmpty?: boolean): Info[] {
40
const v = search_split(s.toLowerCase().trim());
41
const result: Info[] = [];
42
if (v.length == 0 && !allowEmpty) return result;
43
for (const path in searchInfo) {
44
if (
45
v.length == 0 ||
46
(searchInfo[path].search && search_match(searchInfo[path].search, v))
47
) {
48
result.push(searchInfo[path]);
49
}
50
}
51
return result;
52
}
53
54