Skip to content

Commit

Permalink
fix: make dropdown work with boolean and update fieldnames to reflect…
Browse files Browse the repository at this point in the history
… data shape changes
  • Loading branch information
ajhenry committed Feb 1, 2024
1 parent 0b2b0f4 commit 37fb77f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions who-metrics-ui/src/components/RepositoriesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ type SelectOption = {
const dropdownOptions = (field: keyof Repo, filter = ''): SelectOption[] =>
Array.from(new Set(repos.map((repo) => repo[field])))
.map((fieldName) => ({
label: fieldName,
value: fieldName,
// some fields are boolean (hasXxEnabled), so we need to convert them to strings
label: typeof fieldName === 'boolean' ? fieldName.toString() : fieldName,
value: typeof fieldName === 'boolean' ? fieldName.toString() : fieldName,
}))
.filter((fieldName) =>
(fieldName.value as string).toLowerCase().includes(filter.toLowerCase()),
Expand All @@ -72,7 +73,7 @@ const dropdownOptions = (field: keyof Repo, filter = ''): SelectOption[] =>
const getSelectedOption = (
filters: Filter,
filterName: keyof Filter,
filterField: string | number,
filterField: string,
defaultValue = false,
) =>
(filters[filterName] as Record<string, boolean>)[filterField] ?? defaultValue;
Expand Down Expand Up @@ -210,7 +211,7 @@ const SearchableSelectRenderer: FC<{
[selectOption.value]: !getSelectedOption(
filters,
filterName,
selectOption.value,
selectOption.value as string,
),
},
}));
Expand Down Expand Up @@ -243,7 +244,7 @@ const SearchableSelectRenderer: FC<{
[selectOption.value]: !getSelectedOption(
filters,
filterName,
selectOption.value,
selectOption.value as string,
),
},
}));
Expand All @@ -255,7 +256,7 @@ const SearchableSelectRenderer: FC<{
checked={getSelectedOption(
filters,
filterName,
selectOption.value,
selectOption.value as string,
)}
/>
</ActionList.LeadingVisual>
Expand Down Expand Up @@ -349,7 +350,7 @@ const getComparator = (sortColumn: keyof Repo): Comparator => {
case 'collaboratorsCount':
case 'discussionsCount':
case 'forksCount':
case 'issuesCount':
case 'totalIssuesCount':
case 'mergedPullRequestsCount':
case 'openIssuesCount':
case 'openPullRequestsCount':
Expand All @@ -369,7 +370,7 @@ const getComparator = (sortColumn: keyof Repo): Comparator => {

// alphabetical sorting
case 'licenseName':
case 'repoName':
case 'repoNameWithOwner':
case 'repositoryName':
return (a, b) => {
return a[sortColumn]
Expand Down Expand Up @@ -651,7 +652,7 @@ const RepositoriesTable = () => {
<Button
variant="invisible"
onClick={() => {
saveAs(generateCSV(displayRows), "output.csv");
saveAs(generateCSV(displayRows), 'output.csv');
}}
>
Download CSV
Expand All @@ -665,7 +666,7 @@ const RepositoriesTable = () => {
<DataGrid
columns={dataGridColumns}
rows={displayRows}
rowKeyGetter={(repo) => repo.repoName}
rowKeyGetter={(repo) => repo.repositoryName}
defaultColumnOptions={{
sortable: true,
resizable: true,
Expand Down

0 comments on commit 37fb77f

Please sign in to comment.