Skip to content

Commit

Permalink
Merge branch 'main' into lodash-set-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Feb 14, 2023
2 parents 9927cd8 + cf94e1a commit 41bcdfb
Show file tree
Hide file tree
Showing 68 changed files with 2,305 additions and 194 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ packages/kbn-yarn-lock-validator @elastic/kibana-operations
#CC# /x-pack/plugins/translations/ @elastic/kibana-localization @elastic/kibana-core

# Kibana Platform Security
/.github/codeql @elastic/kibana-security
/.github/workflows/codeql.yml @elastic/kibana-security
/src/plugins/telemetry/server/config/telemetry_labels.ts @elastic/kibana-security
/test/interactive_setup_api_integration/ @elastic/kibana-security
/test/interactive_setup_functional/ @elastic/kibana-security
Expand Down
4 changes: 4 additions & 0 deletions .github/paths-labeller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- "src/plugins/bfetch/**/*.*"
- "Team:apm":
- "x-pack/plugins/apm/**/*.*"
- "x-pack/test/apm_api_integration/**/*.*"
- "packages/kbn-apm-synthtrace/**/*.*"
- "packages/kbn-apm-synthtrace-client/**/*.*"
- "packages/kbn-apm-utils/**/*.*"
- "Team:Fleet":
- "x-pack/plugins/fleet/**/*.*"
- "x-pack/test/fleet_api_integration/**/*.*"
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
Expand Up @@ -12,6 +12,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiImage,
useEuiTheme,
makeHighContrastColor,
} from '@elastic/eui';
Expand All @@ -37,7 +38,7 @@ const description = i18n.translate(
/**
* A presentational component that renders a button designed to exit "full screen" mode.
*/
export const ExitFullScreenButton = ({ onClick, className }: Props) => {
export const ExitFullScreenButton = ({ onClick, className, customLogo }: Props) => {
const { euiTheme } = useEuiTheme();
const { colors, size, border } = euiTheme;

Expand All @@ -63,7 +64,11 @@ export const ExitFullScreenButton = ({ onClick, className }: Props) => {
>
<EuiFlexGroup component="span" responsive={false} alignItems="center" gutterSize="s">
<EuiFlexItem component="span" grow={false}>
<EuiIcon type="logoElastic" size="m" />
{customLogo ? (
<EuiImage src={customLogo} size={16} alt="customLogo" />
) : (
<EuiIcon type="logoElastic" size="m" />
)}
</EuiFlexItem>
<EuiFlexItem component="span" grow={false} data-test-subj="exitFullScreenModeText">
{text}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

import { ExitFullScreenButton } from './exit_full_screen_button';
import { ExitFullScreenButtonKibanaProvider, ExitFullScreenButtonProvider } from './services';
import { of } from 'rxjs';

const componentServices = getExitFullScreenButtonServicesMock();
const kibanaServices = getExitFullScreenButtonKibanaDependenciesMock();
Expand Down Expand Up @@ -103,6 +104,16 @@ describe('<ExitFullScreenButton />', () => {
expect(kibanaServices.coreStart.chrome.setIsVisible).toHaveBeenCalledTimes(0);
});

test('renders custom logo', () => {
kibanaServices.coreStart.customBranding.customBranding$ = of({
logo: 'imageSrcAsBase64encodedstring',
});
const component = kibanaMount(
<ExitFullScreenButton onExit={jest.fn()} toggleChrome={false} />
);
expect(component.render()).toMatchSnapshot();
});

describe('onExit', () => {
const onExitHandler = jest.fn();
let component: ReactWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useMountedState from 'react-use/lib/useMountedState';

import type { ExitFullScreenButtonProps as Props } from '@kbn/shared-ux-button-exit-full-screen-types';

import useObservable from 'react-use/lib/useObservable';
import { ExitFullScreenButton as Component } from './exit_full_screen_button.component';
import { useServices } from './services';

Expand All @@ -22,8 +23,10 @@ import { useServices } from './services';
*/
export const ExitFullScreenButton = ({ onExit = () => {}, toggleChrome = true }: Props) => {
const { euiTheme } = useEuiTheme();
const { setIsFullscreen } = useServices();
const { setIsFullscreen, customBranding$ } = useServices();
const isMounted = useMountedState();
const customBranding = useObservable(customBranding$);
const customLogo = customBranding?.logo;

const onClick = useCallback(() => {
if (toggleChrome) {
Expand Down Expand Up @@ -70,5 +73,5 @@ export const ExitFullScreenButton = ({ onExit = () => {}, toggleChrome = true }:
z-index: 5;
`;

return <Component css={buttonCSS} {...{ onClick }} />;
return <Component css={buttonCSS} customLogo={customLogo} {...{ onClick }} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ExitFullScreenButtonKibanaProvider: FC<ExitFullScreenButtonKibanaDe
setIsFullscreen: (isFullscreen: boolean) => {
services.coreStart.chrome.setIsVisible(!isFullscreen);
},
customBranding$: services.coreStart.customBranding.customBranding$,
}}
>
{children}
Expand Down
5 changes: 5 additions & 0 deletions packages/shared-ux/button/exit_full_screen/mocks/src/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
ExitFullScreenButtonKibanaDependencies,
ExitFullScreenButtonServices,
} from '@kbn/shared-ux-button-exit-full-screen-types';
import { of } from 'rxjs';

/**
* Return a Jest mock of the services for the `ExitFullScreenButton` component.
*/
export const getServicesMock = (): ExitFullScreenButtonServices => {
return {
setIsFullscreen: jest.fn(),
customBranding$: of({}),
};
};

Expand All @@ -29,6 +31,9 @@ export const getKibanaDependenciesMock = (): ExitFullScreenButtonKibanaDependenc
chrome: {
setIsVisible: jest.fn(),
},
customBranding: {
customBranding$: of({}),
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
ExitFullScreenButtonProps as Props,
ExitFullScreenButtonServices,
} from '@kbn/shared-ux-button-exit-full-screen-types';
import { of } from 'rxjs';

type PropArguments = Pick<Props, 'toggleChrome'>;

Expand Down Expand Up @@ -51,6 +52,7 @@ export class StorybookMock extends AbstractStorybookMock<
setIsFullscreen: (isFullscreen: boolean) => {
action('setIsFullscreen')(isFullscreen);
},
customBranding$: of({}),
};
}
}
9 changes: 9 additions & 0 deletions packages/shared-ux/button/exit_full_screen/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
*/

import { MouseEventHandler, HTMLAttributes } from 'react';
import { Observable } from 'rxjs';
import { CustomBranding } from '@kbn/core-custom-branding-common';

/**
* Abstract external services for this component.
*/
export interface Services {
/** Function to invoke to set the application to full-screen mode */
setIsFullscreen: (isFullscreen: boolean) => void;
/** Observable that emits the value of custom branding, if set*/
customBranding$: Observable<CustomBranding>;
}

/**
Expand All @@ -29,6 +33,9 @@ export interface KibanaDependencies {
chrome: {
setIsVisible: (isVisible: boolean) => void;
};
customBranding: {
customBranding$: Observable<CustomBranding>;
};
};
}

Expand All @@ -55,4 +62,6 @@ export interface ExitFullScreenButtonComponentProps
extends Pick<HTMLAttributes<HTMLDivElement>, 'className'> {
/** Handler to invoke when one clicks the button. */
onClick: MouseEventHandler<HTMLButtonElement>;
/** If set, custom logo is displayed instead of Elastic logo */
customLogo?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
],
"exclude": [
"target/**/*",
],
"kbn_references": [
"@kbn/core-custom-branding-common",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import type { ContentTypeDefinition } from './content_type_definition';
test('create a content type with just an id', () => {
const type = new ContentType({ id: 'test' });

expect(type.id()).toBe('test');
expect(type.name()).toBe('test');
expect(type.icon()).toBe('questionInCircle');
expect(type.description()).toBe('');
expect(type.id).toBe('test');
expect(type.name).toBe('test');
expect(type.icon).toBe('questionInCircle');
expect(type.description).toBe('');
});

test('create a content type with all the full definition', () => {
Expand All @@ -27,9 +27,9 @@ test('create a content type with all the full definition', () => {
};
const type = new ContentType(definition);

expect(type.id()).toBe(definition.id);
expect(type.name()).toBe(definition.name);
expect(type.icon()).toBe(definition.icon);
expect(type.description()).toBe(definition.description);
expect(type.id).toBe(definition.id);
expect(type.name).toBe(definition.name);
expect(type.icon).toBe(definition.icon);
expect(type.description).toBe(definition.description);
expect(type.definition).toEqual(definition);
});
12 changes: 6 additions & 6 deletions src/plugins/content_management/public/registry/content_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import type { CrudClient } from '../crud_client';
export class ContentType {
constructor(public readonly definition: ContentTypeDefinition) {}

id(): string {
public get id(): string {
return this.definition.id;
}

name(): string {
return this.definition.name ?? this.id();
public get name(): string {
return this.definition.name ?? this.id;
}

description(): string {
public get description(): string {
return this.definition.description ?? '';
}

icon(): string {
public get icon(): string {
return this.definition.icon ?? 'questionInCircle';
}

crud(): CrudClient | undefined {
public get crud(): CrudClient | undefined {
return this.definition.crud;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ test('registering a content type', () => {
description: 'Test description',
});

expect(type.id()).toBe('test');
expect(type.name()).toBe('Test');
expect(type.icon()).toBe('test');
expect(type.description()).toBe('Test description');
expect(type.id).toBe('test');
expect(type.name).toBe('Test');
expect(type.icon).toBe('test');
expect(type.description).toBe('Test description');
});

test('registering already registered content type throws', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/content_management/public/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ContentTypeRegistry {
throw new Error(`Content type with id "${definition.id}" already registered.`);
}
const type = new ContentType(definition);
this.types.set(type.id(), type);
this.types.set(type.id, type);

return type;
}
Expand Down
39 changes: 39 additions & 0 deletions src/plugins/content_management/server/core/content_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { ContentCrud } from './crud';
import { EventBus } from './event_bus';
import { ContentStorage, ContentTypeDefinition } from './types';

export class ContentType {
/** Content definition. */
private readonly _definition: ContentTypeDefinition<ContentStorage>;
/** Content crud instance. */
private readonly contentCrud: ContentCrud;

constructor(definition: ContentTypeDefinition, eventBus: EventBus) {
this._definition = definition;
this.contentCrud = new ContentCrud(definition.id, definition.storage, { eventBus });
}

public get id() {
return this._definition.id;
}

public get definition() {
return this._definition;
}

public get storage() {
return this._definition.storage;
}

public get crud() {
return this.contentCrud;
}
}
Loading

0 comments on commit 41bcdfb

Please sign in to comment.