Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ml-anomaly-embedd…
Browse files Browse the repository at this point in the history
…able-refactor-ui-actions
  • Loading branch information
qn895 committed Apr 6, 2021
2 parents 83c6974 + 7f97f8b commit e901434
Show file tree
Hide file tree
Showing 66 changed files with 3,184 additions and 653 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
"@bazel/ibazel": "^0.14.0",
"@bazel/typescript": "^3.2.3",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.5.0",
"@cypress/webpack-preprocessor": "^5.6.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/eslint-config-kibana": "link:packages/elastic-eslint-config-kibana",
Expand Down Expand Up @@ -682,7 +682,7 @@
"copy-webpack-plugin": "^6.0.2",
"cpy": "^8.1.1",
"css-loader": "^3.4.2",
"cypress": "^6.2.1",
"cypress": "^6.8.0",
"cypress-cucumber-preprocessor": "^2.5.2",
"cypress-multi-reporters": "^1.4.0",
"cypress-pipe": "^2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/core/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export async function bootstrap({ configs, cliArgs, applyConfigOverrides }: Boot
try {
await root.setup();
await root.start();

// notify parent process know when we are ready for dev mode.
if (process.send) {
process.send(['SERVER_LISTENING']);
}
} catch (err) {
await shutdown(err);
}
Expand Down
17 changes: 17 additions & 0 deletions src/core/server/ui_settings/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ describe('ui_settings 7.12.0 migrations', () => {
const migrated = migration(doc);
expect(JSON.parse(migrated.attributes['timepicker:quickRanges'])).toEqual([migratedQuickRange]);
});

// https://github.com/elastic/kibana/issues/95616
test('returns doc when "timepicker:quickRanges" is null', () => {
const doc = {
type: 'config',
id: '8.0.0',
attributes: {
buildNum: 9007199254740991,
'timepicker:quickRanges': null,
},
references: [],
updated_at: '2020-06-09T20:18:20.349Z',
migrationVersion: {},
};
const migrated = migration(doc);
expect(migrated).toEqual(doc);
});
});

