Skip to content

Commit f653a82

Browse files
authored
Merge pull request #2526 from appwrite/feat-SER-443-make-api-endpoint-searchable-command-center
feat: show project Go to Settings for credential queries
2 parents 52111d4 + 9d46d5c commit f653a82

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

src/lib/commandCenter/searchers/projects.ts

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,64 @@ import { sdk } from '$lib/stores/sdk';
44
import { Query } from '@appwrite.io/console';
55
import { get } from 'svelte/store';
66
import type { Searcher } from '../commands';
7+
import { project } from '$routes/(console)/project-[region]-[project]/store';
78
import { base } from '$app/paths';
89

910
export const projectsSearcher = (async (query: string) => {
11+
const q = query.toLowerCase().trim();
12+
const keywords = [
13+
'endpoint',
14+
'api key',
15+
'api-key',
16+
'apikey',
17+
'project id',
18+
'project-id',
19+
'api end'
20+
];
21+
22+
const wantsCredentials = keywords.some((k) => q.includes(k));
23+
24+
if (wantsCredentials) {
25+
const curr = get(project);
26+
if (curr?.$id) {
27+
return [
28+
{
29+
label: 'Go to Settings',
30+
callback: () => {
31+
goto(`${base}/project-${curr.region}-${curr.$id}/settings`);
32+
},
33+
group: 'navigation'
34+
}
35+
];
36+
}
37+
return [];
38+
}
39+
1040
const { projects } = await sdk.forConsole.projects.list({
1141
queries: [Query.equal('teamId', get(organization).$id), Query.orderDesc('')]
1242
});
1343

1444
return projects
15-
.filter((project) => project.name.toLowerCase().includes(query.toLowerCase()))
45+
.filter((project) => {
46+
const searchable = [project.name, project.$id, project.region]
47+
.filter(Boolean)
48+
.join(' ')
49+
.toLowerCase();
50+
51+
const words = q.split(/\s+/).filter(Boolean);
52+
return words.every((w) => searchable.includes(w));
53+
})
1654
.map((project) => {
55+
const href = `${base}/project-${project.region}-${project.$id}`;
56+
57+
const label = project.name;
58+
1759
return {
18-
label: project.name,
60+
label,
1961
callback: () => {
20-
goto(`${base}/project-${project.region}-${project.$id}`);
62+
goto(href);
2163
},
2264
group: 'projects'
23-
} as const;
65+
};
2466
});
2567
}) satisfies Searcher;

0 commit comments

Comments
 (0)