-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into hide-hie-tab-when-no-access
- Loading branch information
Showing
75 changed files
with
1,380 additions
and
619 deletions.
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
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
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
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
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
121 changes: 121 additions & 0 deletions
121
packages/kbn-discover-utils/src/components/custom_control_columns/degraded_docs_control.tsx
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,121 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { EuiCode, EuiSpacer } from '@elastic/eui'; | ||
import { | ||
RowControlColumn, | ||
RowControlComponent, | ||
RowControlProps, | ||
RowControlRowProps, | ||
} from './types'; | ||
import { DEGRADED_DOCS_FIELDS } from '../../field_constants'; | ||
|
||
interface DegradedDocsControlProps extends Partial<RowControlProps> { | ||
enabled?: boolean; | ||
} | ||
|
||
/** | ||
* Degraded docs control factory function. | ||
* @param props Optional props for the generated Control component, useful to override onClick, etc | ||
*/ | ||
export const createDegradedDocsControl = (props?: DegradedDocsControlProps): RowControlColumn => ({ | ||
id: 'connectedDegradedDocs', | ||
headerAriaLabel: actionsHeaderAriaLabelDegradedAction, | ||
renderControl: (Control, rowProps) => { | ||
return <DegradedDocs Control={Control} rowProps={rowProps} {...props} />; | ||
}, | ||
}); | ||
|
||
const actionsHeaderAriaLabelDegradedAction = i18n.translate( | ||
'discover.customControl.degradedDocArialLabel', | ||
{ defaultMessage: 'Access to degraded docs' } | ||
); | ||
|
||
const degradedDocButtonLabelWhenPresent = i18n.translate( | ||
'discover.customControl.degradedDocPresent', | ||
{ | ||
defaultMessage: | ||
"This document couldn't be parsed correctly. Not all fields are properly populated", | ||
} | ||
); | ||
|
||
const degradedDocButtonLabelWhenNotPresent = i18n.translate( | ||
'discover.customControl.degradedDocNotPresent', | ||
{ defaultMessage: 'All fields in this document were parsed correctly' } | ||
); | ||
|
||
const degradedDocButtonLabelWhenDisabled = i18n.translate( | ||
'discover.customControl.degradedDocDisabled', | ||
{ | ||
defaultMessage: | ||
'Degraded document field detection is currently disabled for this search. To enable it, include the METADATA directive for the `_ignored` field in your ES|QL query. For example:', | ||
} | ||
); | ||
|
||
const DegradedDocs = ({ | ||
Control, | ||
enabled = true, | ||
rowProps: { record }, | ||
...props | ||
}: { | ||
Control: RowControlComponent; | ||
rowProps: RowControlRowProps; | ||
} & DegradedDocsControlProps) => { | ||
const isDegradedDocumentExists = DEGRADED_DOCS_FIELDS.some( | ||
(field) => field in record.raw && record.raw[field] !== null | ||
); | ||
|
||
if (!enabled) { | ||
const codeSample = 'FROM logs-* METADATA _ignored'; | ||
|
||
const tooltipContent = ( | ||
<div> | ||
{degradedDocButtonLabelWhenDisabled} | ||
<EuiSpacer size="s" /> | ||
<EuiCode>{codeSample}</EuiCode> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Control | ||
disabled | ||
data-test-subj="docTableDegradedDocDisabled" | ||
tooltipContent={tooltipContent} | ||
label={`${degradedDocButtonLabelWhenDisabled} ${codeSample}`} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
return isDegradedDocumentExists ? ( | ||
<Control | ||
data-test-subj="docTableDegradedDocExist" | ||
color="danger" | ||
tooltipContent={degradedDocButtonLabelWhenPresent} | ||
label={degradedDocButtonLabelWhenPresent} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
) : ( | ||
<Control | ||
data-test-subj="docTableDegradedDocDoesNotExist" | ||
color="text" | ||
tooltipContent={degradedDocButtonLabelWhenNotPresent} | ||
label={degradedDocButtonLabelWhenNotPresent} | ||
iconType="indexClose" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/kbn-discover-utils/src/components/custom_control_columns/index.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,11 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
export { createDegradedDocsControl } from './degraded_docs_control'; | ||
export { createStacktraceControl } from './stacktrace_control'; |
79 changes: 79 additions & 0 deletions
79
packages/kbn-discover-utils/src/components/custom_control_columns/stacktrace_control.tsx
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,79 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { | ||
RowControlColumn, | ||
RowControlComponent, | ||
RowControlProps, | ||
RowControlRowProps, | ||
} from './types'; | ||
import { LogDocument } from '../../data_types'; | ||
import { getStacktraceFields } from '../../utils/get_stack_trace_fields'; | ||
|
||
/** | ||
* Stacktrace control factory function. | ||
* @param props Optional props for the generated Control component, useful to override onClick, etc | ||
*/ | ||
export const createStacktraceControl = (props?: Partial<RowControlProps>): RowControlColumn => ({ | ||
id: 'connectedStacktraceDocs', | ||
headerAriaLabel: actionsHeaderAriaLabelStacktraceAction, | ||
renderControl: (Control, rowProps) => { | ||
return <Stacktrace Control={Control} rowProps={rowProps} {...props} />; | ||
}, | ||
}); | ||
|
||
const actionsHeaderAriaLabelStacktraceAction = i18n.translate( | ||
'discover.customControl.stacktraceArialLabel', | ||
{ defaultMessage: 'Access to available stacktraces' } | ||
); | ||
|
||
const stacktraceAvailableControlButton = i18n.translate( | ||
'discover.customControl.stacktrace.available', | ||
{ defaultMessage: 'Stacktraces available' } | ||
); | ||
|
||
const stacktraceNotAvailableControlButton = i18n.translate( | ||
'discover.customControl.stacktrace.notAvailable', | ||
{ defaultMessage: 'Stacktraces not available' } | ||
); | ||
|
||
const Stacktrace = ({ | ||
Control, | ||
rowProps: { record }, | ||
...props | ||
}: { | ||
Control: RowControlComponent; | ||
rowProps: RowControlRowProps; | ||
} & Partial<RowControlProps>) => { | ||
const stacktrace = getStacktraceFields(record as LogDocument); | ||
const hasValue = Object.values(stacktrace).some(Boolean); | ||
|
||
return hasValue ? ( | ||
<Control | ||
data-test-subj="docTableStacktraceExist" | ||
label={stacktraceAvailableControlButton} | ||
tooltipContent={stacktraceAvailableControlButton} | ||
iconType="apmTrace" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
) : ( | ||
<Control | ||
disabled | ||
data-test-subj="docTableStacktraceDoesNotExist" | ||
label={stacktraceNotAvailableControlButton} | ||
tooltipContent={stacktraceNotAvailableControlButton} | ||
iconType="apmTrace" | ||
onClick={undefined} | ||
{...props} | ||
/> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/kbn-discover-utils/src/components/custom_control_columns/types.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,36 @@ | ||
/* | ||
* 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 { EuiButtonIconProps, EuiDataGridControlColumn, IconType } from '@elastic/eui'; | ||
import React, { FC, ReactElement } from 'react'; | ||
import { DataTableRecord } from '../../types'; | ||
|
||
export interface RowControlRowProps { | ||
rowIndex: number; | ||
record: DataTableRecord; | ||
} | ||
|
||
export interface RowControlProps { | ||
'data-test-subj'?: string; | ||
color?: EuiButtonIconProps['color']; | ||
disabled?: boolean; | ||
label: string; | ||
iconType: IconType; | ||
onClick: ((props: RowControlRowProps) => void) | undefined; | ||
tooltipContent?: React.ReactNode; | ||
} | ||
|
||
export type RowControlComponent = FC<RowControlProps>; | ||
|
||
export interface RowControlColumn { | ||
id: string; | ||
headerAriaLabel: string; | ||
headerCellRender?: EuiDataGridControlColumn['headerCellRender']; | ||
renderControl: (Control: RowControlComponent, props: RowControlRowProps) => ReactElement; | ||
} |
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
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
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
Oops, something went wrong.