Skip to content

Commit

Permalink
fix: LaunchDevly: Pagination for 'Only show flags with overrides' (#426)
Browse files Browse the repository at this point in the history
Fix pagination for 'Only show flags with overrides'
  • Loading branch information
cdelst committed Sep 13, 2024
1 parent dd9df47 commit 28bfb60
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions internal/dev_server/ui/src/Flags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,24 @@ function Flags({
const filteredFlags = useMemo(() => {
if (!flags) return [];
const flagEntries = Object.entries(flags);
const search = searchTerm.toLowerCase();
const filtered = fuzzysort
.go(search, flagEntries, { all: true, key: '0', threshold: 0.7 })
.map((result) => result.obj);
return filtered;
}, [flags, searchTerm]);
return flagEntries
.filter((entry) => {
if (!searchTerm) return true;
const [flagKey] = entry;
const result = fuzzysort.single(searchTerm.toLowerCase(), flagKey);
return result && result.score > -5000; // Adjust threshold as needed
})
.filter((entry) => {
const [flagKey] = entry;
const hasOverride = flagKey in overrides;

if (onlyShowOverrides && !hasOverride) {
return false;
}

return true;
});
}, [flags, searchTerm, onlyShowOverrides]);

const paginatedFlags = useMemo(() => {
const startIndex = currentPage * flagsPerPage; // Adjust startIndex calculation
Expand Down Expand Up @@ -231,6 +243,7 @@ function Flags({
setSearchTerm(e.target.value);
setCurrentPage(0); // Reset pagination
}}
value={searchTerm}
aria-label="Search flags input"
/>
<IconButton
Expand All @@ -249,10 +262,6 @@ function Flags({
const hasOverride = flagKey in overrides;
const currentValue = hasOverride ? overrideValue : flagValue;

if (onlyShowOverrides && !hasOverride) {
return null;
}

return (
<li
key={flagKey}
Expand Down

0 comments on commit 28bfb60

Please sign in to comment.