Skip to content

Commit 5dab1de

Browse files
authored
Merge pull request #338 from devtron-labs/fix/improve-log-search
feat: incremental log search on individual matches
2 parents d585b0e + 3697c3e commit 5dab1de

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/Shared/Components/CICDHistory/LogsRenderer.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ const LogsRenderer = ({
205205

206206
function createMarkup({
207207
log,
208-
useCurrentSelectionColor = false,
208+
currentIndex = -1,
209209
targetSearchKey = searchKey,
210+
searchMatchResults = null,
211+
searchIndex = '',
210212
}: CreateMarkupPropsType): CreateMarkupReturnType {
211213
let isSearchKeyPresent = false
212214
try {
@@ -226,11 +228,12 @@ const LogsRenderer = ({
226228
// Question: Can we directly set it as true inside the replace function?
227229
isSearchKeyPresent = isSearchKeyPresent || searchRegex.test(part)
228230
acc.push(
229-
part.replace(
230-
searchRegex,
231-
(match) =>
232-
`\x1B[0m\x1B[48;2;${useCurrentSelectionColor ? '0;102;204' : '197;141;54'}m${match}\x1B[0m${index > 0 ? availableEscapeCodes[index - 1] : ''}`,
233-
),
231+
part.replace(searchRegex, (match) => {
232+
if (searchIndex) {
233+
searchMatchResults?.push(searchIndex)
234+
}
235+
return `\x1B[0m\x1B[48;2;${searchMatchResults && currentIndex === searchMatchResults.length - 1 ? '0;102;204' : '197;141;54'}m${match}\x1B[0m${index > 0 ? availableEscapeCodes[index - 1] : ''}`
236+
}),
234237
)
235238
} catch {
236239
acc.push(part)
@@ -360,16 +363,22 @@ const LogsRenderer = ({
360363
// Ideally in case of parallel build should receive stage name with logs
361364
// NOTE: For now would always append log to last stage, can show a loader on stage tiles till processed
362365
if (acc.length > 0) {
366+
const lastStage = acc[acc.length - 1]
367+
368+
const searchIndex = getLogSearchIndex({
369+
stageIndex: acc.length - 1,
370+
lineNumberInsideStage: lastStage.logs.length,
371+
})
372+
363373
// In case targetSearchKey is not present createMarkup will internally fallback to searchKey
364374
const { __html, isSearchKeyPresent } = createMarkup({
365375
log: streamItem,
366-
// NOTE: the last matched search result was added to the searchMatchResults list
367-
// therefore if currentSearchIndex matches it's length then paint it blue if searchKey is present
368-
useCurrentSelectionColor: currentIndex === searchMatchResults.length,
376+
currentIndex,
377+
searchMatchResults,
369378
targetSearchKey,
379+
searchIndex,
370380
})
371381

372-
const lastStage = acc[acc.length - 1]
373382
lastStage.logs.push(__html)
374383
if (isSearchKeyPresent) {
375384
lastStage.isOpen = getIsStageOpen(
@@ -384,13 +393,6 @@ const LogsRenderer = ({
384393
}
385394

386395
searchKeyStatusMap[lastStage.stage][lastStage.startTime] = true
387-
388-
searchMatchResults.push(
389-
getLogSearchIndex({
390-
stageIndex: acc.length - 1,
391-
lineNumberInsideStage: lastStage.logs.length - 1,
392-
}),
393-
)
394396
}
395397
}
396398

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,21 @@ export interface CreateMarkupReturnType {
763763
isSearchKeyPresent: boolean
764764
}
765765

766-
export interface CreateMarkupPropsType {
767-
log: string
768-
useCurrentSelectionColor?: boolean
769-
targetSearchKey?: string
770-
}
766+
export type CreateMarkupPropsType =
767+
| {
768+
log: string
769+
currentIndex?: never
770+
targetSearchKey?: never
771+
searchMatchResults?: never
772+
searchIndex?: never
773+
}
774+
| {
775+
log: string
776+
currentIndex: number
777+
targetSearchKey: string
778+
searchMatchResults: string[]
779+
searchIndex: string
780+
}
771781

772782
export type TriggerHistoryFilterCriteriaType = `${string}|${string}|${string}`[]
773783
export const terminalStatus = new Set(['error', 'healthy', 'succeeded', 'cancelled', 'failed', 'aborted'])

0 commit comments

Comments
 (0)