-
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.
Show examples in category table row expansions
- Loading branch information
1 parent
298d547
commit 59b37bc
Showing
9 changed files
with
289 additions
and
33 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/infra/public/components/basic_table/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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './row_expansion_button'; |
44 changes: 44 additions & 0 deletions
44
x-pack/legacy/plugins/infra/public/components/basic_table/row_expansion_button.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,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiButtonIcon } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { useCallback } from 'react'; | ||
|
||
export const RowExpansionButton = <Item extends any>({ | ||
isExpanded, | ||
item, | ||
onCollapse, | ||
onExpand, | ||
}: { | ||
isExpanded: boolean; | ||
item: Item; | ||
onCollapse: (item: Item) => void; | ||
onExpand: (item: Item) => void; | ||
}) => { | ||
const handleClick = useCallback(() => (isExpanded ? onCollapse(item) : onExpand(item)), [ | ||
isExpanded, | ||
item, | ||
onCollapse, | ||
onExpand, | ||
]); | ||
|
||
return ( | ||
<EuiButtonIcon | ||
onClick={handleClick} | ||
aria-label={isExpanded ? collapseAriaLabel : expandAriaLabel} | ||
iconType={isExpanded ? 'arrowUp' : 'arrowDown'} | ||
/> | ||
); | ||
}; | ||
|
||
const collapseAriaLabel = i18n.translate('xpack.infra.table.collapseRowLabel', { | ||
defaultMessage: 'Collapse', | ||
}); | ||
|
||
const expandAriaLabel = i18n.translate('xpack.infra.table.expandRowLabel', { | ||
defaultMessage: 'Expand', | ||
}); |
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
36 changes: 36 additions & 0 deletions
36
...a/public/pages/logs/log_entry_categories/sections/top_categories/category_details_row.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,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
|
||
import { TimeRange } from '../../../../../../common/http_api/shared'; | ||
import { useLogEntryCategoryExamples } from '../../use_log_entry_category_examples'; | ||
|
||
export const CategoryDetailsRow: React.FunctionComponent<{ | ||
categoryId: number; | ||
timeRange: TimeRange; | ||
sourceId: string; | ||
}> = ({ categoryId, timeRange, sourceId }) => { | ||
const { getLogEntryCategoryExamples, logEntryCategoryExamples } = useLogEntryCategoryExamples({ | ||
categoryId, | ||
endTime: timeRange.endTime, | ||
exampleCount: 5, | ||
sourceId, | ||
startTime: timeRange.startTime, | ||
}); | ||
|
||
useEffect(() => { | ||
getLogEntryCategoryExamples(); | ||
}, [getLogEntryCategoryExamples]); | ||
|
||
return ( | ||
<div> | ||
{logEntryCategoryExamples.map(categoryExample => ( | ||
<div>{categoryExample.message}</div> | ||
))} | ||
</div> | ||
); | ||
}; |
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
50 changes: 50 additions & 0 deletions
50
...a/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_examples.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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { fold } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { identity } from 'fp-ts/lib/function'; | ||
import { npStart } from 'ui/new_platform'; | ||
|
||
import { | ||
getLogEntryCategoryExamplesRequestPayloadRT, | ||
getLogEntryCategoryExamplesSuccessReponsePayloadRT, | ||
LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, | ||
} from '../../../../../common/http_api/log_analysis'; | ||
import { createPlainError, throwErrors } from '../../../../../common/runtime_types'; | ||
|
||
export const callGetLogEntryCategoryExamplesAPI = async ( | ||
sourceId: string, | ||
startTime: number, | ||
endTime: number, | ||
categoryId: number, | ||
exampleCount: number | ||
) => { | ||
const response = await npStart.core.http.fetch( | ||
LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify( | ||
getLogEntryCategoryExamplesRequestPayloadRT.encode({ | ||
data: { | ||
categoryId, | ||
exampleCount, | ||
sourceId, | ||
timeRange: { | ||
startTime, | ||
endTime, | ||
}, | ||
}, | ||
}) | ||
), | ||
} | ||
); | ||
|
||
return pipe( | ||
getLogEntryCategoryExamplesSuccessReponsePayloadRT.decode(response), | ||
fold(throwErrors(createPlainError), identity) | ||
); | ||
}; |
59 changes: 59 additions & 0 deletions
59
.../plugins/infra/public/pages/logs/log_entry_categories/use_log_entry_category_examples.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,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useMemo, useState } from 'react'; | ||
|
||
import { LogEntryCategoryExample } from '../../../../common/http_api'; | ||
import { useTrackedPromise } from '../../../utils/use_tracked_promise'; | ||
import { callGetLogEntryCategoryExamplesAPI } from './service_calls/get_log_entry_category_examples'; | ||
|
||
export const useLogEntryCategoryExamples = ({ | ||
categoryId, | ||
endTime, | ||
exampleCount, | ||
sourceId, | ||
startTime, | ||
}: { | ||
categoryId: number; | ||
endTime: number; | ||
exampleCount: number; | ||
sourceId: string; | ||
startTime: number; | ||
}) => { | ||
const [logEntryCategoryExamples, setLogEntryCategoryExamples] = useState< | ||
LogEntryCategoryExample[] | ||
>([]); | ||
|
||
const [getLogEntryCategoryExamplesRequest, getLogEntryCategoryExamples] = useTrackedPromise( | ||
{ | ||
cancelPreviousOn: 'creation', | ||
createPromise: async () => { | ||
return await callGetLogEntryCategoryExamplesAPI( | ||
sourceId, | ||
startTime, | ||
endTime, | ||
categoryId, | ||
exampleCount | ||
); | ||
}, | ||
onResolve: ({ data: { examples } }) => { | ||
setLogEntryCategoryExamples(examples); | ||
}, | ||
}, | ||
[categoryId, endTime, exampleCount, sourceId, startTime] | ||
); | ||
|
||
const isLoadingLogEntryCategoryExamples = useMemo( | ||
() => getLogEntryCategoryExamplesRequest.state === 'pending', | ||
[getLogEntryCategoryExamplesRequest.state] | ||
); | ||
|
||
return { | ||
getLogEntryCategoryExamples, | ||
isLoadingLogEntryCategoryExamples, | ||
logEntryCategoryExamples, | ||
}; | ||
}; |
Oops, something went wrong.