Skip to content

Commit

Permalink
Merge branch 'main' into 204238-ecoinventory-v2-turn-off-entitycentri…
Browse files Browse the repository at this point in the history
…cexperience-feature-flag-by-default
  • Loading branch information
iblancof authored Dec 17, 2024
2 parents c3ce02c + effd84d commit 512946e
Show file tree
Hide file tree
Showing 27 changed files with 523 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ describe('Share modal embed content tab', () => {

beforeEach(() => {
component = mountWithIntl(
<EmbedContent
isDirty={false}
objectType="dashboard"
setIsNotSaved={() => jest.fn()}
shareableUrl="/home#/"
/>
<EmbedContent isDirty={false} objectType="dashboard" shareableUrl="/home#/" />
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type EmbedProps = Pick<
| 'objectType'
| 'isDirty'
> & {
setIsNotSaved: () => void;
objectConfig?: ShareContextObjectTypeConfig;
};

Expand All @@ -55,7 +54,6 @@ export const EmbedContent = ({
shareableUrl,
objectType,
objectConfig = {},
setIsNotSaved,
isDirty,
}: EmbedProps) => {
const isMounted = useMountedState();
Expand All @@ -67,10 +65,6 @@ export const EmbedContent = ({
const [anonymousAccessParameters] = useState<AnonymousAccessState['accessURLParameters']>(null);
const [usePublicUrl] = useState<boolean>(false);

useEffect(() => {
if (objectType !== 'dashboard') setIsNotSaved();
}, [url, setIsNotSaved, objectType]);

const makeUrlEmbeddable = useCallback((tempUrl: string): string => {
const embedParam = '?embed=true';
const urlHasQueryString = tempUrl.indexOf('?') !== -1;
Expand Down
34 changes: 1 addition & 33 deletions src/plugins/share/public/components/tabs/embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,13 @@
*/

import { i18n } from '@kbn/i18n';
import React, { useCallback } from 'react';
import React from 'react';
import { type IModalTabDeclaration } from '@kbn/shared-ux-tabbed-modal';
import { EmbedContent } from './embed_content';
import { useShareTabsContext } from '../../context';

const EMBED_TAB_ACTIONS = {
SET_EMBED_URL: 'SET_EMBED_URL',
SET_IS_NOT_SAVED: 'SET_IS_NOT_SAVED',
};

type IEmbedTab = IModalTabDeclaration<{ url: string; isNotSaved: boolean }>;

const embedTabReducer: IEmbedTab['reducer'] = (state = { url: '', isNotSaved: false }, action) => {
switch (action.type) {
case EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED:
return {
...state,
isNotSaved: action.payload,
};
case EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED:
return {
...state,
isNotSaved: action.payload,
};
default:
return state;
}
};

const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch }) => {
const {
embedUrlParamExtensions,
Expand All @@ -47,13 +25,6 @@ const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch })
isDirty,
} = useShareTabsContext()!;

const setIsNotSaved = useCallback(() => {
dispatch({
type: EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED,
payload: objectType === 'dashboard' ? isDirty : false,
});
}, [dispatch, objectType, isDirty]);

return (
<EmbedContent
{...{
Expand All @@ -62,8 +33,6 @@ const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch })
shareableUrl,
objectType,
objectConfig: objectTypeMeta?.config?.embed,
isNotSaved: state?.isNotSaved,
setIsNotSaved,
isDirty,
}}
/>
Expand All @@ -75,6 +44,5 @@ export const embedTab: IEmbedTab = {
name: i18n.translate('share.contextMenu.embedCodeTab', {
defaultMessage: 'Embed',
}),
reducer: embedTabReducer,
content: EmbedTabContent,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const graphRequestSchema = schema.object({
nodesLimit: schema.maybe(schema.number()),
showUnknownTarget: schema.maybe(schema.boolean()),
query: schema.object({
eventIds: schema.arrayOf(schema.string()),
originEventIds: schema.arrayOf(
schema.object({ id: schema.string(), isAlert: schema.boolean() })
),
// TODO: use zod for range validation instead of config schema
start: schema.oneOf([schema.number(), schema.string()]),
end: schema.oneOf([schema.number(), schema.string()]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function scoreSuggestions({
type: 'string',
},
},
required: ['score'],
required: ['scores'],
} as const,
};

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/fleet/common/experimental_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type ExperimentalFeatures = typeof allowedExperimentalValues;
const _allowedExperimentalValues = {
createPackagePolicyMultiPageLayout: true,
packageVerification: true,
showDevtoolsRequest: true,
diagnosticFileUploadEnabled: true,
displayAgentMetrics: true,
showIntegrationsSubcategories: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n';
import { omit } from 'lodash';
import { set } from '@kbn/safer-lodash-set';

import { ExperimentalFeaturesService } from '../../../../../services';
import {
generateCreatePackagePolicyDevToolsRequest,
generateCreateAgentPolicyDevToolsRequest,
Expand Down Expand Up @@ -39,12 +38,7 @@ export function useDevToolsRequest({
packageInfo?: PackageInfo;
packagePolicyId?: string;
}) {
const { showDevtoolsRequest: isShowDevtoolRequestExperimentEnabled } =
ExperimentalFeaturesService.get();

const showDevtoolsRequest =
!HIDDEN_API_REFERENCE_PACKAGES.includes(packageInfo?.name ?? '') &&
isShowDevtoolRequestExperimentEnabled;
const showDevtoolsRequest = !HIDDEN_API_REFERENCE_PACKAGES.includes(packageInfo?.name ?? '');

const [devtoolRequest, devtoolRequestDescription] = useMemo(() => {
if (selectedPolicyTab === SelectedPolicyTab.NEW) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
ConfirmDeployAgentPolicyModal,
} from '../../../components';
import { DevtoolsRequestFlyoutButton } from '../../../../../components';
import { ExperimentalFeaturesService } from '../../../../../services';
import { generateUpdateAgentPolicyDevToolsRequest } from '../../../services';
import { UNKNOWN_SPACE } from '../../../../../../../../common/constants';

Expand Down Expand Up @@ -155,7 +154,6 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
setIsLoading(false);
};

const { showDevtoolsRequest } = ExperimentalFeaturesService.get();
const devtoolRequest = useMemo(
() =>
generateUpdateAgentPolicyDevToolsRequest(
Expand Down Expand Up @@ -235,28 +233,26 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
/>
</EuiButtonEmpty>
</EuiFlexItem>
{showDevtoolsRequest ? (
<EuiFlexItem grow={false}>
<DevtoolsRequestFlyoutButton
isDisabled={
isLoading ||
Object.keys(validation).length > 0 ||
hasAdvancedSettingsErrors ||
hasInvalidSpaceError
<EuiFlexItem grow={false}>
<DevtoolsRequestFlyoutButton
isDisabled={
isLoading ||
Object.keys(validation).length > 0 ||
hasAdvancedSettingsErrors ||
hasInvalidSpaceError
}
btnProps={{
color: 'text',
}}
description={i18n.translate(
'xpack.fleet.editAgentPolicy.devtoolsRequestDescription',
{
defaultMessage: 'This Kibana request updates an agent policy.',
}
btnProps={{
color: 'text',
}}
description={i18n.translate(
'xpack.fleet.editAgentPolicy.devtoolsRequestDescription',
{
defaultMessage: 'This Kibana request updates an agent policy.',
}
)}
request={devtoolRequest}
/>
</EuiFlexItem>
) : null}
)}
request={devtoolRequest}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={onSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { useAuthz, useStartServices, sendCreateAgentPolicy } from '../../../../h
import { AgentPolicyForm, agentPolicyFormValidation } from '../../components';
import { DevtoolsRequestFlyoutButton } from '../../../../components';
import { generateCreateAgentPolicyDevToolsRequest } from '../../services';
import { ExperimentalFeaturesService } from '../../../../services';
import { generateNewAgentPolicyWithDefaults } from '../../../../../../../common/services/generate_new_agent_policy';

const FlyoutWithHigherZIndex = styled(EuiFlyout)`
Expand Down Expand Up @@ -109,7 +108,6 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent<Props> = ({
/>
</EuiFlyoutBody>
);
const { showDevtoolsRequest } = ExperimentalFeaturesService.get();
const agentPolicyContent = useMemo(
() => generateCreateAgentPolicyDevToolsRequest(agentPolicy, withSysMonitoring),
[agentPolicy, withSysMonitoring]
Expand All @@ -128,25 +126,23 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent<Props> = ({
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="none">
{showDevtoolsRequest ? (
<EuiFlexItem grow={false}>
<DevtoolsRequestFlyoutButton
isDisabled={
isLoading ||
Object.keys(validation).length > 0 ||
hasAdvancedSettingsErrors ||
hasInvalidSpaceError
<EuiFlexItem grow={false}>
<DevtoolsRequestFlyoutButton
isDisabled={
isLoading ||
Object.keys(validation).length > 0 ||
hasAdvancedSettingsErrors ||
hasInvalidSpaceError
}
description={i18n.translate(
'xpack.fleet.createAgentPolicy.devtoolsRequestDescription',
{
defaultMessage: 'This Kibana request creates a new agent policy.',
}
description={i18n.translate(
'xpack.fleet.createAgentPolicy.devtoolsRequestDescription',
{
defaultMessage: 'This Kibana request creates a new agent policy.',
}
)}
request={agentPolicyContent}
/>
</EuiFlexItem>
) : null}
)}
request={agentPolicyContent}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
fill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getLensOperationFromRuleMetric = (metric: GenericMetric): LensOpera
const { aggType, field, filter = '' } = metric;
let operation: string = aggType;
const operationArgs: string[] = [];
const escapedFilter = filter.replace(/'/g, "\\'");
const escapedFilter = filter.replace(/\\/g, '\\\\').replace(/'/g, "\\'");

if (aggType === Aggregators.RATE) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,46 @@ const useGraphPopovers = (
};

interface GraphInvestigationProps {
dataView: DataView;
eventIds: string[];
timestamp: string | null;
/**
* The initial state to use for the graph investigation view.
*/
initialState: {
/**
* The data view to use for the graph investigation view.
*/
dataView: DataView;

/**
* The origin events for the graph investigation view.
*/
originEventIds: Array<{
/**
* The ID of the origin event.
*/
id: string;

/**
* A flag indicating whether the origin event is an alert or not.
*/
isAlert: boolean;
}>;

/**
* The initial timerange for the graph investigation view.
*/
timeRange: TimeRange;
};
}

/**
* Graph investigation view allows the user to expand nodes and view related entities.
*/
export const GraphInvestigation: React.FC<GraphInvestigationProps> = memo(
({ dataView, eventIds, timestamp = new Date().toISOString() }: GraphInvestigationProps) => {
({
initialState: { dataView, originEventIds, timeRange: initialTimeRange },
}: GraphInvestigationProps) => {
const [searchFilters, setSearchFilters] = useState<Filter[]>(() => []);
const [timeRange, setTimeRange] = useState<TimeRange>({
from: `${timestamp}||-30m`,
to: `${timestamp}||+30m`,
});
const [timeRange, setTimeRange] = useState<TimeRange>(initialTimeRange);

const {
services: { uiSettings },
Expand All @@ -153,7 +178,7 @@ export const GraphInvestigation: React.FC<GraphInvestigationProps> = memo(
[...searchFilters],
getEsQueryConfig(uiSettings as Parameters<typeof getEsQueryConfig>[0])
),
[searchFilters, dataView, uiSettings]
[dataView, searchFilters, uiSettings]
);

const { nodeExpandPopover, openPopoverCallback } = useGraphPopovers(
Expand All @@ -166,7 +191,7 @@ export const GraphInvestigation: React.FC<GraphInvestigationProps> = memo(
const { data, refresh, isFetching } = useFetchGraphData({
req: {
query: {
eventIds,
originEventIds,
esQuery: query,
start: timeRange.from,
end: timeRange.to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('useFetchGraphData', () => {
return useFetchGraphData({
req: {
query: {
eventIds: [],
originEventIds: [],
start: '2021-09-01T00:00:00.000Z',
end: '2021-09-01T23:59:59.999Z',
},
Expand All @@ -52,7 +52,7 @@ describe('useFetchGraphData', () => {
return useFetchGraphData({
req: {
query: {
eventIds: [],
originEventIds: [],
start: '2021-09-01T00:00:00.000Z',
end: '2021-09-01T23:59:59.999Z',
},
Expand All @@ -75,7 +75,7 @@ describe('useFetchGraphData', () => {
return useFetchGraphData({
req: {
query: {
eventIds: [],
originEventIds: [],
start: '2021-09-01T00:00:00.000Z',
end: '2021-09-01T23:59:59.999Z',
},
Expand All @@ -98,7 +98,7 @@ describe('useFetchGraphData', () => {
return useFetchGraphData({
req: {
query: {
eventIds: [],
originEventIds: [],
start: '2021-09-01T00:00:00.000Z',
end: '2021-09-01T23:59:59.999Z',
},
Expand Down
Loading

0 comments on commit 512946e

Please sign in to comment.