@@ -50,7 +50,7 @@ function highlightSubstring(str, substr) {
50
50
}
51
51
52
52
const Packages = ( ) => {
53
- const [ allPackages , setAllPackages ] = useState ( [ ] ) ;
53
+ const [ allPackages , setAllPackages ] = useState ( { } ) ;
54
54
const [ latestPackages , setLatestPackages ] = useState ( [ ] ) ;
55
55
const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
56
56
@@ -63,13 +63,7 @@ const Packages = () => {
63
63
const data = await response . json ( ) ;
64
64
65
65
if ( typeof data === "object" && data !== null ) {
66
- // Convert the object into an array of { pkg_name, repositories } objects
67
- const packagesArray = Object . entries ( data ) . map ( ( [ name , repos ] ) => ( {
68
- name,
69
- repos,
70
- } ) ) ;
71
-
72
- setAllPackages ( packagesArray ) ;
66
+ setAllPackages ( Object . fromEntries ( Object . entries ( data ) . map ( ( [ key , value ] ) => [ key . toLowerCase ( ) , value ] ) ) ) ;
73
67
} else {
74
68
console . error ( "Invalid data format. Expected an object." ) ;
75
69
}
@@ -110,28 +104,24 @@ const Packages = () => {
110
104
111
105
const searchTermLower = searchTerm . toLowerCase ( ) ;
112
106
var filteredPackages = [ ] ;
113
- if ( searchTerm . length >= 3 ) {
114
- // For queries with three or more characters, search the entire string for a match
115
- filteredPackages = allPackages . filter ( ( pkg ) =>
116
- pkg . name . toLowerCase ( ) . includes ( searchTermLower )
117
- ) ;
118
- } else if ( searchTerm . length > 0 ) {
119
- // For queries with less than three characters,
120
- // only search if the package name starts with the query for performance reasons
121
- filteredPackages = allPackages . filter ( ( pkg ) =>
122
- pkg . name . toLowerCase ( ) . startsWith ( searchTermLower )
123
- ) ;
107
+ var inclusionCriteria ;
108
+ if ( searchTerm . length > 0 ) {
109
+ if ( searchTerm . length >= 3 ) {
110
+ inclusionCriteria = ( name ) => name . includes ( searchTermLower ) ;
111
+ } else {
112
+ inclusionCriteria = ( name ) => name . startsWith ( searchTermLower ) ;
113
+ }
114
+ for ( const name in allPackages ) {
115
+ if ( inclusionCriteria ( name ) ) {
116
+ filteredPackages . push ( name ) ;
117
+ }
118
+ }
124
119
}
120
+
125
121
// Sort the filtered packages in place by their Levenshtein distance
126
122
filteredPackages . sort ( ( a , b ) => {
127
- const aDistance = levenshteinDistance (
128
- a . name . toLowerCase ( ) ,
129
- searchTermLower
130
- ) ;
131
- const bDistance = levenshteinDistance (
132
- b . name . toLowerCase ( ) ,
133
- searchTermLower
134
- ) ;
123
+ const aDistance = levenshteinDistance ( a , searchTermLower ) ;
124
+ const bDistance = levenshteinDistance ( b , searchTermLower ) ;
135
125
return aDistance - bDistance ;
136
126
} ) ;
137
127
@@ -154,19 +144,19 @@ const Packages = () => {
154
144
< tbody >
155
145
{ ( filteredPackages . length &&
156
146
filteredPackages . map ( ( pkg ) => (
157
- < tr key = { pkg . name } >
147
+ < tr key = { pkg } >
158
148
< td >
159
149
< a
160
- href = { `https://anaconda.org/conda-forge/${ pkg . name } ` }
150
+ href = { `https://anaconda.org/conda-forge/${ pkg } ` }
161
151
target = "_blank"
162
- title = { `View ${ pkg . name } on anaconda.org` }
152
+ title = { `View ${ pkg } on anaconda.org` }
163
153
>
164
- { highlightSubstring ( pkg . name , searchTermLower ) }
154
+ { highlightSubstring ( pkg , searchTermLower ) }
165
155
</ a >
166
156
</ td >
167
157
< td >
168
- { pkg . repos . map ( ( repo ) => (
169
- < span >
158
+ { allPackages [ pkg ] . map ( ( repo ) => (
159
+ < span key = { ` ${ pkg } - ${ repo } ` } >
170
160
< a
171
161
href = { `https://github.com/conda-forge/${ repo } -feedstock` }
172
162
target = "_blank"
@@ -199,24 +189,31 @@ const Packages = () => {
199
189
< div >
200
190
< Admonition type = "tip" coll >
201
191
< p >
202
- The following packages have been published to{ " " }
203
- < a href = "https://anaconda.org/conda-forge" target = "_blank" >
192
+ The following packages have recently received updates in{ " " }
193
+ < a
194
+ href = "https://anaconda.org/conda-forge"
195
+ target = "_blank"
196
+ rel = "noopener noreferrer"
197
+ >
204
198
Anaconda.org
205
- </ a > { " " }
206
- recently.
207
- Check{ " " }
208
- < a href = "https://github.com/conda-forge/feedstock/commits" >
199
+ </ a >
200
+ . Check{ " " }
201
+ < a
202
+ href = "https://github.com/conda-forge/feedstocks/commits"
203
+ target = "_blank"
204
+ rel = "noopener noreferrer"
205
+ >
209
206
conda-forge/feedstocks
210
207
</ a > { " " }
211
- for the last updates in our feedstocks.
208
+ for an overview of the latest commits in our feedstocks.
212
209
</ p >
213
210
</ Admonition >
214
211
< table >
215
212
< thead >
216
213
< tr >
217
214
< th > #</ th >
218
215
< th > Package</ th >
219
- < th > Feedstock</ th >
216
+ < th > Feedstock(s) </ th >
220
217
< th > Last updated</ th >
221
218
</ tr >
222
219
</ thead >
@@ -228,11 +225,26 @@ const Packages = () => {
228
225
< a
229
226
href = { `https://anaconda.org/conda-forge/${ item . name } ` }
230
227
target = "_blank"
228
+ rel = "noopener noreferrer"
231
229
>
232
230
{ item . name }
233
231
</ a >
234
232
</ td >
235
- < td > ...</ td >
233
+ < td >
234
+ { ( allPackages [ item . name . toLowerCase ( ) ] || [ ] ) . map ( ( repo ) => (
235
+ < span key = { `${ item . name } -${ index } -${ repo } ` } >
236
+ < a
237
+ href = { `https://github.com/conda-forge/${ repo } -feedstock` }
238
+ target = "_blank"
239
+ rel = "noopener noreferrer"
240
+ title = { `View ${ repo } -feedstock on GitHub` }
241
+ >
242
+ { repo } -feedstock
243
+ </ a >
244
+ < br />
245
+ </ span >
246
+ ) ) }
247
+ </ td >
236
248
< td > { item . date } </ td >
237
249
</ tr >
238
250
) ) }
@@ -242,7 +254,7 @@ const Packages = () => {
242
254
) ;
243
255
resultsPill = (
244
256
< span className = "badge badge--success margin-left--sm" >
245
- { allPackages . length } packages loaded
257
+ { Object . keys ( allPackages ) . length } packages loaded
246
258
</ span >
247
259
) ;
248
260
}
0 commit comments