-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UnifiedDocViewer] Filter on field name and value in expanded document view #192299
Merged
jughosta
merged 28 commits into
elastic:main
from
jughosta:163275-search-by-field-value
Sep 26, 2024
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4704854
[Discover] Initial changes
jughosta c184eff
[Discover] Allow to filter by field value in DocViewer
jughosta b565e49
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine c6007aa
[Discover] Fix field name prop
jughosta f28897e
Merge remote-tracking branch 'origin/163275-search-by-field-value' in…
jughosta 858ea3e
Merge branch 'main' into 163275-search-by-field-value
jughosta 9d5b93c
Merge main
jughosta adcae38
Update highlighting
jughosta 0dfdaf1
Merge remote-tracking branch 'upstream/main' into 163275-search-by-fi…
jughosta ca708e1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 7cf1f6d
Merge branch 'main' into 163275-search-by-field-value
jughosta c788504
Merge branch 'main' into 163275-search-by-field-value
jughosta 70cfa7a
[Discover] Update tests. Enable the highlight.
jughosta f81fbef
[Discover] Add functional tests
jughosta b17c369
[Discover] Simplify matching
jughosta 723adef
[Discover] Update tests
jughosta e7a330c
Merge branch 'main' into 163275-search-by-field-value
jughosta c373989
[Discover] Update tests
jughosta ed83330
[Discover] Fix tests
jughosta 114f8b8
Merge branch 'main' into 163275-search-by-field-value
jughosta 4528692
Merge branch 'main' into 163275-search-by-field-value
jughosta 3ca7127
Merge remote-tracking branch 'upstream/main' into 163275-search-by-fi…
jughosta b20c54e
[Discover] Rename to isHighlighted
jughosta 34164a1
Merge branch 'main' into 163275-search-by-field-value
jughosta a7c72c8
Merge branch 'main' into 163275-search-by-field-value
jughosta 5d95f34
Merge branch 'main' into 163275-search-by-field-value
jughosta d3812d8
Merge branch 'main' into 163275-search-by-field-value
jughosta fce8a11
Merge branch 'main' into 163275-search-by-field-value
jughosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
210 changes: 35 additions & 175 deletions
210
..._viewer/public/components/doc_viewer_table/__snapshots__/table_cell_actions.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
129 changes: 129 additions & 0 deletions
129
src/plugins/unified_doc_viewer/public/components/doc_viewer_table/field_row.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import type { DataView, DataViewField } from '@kbn/data-views-plugin/common'; | ||
import type { DataTableColumnsMeta, DataTableRecord } from '@kbn/discover-utils/types'; | ||
import { | ||
formatFieldValue, | ||
getIgnoredReason, | ||
IgnoredReason, | ||
isNestedFieldParent, | ||
} from '@kbn/discover-utils'; | ||
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; | ||
import { getFieldIconType, getTextBasedColumnIconType } from '@kbn/field-utils'; | ||
|
||
export class FieldRow { | ||
readonly name: string; | ||
readonly flattenedValue: unknown; | ||
readonly dataViewField: DataViewField | undefined; | ||
readonly isPinned: boolean; | ||
readonly columnsMeta: DataTableColumnsMeta | undefined; | ||
|
||
readonly #hit: DataTableRecord; | ||
readonly #dataView: DataView; | ||
readonly #fieldFormats: FieldFormatsStart; | ||
|
||
#isFormattedAsHtml: boolean; | ||
#isFormattedAsText: boolean; | ||
|
||
#formattedAsHtml: string | undefined; | ||
#formattedAsText: string | undefined; | ||
|
||
#fieldType: string | undefined; | ||
|
||
constructor({ | ||
name, | ||
flattenedValue, | ||
hit, | ||
dataView, | ||
fieldFormats, | ||
isPinned, | ||
columnsMeta, | ||
}: { | ||
name: string; | ||
flattenedValue: unknown; | ||
hit: DataTableRecord; | ||
dataView: DataView; | ||
fieldFormats: FieldFormatsStart; | ||
isPinned: boolean; | ||
columnsMeta: DataTableColumnsMeta | undefined; | ||
}) { | ||
this.#hit = hit; | ||
this.#dataView = dataView; | ||
this.#fieldFormats = fieldFormats; | ||
this.#isFormattedAsHtml = false; | ||
this.#isFormattedAsText = false; | ||
|
||
this.name = name; | ||
this.flattenedValue = flattenedValue; | ||
this.dataViewField = dataView.getFieldByName(name); | ||
this.isPinned = isPinned; | ||
this.columnsMeta = columnsMeta; | ||
} | ||
|
||
// format as html in a lazy way | ||
public get formattedAsHtml(): string | undefined { | ||
if (!this.#isFormattedAsHtml) { | ||
this.#formattedAsHtml = formatFieldValue( | ||
this.flattenedValue, | ||
this.#hit.raw, | ||
this.#fieldFormats, | ||
this.#dataView, | ||
this.dataViewField, | ||
'html' | ||
); | ||
this.#isFormattedAsHtml = true; | ||
} | ||
|
||
return this.#formattedAsHtml; | ||
} | ||
|
||
// format as text in a lazy way | ||
public get formattedAsText(): string | undefined { | ||
if (!this.#isFormattedAsText) { | ||
this.#formattedAsText = String( | ||
formatFieldValue( | ||
this.flattenedValue, | ||
this.#hit.raw, | ||
this.#fieldFormats, | ||
this.#dataView, | ||
this.dataViewField, | ||
'text' | ||
) | ||
); | ||
this.#isFormattedAsText = true; | ||
} | ||
|
||
return this.#formattedAsText; | ||
} | ||
|
||
public get fieldType(): string | undefined { | ||
if (!this.#fieldType) { | ||
const columnMeta = this.columnsMeta?.[this.name]; | ||
const columnIconType = getTextBasedColumnIconType(columnMeta); | ||
const fieldType = columnIconType | ||
? columnIconType // for text-based results types come separately | ||
: isNestedFieldParent(this.name, this.#dataView) | ||
? 'nested' | ||
: this.dataViewField | ||
? getFieldIconType(this.dataViewField) | ||
: undefined; | ||
|
||
this.#fieldType = fieldType; | ||
} | ||
|
||
return this.#fieldType; | ||
} | ||
|
||
public get ignoredReason(): IgnoredReason | undefined { | ||
return this.dataViewField | ||
? getIgnoredReason(this.dataViewField, this.#hit.raw._ignored) | ||
: undefined; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Do we need a separate variable for
this.#isFormattedAsHtml
(andthis.#isFormattedAsText
) or can we just check ifthis.#formattedAsHtml
isundefined
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukasolson I added it so we don't run the formatter again if it returns an empty result. Would it be okay to keep it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, yeah we can leave as is.