Skip to content

Commit

Permalink
Merge branch 'main' into ml-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Jul 26, 2024
2 parents bc21b26 + 5817a9c commit cf3c6d3
Show file tree
Hide file tree
Showing 145 changed files with 3,024 additions and 4,947 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source .buildkite/scripts/common/util.sh

echo --- Security Solution OpenAPI Code Generation

echo -e "\n[Security Solution OpenAPI Code Generation] OpenAPI Common Package\n"
echo -e "\n[Security Solution OpenAPI Code Generation] OpenAPI Common Package"

(cd packages/kbn-openapi-common && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true
Expand All @@ -16,12 +16,12 @@ echo -e "\n[Security Solution OpenAPI Code Generation] Lists Common Package\n"
(cd packages/kbn-securitysolution-lists-common && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true

echo -e "\n[Security Solution OpenAPI Code Generation] Exceptions Common Package\n"
echo -e "\n[Security Solution OpenAPI Code Generation] Exceptions Common Package"

(cd packages/kbn-securitysolution-exceptions-common && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true

echo -e "\n[Security Solution OpenAPI Code Generation] Security Solution Plugin\n"
echo -e "\n[Security Solution OpenAPI Code Generation] Security Solution Plugin"

(cd x-pack/plugins/security_solution && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ echo -e "\n[Security Solution OpenAPI Bundling] Detections API\n"
(cd x-pack/plugins/security_solution && yarn openapi:bundle:detections)
check_for_changed_files "yarn openapi:bundle:detections" true

echo -e "\n[Security Solution OpenAPI Bundling] Timeline API\n"

(cd x-pack/plugins/security_solution && yarn openapi:bundle:timeline)
check_for_changed_files "yarn openapi:bundle:timeline" true

echo -e "\n[Security Solution OpenAPI Bundling] Entity Analytics API\n"

(cd x-pack/plugins/security_solution && yarn openapi:bundle:entity-analytics)
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/launchdarkly-code-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ concurrency:
jobs:
launchDarklyCodeReferences:
name: LaunchDarkly Code References
if: github.event.repository.fork == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 11 # This value must be set if the lookback configuration option is not disabled for find-code-references. Read more: https://github.com/launchdarkly/ld-find-code-refs#searching-for-unused-flags-extinctions
- name: LaunchDarkly Code References
uses: launchdarkly/find-code-references@v2.12.0
with:
accessToken: ${{ secrets.LD_ACCESS_TOKEN }}
projKey: ${{ secrets.LD_PROJECT_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 11 # This value must be set if the lookback configuration option is not disabled for find-code-references. Read more: https://github.com/launchdarkly/ld-find-code-refs#searching-for-unused-flags-extinctions
- name: LaunchDarkly Code References
uses: launchdarkly/find-code-references@v2.12.0
with:
accessToken: ${{ secrets.LD_ACCESS_TOKEN }}
projKey: ${{ secrets.LD_PROJECT_KEY }}
6 changes: 3 additions & 3 deletions examples/controls_example/public/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
EuiTab,
EuiTabs,
} from '@elastic/eui';
import { I18nProvider } from '@kbn/i18n-react';
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';

import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { ControlsExampleStartDeps } from '../plugin';
Expand Down Expand Up @@ -48,7 +48,7 @@ const App = ({
}

return (
<I18nProvider>
<KibanaRenderContextProvider i18n={core.i18n} theme={core.theme}>
<EuiPage>
<EuiPageBody>
<EuiPageSection>
Expand Down Expand Up @@ -78,7 +78,7 @@ const App = ({
</EuiPageTemplate.Section>
</EuiPageBody>
</EuiPage>
</I18nProvider>
</KibanaRenderContextProvider>
);
};

Expand Down
52 changes: 35 additions & 17 deletions examples/controls_example/public/app/react_control_example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const controlGroupPanels = {
title: 'Message',
grow: true,
width: 'medium',
searchString: 'this',
enhancements: {},
},
},
Expand Down Expand Up @@ -144,6 +143,7 @@ export const ReactControlExample = ({
);

const [controlGroupApi, setControlGroupApi] = useState<ControlGroupApi | undefined>(undefined);
const [isControlGroupInitialized, setIsControlGroupInitialized] = useState(false);
const [dataViewNotFound, setDataViewNotFound] = useState(false);

const dashboardApi = useMemo(() => {
Expand Down Expand Up @@ -222,6 +222,22 @@ export const ReactControlExample = ({
};
}, [controlGroupFilters$, controlGroupApi]);

useEffect(() => {
if (!controlGroupApi) {
return;
}
let ignore = false;
controlGroupApi.untilInitialized().then(() => {
if (!ignore) {
setIsControlGroupInitialized(true);
}
});

return () => {
ignore = true;
};
}, [controlGroupApi]);

useEffect(() => {
if (!controlGroupApi) return;

Expand Down Expand Up @@ -376,22 +392,24 @@ export const ReactControlExample = ({
key={`control_group`}
/>
<EuiSpacer size="l" />
<div style={{ height: '400px' }}>
<ReactEmbeddableRenderer
type={'data_table'}
getParentApi={() => ({
...dashboardApi,
getSerializedStateForChild: () => ({
rawState: {},
references: [],
}),
})}
hidePanelChrome={false}
onApiAvailable={(api) => {
dashboardApi?.setChild(api);
}}
/>
</div>
{isControlGroupInitialized && (
<div style={{ height: '400px' }}>
<ReactEmbeddableRenderer
type={'data_table'}
getParentApi={() => ({
...dashboardApi,
getSerializedStateForChild: () => ({
rawState: {},
references: [],
}),
})}
hidePanelChrome={false}
onApiAvailable={(api) => {
dashboardApi?.setChild(api);
}}
/>
</div>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import classNames from 'classnames';
import React from 'react';

import { EuiFlexGroup, EuiFlexItem, EuiFormLabel, EuiIcon } from '@elastic/eui';
import {
useBatchedOptionalPublishingSubjects,
useStateFromPublishingSubject,
} from '@kbn/presentation-publishing';
import { useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import { DEFAULT_CONTROL_GROW } from '@kbn/controls-plugin/common';

import { BehaviorSubject } from 'rxjs';
import { DefaultControlApi } from '../types';

/**
Expand All @@ -23,16 +22,16 @@ import { DefaultControlApi } from '../types';
* can be quite cumbersome.
*/
export const ControlClone = ({
controlStyle,
labelPosition,
controlApi,
}: {
controlStyle: string;
controlApi: DefaultControlApi;
labelPosition: string;
controlApi: DefaultControlApi | undefined;
}) => {
const width = useStateFromPublishingSubject(controlApi.width);
const [panelTitle, defaultPanelTitle] = useBatchedOptionalPublishingSubjects(
controlApi.panelTitle,
controlApi.defaultPanelTitle
const [width, panelTitle, defaultPanelTitle] = useBatchedPublishingSubjects(
controlApi ? controlApi.width : new BehaviorSubject(DEFAULT_CONTROL_GROW),
controlApi?.panelTitle ? controlApi.panelTitle : new BehaviorSubject(undefined),
controlApi?.defaultPanelTitle ? controlApi.defaultPanelTitle : new BehaviorSubject('')
);

return (
Expand All @@ -41,17 +40,17 @@ export const ControlClone = ({
'controlFrameCloneWrapper--small': width === 'small',
'controlFrameCloneWrapper--medium': width === 'medium',
'controlFrameCloneWrapper--large': width === 'large',
'controlFrameCloneWrapper--twoLine': controlStyle === 'twoLine',
'controlFrameCloneWrapper--twoLine': labelPosition === 'twoLine',
})}
>
{controlStyle === 'twoLine' ? (
{labelPosition === 'twoLine' ? (
<EuiFormLabel>{panelTitle ?? defaultPanelTitle}</EuiFormLabel>
) : undefined}
<EuiFlexGroup responsive={false} gutterSize="none" className={'controlFrame__draggable'}>
<EuiFlexItem grow={false}>
<EuiIcon type="grabHorizontal" className="controlFrame__dragHandle" />
</EuiFlexItem>
{controlStyle === 'oneLine' ? (
{labelPosition === 'oneLine' ? (
<EuiFlexItem>
<label className="controlFrameCloneWrapper__label">
{panelTitle ?? defaultPanelTitle}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* 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 React, { useCallback, useEffect, useState } from 'react';
import { BehaviorSubject } from 'rxjs';
import {
DndContext,
DragEndEvent,
DragOverlay,
KeyboardSensor,
MeasuringStrategy,
PointerSensor,
useSensor,
useSensors,
} from '@dnd-kit/core';
import {
arrayMove,
rectSortingStrategy,
SortableContext,
sortableKeyboardCoordinates,
} from '@dnd-kit/sortable';
import {
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiLoadingChart,
EuiPanel,
EuiToolTip,
} from '@elastic/eui';
import { ControlStyle } from '@kbn/controls-plugin/public';
import { useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import { ControlsInOrder } from '../init_controls_manager';
import { ControlGroupApi } from '../types';
import { ControlRenderer } from '../../control_renderer';
import { ControlClone } from '../../components/control_clone';
import { DefaultControlApi } from '../../types';
import { ControlGroupStrings } from '../control_group_strings';

interface Props {
applySelections: () => void;
controlGroupApi: ControlGroupApi;
controlsManager: {
controlsInOrder$: BehaviorSubject<ControlsInOrder>;
getControlApi: (uuid: string) => DefaultControlApi | undefined;
setControlApi: (uuid: string, controlApi: DefaultControlApi) => void;
};
hasUnappliedSelections: boolean;
labelPosition: ControlStyle;
}

export function ControlGroup({
applySelections,
controlGroupApi,
controlsManager,
labelPosition,
hasUnappliedSelections,
}: Props) {
const [isInitialized, setIsInitialized] = useState(false);
const [autoApplySelections, controlsInOrder] = useBatchedPublishingSubjects(
controlGroupApi.autoApplySelections$,
controlsManager.controlsInOrder$
);

/** Handle drag and drop */
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
);
const [draggingId, setDraggingId] = useState<string | null>(null);
const onDragEnd = useCallback(
({ over, active }: DragEndEvent) => {
const oldIndex = active?.data.current?.sortable.index;
const newIndex = over?.data.current?.sortable.index;
if (oldIndex !== undefined && newIndex !== undefined && oldIndex !== newIndex) {
controlsManager.controlsInOrder$.next(arrayMove([...controlsInOrder], oldIndex, newIndex));
}
(document.activeElement as HTMLElement)?.blur(); // hide hover actions on drop; otherwise, they get stuck
setDraggingId(null);
},
[controlsInOrder, controlsManager.controlsInOrder$]
);

useEffect(() => {
let ignore = false;
controlGroupApi.untilInitialized().then(() => {
if (!ignore) {
setIsInitialized(true);
}
});

return () => {
ignore = true;
};
}, [controlGroupApi]);

return (
<EuiPanel borderRadius="m" paddingSize="none" color={draggingId ? 'success' : 'transparent'}>
<EuiFlexGroup alignItems="center" gutterSize="s" wrap={true}>
{!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>
)}
</EuiFlexGroup>
</EuiPanel>
);
}
Loading

0 comments on commit cf3c6d3

Please sign in to comment.