Skip to content
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
merged 28 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4704854
[Discover] Initial changes
jughosta Sep 6, 2024
c184eff
[Discover] Allow to filter by field value in DocViewer
jughosta Sep 6, 2024
b565e49
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Sep 6, 2024
c6007aa
[Discover] Fix field name prop
jughosta Sep 6, 2024
f28897e
Merge remote-tracking branch 'origin/163275-search-by-field-value' in…
jughosta Sep 6, 2024
858ea3e
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 9, 2024
9d5b93c
Merge main
jughosta Sep 11, 2024
adcae38
Update highlighting
jughosta Sep 11, 2024
0dfdaf1
Merge remote-tracking branch 'upstream/main' into 163275-search-by-fi…
jughosta Sep 11, 2024
ca708e1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 11, 2024
7cf1f6d
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 11, 2024
c788504
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 12, 2024
70cfa7a
[Discover] Update tests. Enable the highlight.
jughosta Sep 12, 2024
f81fbef
[Discover] Add functional tests
jughosta Sep 12, 2024
b17c369
[Discover] Simplify matching
jughosta Sep 12, 2024
723adef
[Discover] Update tests
jughosta Sep 12, 2024
e7a330c
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 13, 2024
c373989
[Discover] Update tests
jughosta Sep 13, 2024
ed83330
[Discover] Fix tests
jughosta Sep 13, 2024
114f8b8
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 13, 2024
4528692
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 16, 2024
3ca7127
Merge remote-tracking branch 'upstream/main' into 163275-search-by-fi…
jughosta Sep 19, 2024
b20c54e
[Discover] Rename to isHighlighted
jughosta Sep 19, 2024
34164a1
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 23, 2024
a7c72c8
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 24, 2024
5d95f34
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 25, 2024
d3812d8
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 25, 2024
fce8a11
Merge branch 'main' into 163275-search-by-field-value
jughosta Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-unified-data-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { EuiDataGridCellValueElementProps, EuiDataGridColumn } from '@elast
import type { DataTableRecord } from '@kbn/discover-utils/src/types';
import type { DataView } from '@kbn/data-views-plugin/common';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
export type { DataTableColumnsMeta } from '@kbn/discover-utils/src/types';
export type { DataTableColumnsMeta } from '@kbn/discover-utils/types';
export type { DataGridDensity } from './constants';

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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) {
Copy link
Member

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 (and this.#isFormattedAsText) or can we just check if this.#formattedAsHtml is undefined?

Copy link
Contributor Author

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?

Copy link
Member

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.

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;
}
}
Loading