Skip to content

Commit

Permalink
select first N and last N summary logs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
vish9812 authored Feb 28, 2024
1 parent 8dc7596 commit 04b1b8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
23 changes: 23 additions & 0 deletions ui/src/components/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ function Filters(props: FiltersProps) {
}
}

function handleNLogsEnter(e: KeyboardEvent) {
if (e.key === "Enter") {
handleLogsSelectionChanged(gridsRefs);
}
}

function getSimpleSearchHTML(term: SearchTerm, i: Accessor<number>) {
return (
<>
Expand Down Expand Up @@ -207,6 +213,23 @@ function Filters(props: FiltersProps) {
label="Errors Only"
labelPlacement="start"
/>
<Divider orientation="vertical" flexItem></Divider>
<TextField
label="First N Logs"
value={filters.firstN}
onChange={(_, val) =>
setFilters("firstN", isNaN(+val) || +val < 0 ? 0 : +val)
}
onKeyDown={handleNLogsEnter}
/>
<TextField
label="Last N Logs"
value={filters.lastN}
onChange={(_, val) =>
setFilters("lastN", isNaN(+val) || +val < 0 ? 0 : +val)
}
onKeyDown={handleNLogsEnter}
/>
</Stack>
</Grid>
<Grid item xs={12} container spacing={2}>
Expand Down
16 changes: 15 additions & 1 deletion ui/src/components/filters/useViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface FiltersData {
terms: SearchTerm[];
logs: JSONLogs;
errorsOnly: boolean;
firstN: number;
lastN: number;
}

function defaultFilters(): FiltersData {
Expand All @@ -46,6 +48,8 @@ function defaultFilters(): FiltersData {
],
logs: [],
errorsOnly: false,
firstN: 0,
lastN: 0,
};
}

Expand Down Expand Up @@ -102,7 +106,17 @@ function useViewModel(props: FiltersProps) {

function populateMap(gridRef: AgGridSolidRef) {
for (const r of gridRef.api.getSelectedRows() as GroupedMsg[]) {
r.logs.forEach((l) => map.set(l[LogData.logKeys.id], l));
let nLogs: JSONLogs = [];
if (filters.firstN) {
nLogs = r.logs.slice(0, filters.firstN);
}
if (filters.lastN) {
nLogs = [...nLogs, ...r.logs.slice(-filters.lastN)];
}

if (!nLogs.length) nLogs = r.logs;

nLogs.forEach((l) => map.set(l[LogData.logKeys.id], l));
}
}
}
Expand Down

0 comments on commit 04b1b8a

Please sign in to comment.