Skip to content

Commit 04b1b8a

Browse files
authored
select first N and last N summary logs (#11)
1 parent 8dc7596 commit 04b1b8a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

ui/src/components/filters/index.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ function Filters(props: FiltersProps) {
120120
}
121121
}
122122

123+
function handleNLogsEnter(e: KeyboardEvent) {
124+
if (e.key === "Enter") {
125+
handleLogsSelectionChanged(gridsRefs);
126+
}
127+
}
128+
123129
function getSimpleSearchHTML(term: SearchTerm, i: Accessor<number>) {
124130
return (
125131
<>
@@ -207,6 +213,23 @@ function Filters(props: FiltersProps) {
207213
label="Errors Only"
208214
labelPlacement="start"
209215
/>
216+
<Divider orientation="vertical" flexItem></Divider>
217+
<TextField
218+
label="First N Logs"
219+
value={filters.firstN}
220+
onChange={(_, val) =>
221+
setFilters("firstN", isNaN(+val) || +val < 0 ? 0 : +val)
222+
}
223+
onKeyDown={handleNLogsEnter}
224+
/>
225+
<TextField
226+
label="Last N Logs"
227+
value={filters.lastN}
228+
onChange={(_, val) =>
229+
setFilters("lastN", isNaN(+val) || +val < 0 ? 0 : +val)
230+
}
231+
onKeyDown={handleNLogsEnter}
232+
/>
210233
</Stack>
211234
</Grid>
212235
<Grid item xs={12} container spacing={2}>

ui/src/components/filters/useViewModel.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ interface FiltersData {
3030
terms: SearchTerm[];
3131
logs: JSONLogs;
3232
errorsOnly: boolean;
33+
firstN: number;
34+
lastN: number;
3335
}
3436

3537
function defaultFilters(): FiltersData {
@@ -46,6 +48,8 @@ function defaultFilters(): FiltersData {
4648
],
4749
logs: [],
4850
errorsOnly: false,
51+
firstN: 0,
52+
lastN: 0,
4953
};
5054
}
5155

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

103107
function populateMap(gridRef: AgGridSolidRef) {
104108
for (const r of gridRef.api.getSelectedRows() as GroupedMsg[]) {
105-
r.logs.forEach((l) => map.set(l[LogData.logKeys.id], l));
109+
let nLogs: JSONLogs = [];
110+
if (filters.firstN) {
111+
nLogs = r.logs.slice(0, filters.firstN);
112+
}
113+
if (filters.lastN) {
114+
nLogs = [...nLogs, ...r.logs.slice(-filters.lastN)];
115+
}
116+
117+
if (!nLogs.length) nLogs = r.logs;
118+
119+
nLogs.forEach((l) => map.set(l[LogData.logKeys.id], l));
106120
}
107121
}
108122
}

0 commit comments

Comments
 (0)