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

[Logs Shared] Types refactor #173819

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ export const CategoryExampleMessage: React.FunctionComponent<{
const openMenu = useCallback(() => setIsMenuOpen(true), []);
const closeMenu = useCallback(() => setIsMenuOpen(false), []);

const time = moment(timestamp).toISOString();

const viewInStreamLinkProps = useLinkProps({
app: 'logs',
pathname: 'stream',
search: {
logPosition: encode({
end: moment(timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
position: { tiebreaker, time: moment(timestamp).toISOString() },
position: { tiebreaker, time },
start: moment(timeRange.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
streamLive: false,
}),
Expand All @@ -79,7 +81,7 @@ export const CategoryExampleMessage: React.FunctionComponent<{
onMouseLeave={setNotHovered}
>
<LogEntryColumn {...columnWidths[timestampColumnId]}>
<LogEntryTimestampColumn format={exampleTimestampFormat} time={timestamp} />
<LogEntryTimestampColumn format={exampleTimestampFormat} time={time} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: caught typing issue thanks to typed dynamic implementation.

</LogEntryColumn>
<LogEntryColumn {...columnWidths[messageColumnId]}>
<LogEntryMessageColumn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
// handle special cases for the dataset value
const humanFriendlyDataset = getFriendlyNameForPartitionId(dataset);

const time = moment(timestamp).toISOString();

const viewInStreamLinkProps = useLinkProps({
app: 'logs',
pathname: 'stream',
search: {
logPosition: encode({
end: moment(timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
position: { tiebreaker, time: moment(timestamp).toISOString() },
position: { tiebreaker, time },
start: moment(timeRange.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
streamLive: false,
}),
Expand Down Expand Up @@ -182,7 +184,7 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
onMouseLeave={setItemIsNotHovered}
>
<LogEntryColumn {...columnWidths[timestampColumnId]}>
<LogEntryTimestampColumn format={exampleTimestampFormat} time={timestamp} />
<LogEntryTimestampColumn format={exampleTimestampFormat} time={time} />
</LogEntryColumn>
<LogEntryColumn {...columnWidths[messageColumnId]}>
<LogEntryMessageColumn
Expand Down Expand Up @@ -301,7 +303,10 @@ export const LogEntryExampleMessageHeaders: React.FunctionComponent<{
data-test-subj="logColumnHeader messageLogColumnHeader"
key={columnConfiguration.messageColumn.id}
>
Message
{i18n.translate(
'xpack.infra.logEntryExampleMessageHeaders.logColumnHeader.messageLabel',
{ defaultMessage: 'Message' }
)}
</LogColumnHeader>
);
} else if (isFieldLogColumnConfiguration(columnConfiguration)) {
Expand Down
13 changes: 8 additions & 5 deletions x-pack/plugins/logs_shared/common/dynamic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import React, { lazy, Suspense } from 'react';
import React, { ComponentProps, ComponentType, lazy, Suspense } from 'react';

type LoadableComponent = () => Promise<{
default: React.ComponentType<any>;
type LoadableComponent<TComponent extends ComponentType<any>> = () => Promise<{
default: TComponent;
}>;

interface DynamicOptions {
Expand All @@ -21,10 +21,13 @@ interface DynamicOptions {
* @example
* const Header = dynamic(() => import('./components/header'))
*/
export function dynamic(loader: LoadableComponent, options: DynamicOptions = {}) {
export function dynamic<TComponent extends ComponentType<any>>(
loader: LoadableComponent<TComponent>,
options: DynamicOptions = {}
) {
const Component = lazy(loader);

return (props: any) => (
return (props: ComponentProps<TComponent>) => (
<Suspense fallback={options.fallback ?? null}>
<Component {...props} />
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ObservabilityAIAssistantPluginStart } from '@kbn/observability-ai-assistant-plugin/public';
import React from 'react';
import { dynamic } from '../../../common/dynamic';
import { LogAIAssistantProps } from './log_ai_assistant';

export const LogAIAssistant = dynamic(() => import('./log_ai_assistant'));

export function createLogAIAssistant({
observabilityAIAssistant,
}: {
observabilityAIAssistant: ObservabilityAIAssistantPluginStart;
}) {
return ({ ...props }) => (
}: Pick<LogAIAssistantProps, 'observabilityAIAssistant'>) {
return (props: Omit<LogAIAssistantProps, 'observabilityAIAssistant'>) => (
<LogAIAssistant observabilityAIAssistant={observabilityAIAssistant} {...props} />
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { LogEntryColumnContent } from './log_entry_column';

interface LogEntryContextMenuItem {
export interface LogEntryContextMenuItem {
label: string;
onClick: (e: React.MouseEvent) => void;
href?: string;
}

interface LogEntryContextMenuProps {
export interface LogEntryContextMenuProps {
'aria-label'?: string;
isOpen: boolean;
onOpen: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
WrapMode,
} from './text_styles';

interface LogEntryFieldColumnProps {
export interface LogEntryFieldColumnProps {
columnValue: LogColumn;
highlights: LogColumn[];
isActiveHighlight: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
WrapMode,
} from './text_styles';

interface LogEntryMessageColumnProps {
export interface LogEntryMessageColumnProps {
columnValue: LogColumn;
highlights: LogColumn[];
isActiveHighlight: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { TimeFormat, useFormattedTime } from '../../formatted_time';
import { LogEntryColumnContent } from './log_entry_column';

interface LogEntryTimestampColumnProps {
export interface LogEntryTimestampColumnProps {
format?: TimeFormat;
time: string;
render?: (time: string) => React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { LogDateRow } from './log_date_row';
import { LogEntry } from '../../../../common/log_entry';
import { LogColumnRenderConfiguration } from '../../../utils/log_column_render_configuration';

interface ScrollableLogTextStreamViewProps {
export interface ScrollableLogTextStreamViewProps {
columnConfigurations: LogColumnRenderConfiguration[];
items: StreamItem[];
scale: TextScale;
Expand Down