Skip to content

Commit 4f6350f

Browse files
committed
store feedstock-outputs as an object and query it as needed
1 parent 6b73c52 commit 4f6350f

File tree

1 file changed

+55
-43
lines changed

1 file changed

+55
-43
lines changed

src/components/Packages/index.jsx

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function highlightSubstring(str, substr) {
5050
}
5151

5252
const Packages = () => {
53-
const [allPackages, setAllPackages] = useState([]);
53+
const [allPackages, setAllPackages] = useState({});
5454
const [latestPackages, setLatestPackages] = useState([]);
5555
const [searchTerm, setSearchTerm] = useState("");
5656

@@ -63,13 +63,7 @@ const Packages = () => {
6363
const data = await response.json();
6464

6565
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])));
7367
} else {
7468
console.error("Invalid data format. Expected an object.");
7569
}
@@ -110,28 +104,24 @@ const Packages = () => {
110104

111105
const searchTermLower = searchTerm.toLowerCase();
112106
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+
}
124119
}
120+
125121
// Sort the filtered packages in place by their Levenshtein distance
126122
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);
135125
return aDistance - bDistance;
136126
});
137127

@@ -154,19 +144,19 @@ const Packages = () => {
154144
<tbody>
155145
{(filteredPackages.length &&
156146
filteredPackages.map((pkg) => (
157-
<tr key={pkg.name}>
147+
<tr key={pkg}>
158148
<td>
159149
<a
160-
href={`https://anaconda.org/conda-forge/${pkg.name}`}
150+
href={`https://anaconda.org/conda-forge/${pkg}`}
161151
target="_blank"
162-
title={`View ${pkg.name} on anaconda.org`}
152+
title={`View ${pkg} on anaconda.org`}
163153
>
164-
{highlightSubstring(pkg.name, searchTermLower)}
154+
{highlightSubstring(pkg, searchTermLower)}
165155
</a>
166156
</td>
167157
<td>
168-
{pkg.repos.map((repo) => (
169-
<span>
158+
{allPackages[pkg].map((repo) => (
159+
<span key={`${pkg}-${repo}`}>
170160
<a
171161
href={`https://github.com/conda-forge/${repo}-feedstock`}
172162
target="_blank"
@@ -199,24 +189,31 @@ const Packages = () => {
199189
<div>
200190
<Admonition type="tip" coll>
201191
<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+
>
204198
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+
>
209206
conda-forge/feedstocks
210207
</a>{" "}
211-
for the last updates in our feedstocks.
208+
for an overview of the latest commits in our feedstocks.
212209
</p>
213210
</Admonition>
214211
<table>
215212
<thead>
216213
<tr>
217214
<th>#</th>
218215
<th>Package</th>
219-
<th>Feedstock</th>
216+
<th>Feedstock(s)</th>
220217
<th>Last updated</th>
221218
</tr>
222219
</thead>
@@ -228,11 +225,26 @@ const Packages = () => {
228225
<a
229226
href={`https://anaconda.org/conda-forge/${item.name}`}
230227
target="_blank"
228+
rel="noopener noreferrer"
231229
>
232230
{item.name}
233231
</a>
234232
</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>
236248
<td>{item.date}</td>
237249
</tr>
238250
))}
@@ -242,7 +254,7 @@ const Packages = () => {
242254
);
243255
resultsPill = (
244256
<span className="badge badge--success margin-left--sm">
245-
{allPackages.length} packages loaded
257+
{Object.keys(allPackages).length} packages loaded
246258
</span>
247259
);
248260
}

0 commit comments

Comments
 (0)