From c13a026b016bd47e88f97ac845f9f44323b280ca Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Fri, 17 Apr 2020 12:15:04 -0700 Subject: [PATCH 1/2] [Alerting] "Create alert" and alert list design improvements (#63515) * added header to actions section * adjusted some spacing in Create Alert * lighter text in Actions section headings * fixed bulk actions dropdown * improve alert collapsed item actions * improve dropdown and adjust some buttos * adjust font size of steps to match hierarchy * need to check master * improve collapsed actions menu * added periods to help texts * going back to EuiButtonEmpty to be able to use isLoading * fix prop * remove Fragment * remove translations we're not using * Fix functional tests Co-authored-by: Mike Cote --- .../translations/translations/ja-JP.json | 5 +- .../translations/translations/zh-CN.json | 7 +- .../threshold/expression.scss | 12 +- .../threshold/expression.tsx | 8 +- .../components/prompts/empty_prompt.tsx | 2 - .../action_connector_form/action_form.tsx | 381 ++++++++++-------- .../components/actions_connectors_list.tsx | 2 - .../alerts_list/components/alerts_list.tsx | 2 - .../components/collapsed_item_actions.scss | 23 ++ .../components/collapsed_item_actions.tsx | 143 ++++--- .../components/alert_quick_edit_buttons.scss | 5 + .../components/alert_quick_edit_buttons.tsx | 123 +++--- .../components/bulk_operation_popover.tsx | 11 +- .../apps/triggers_actions_ui/alerts.ts | 30 +- 14 files changed, 426 insertions(+), 328 deletions(-) create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/collapsed_item_actions.scss create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.scss diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 2f05088c4a62b..4e6e74aabc7e4 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -15960,7 +15960,7 @@ "xpack.triggersActionsUI.sections.alertAdd.saveButtonLabel": "保存", "xpack.triggersActionsUI.sections.alertAdd.saveErrorNotificationText": "アラートを作成できません。", "xpack.triggersActionsUI.sections.alertAdd.saveSuccessNotificationText": "「{alertName}」 を保存しました", - "xpack.triggersActionsUI.sections.alertAdd.selectIndex": "インデックスを選択してください。", + "xpack.triggersActionsUI.sections.alertAdd.selectIndex": "インデックスを選択してください", "xpack.triggersActionsUI.sections.alertAdd.threshold.closeIndexPopoverLabel": "閉じる", "xpack.triggersActionsUI.sections.alertAdd.threshold.fixErrorInExpressionBelowValidationMessage": "下の表現のエラーを修正してください。", "xpack.triggersActionsUI.sections.alertAdd.threshold.howToBroadenSearchQueryDescription": "* で検索クエリの範囲を広げます。", @@ -16044,7 +16044,6 @@ "xpack.triggersActionsUI.sections.alertsList.bulkActionPopover.muteAllTitle": "ミュート", "xpack.triggersActionsUI.sections.alertsList.bulkActionPopover.unmuteAllTitle": "ミュート解除", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.deleteTitle": "削除", - "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.enableTitle": "有効にする", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.muteTitle": "ミュート", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.popoverButtonTitle": "アクション", "xpack.triggersActionsUI.components.emptyPrompt.emptyButton": "アラートの作成", @@ -16757,4 +16756,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "フィールドを選択してください。", "xpack.watcher.watcherDescription": "アラートの作成、管理、監視によりデータへの変更を検知します。" } -} +} \ No newline at end of file diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 620aa6c7f225c..70ec0ef2b0dac 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -15957,7 +15957,7 @@ "xpack.triggersActionsUI.sections.addModalConnectorForm.updateSuccessNotificationText": "已创建“{connectorName}”", "xpack.triggersActionsUI.sections.alertAdd.betaBadgeTooltipContent": "{pluginName} 为公测版,可能会进行更改。设计和代码相对于正式发行版功能还不够成熟,将按原样提供,且不提供任何保证。公测版功能不受正式发行版功能支持 SLA 的约束。", "xpack.triggersActionsUI.sections.alertAdd.cancelButtonLabel": "取消", - "xpack.triggersActionsUI.sections.alertAdd.conditionPrompt": "定义条件。", + "xpack.triggersActionsUI.sections.alertAdd.conditionPrompt": "定义条件", "xpack.triggersActionsUI.sections.alertAdd.errorLoadingAlertVisualizationTitle": "无法加载告警可视化", "xpack.triggersActionsUI.sections.alertAdd.flyoutTitle": "创建告警", "xpack.triggersActionsUI.sections.alertAdd.loadingAlertVisualizationDescription": "正在加载告警可视化……", @@ -15965,7 +15965,7 @@ "xpack.triggersActionsUI.sections.alertAdd.saveButtonLabel": "保存", "xpack.triggersActionsUI.sections.alertAdd.saveErrorNotificationText": "无法创建告警。", "xpack.triggersActionsUI.sections.alertAdd.saveSuccessNotificationText": "已保存“{alertName}”", - "xpack.triggersActionsUI.sections.alertAdd.selectIndex": "选择索引。", + "xpack.triggersActionsUI.sections.alertAdd.selectIndex": "选择索引", "xpack.triggersActionsUI.sections.alertAdd.threshold.closeIndexPopoverLabel": "关闭", "xpack.triggersActionsUI.sections.alertAdd.threshold.fixErrorInExpressionBelowValidationMessage": "表达式包含错误。", "xpack.triggersActionsUI.sections.alertAdd.threshold.howToBroadenSearchQueryDescription": "使用 * 可扩大您的查询范围。", @@ -16049,7 +16049,6 @@ "xpack.triggersActionsUI.sections.alertsList.bulkActionPopover.muteAllTitle": "静音", "xpack.triggersActionsUI.sections.alertsList.bulkActionPopover.unmuteAllTitle": "取消静音", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.deleteTitle": "删除", - "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.enableTitle": "启用", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.muteTitle": "静音", "xpack.triggersActionsUI.sections.alertsList.collapsedItemActons.popoverButtonTitle": "操作", "xpack.triggersActionsUI.components.emptyPrompt.emptyButton": "创建告警", @@ -16762,4 +16761,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "此字段必填。", "xpack.watcher.watcherDescription": "通过创建、管理和监测警报来检测数据中的更改。" } -} +} \ No newline at end of file diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.scss b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.scss index d0a7039ae24e1..3734cf5d5218b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.scss +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.scss @@ -1,3 +1,13 @@ .actAlertVisualization__chart { - height: $euiSize * 15; + height: $euiSize * 14; +} + +.actAddAlertSteps { + .euiStep__titleWrapper { + align-items: center; + } + + .euiStep__title { + @include euiTitle('xs'); + } } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.tsx index 7557b17f5b67d..43955db97f295 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.tsx @@ -283,7 +283,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent @@ -396,7 +396,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent @@ -445,12 +445,10 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent ) : null} - - +
{canShowVizualization ? ( - void }) => ( data-test-subj="createFirstAlertButton" key="create-action" fill - iconType="plusInCircle" - iconSide="left" onClick={onCTAClicked} > - - - - - -
- - - - - - {checkEnabledResult.isEnabled === false && ( - - - - )} - - -
-
-
- - } - extraAction={ - { - const updatedActions = actions.filter((_item: AlertAction, i: number) => i !== index); - setAlertProperty(updatedActions); - setIsAddActionPanelOpen( - updatedActions.filter((item: AlertAction) => item.id !== actionItem.id).length === 0 - ); - setActiveActionItem(undefined); - }} - /> - } - paddingSize="l" - > - {accordionContent} - + + + + + + + +

