Skip to content

Commit eeb7caf

Browse files
feat(search): enable repository search (#7027)
* feat(search): enable repository search * Undo accidental templateCard changes
1 parent c9f0a5f commit eeb7caf

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/app/src/app/overmind/namespaces/dashboard/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ export const getPage = async ({ actions }: Context, page: sandboxesTypes) => {
10001000
break;
10011001
case sandboxesTypes.SEARCH:
10021002
dashboard.getSearchSandboxes();
1003+
dashboard.getRepositoriesByTeam({ bypassLoading: true });
10031004
break;
10041005
case sandboxesTypes.ALWAYS_ON:
10051006
dashboard.getAlwaysOnSandboxes();

packages/app/src/app/pages/Dashboard/Content/routes/Search/searchItems.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useAppState, useActions } from 'app/overmind';
77
import Fuse from 'fuse.js';
88
import React, { useEffect } from 'react';
99
import { sandboxesTypes } from 'app/overmind/namespaces/dashboard/types';
10+
import type { ProjectFragment as Repository } from 'app/graphql/types';
1011

1112
const useSearchedSandboxes = (query: string) => {
1213
const state = useAppState();
@@ -43,7 +44,19 @@ export const searchIndex = (dashboard: any) => {
4344
}))
4445
.filter(f => f.title);
4546

46-
return new Fuse([...sandboxes, ...folders], {
47+
const repositories = dashboard.repositories?.map((repo: Repository) => {
48+
return {
49+
title: repo.repository.name,
50+
/**
51+
* Due to the lack of description we add the owner so we can at least
52+
* include that in the search query.
53+
*/
54+
description: repo.repository.owner,
55+
...repo,
56+
};
57+
});
58+
59+
return new Fuse([...sandboxes, ...folders, ...(repositories || [])], {
4760
threshold: 0.1,
4861
distance: 1000,
4962
keys: [
@@ -60,14 +73,24 @@ export const useGetItems = ({ query, getFilteredSandboxes }) => {
6073
const foundResults: Array<
6174
SandboxFragmentDashboardFragment | SidebarCollectionDashboardFragment
6275
> = useSearchedSandboxes(query) || [];
76+
6377
// @ts-ignore
6478
const sandboxesInSearch = foundResults.filter(s => !s.path);
6579
// @ts-ignore
6680
const foldersInSearch = foundResults.filter(s => s.path);
81+
// @ts-ignore
82+
const repositoriesInSearch = foundResults.filter(s => s.repository);
83+
6784
const filteredSandboxes: SandboxFragmentDashboardFragment[] = getFilteredSandboxes(
6885
sandboxesInSearch
6986
);
70-
const orderedSandboxes = [...foldersInSearch, ...filteredSandboxes];
87+
88+
const orderedSandboxes = [
89+
...foldersInSearch,
90+
...filteredSandboxes,
91+
...repositoriesInSearch,
92+
];
93+
7194
// @ts-ignore
7295
const items: DashboardGridItem[] =
7396
foundResults != null
@@ -80,6 +103,19 @@ export const useGetItems = ({ query, getFilteredSandboxes }) => {
80103
};
81104
}
82105

106+
// @ts-ignore
107+
if (found.repository) {
108+
return {
109+
type: 'repository',
110+
repository: {
111+
// @ts-ignore
112+
branches: found.branches,
113+
// @ts-ignore
114+
repository: found.repository,
115+
},
116+
};
117+
}
118+
83119
return {
84120
type: 'sandbox',
85121
sandbox: found,

0 commit comments

Comments
 (0)