Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions src/lib/commandCenter/searchers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,64 @@ import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { base } from '$app/paths';

export const projectsSearcher = (async (query: string) => {
const q = query.toLowerCase().trim();
const keywords = [
'endpoint',
'api key',
'api-key',
'apikey',
'project id',
'project-id',
'api end'
];

const wantsCredentials = keywords.some((k) => q.includes(k));

if (wantsCredentials) {
const curr = get(project);
if (curr?.$id) {
return [
{
label: 'Go to Settings',
callback: () => {
goto(`${base}/project-${curr.region}-${curr.$id}/settings`);
},
group: 'navigation'
}
];
}
return [];
}

const { projects } = await sdk.forConsole.projects.list({
queries: [Query.equal('teamId', get(organization).$id), Query.orderDesc('')]
});

return projects
.filter((project) => project.name.toLowerCase().includes(query.toLowerCase()))
.filter((project) => {
const searchable = [project.name, project.$id, project.region]
.filter(Boolean)
.join(' ')
.toLowerCase();

const words = q.split(/\s+/).filter(Boolean);
return words.every((w) => searchable.includes(w));
})
.map((project) => {
const href = `${base}/project-${project.region}-${project.$id}`;

const label = project.name;

return {
label: project.name,
label,
callback: () => {
goto(`${base}/project-${project.region}-${project.$id}`);
goto(href);
},
group: 'projects'
} as const;
};
});
}) satisfies Searcher;
8 changes: 4 additions & 4 deletions src/lib/components/id.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
}
}
export function truncateText(node: HTMLElement) {
let originalText = node.textContent;
export function truncateText(node: HTMLElement, text?: string) {
let originalText = text ?? node.textContent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? 🤔

actions should always work with elements and usually shouldnt have a new context passed 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Without the param, update doesn’t trigger when the slot text changes,so when switching projects via the breadcrumb, the flag re-renders but the region text stays stale until a remount or refresh. 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its fixed since we removed the regional name here , reverting 👍

function checkOverflow() {
node.textContent = originalText;
Expand Down Expand Up @@ -70,8 +70,8 @@
window.addEventListener('resize', debouncedCheck);
return {
update() {
originalText = node.textContent;
update(newText?: string) {
originalText = newText ?? node.textContent;
addToBatch(checkOverflow);
},
destroy() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/regionEndpoint.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class="text u-line-height-1-5"
style:overflow="hidden"
style:word-break="break-all"
use:truncateText
use:truncateText={region?.name}
style:font-family="unset">
{region?.name}
</span>
Expand Down