Skip to content

Commit

Permalink
Merge branch 'main' into control_group_state_diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 30, 2024
2 parents beec17a + 7e0dab9 commit 0a65814
Show file tree
Hide file tree
Showing 35 changed files with 330 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { BehaviorSubject } from 'rxjs';
import {
DndContext,
Expand Down Expand Up @@ -98,64 +98,84 @@ export function ControlGroup({
};
}, [controlGroupApi]);

const ApplyButtonComponent = useMemo(() => {
return (
<EuiButtonIcon
size="m"
disabled={!hasUnappliedSelections}
iconSize="m"
display="fill"
color={'success'}
iconType={'check'}
data-test-subj="controlGroup--applyFiltersButton"
aria-label={ControlGroupStrings.management.getApplyButtonTitle(hasUnappliedSelections)}
onClick={applySelections}
/>
);
}, [hasUnappliedSelections, applySelections]);

return (
<EuiPanel borderRadius="m" paddingSize="none" color={draggingId ? 'success' : 'transparent'}>
<EuiFlexGroup alignItems="center" gutterSize="s" wrap={true}>
<EuiPanel
borderRadius="m"
paddingSize="none"
color={draggingId ? 'success' : 'transparent'}
className="controlsWrapper"
>
<EuiFlexGroup
gutterSize="s"
direction="row"
responsive={false}
data-test-subj="controls-group"
>
{!isInitialized && <EuiLoadingChart />}
<DndContext
onDragStart={({ active }) => setDraggingId(`${active.id}`)}
onDragEnd={onDragEnd}
onDragCancel={() => setDraggingId(null)}
sensors={sensors}
measuring={{
droppable: {
strategy: MeasuringStrategy.BeforeDragging,
},
}}
>
<SortableContext items={controlsInOrder} strategy={rectSortingStrategy}>
{controlsInOrder.map(({ id, type }) => (
<ControlRenderer
key={id}
uuid={id}
type={type}
getParentApi={() => controlGroupApi}
onApiAvailable={(controlApi) => {
controlsManager.setControlApi(id, controlApi);
}}
isControlGroupInitialized={isInitialized}
/>
))}
</SortableContext>
<DragOverlay>
{draggingId ? (
<ControlClone
key={draggingId}
labelPosition={labelPosition}
controlApi={controlsManager.getControlApi(draggingId)}
/>
) : null}
</DragOverlay>
</DndContext>
{!autoApplySelections && (
<EuiFlexItem grow={false}>
<EuiToolTip
content={ControlGroupStrings.management.getApplyButtonTitle(hasUnappliedSelections)}
>
<EuiButtonIcon
size="m"
disabled={!hasUnappliedSelections}
iconSize="m"
display="fill"
color={'success'}
iconType={'check'}
data-test-subj="controlGroup--applyFiltersButton"
aria-label={ControlGroupStrings.management.getApplyButtonTitle(
hasUnappliedSelections
)}
onClick={applySelections}
/>
</EuiToolTip>
<EuiFlexItem>
<DndContext
onDragStart={({ active }) => setDraggingId(`${active.id}`)}
onDragEnd={onDragEnd}
onDragCancel={() => setDraggingId(null)}
sensors={sensors}
measuring={{
droppable: {
strategy: MeasuringStrategy.BeforeDragging,
},
}}
>
<SortableContext items={controlsInOrder} strategy={rectSortingStrategy}>
<EuiFlexGroup className="controlGroup" alignItems="center" gutterSize="s" wrap={true}>
{controlsInOrder.map(({ id, type }) => (
<ControlRenderer
key={id}
uuid={id}
type={type}
getParentApi={() => controlGroupApi}
onApiAvailable={(controlApi) => {
controlsManager.setControlApi(id, controlApi);
}}
isControlGroupInitialized={isInitialized}
/>
))}
</EuiFlexGroup>
</SortableContext>
<DragOverlay>
{draggingId ? (
<ControlClone
key={draggingId}
labelPosition={labelPosition}
controlApi={controlsManager.getControlApi(draggingId)}
/>
) : null}
</DragOverlay>
</DndContext>
</EuiFlexItem>
{isInitialized && !autoApplySelections && (
<EuiFlexItem grow={false} className="controlGroup--endButtonGroup">
{hasUnappliedSelections ? (
ApplyButtonComponent
) : (
<EuiToolTip content={ControlGroupStrings.management.getApplyButtonTitle(false)}>
{ApplyButtonComponent}
</EuiToolTip>
)}
</EuiFlexItem>
)}
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.timeSlider-playToggle:enabled {
background-color: $euiColorPrimary !important;
.timeSlider-playToggle {
height: 100%;
&:enabled {
background-color: $euiColorPrimary !important;
}
}

.timeSlider-prependButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export function PlayButton(props: Props) {
/>
);
return props.disablePlayButton ? (
<EuiToolTip content={TimeSliderStrings.control.getPlayButtonDisabledTooltip()}>
<EuiToolTip
display="block"
anchorClassName="timeSlider-playToggle"
content={TimeSliderStrings.control.getPlayButtonDisabledTooltip()}
>
{Button}
</EuiToolTip>
) : (
Expand Down
2 changes: 0 additions & 2 deletions examples/response_stream/common/api/reducer_stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
*/

export { reducerStreamReducer } from './reducer';
export { reducerStreamRequestBodySchema } from './request_body_schema';
export type { ReducerStreamRequestBodySchema } from './request_body_schema';
2 changes: 1 addition & 1 deletion examples/response_stream/server/routes/reducer_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
deleteEntityAction,
ReducerStreamApiAction,
} from '../../common/api/reducer_stream/reducer_actions';
import { reducerStreamRequestBodySchema } from '../../common/api/reducer_stream';
import { reducerStreamRequestBodySchema } from './schemas/reducer_stream';
import { RESPONSE_STREAM_API_ENDPOINT } from '../../common/api';

import { entities, getActions } from './shared';
Expand Down
2 changes: 1 addition & 1 deletion examples/response_stream/server/routes/redux_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
error,
type ReduxStreamApiAction,
} from '../../common/api/redux_stream/data_slice';
import { reducerStreamRequestBodySchema } from '../../common/api/reducer_stream';
import { reducerStreamRequestBodySchema } from './schemas/reducer_stream';
import { RESPONSE_STREAM_API_ENDPOINT } from '../../common/api';

import { entities, getActions } from './shared';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export { reducerStreamRequestBodySchema } from './request_body_schema';
export type { ReducerStreamRequestBodySchema } from './request_body_schema';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type { IRouter, Logger } from '@kbn/core/server';
import { streamFactory } from '@kbn/ml-response-stream/server';

import { simpleStringStreamRequestBodySchema } from '../../common/api/simple_string_stream';
import { simpleStringStreamRequestBodySchema } from './schemas/simple_string_stream';
import { RESPONSE_STREAM_API_ENDPOINT } from '../../common/api';

function timeout(ms: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-cli-dev-mode/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/cli-dev-mode",
"devOnly": true,
"owner": "@elastic/kibana-operations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { extractByJsonPointer } from '../../../utils/extract_by_json_pointer';
import { isPlainObjectType } from '../../../utils/is_plain_object_type';
import { parseRef } from '../../../utils/parse_ref';
import { DocumentNodeProcessor } from './types/document_node_processor';
import { isLocalRef } from './utils/is_local_ref';

/**
* Creates a node processor to prefix possibly conflicting components and security requirements
Expand Down Expand Up @@ -58,6 +59,23 @@ export function createNamespaceComponentsProcessor(pointer: string): DocumentNod
// `components.securitySchemes`. It means items in `security` implicitly reference
// `components.securitySchemes` items which should be handled.
onNodeLeave(node, context) {
// Handle mappings
if (context.parentKey === 'mapping' && isPlainObjectType(node)) {
for (const key of Object.keys(node)) {
const maybeRef = node[key];

if (typeof maybeRef !== 'string' || !isLocalRef(maybeRef)) {
throw new Error(
`Expected mappings to have local references but got "${maybeRef}" in ${JSON.stringify(
node
)}`
);
}

node[key] = decorateRefBaseName(maybeRef, namespace);
}
}

if ('security' in node && Array.isArray(node.security)) {
for (const securityRequirements of node.security) {
prefixObjectKeys(securityRequirements);
Expand Down
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 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.
*/

export function isLocalRef(ref: string): boolean {
return ref.startsWith('#/');
}
3 changes: 0 additions & 3 deletions packages/kbn-openapi-bundler/src/openapi_merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export interface MergerConfig {
outputFilePath: string;
options?: {
mergedSpecInfo?: Partial<OpenAPIV3.InfoObject>;
conflictsResolution?: {
prependComponentsWith: 'title';
};
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-openapi-bundler/src/utils/write_documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ function getVersionedOutputFilePath(outputFilePath: string, version: string): st

const filename = basename(outputFilePath);

return outputFilePath.replace(filename, `${version}-${filename}`);
return outputFilePath.replace(filename, `${version}_${filename}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,89 @@ describe('OpenAPI Merger - merging specs with conflicting components', () => {
Spec2_SomeCallback: expect.anything(),
});
});

it('prefixes discriminator mapping local references', async () => {
const spec1 = createOASDocument({
info: {
title: 'Spec1',
version: '2023-10-31',
},
paths: {
'/api/some_api': {
get: {
responses: {
'200': {
description: 'Successful response',
content: {
'application/json': {
schema: {
oneOf: [
{ $ref: '#/components/schemas/Component1' },
{ $ref: '#/components/schemas/Component2' },
],
discriminator: {
propertyName: 'commonProp',
mapping: {
component1: '#/components/schemas/Component1',
},
},
},
},
},
},
},
},
},
},
components: {
schemas: {
Component1: {
type: 'object',
properties: {
commonProp: {
type: 'string',
},
extraProp1: {
type: 'boolean',
},
},
},
Component2: {
type: 'object',
properties: {
commonProp: {
type: 'string',
},
extraProp2: {
type: 'integer',
},
},
},
},
},
});

const [mergedSpec] = Object.values(
await mergeSpecs({
1: spec1,
})
);

expect(mergedSpec.paths['/api/some_api']?.get?.responses['200']).toMatchObject({
content: {
'application/json; Elastic-Api-Version=2023-10-31': {
schema: expect.objectContaining({
discriminator: expect.objectContaining({
mapping: {
component1: '#/components/schemas/Spec1_Component1',
},
}),
}),
},
},
});
expect(mergedSpec.components?.schemas).toMatchObject({
Spec1_Component1: expect.anything(),
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('Service inventory - header filters', () => {
specialServiceName,
})
);
cy.dismissServiceGroupsTour();
});

after(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ describe('Service inventory', () => {

it('when selecting a different time range and clicking the update button', () => {
cy.wait(mainAliasNames);
cy.getByTestSubj('apmServiceGroupsTourDismissButton').click();

cy.selectAbsoluteTimeRange(
moment(timeRange.rangeFrom).subtract(5, 'm').toISOString(),
Expand Down
Loading

0 comments on commit 0a65814

Please sign in to comment.