@@ -7,6 +7,7 @@ import { useAppState, useActions } from 'app/overmind';
7
7
import Fuse from 'fuse.js' ;
8
8
import React , { useEffect } from 'react' ;
9
9
import { sandboxesTypes } from 'app/overmind/namespaces/dashboard/types' ;
10
+ import type { ProjectFragment as Repository } from 'app/graphql/types' ;
10
11
11
12
const useSearchedSandboxes = ( query : string ) => {
12
13
const state = useAppState ( ) ;
@@ -43,7 +44,19 @@ export const searchIndex = (dashboard: any) => {
43
44
} ) )
44
45
. filter ( f => f . title ) ;
45
46
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 || [ ] ) ] , {
47
60
threshold : 0.1 ,
48
61
distance : 1000 ,
49
62
keys : [
@@ -60,14 +73,24 @@ export const useGetItems = ({ query, getFilteredSandboxes }) => {
60
73
const foundResults : Array <
61
74
SandboxFragmentDashboardFragment | SidebarCollectionDashboardFragment
62
75
> = useSearchedSandboxes ( query ) || [ ] ;
76
+
63
77
// @ts -ignore
64
78
const sandboxesInSearch = foundResults . filter ( s => ! s . path ) ;
65
79
// @ts -ignore
66
80
const foldersInSearch = foundResults . filter ( s => s . path ) ;
81
+ // @ts -ignore
82
+ const repositoriesInSearch = foundResults . filter ( s => s . repository ) ;
83
+
67
84
const filteredSandboxes : SandboxFragmentDashboardFragment [ ] = getFilteredSandboxes (
68
85
sandboxesInSearch
69
86
) ;
70
- const orderedSandboxes = [ ...foldersInSearch , ...filteredSandboxes ] ;
87
+
88
+ const orderedSandboxes = [
89
+ ...foldersInSearch ,
90
+ ...filteredSandboxes ,
91
+ ...repositoriesInSearch ,
92
+ ] ;
93
+
71
94
// @ts -ignore
72
95
const items : DashboardGridItem [ ] =
73
96
foundResults != null
@@ -80,6 +103,19 @@ export const useGetItems = ({ query, getFilteredSandboxes }) => {
80
103
} ;
81
104
}
82
105
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
+
83
119
return {
84
120
type : 'sandbox' ,
85
121
sandbox : found ,
0 commit comments