+ + + + + + {checkEnabledResult.isEnabled === false && ( + + + + )} + + +

+
+
+ + } + extraAction={ + { + const updatedActions = actions.filter( + (_item: AlertAction, i: number) => i !== index + ); + setAlertProperty(updatedActions); + setIsAddActionPanelOpen( + updatedActions.filter((item: AlertAction) => item.id !== actionItem.id).length === + 0 + ); + setActiveActionItem(undefined); + }} + /> + } + paddingSize="l" + > + {accordionContent} +
+ +
); }; @@ -341,96 +349,103 @@ export const ActionForm = ({ const actionTypeRegistered = actionTypeRegistry.get(actionItem.actionTypeId); if (!actionTypeRegistered || actionItem.group !== defaultActionGroupId) return null; return ( - - - - - - -
- -
-
-
- - } - extraAction={ - { - const updatedActions = actions.filter((_item: AlertAction, i: number) => i !== index); - setAlertProperty(updatedActions); - setIsAddActionPanelOpen( - updatedActions.filter((item: AlertAction) => item.id !== actionItem.id).length === 0 - ); - setActiveActionItem(undefined); - }} - /> - } - paddingSize="l" - > - actionItem.id === emptyId) ? ( - - ) : ( - - ) + + + + + + + +

+ +

