Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into allow-editing-prebu…
Browse files Browse the repository at this point in the history
…ilt-in-ui
  • Loading branch information
dplumlee committed Nov 7, 2024
2 parents a3246d2 + a19dd8e commit 9ef2f4f
Show file tree
Hide file tree
Showing 27 changed files with 695 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ export const unsavedChangesBadgeStrings = {
}),
};

export const leaveConfirmStrings = {
getLeaveTitle: () =>
i18n.translate('dashboard.appLeaveConfirmModal.unsavedChangesTitle', {
defaultMessage: 'Unsaved changes',
}),
getLeaveSubtitle: () =>
i18n.translate('dashboard.appLeaveConfirmModal.unsavedChangesSubtitle', {
defaultMessage: 'Leave Dashboard with unsaved work?',
}),
getLeaveCancelButtonText: () =>
i18n.translate('dashboard.appLeaveConfirmModal.cancelButtonLabel', {
defaultMessage: 'Cancel',
}),
};

export const getCreateVisualizationButtonTitle = () =>
i18n.translate('dashboard.solutionToolbar.addPanelButtonLabel', {
defaultMessage: 'Create visualization',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
dashboardManagedBadge,
getDashboardBreadcrumb,
getDashboardTitle,
leaveConfirmStrings,
unsavedChangesBadgeStrings,
} from '../dashboard_app/_dashboard_app_strings';
import { useDashboardMountContext } from '../dashboard_app/hooks/dashboard_mount_context';
Expand All @@ -48,7 +47,6 @@ import { getDashboardRecentlyAccessedService } from '../services/dashboard_recen
import {
coreServices,
dataService,
embeddableService,
navigationService,
serverlessService,
} from '../services/kibana_services';
Expand Down Expand Up @@ -195,16 +193,6 @@ export function InternalDashboardTopNav({
*/
useEffect(() => {
onAppLeave((actions) => {
if (
viewMode === 'edit' &&
hasUnsavedChanges &&
!embeddableService.getStateTransfer().isTransferInProgress
) {
return actions.confirm(
leaveConfirmStrings.getLeaveSubtitle(),
leaveConfirmStrings.getLeaveTitle()
);
}
return actions.default();
});
return () => {
Expand Down
4 changes: 1 addition & 3 deletions test/functional/apps/dashboard/group1/edit_visualizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import expect from '@kbn/expect';

export default function ({ getService, getPageObjects }) {
const { dashboard, header, visualize, common, visEditor } = getPageObjects([
const { dashboard, header, visualize, visEditor } = getPageObjects([
'dashboard',
'header',
'visualize',
Expand Down Expand Up @@ -114,7 +114,6 @@ export default function ({ getService, getPageObjects }) {

await header.waitUntilLoadingHasFinished();
await appsMenu.clickLink('Visualize Library');
await common.clickConfirmOnModal();
expect(await testSubjects.exists('visualizationLandingPage')).to.be(true);
});

Expand All @@ -132,7 +131,6 @@ export default function ({ getService, getPageObjects }) {

await header.waitUntilLoadingHasFinished();
await appsMenu.clickLink('Visualize Library');
await common.clickConfirmOnModal();
expect(await testSubjects.exists('visualizationLandingPage')).to.be(true);
});

Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/canvas/public/state/actions/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ function getBareElement(el, includeId = false) {

export const elementLayer = createAction('elementLayer');

export const setMultiplePositions = createAction('setMultiplePosition', (repositionedElements) => ({
repositionedElements,
}));
export const setMultiplePositions = createAction(
'setMultiplePositions',
(repositionedElements) => ({
repositionedElements,
})
);

export const flushContext = createAction('flushContext');
export const flushContextAfterIndex = createAction('flushContextAfterIndex');
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/links/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useCaseViewNavigation, useConfigureCasesNavigation } from '../../common
import * as i18n from './translations';

export interface CasesNavigation<T = React.MouseEvent | MouseEvent | null, K = null> {
href: K extends 'configurable' ? (arg: T) => string : string;
href?: K extends 'configurable' ? (arg: T) => string : string;
onClick: K extends 'configurable'
? (arg: T, arg2: React.MouseEvent | MouseEvent) => Promise<void> | void
: (arg: T) => Promise<void> | void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,38 @@ describe('Alert events', () => {
expect(wrapper.text()).toBe('added an alert from Awesome rule');
});

it('does NOT render the link when the rule id is null', async () => {
it('renders the link when onClick is provided but href is not valid', async () => {
const wrapper = mount(
<TestProviders>
<SingleAlertCommentEvent {...props} ruleId={null} />
<SingleAlertCommentEvent {...props} getRuleDetailsHref={undefined} />
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="alert-rule-link-action-id-1"]`).first().exists()
).toBeTruthy();
});

it('renders the link when href is valid but onClick is not available', async () => {
const wrapper = mount(
<TestProviders>
<SingleAlertCommentEvent {...props} onRuleDetailsClick={undefined} />
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="alert-rule-link-action-id-1"]`).first().exists()
).toBeTruthy();
});

it('does NOT render the link when the href and onclick are invalid but it shows the rule name', async () => {
const wrapper = mount(
<TestProviders>
<SingleAlertCommentEvent
{...props}
getRuleDetailsHref={undefined}
onRuleDetailsClick={undefined}
/>
</TestProviders>
);

Expand All @@ -61,10 +89,10 @@ describe('Alert events', () => {
expect(wrapper.text()).toBe('added an alert from Awesome rule');
});

it('does NOT render the link when the href is invalid but it shows the rule name', async () => {
it('does NOT render the link when the rule id is null', async () => {
const wrapper = mount(
<TestProviders>
<SingleAlertCommentEvent {...props} getRuleDetailsHref={undefined} />
<SingleAlertCommentEvent {...props} ruleId={null} />
</TestProviders>
);

Expand Down Expand Up @@ -131,9 +159,28 @@ describe('Alert events', () => {
expect(result.getByTestId('alert-rule-link-action-id-1')).toHaveTextContent('Awesome rule');
});

it('does NOT render the link when the rule id is null', async () => {
it('renders the link when onClick is provided but href is not valid', async () => {
const result = appMock.render(
<MultipleAlertsCommentEvent {...props} totalAlerts={2} ruleId={null} />
<MultipleAlertsCommentEvent {...props} totalAlerts={2} getRuleDetailsHref={undefined} />
);
expect(result.getByTestId('alert-rule-link-action-id-1')).toHaveTextContent('Awesome rule');
});

it('renders the link when href is valid but onClick is not available', async () => {
const result = appMock.render(
<MultipleAlertsCommentEvent {...props} totalAlerts={2} onRuleDetailsClick={undefined} />
);
expect(result.getByTestId('alert-rule-link-action-id-1')).toHaveTextContent('Awesome rule');
});

it('does NOT render the link when the href and onclick are invalid but it shows the rule name', async () => {
const result = appMock.render(
<MultipleAlertsCommentEvent
{...props}
totalAlerts={2}
getRuleDetailsHref={undefined}
onRuleDetailsClick={undefined}
/>
);

expect(result.getByTestId('multiple-alerts-user-action-action-id-1')).toHaveTextContent(
Expand All @@ -142,9 +189,9 @@ describe('Alert events', () => {
expect(result.queryByTestId('alert-rule-link-action-id-1')).toBeFalsy();
});

it('does NOT render the link when the href is invalid but it shows the rule name', async () => {
it('does NOT render the link when the rule id is null', async () => {
const result = appMock.render(
<MultipleAlertsCommentEvent {...props} totalAlerts={2} getRuleDetailsHref={undefined} />
<MultipleAlertsCommentEvent {...props} totalAlerts={2} ruleId={null} />
);

expect(result.getByTestId('multiple-alerts-user-action-action-id-1')).toHaveTextContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { memo, useCallback } from 'react';
import React, { memo, useCallback, useMemo } from 'react';
import { isEmpty } from 'lodash';
import { EuiLoadingSpinner } from '@elastic/eui';

Expand Down Expand Up @@ -38,12 +38,18 @@ const RuleLink: React.FC<SingleAlertProps> = memo(

const ruleDetailsHref = getRuleDetailsHref?.(ruleId);
const finalRuleName = ruleName ?? i18n.UNKNOWN_RULE;
const isValidLink = useMemo(() => {
if (!onRuleDetailsClick && !ruleDetailsHref) {
return false;
}
return !isEmpty(ruleId);
}, [onRuleDetailsClick, ruleDetailsHref, ruleId]);

if (loadingAlertData) {
return <EuiLoadingSpinner size="m" data-test-subj={`alert-loading-spinner-${actionId}`} />;
}

if (!isEmpty(ruleId) && ruleDetailsHref != null) {
if (isValidLink) {
return (
<LinkAnchor
onClick={onLinkClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export const mergeInputsOverrides = (

export const getFullInputStreams = (
input: PackagePolicyInput,
allStreamEnabled: boolean = false
allStreamEnabled: boolean = false,
streamsOriginalIdsMap?: Map<string, string> // Map of stream ids <destinationId, originalId>
): FullAgentPolicyInputStream => {
return {
...(input.compiled_input || {}),
Expand All @@ -121,15 +122,18 @@ export const getFullInputStreams = (
streams: input.streams
.filter((stream) => stream.enabled || allStreamEnabled)
.map((stream) => {
const streamId = stream.id;
const fullStream: FullAgentPolicyInputStream = {
id: stream.id,
id: streamId,
data_stream: stream.data_stream,
...stream.compiled_stream,
...Object.entries(stream.config || {}).reduce((acc, [key, { value }]) => {
acc[key] = value;
return acc;
}, {} as { [k: string]: any }),
};
streamsOriginalIdsMap?.set(fullStream.id, streamId);

return fullStream;
}),
}
Expand Down
Loading

0 comments on commit 9ef2f4f

Please sign in to comment.