Skip to content

Commit 2003299

Browse files
committed
show only project Go to Settings for credential queries
1 parent 833563e commit 2003299

3 files changed

Lines changed: 61 additions & 15 deletions

File tree

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,71 @@
11
import { goto } from '$app/navigation';
22
import { organization } from '$lib/stores/organization';
3-
import { sdk } from '$lib/stores/sdk';
3+
import { sdk, getApiEndpoint } 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 wantsCredentials =
13+
q.includes('endpoint') ||
14+
q.includes('api key') ||
15+
q.includes('api-key') ||
16+
q.includes('apikey') ||
17+
q.includes('project id') ||
18+
q.includes('project-id') ||
19+
q === 'id' ||
20+
q.endsWith(' id') ||
21+
q.startsWith('end') ||
22+
q.includes('api end') ||
23+
(q.includes('api') && q.includes('end'));
24+
25+
if (wantsCredentials) {
26+
const curr = get(project);
27+
if (curr?.$id) {
28+
return [
29+
{
30+
label: 'Go to Settings',
31+
callback: () => {
32+
goto(`${base}/project-${curr.region}-${curr.$id}/settings`);
33+
},
34+
group: 'navigation'
35+
}
36+
];
37+
}
38+
return [];
39+
}
40+
1041
const { projects } = await sdk.forConsole.projects.list({
1142
queries: [Query.equal('teamId', get(organization).$id), Query.orderDesc('')]
1243
});
1344

1445
return projects
15-
.filter((project) => project.name.toLowerCase().includes(query.toLowerCase()))
16-
.map((project) => {
17-
return {
18-
label: project.name,
19-
callback: () => {
20-
goto(`${base}/project-${project.region}-${project.$id}`);
21-
},
22-
group: 'projects'
23-
} as const;
46+
.filter((project) => {
47+
const endpoint = getApiEndpoint(project.region);
48+
const searchable = [project.name, project.$id, project.region, endpoint]
49+
.filter(Boolean)
50+
.join(' ')
51+
.toLowerCase();
52+
53+
const words = q.split(/\s+/).filter(Boolean);
54+
return words.every((w) => searchable.includes(w));
55+
})
56+
.flatMap((project) => {
57+
const href = `${base}/project-${project.region}-${project.$id}`;
58+
59+
const label = project.name;
60+
61+
return [
62+
{
63+
label,
64+
callback: () => {
65+
goto(href);
66+
},
67+
group: 'projects'
68+
}
69+
];
2470
});
2571
}) satisfies Searcher;

src/lib/components/id.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
}
3030
}
3131
32-
export function truncateText(node: HTMLElement) {
33-
let originalText = node.textContent;
32+
export function truncateText(node: HTMLElement, text?: string) {
33+
let originalText = text ?? node.textContent;
3434
3535
function checkOverflow() {
3636
node.textContent = originalText;
@@ -70,8 +70,8 @@
7070
window.addEventListener('resize', debouncedCheck);
7171
7272
return {
73-
update() {
74-
originalText = node.textContent;
73+
update(newText?: string) {
74+
originalText = newText ?? node.textContent;
7575
addToBatch(checkOverflow);
7676
},
7777
destroy() {

src/lib/components/regionEndpoint.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
class="text u-line-height-1-5"
3939
style:overflow="hidden"
4040
style:word-break="break-all"
41-
use:truncateText
41+
use:truncateText={region?.name}
4242
style:font-family="unset">
4343
{region?.name}
4444
</span>

0 commit comments

Comments
 (0)