+
+
+ } - actions={[ - { - setActiveActionItem({ actionTypeId: actionItem.actionTypeId, index }); - setAddModalVisibility(true); + const updatedActions = actions.filter( + (_item: AlertAction, i: number) => i !== index + ); + setAlertProperty(updatedActions); + setIsAddActionPanelOpen( + updatedActions.filter((item: AlertAction) => item.id !== actionItem.id).length === + 0 + ); + setActiveActionItem(undefined); }} - > - - , - ]} - /> -
+ /> + } + paddingSize="l" + > + actionItem.id === emptyId) ? ( + + ) : ( + + ) + } + actions={[ + { + setActiveActionItem({ actionTypeId: actionItem.actionTypeId, index }); + setAddModalVisibility(true); + }} + > + + , + ]} + /> +
+ +
); }; @@ -537,19 +552,34 @@ export const ActionForm = ({ ) : ( - {alertActionsList} - - {isAddActionPanelOpen === false ? ( - setIsAddActionPanelOpen(true)} - > + +

- +

+
+ + {alertActionsList} + {isAddActionPanelOpen === false ? ( +
+ + + + setIsAddActionPanelOpen(true)} + > + + + + +
) : null} {isAddActionPanelOpen ? ( @@ -558,7 +588,7 @@ export const ActionForm = ({
@@ -571,6 +601,7 @@ export const ActionForm = ({ - + {isLoadingActionTypes ? ( { data-test-subj="createActionButton" key="create-action" fill - iconType="plusInCircle" - iconSide="left" onClick={() => setAddFlyoutVisibility(true)} > { key="create-alert" data-test-subj="createAlertButton" fill - iconType="plusInCircle" - iconSide="left" onClick={() => setAlertFlyoutVisibility(true)} > = ({ isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} ownFocus + panelPaddingSize="none" data-test-subj="collapsedItemActions" > - - { - if (item.enabled) { - await disableAlert(item); - } else { - await enableAlert(item); + +
+ { + if (item.enabled) { + await disableAlert(item); + } else { + await enableAlert(item); + } + onAlertChanged(); + }} + label={ + } - onAlertChanged(); - }} - label={ + /> + + - } - /> - - - { - if (item.muteAll) { - await unmuteAlert(item); - } else { - await muteAlert(item); + +
+
+ { + if (item.muteAll) { + await unmuteAlert(item); + } else { + await muteAlert(item); + } + onAlertChanged(); + }} + label={ + } - onAlertChanged(); - }} - label={ + /> + + - } - /> - - - - setAlertsToDelete([item.id])} - > - - - - + +
+ + setAlertsToDelete([item.id])} + > +
+
+ +
+
+ +

+ +

+
+
+
+
+
); }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.scss b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.scss new file mode 100644 index 0000000000000..a5b4cc258c1b5 --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.scss @@ -0,0 +1,5 @@ +.actBulkActionPopover__deleteAll { + .euiButtonEmpty__text { + padding-top: $euiSizeXS; + } +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.tsx index eeae0cf54f1a1..26bc8b869a06b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/alert_quick_edit_buttons.tsx @@ -5,9 +5,9 @@ */ import { i18n } from '@kbn/i18n'; -import React, { useState, Fragment } from 'react'; +import React, { useState } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiButtonEmpty } from '@elastic/eui'; +import { EuiButtonEmpty, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { Alert } from '../../../../types'; import { useAppDependencies } from '../../../app_context'; @@ -15,6 +15,7 @@ import { withBulkAlertOperations, ComponentOpts as BulkOperationsComponentOpts, } from './with_bulk_alert_api_operations'; +import './alert_quick_edit_buttons.scss'; export type ComponentOpts = { selectedItems: Alert[]; @@ -147,72 +148,84 @@ export const AlertQuickEditButtons: React.FunctionComponent = ({ } return ( - + {!allAlertsMuted && ( - - - + + + + + )} {allAlertsMuted && ( - - - + + + + + )} {allAlertsDisabled && ( - - - + + + + + )} {!allAlertsDisabled && ( + + + + + + )} + - )} - - - - - + +
); }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/bulk_operation_popover.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/bulk_operation_popover.tsx index d0fd0e1792818..935b0bd8985ca 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/bulk_operation_popover.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/bulk_operation_popover.tsx @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useState } from 'react'; +import React, { useState, Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiButton, EuiFormRow, EuiPopover } from '@elastic/eui'; +import { EuiButton, EuiPopover } from '@elastic/eui'; export const BulkOperationPopover: React.FunctionComponent = ({ children }) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); @@ -16,6 +16,7 @@ export const BulkOperationPopover: React.FunctionComponent = ({ children }) => { isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} data-test-subj="bulkAction" + panelPaddingSize="s" button={ { > {children && React.Children.map(children, child => - React.isValidElement(child) ? ( - {React.cloneElement(child, {})} - ) : ( - child - ) + React.isValidElement(child) ? {React.cloneElement(child, {})} : child )} ); diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts index bce8e08cd16d3..bbf8881f0c62a 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts @@ -343,15 +343,15 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click('collapsedItemActions'); - await pageObjects.triggersActionsUI.toggleSwitch('enableSwitch'); + await pageObjects.triggersActionsUI.toggleSwitch('disableSwitch'); await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name); await testSubjects.click('collapsedItemActions'); - const enableSwitchAfterDisable = await testSubjects.find('enableSwitch'); - const isChecked = await enableSwitchAfterDisable.getAttribute('aria-checked'); - expect(isChecked).to.eql('false'); + const disableSwitchAfterDisable = await testSubjects.find('disableSwitch'); + const isChecked = await disableSwitchAfterDisable.getAttribute('aria-checked'); + expect(isChecked).to.eql('true'); }); it('should re-enable single alert', async () => { @@ -361,21 +361,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click('collapsedItemActions'); - await pageObjects.triggersActionsUI.toggleSwitch('enableSwitch'); + await pageObjects.triggersActionsUI.toggleSwitch('disableSwitch'); await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name); await testSubjects.click('collapsedItemActions'); - await pageObjects.triggersActionsUI.toggleSwitch('enableSwitch'); + await pageObjects.triggersActionsUI.toggleSwitch('disableSwitch'); await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name); await testSubjects.click('collapsedItemActions'); - const enableSwitchAfterReEnable = await testSubjects.find('enableSwitch'); - const isChecked = await enableSwitchAfterReEnable.getAttribute('aria-checked'); - expect(isChecked).to.eql('true'); + const disableSwitchAfterReEnable = await testSubjects.find('disableSwitch'); + const isChecked = await disableSwitchAfterReEnable.getAttribute('aria-checked'); + expect(isChecked).to.eql('false'); }); it('should mute single alert', async () => { @@ -507,9 +507,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click('collapsedItemActions'); - const enableSwitch = await testSubjects.find('enableSwitch'); - const isChecked = await enableSwitch.getAttribute('aria-checked'); - expect(isChecked).to.eql('false'); + const disableSwitch = await testSubjects.find('disableSwitch'); + const isChecked = await disableSwitch.getAttribute('aria-checked'); + expect(isChecked).to.eql('true'); }); it('should enable all selection', async () => { @@ -532,9 +532,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await testSubjects.click('collapsedItemActions'); - const enableSwitch = await testSubjects.find('enableSwitch'); - const isChecked = await enableSwitch.getAttribute('aria-checked'); - expect(isChecked).to.eql('true'); + const disableSwitch = await testSubjects.find('disableSwitch'); + const isChecked = await disableSwitch.getAttribute('aria-checked'); + expect(isChecked).to.eql('false'); }); it('should delete all selection', async () => { From f179ec40694e8c29c7856e5420315f5c73e54029 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 17 Apr 2020 13:56:20 -0600 Subject: [PATCH 2/2] Migrate legacy maps licensing (x-pack/tilemap) to NP (#63539) * Move logic to NP and add basic plugin structure * Remove unused server-side licensing logic and old index * Set license in maps_legacy via new plugin * Change add to set for service settings queryParams function * Fix accidentally changed emsClient method call * Require at least a basic license * Type updates * Remove unneeded legacy license test * Remove unused headers in test --- .../public/__tests__/map/service_settings.js | 16 +++--- .../public/map/service_settings.js | 9 +++- x-pack/index.js | 2 - x-pack/legacy/plugins/tilemap/index.js | 31 ------------ .../update_tilemap_settings.js | 16 ------ .../server/lib/__tests__/inspect_settings.js | 36 -------------- .../tilemap/server/lib/inspect_settings.js | 32 ------------ .../maps_legacy_licensing}/README.md | 0 .../plugins/maps_legacy_licensing/kibana.json | 8 +++ .../maps_legacy_licensing/public/index.ts | 11 +++++ .../maps_legacy_licensing/public/plugin.ts | 49 +++++++++++++++++++ .../test/licensing_plugin/legacy/updates.ts | 7 +-- 12 files changed, 84 insertions(+), 133 deletions(-) delete mode 100644 x-pack/legacy/plugins/tilemap/index.js delete mode 100644 x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js delete mode 100644 x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js delete mode 100644 x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js rename x-pack/{legacy/plugins/tilemap => plugins/maps_legacy_licensing}/README.md (100%) create mode 100644 x-pack/plugins/maps_legacy_licensing/kibana.json create mode 100644 x-pack/plugins/maps_legacy_licensing/public/index.ts create mode 100644 x-pack/plugins/maps_legacy_licensing/public/plugin.ts diff --git a/src/plugins/maps_legacy/public/__tests__/map/service_settings.js b/src/plugins/maps_legacy/public/__tests__/map/service_settings.js index a9272ea396639..4cbe098501c67 100644 --- a/src/plugins/maps_legacy/public/__tests__/map/service_settings.js +++ b/src/plugins/maps_legacy/public/__tests__/map/service_settings.js @@ -143,24 +143,24 @@ describe('service_settings (FKA tilemaptest)', function() { } it('accepts an object', async () => { - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar' }); }); it('merged additions with previous values', async () => { // ensure that changes are always additive - serviceSettings.addQueryParams({ foo: 'bar' }); - serviceSettings.addQueryParams({ bar: 'stool' }); + serviceSettings.setQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ bar: 'stool' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar', bar: 'stool' }); }); it('overwrites conflicting previous values', async () => { // ensure that conflicts are overwritten - serviceSettings.addQueryParams({ foo: 'bar' }); - serviceSettings.addQueryParams({ bar: 'stool' }); - serviceSettings.addQueryParams({ foo: 'tstool' }); + serviceSettings.setQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ bar: 'stool' }); + serviceSettings.setQueryParams({ foo: 'tstool' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'tstool', bar: 'stool' }); }); @@ -168,7 +168,7 @@ describe('service_settings (FKA tilemaptest)', function() { it('when overridden, should continue to work', async () => { mapConfig.emsFileApiUrl = emsFileApiUrl2; mapConfig.emsTileApiUrl = emsTileApiUrl2; - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar' }); }); @@ -292,7 +292,7 @@ describe('service_settings (FKA tilemaptest)', function() { describe('File layers', function() { it('should load manifest (all props)', async function() { - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); const fileLayers = await serviceSettings.getFileLayers(); expect(fileLayers.length).to.be(18); const assertions = fileLayers.map(async function(fileLayer) { diff --git a/src/plugins/maps_legacy/public/map/service_settings.js b/src/plugins/maps_legacy/public/map/service_settings.js index 11c853d39e107..f4f0d66ee20de 100644 --- a/src/plugins/maps_legacy/public/map/service_settings.js +++ b/src/plugins/maps_legacy/public/map/service_settings.js @@ -69,6 +69,10 @@ export class ServiceSettings { return origin === ORIGIN.EMS && this._showZoomMessage; } + enableZoomMessage() { + this._showZoomMessage = true; + } + disableZoomMessage() { this._showZoomMessage = false; } @@ -148,11 +152,12 @@ export class ServiceSettings { } /** - * Add optional query-parameters to all requests + * Set optional query-parameters for all requests * * @param additionalQueryParams */ - addQueryParams(additionalQueryParams) { + setQueryParams(additionalQueryParams) { + // Functions more as a "set" than an "add" in ems-client this._emsClient.addQueryParams(additionalQueryParams); } diff --git a/x-pack/index.js b/x-pack/index.js index 61fd4f1752316..7fbd992120ea6 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -9,7 +9,6 @@ import { graph } from './legacy/plugins/graph'; import { monitoring } from './legacy/plugins/monitoring'; import { reporting } from './legacy/plugins/reporting'; import { security } from './legacy/plugins/security'; -import { tilemap } from './legacy/plugins/tilemap'; import { dashboardMode } from './legacy/plugins/dashboard_mode'; import { logstash } from './legacy/plugins/logstash'; import { beats } from './legacy/plugins/beats_management'; @@ -40,7 +39,6 @@ module.exports = function(kibana) { reporting(kibana), spaces(kibana), security(kibana), - tilemap(kibana), dashboardMode(kibana), logstash(kibana), beats(kibana), diff --git a/x-pack/legacy/plugins/tilemap/index.js b/x-pack/legacy/plugins/tilemap/index.js deleted file mode 100644 index d4105519ee0a7..0000000000000 --- a/x-pack/legacy/plugins/tilemap/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status'; -import { inspectSettings } from './server/lib/inspect_settings'; -import { resolve } from 'path'; - -export const tilemap = kibana => { - return new kibana.Plugin({ - id: 'tilemap', - configPrefix: 'xpack.tilemap', - require: ['xpack_main', 'vis_type_vislib'], - publicDir: resolve(__dirname, 'public'), - uiExports: { - hacks: ['plugins/tilemap/vis_type_enhancers/update_tilemap_settings'], - }, - init: function(server) { - const thisPlugin = this; - const xpackMainPlugin = server.plugins.xpack_main; - mirrorPluginStatus(xpackMainPlugin, thisPlugin); - xpackMainPlugin.status.once('green', () => { - xpackMainPlugin.info - .feature(thisPlugin.id) - .registerLicenseCheckResultsGenerator(inspectSettings); - }); - }, - }); -}; diff --git a/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js b/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js deleted file mode 100644 index 294bc31e3893e..0000000000000 --- a/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { xpackInfo } from 'plugins/xpack_main/services/xpack_info'; -import { npSetup } from 'ui/new_platform'; - -const tileMapPluginInfo = xpackInfo.get('features.tilemap'); - -if (tileMapPluginInfo && (tileMapPluginInfo.license.active || tileMapPluginInfo.license.valid)) { - const { serviceSettings } = npSetup.plugins.mapsLegacy; - serviceSettings.addQueryParams({ license: tileMapPluginInfo.license.uid }); - serviceSettings.disableZoomMessage(); -} diff --git a/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js b/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js deleted file mode 100644 index ce7987ee396b8..0000000000000 --- a/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import expect from '@kbn/expect'; -import { inspectSettings } from '../../../server/lib/inspect_settings'; - -describe('inspectSettings', function() { - it('should propagate x-pack info', function() { - const mockSettings = { - isAvailable: () => true, - license: { - getUid: () => 'foobar', - isActive: () => true, - isOneOf: () => true, - }, - }; - - const licenseInfo = inspectSettings(mockSettings); - expect(licenseInfo.license.uid).to.equal('foobar'); - expect(licenseInfo.license.active).to.equal(true); - expect(licenseInfo.license.valid).to.equal(true); - }); - - it('should break when unavailable info', function() { - const mockSettings = { - isAvailable: () => false, - }; - - const licenseInfo = inspectSettings(mockSettings); - expect(licenseInfo).to.have.property('message'); - expect(typeof licenseInfo.message === 'string').to.be.ok(); - }); -}); diff --git a/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js b/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js deleted file mode 100644 index cd6fb8bd8c110..0000000000000 --- a/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export function inspectSettings(xpackInfo) { - if (!xpackInfo || !xpackInfo.isAvailable()) { - return { - message: - 'You cannot use the Tilemap Plugin because license information is not available at this time.', - }; - } - - /** - *Propagate these settings to the client - */ - return { - license: { - uid: xpackInfo.license.getUid(), - active: xpackInfo.license.isActive(), - valid: xpackInfo.license.isOneOf([ - 'trial', - 'standard', - 'basic', - 'gold', - 'platinum', - 'enterprise', - ]), - }, - }; -} diff --git a/x-pack/legacy/plugins/tilemap/README.md b/x-pack/plugins/maps_legacy_licensing/README.md similarity index 100% rename from x-pack/legacy/plugins/tilemap/README.md rename to x-pack/plugins/maps_legacy_licensing/README.md diff --git a/x-pack/plugins/maps_legacy_licensing/kibana.json b/x-pack/plugins/maps_legacy_licensing/kibana.json new file mode 100644 index 0000000000000..e98c33d21ec40 --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/kibana.json @@ -0,0 +1,8 @@ +{ + "id": "mapsLegacyLicensing", + "version": "8.0.0", + "kibanaVersion": "kibana", + "server": false, + "ui": true, + "requiredPlugins": ["licensing", "mapsLegacy"] +} diff --git a/x-pack/plugins/maps_legacy_licensing/public/index.ts b/x-pack/plugins/maps_legacy_licensing/public/index.ts new file mode 100644 index 0000000000000..edda6118f92dd --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/public/index.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import { MapsLegacyLicensing } from './plugin'; + +export function plugin() { + return new MapsLegacyLicensing(); +} diff --git a/x-pack/plugins/maps_legacy_licensing/public/plugin.ts b/x-pack/plugins/maps_legacy_licensing/public/plugin.ts new file mode 100644 index 0000000000000..69c25efd96e75 --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/public/plugin.ts @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { LicensingPluginSetup, ILicense } from '../../licensing/public'; + +/** + * These are the interfaces with your public contracts. You should export these + * for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces. + * @public + */ + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface MapsLegacyLicensingSetupDependencies { + licensing: LicensingPluginSetup; + mapsLegacy: any; +} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface MapsLegacyLicensingStartDependencies {} + +export type MapsLegacyLicensingSetup = ReturnType; +export type MapsLegacyLicensingStart = ReturnType; + +export class MapsLegacyLicensing + implements Plugin { + public setup(core: CoreSetup, plugins: MapsLegacyLicensingSetupDependencies) { + const { + licensing, + mapsLegacy: { serviceSettings }, + } = plugins; + if (licensing) { + licensing.license$.subscribe((license: ILicense) => { + const { uid, isActive } = license; + if (isActive && license.hasAtLeast('basic')) { + serviceSettings.setQueryParams({ license: uid }); + serviceSettings.disableZoomMessage(); + } else { + serviceSettings.setQueryParams({ license: undefined }); + serviceSettings.enableZoomMessage(); + } + }); + } + } + + public start(core: CoreStart, plugins: MapsLegacyLicensingStartDependencies) {} +} diff --git a/x-pack/test/licensing_plugin/legacy/updates.ts b/x-pack/test/licensing_plugin/legacy/updates.ts index 5fa1299d1f285..03b61b9db87f8 100644 --- a/x-pack/test/licensing_plugin/legacy/updates.ts +++ b/x-pack/test/licensing_plugin/legacy/updates.ts @@ -50,14 +50,9 @@ export default function(ftrContext: FtrProviderContext) { await scenario.startBasic(); await scenario.waitForPluginToDetectLicenseUpdate(); - const { body: legacyBasicLicense, header: legacyBasicLicenseHeaders } = await supertest - .get('/api/xpack/v1/info') - .expect(200); + const { body: legacyBasicLicense } = await supertest.get('/api/xpack/v1/info').expect(200); expect(legacyBasicLicense.license?.type).to.be('basic'); expect(legacyBasicLicense.features).to.have.property('security'); - expect(legacyBasicLicenseHeaders['kbn-xpack-sig']).to.not.be( - legacyInitialLicenseHeaders['kbn-xpack-sig'] - ); // banner shown only when license expired not just deleted await testSubjects.missingOrFail('licenseExpiredBanner');