describe('ui_settings 7.13.0 migrations', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/ui_settings/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const migrations = {
...doc,
...(doc.attributes && {
attributes: Object.keys(doc.attributes).reduce((acc, key) => {
if (key === 'timepicker:quickRanges' && doc.attributes[key].indexOf('section') > -1) {
if (key === 'timepicker:quickRanges' && doc.attributes[key]?.indexOf('section') > -1) {
const ranges = JSON.parse(doc.attributes[key]).map(
({ from, to, display }: { from: string; to: string; display: string }) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
EuiOutsideClickDetector,
} from '@elastic/eui';
import { DashboardCopyToCapabilities } from './copy_to_dashboard_action';
import { DashboardPicker } from '../../services/presentation_util';
import { LazyDashboardPicker, withSuspense } from '../../services/presentation_util';
import { dashboardCopyToDashboardAction } from '../../dashboard_strings';
import { EmbeddableStateTransfer, IEmbeddable } from '../../services/embeddable';
import { createDashboardEditUrl, DashboardConstants } from '../..';
Expand All @@ -37,6 +37,8 @@ interface CopyToDashboardModalProps {
closeModal: () => void;
}

const DashboardPicker = withSuspense(LazyDashboardPicker);

export function CopyToDashboardModal({
PresentationUtilContext,
stateTransfer,
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/dashboard/public/services/presentation_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
* Side Public License, v 1.
*/

export { PresentationUtilPluginStart, DashboardPicker } from '../../../presentation_util/public';
export {
PresentationUtilPluginStart,
LazyDashboardPicker,
withSuspense,
} from '../../../presentation_util/public';
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const geti18nTexts = (fieldsToDelete?: string[]) => {
typeConfirm: i18n.translate(
'indexPatternFieldEditor.deleteRuntimeField.confirmModal.typeConfirm',
{
defaultMessage: "Type 'REMOVE' to confirm",
defaultMessage: 'Enter REMOVE to confirm',
}
),
warningRemovingFields: i18n.translate(
'indexPatternFieldEditor.deleteRuntimeField.confirmModal.warningRemovingFields',
{
defaultMessage:
'Warning: Removing fields may break searches or visualizations that rely on this field.',
'Removing fields can break searches and visualizations that rely on this field.',
}
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,29 @@ const geti18nTexts = (field?: Field) => {
confirmButtonText: i18n.translate(
'indexPatternFieldEditor.deleteRuntimeField.confirmationModal.saveButtonLabel',
{
defaultMessage: 'Save',
defaultMessage: 'Save changes',
}
),
warningChangingFields: i18n.translate(
'indexPatternFieldEditor.deleteRuntimeField.confirmModal.warningChangingFields',
{
defaultMessage:
'Warning: Changing name or type may break searches or visualizations that rely on this field.',
'Changing name or type can break searches and visualizations that rely on this field.',
}
),
typeConfirm: i18n.translate(
'indexPatternFieldEditor.saveRuntimeField.confirmModal.typeConfirm',
{
defaultMessage: "Type 'CHANGE' to continue:",
defaultMessage: 'Enter CHANGE to continue',
}
),
titleConfirmChanges: i18n.translate(
'indexPatternFieldEditor.saveRuntimeField.confirmModal.title',
{
defaultMessage: `Save changes to '{name}'`,
values: {
name: field?.name,
},
}
),
};
Expand Down Expand Up @@ -211,7 +220,7 @@ const FieldEditorFlyoutContentComponent = ({

const modal = isModalVisible ? (
<EuiConfirmModal
title={`Confirm changes to '${field?.name}'`}
title={i18nTexts.titleConfirmChanges}
data-test-subj="runtimeFieldSaveConfirmModal"
cancelButtonText={i18nTexts.cancelButtonText}
confirmButtonText={i18nTexts.confirmButtonText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ export function DashboardPicker(props: DashboardPickerProps) {
/>
);
}

// required for dynamic import using React.lazy()
// eslint-disable-next-line import/no-default-export
export default DashboardPicker;
32 changes: 32 additions & 0 deletions src/plugins/presentation_util/public/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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, { Suspense, ComponentType, ReactElement } from 'react';
import { EuiLoadingSpinner, EuiErrorBoundary } from '@elastic/eui';

/**
* A HOC which supplies React.Suspense with a fallback component, and a `EuiErrorBoundary` to contain errors.
* @param Component A component deferred by `React.lazy`
* @param fallback A fallback component to render while things load; default is `EuiLoadingSpinner`
*/
export const withSuspense = <P extends {}>(
Component: ComponentType<P>,
fallback: ReactElement | null = <EuiLoadingSpinner />
) => (props: P) => (
<EuiErrorBoundary>
<Suspense fallback={fallback}>
<Component {...props} />
</Suspense>
</EuiErrorBoundary>
);

export const LazyDashboardPicker = React.lazy(() => import('./dashboard_picker'));

export const LazySavedObjectSaveModalDashboard = React.lazy(
() => import('./saved_object_save_modal_dashboard')
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,15 @@ import React, { useState } from 'react';

import { i18n } from '@kbn/i18n';

import {
OnSaveProps,
SaveModalState,
SavedObjectSaveModal,
} from '../../../../plugins/saved_objects/public';
import { OnSaveProps, SavedObjectSaveModal } from '../../../../plugins/saved_objects/public';

import './saved_object_save_modal_dashboard.scss';
import { pluginServices } from '../services';
import { SaveModalDashboardProps } from './types';
import { SaveModalDashboardSelector } from './saved_object_save_modal_dashboard_selector';

interface SaveModalDocumentInfo {
id?: string;
title: string;
description?: string;
}

export interface SaveModalDashboardProps {
documentInfo: SaveModalDocumentInfo;
canSaveByReference: boolean;
objectType: string;
onClose: () => void;
onSave: (props: OnSaveProps & { dashboardId: string | null; addToLibrary: boolean }) => void;
tagOptions?: React.ReactNode | ((state: SaveModalState) => React.ReactNode);
}
import './saved_object_save_modal_dashboard.scss';

export function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
const { documentInfo, tagOptions, objectType, onClose, canSaveByReference } = props;
const { id: documentId } = documentInfo;
const initialCopyOnSave = !Boolean(documentId);
Expand Down Expand Up @@ -136,3 +119,7 @@ export function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
/>
);
}

// required for dynamic import using React.lazy()
// eslint-disable-next-line import/no-default-export
export default SavedObjectSaveModalDashboard;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
EuiCheckbox,
} from '@elastic/eui';

import { DashboardPicker, DashboardPickerProps } from './dashboard_picker';
import DashboardPicker, { DashboardPickerProps } from './dashboard_picker';

import './saved_object_save_modal_dashboard.scss';

Expand Down
24 changes: 24 additions & 0 deletions src/plugins/presentation_util/public/components/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { OnSaveProps, SaveModalState } from '../../../../plugins/saved_objects/public';

interface SaveModalDocumentInfo {
id?: string;
title: string;
description?: string;
}

export interface SaveModalDashboardProps {
documentInfo: SaveModalDocumentInfo;
canSaveByReference: boolean;
objectType: string;
onClose: () => void;
onSave: (props: OnSaveProps & { dashboardId: string | null; addToLibrary: boolean }) => void;
tagOptions?: React.ReactNode | ((state: SaveModalState) => React.ReactNode);
}
8 changes: 3 additions & 5 deletions src/plugins/presentation_util/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

import { PresentationUtilPlugin } from './plugin';

export {
SavedObjectSaveModalDashboard,
SaveModalDashboardProps,
} from './components/saved_object_save_modal_dashboard';
export { LazyDashboardPicker, LazySavedObjectSaveModalDashboard, withSuspense } from './components';

export { DashboardPicker } from './components/dashboard_picker';
export { SaveModalDashboardProps } from './components/types';

export function plugin() {
return new PresentationUtilPlugin();
}

export { PresentationUtilPluginSetup, PresentationUtilPluginStart } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
SavedObjectSaveOpts,
OnSaveProps,
} from '../../../../saved_objects/public';
import { SavedObjectSaveModalDashboard } from '../../../../presentation_util/public';
import {
LazySavedObjectSaveModalDashboard,
withSuspense,
} from '../../../../presentation_util/public';
import { unhashUrl } from '../../../../kibana_utils/public';

import {
Expand Down Expand Up @@ -52,6 +55,8 @@ interface TopNavConfigParams {
embeddableId?: string;
}

const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard);

export const showPublicUrlSwitch = (anonymousUserCapabilities: Capabilities) => {
if (!anonymousUserCapabilities.visualize) return false;

Expand Down Expand Up @@ -420,40 +425,47 @@ export const getTopNavConfig = (
const useByRefFlow =
!!originatingApp || !dashboard.dashboardFeatureFlagConfig.allowByValueEmbeddables;

const saveModal = useByRefFlow ? (
<SavedObjectSaveModalOrigin
documentInfo={savedVis || { title: '' }}
onSave={onSave}
options={tagOptions}
getAppNameFromId={stateTransfer.getAppNameFromId}
objectType={'visualization'}
onClose={() => {}}
originatingApp={originatingApp}
returnToOriginSwitchLabel={
originatingApp && embeddableId
? i18n.translate('visualize.topNavMenu.updatePanel', {
defaultMessage: 'Update panel on {originatingAppName}',
values: {
originatingAppName: stateTransfer.getAppNameFromId(originatingApp),
},
})
: undefined
}
/>
) : (
<SavedObjectSaveModalDashboard
documentInfo={{
id: visualizeCapabilities.save ? savedVis?.id : undefined,
title: savedVis?.title || '',
description: savedVis?.description || '',
}}
canSaveByReference={Boolean(visualizeCapabilities.save)}
onSave={onSave}
tagOptions={tagOptions}
objectType={'visualization'}
onClose={() => {}}
/>
);
let saveModal;

if (useByRefFlow) {
saveModal = (
<SavedObjectSaveModalOrigin
documentInfo={savedVis || { title: '' }}
onSave={onSave}
options={tagOptions}
getAppNameFromId={stateTransfer.getAppNameFromId}
objectType={'visualization'}
onClose={() => {}}
originatingApp={originatingApp}
returnToOriginSwitchLabel={
originatingApp && embeddableId
? i18n.translate('visualize.topNavMenu.updatePanel', {
defaultMessage: 'Update panel on {originatingAppName}',
values: {
originatingAppName: stateTransfer.getAppNameFromId(originatingApp),
},
})
: undefined
}
/>
);
} else {
saveModal = (
<SavedObjectSaveModalDashboard
documentInfo={{
id: visualizeCapabilities.save ? savedVis?.id : undefined,
title: savedVis?.title || '',
description: savedVis?.description || '',
}}
canSaveByReference={Boolean(visualizeCapabilities.save)}
onSave={onSave}
tagOptions={tagOptions}
objectType={'visualization'}
onClose={() => {}}
/>
);
}

showSaveModal(
saveModal,
I18nContext,
Expand Down
Loading

0 comments on commit e901434

Please sign in to comment.