').css({
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- });
-
- $parent.appendTo(document.body);
- trash.push($parent);
-
- const $el = $('
')
- .css({
- 'overflow-x': 'auto',
- width: $parent.width(),
- })
- .appendTo($parent);
-
- spyScrollWidth = jest.spyOn(window.HTMLElement.prototype, 'scrollWidth', 'get');
- spyScrollWidth.mockReturnValue($parent.width() * ratioX);
- angular.element.prototype.height = jest.fn(() => $parent.height() * ratioY);
-
- const $content = $('
')
- .css({
- width: $parent.width() * ratioX,
- height: $parent.height() * ratioY,
- })
- .appendTo($el);
-
- $compile($parent)($rootScope);
- flushPendingTasks();
-
- return {
- $container: $el,
- $content: $content,
- $scroller: $parent.find('.dscTableFixedScroll__scroller'),
- };
- };
- });
- });
-
- afterEach(function () {
- trash.splice(0).forEach(function ($el) {
- $el.remove();
- });
-
- sandbox.restore();
- spyScrollWidth.mockRestore();
- });
-
- afterAll(() => {
- mockWidth.mockRestore();
- mockHeight.mockRestore();
- delete angular.element.prototype.width;
- delete angular.element.prototype.height;
- delete angular.element.prototype.offset;
- });
-
- test('does nothing when not needed', function () {
- let els = compile(0.5, 1.5);
- expect(els.$scroller).toHaveLength(0);
-
- els = compile(1.5, 0.5);
- expect(els.$scroller).toHaveLength(0);
- });
-
- test('attaches a scroller below the element when the content is larger then the container', function () {
- const els = compile(1.5);
- expect(els.$scroller.length).toBe(1);
- });
-
- test('copies the width of the container', function () {
- const els = compile(1.5);
- expect(els.$scroller.width()).toBe(els.$container.width());
- });
-
- test('mimics the scrollWidth of the element', function () {
- const els = compile(1.5);
- expect(els.$scroller.prop('scrollWidth')).toBe(els.$container.prop('scrollWidth'));
- });
-
- describe('scroll event handling / tug of war prevention', function () {
- test('listens when needed, unlistens when not needed', function (done) {
- const on = sandbox.spy($.fn, 'on');
- const off = sandbox.spy($.fn, 'off');
- const jqLiteOn = sandbox.spy(angular.element.prototype, 'on');
- const jqLiteOff = sandbox.spy(angular.element.prototype, 'off');
-
- const els = compile(1.5);
- expect(on.callCount).toBe(1);
- expect(jqLiteOn.callCount).toBe(1);
- checkThisVals('$.fn.on', on, jqLiteOn);
-
- expect(off.callCount).toBe(0);
- expect(jqLiteOff.callCount).toBe(0);
- currentJqLiteWidth = els.$container.prop('scrollWidth');
- flushPendingTasks();
- expect(off.callCount).toBe(1);
- expect(jqLiteOff.callCount).toBe(1);
- checkThisVals('$.fn.off', off, jqLiteOff);
- done();
-
- function checkThisVals(namejQueryFn, spyjQueryFn, spyjqLiteFn) {
- // the this values should be different
- expect(spyjQueryFn.thisValues[0].is(spyjqLiteFn.thisValues[0])).toBeFalsy();
- // but they should be either $scroller or $container
- const el = spyjQueryFn.thisValues[0];
-
- if (el.is(els.$scroller) || el.is(els.$container)) return;
-
- done.fail('expected ' + namejQueryFn + ' to be called with $scroller or $container');
- }
- });
-
- // Turn off this row because tests failed.
- // Scroll event is not catched in fixed_scroll.
- // As container is jquery element in test but inside fixed_scroll it's a jqLite element.
- // it would need jquery in jest to make this work.
- [
- //{ from: '$container', to: '$scroller' },
- { from: '$scroller', to: '$container' },
- ].forEach(function (names) {
- describe('scroll events ' + JSON.stringify(names), function () {
- let spyJQueryScrollLeft;
- let spyJQLiteScrollLeft;
- let els;
- let $from;
- let $to;
-
- beforeEach(function () {
- spyJQueryScrollLeft = sandbox.spy($.fn, 'scrollLeft');
- spyJQLiteScrollLeft = sandbox.stub();
- angular.element.prototype.scrollLeft = spyJQLiteScrollLeft;
- els = compile(1.5);
- $from = els[names.from];
- $to = els[names.to];
- });
-
- test('transfers the scrollLeft', function () {
- expect(spyJQueryScrollLeft.callCount).toBe(0);
- expect(spyJQLiteScrollLeft.callCount).toBe(0);
- $from.scroll();
- expect(spyJQueryScrollLeft.callCount).toBe(1);
- expect(spyJQLiteScrollLeft.callCount).toBe(1);
-
- // first call should read the scrollLeft from the $container
- const firstCall = spyJQueryScrollLeft.getCall(0);
- expect(firstCall.args).toEqual([]);
-
- // second call should be setting the scrollLeft on the $scroller
- const secondCall = spyJQLiteScrollLeft.getCall(0);
- expect(secondCall.args).toEqual([firstCall.returnValue]);
- });
-
- /**
- * In practice, calling $el.scrollLeft() causes the "scroll" event to trigger,
- * but the browser seems to be very careful about triggering the event too much
- * and I can't reliably recreate the browsers behavior in a test. So... faking it!
- */
- test('prevents tug of war by ignoring echo scroll events', function () {
- $from.scroll();
- expect(spyJQueryScrollLeft.callCount).toBe(1);
- expect(spyJQLiteScrollLeft.callCount).toBe(1);
-
- spyJQueryScrollLeft.resetHistory();
- spyJQLiteScrollLeft.resetHistory();
- $to.scroll();
- expect(spyJQueryScrollLeft.callCount).toBe(0);
- expect(spyJQLiteScrollLeft.callCount).toBe(0);
- });
- });
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/histogram.tsx b/src/plugins/discover_legacy/public/application/angular/directives/histogram.tsx
deleted file mode 100644
index 4c1263192322..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/histogram.tsx
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiSpacer } from '@elastic/eui';
-import moment from 'moment-timezone';
-import { unitOfTime } from 'moment';
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import { euiThemeVars } from '@osd/ui-shared-deps/theme';
-
-import {
- AnnotationDomainType,
- Axis,
- Chart,
- HistogramBarSeries,
- LineAnnotation,
- Position,
- ScaleType,
- Settings,
- RectAnnotation,
- TooltipValue,
- TooltipType,
- ElementClickListener,
- XYChartElementEvent,
- BrushEndListener,
- Theme,
-} from '@elastic/charts';
-
-import { i18n } from '@osd/i18n';
-import { IUiSettingsClient } from 'opensearch-dashboards/public';
-import { EuiChartThemeType } from '@elastic/eui/dist/eui_charts_theme';
-import { Subscription, combineLatest } from 'rxjs';
-import { getServices } from '../../../opensearch_dashboards_services';
-import { Chart as IChart } from '../helpers/point_series';
-
-export interface DiscoverHistogramProps {
- chartData: IChart;
- timefilterUpdateHandler: (ranges: { from: number; to: number }) => void;
-}
-
-interface DiscoverHistogramState {
- chartsTheme: EuiChartThemeType['theme'];
- chartsBaseTheme: Theme;
-}
-
-function findIntervalFromDuration(
- dateValue: number,
- opensearchValue: number,
- opensearchUnit: unitOfTime.Base,
- timeZone: string
-) {
- const date = moment.tz(dateValue, timeZone);
- const startOfDate = moment.tz(date, timeZone).startOf(opensearchUnit);
- const endOfDate = moment
- .tz(date, timeZone)
- .startOf(opensearchUnit)
- .add(opensearchValue, opensearchUnit);
- return endOfDate.valueOf() - startOfDate.valueOf();
-}
-
-function getIntervalInMs(
- value: number,
- opensearchValue: number,
- opensearchUnit: unitOfTime.Base,
- timeZone: string
-): number {
- switch (opensearchUnit) {
- case 's':
- return 1000 * opensearchValue;
- case 'ms':
- return 1 * opensearchValue;
- default:
- return findIntervalFromDuration(value, opensearchValue, opensearchUnit, timeZone);
- }
-}
-
-function getTimezone(uiSettings: IUiSettingsClient) {
- if (uiSettings.isDefault('dateFormat:tz')) {
- const detectedTimezone = moment.tz.guess();
- if (detectedTimezone) return detectedTimezone;
- else return moment().format('Z');
- } else {
- return uiSettings.get('dateFormat:tz', 'Browser');
- }
-}
-
-export function findMinInterval(
- xValues: number[],
- opensearchValue: number,
- opensearchUnit: string,
- timeZone: string
-): number {
- return xValues.reduce((minInterval, currentXvalue, index) => {
- let currentDiff = minInterval;
- if (index > 0) {
- currentDiff = Math.abs(xValues[index - 1] - currentXvalue);
- }
- const singleUnitInterval = getIntervalInMs(
- currentXvalue,
- opensearchValue,
- opensearchUnit as unitOfTime.Base,
- timeZone
- );
- return Math.min(minInterval, singleUnitInterval, currentDiff);
- }, Number.MAX_SAFE_INTEGER);
-}
-
-export class DiscoverHistogram extends Component
{
- public static propTypes = {
- chartData: PropTypes.object,
- timefilterUpdateHandler: PropTypes.func,
- };
-
- private subscription?: Subscription;
- public state = {
- chartsTheme: getServices().theme.chartsDefaultTheme,
- chartsBaseTheme: getServices().theme.chartsDefaultBaseTheme,
- };
-
- componentDidMount() {
- this.subscription = combineLatest(
- getServices().theme.chartsTheme$,
- getServices().theme.chartsBaseTheme$
- ).subscribe(([chartsTheme, chartsBaseTheme]) =>
- this.setState({ chartsTheme, chartsBaseTheme })
- );
- }
-
- componentWillUnmount() {
- if (this.subscription) {
- this.subscription.unsubscribe();
- }
- }
-
- public onBrushEnd: BrushEndListener = ({ x }) => {
- if (!x) {
- return;
- }
- const [from, to] = x;
- this.props.timefilterUpdateHandler({ from, to });
- };
-
- public onElementClick = (xInterval: number): ElementClickListener => ([elementData]) => {
- const startRange = (elementData as XYChartElementEvent)[0].x;
-
- const range = {
- from: startRange,
- to: startRange + xInterval,
- };
-
- this.props.timefilterUpdateHandler(range);
- };
-
- public formatXValue = (val: string) => {
- const xAxisFormat = this.props.chartData.xAxisFormat.params!.pattern;
-
- return moment(val).format(xAxisFormat);
- };
-
- public renderBarTooltip = (xInterval: number, domainStart: number, domainEnd: number) => (
- headerData: TooltipValue
- ): JSX.Element | string => {
- const headerDataValue = headerData.value;
- const formattedValue = this.formatXValue(headerDataValue);
-
- const partialDataText = i18n.translate('discover.histogram.partialData.bucketTooltipText', {
- defaultMessage:
- 'The selected time range does not include this entire bucket, it may contain partial data.',
- });
-
- if (headerDataValue < domainStart || headerDataValue + xInterval > domainEnd) {
- return (
-
-
-
-
-
- {partialDataText}
-
-
- {formattedValue}
-
- );
- }
-
- return formattedValue;
- };
-
- public render() {
- const uiSettings = getServices().uiSettings;
- const timeZone = getTimezone(uiSettings);
- const { chartData } = this.props;
- const { chartsTheme, chartsBaseTheme } = this.state;
-
- if (!chartData) {
- return null;
- }
-
- const data = chartData.values;
-
- /**
- * Deprecation: [interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval].
- * see https://github.com/elastic/kibana/issues/27410
- * TODO: Once the Discover query has been update, we should change the below to use the new field
- */
- const { intervalOpenSearchValue, intervalOpenSearchUnit, interval } = chartData.ordered;
- const xInterval = interval.asMilliseconds();
-
- const xValues = chartData.xAxisOrderedValues;
- const lastXValue = xValues[xValues.length - 1];
-
- const domain = chartData.ordered;
- const domainStart = domain.min.valueOf();
- const domainEnd = domain.max.valueOf();
-
- const domainMin = data[0]?.x > domainStart ? domainStart : data[0]?.x;
- const domainMax = domainEnd - xInterval > lastXValue ? domainEnd - xInterval : lastXValue;
-
- const xDomain = {
- min: domainMin,
- max: domainMax,
- minInterval: findMinInterval(
- xValues,
- intervalOpenSearchValue,
- intervalOpenSearchUnit,
- timeZone
- ),
- };
-
- // Domain end of 'now' will be milliseconds behind current time, so we extend time by 1 minute and check if
- // the annotation is within this range; if so, the line annotation uses the domainEnd as its value
- const now = moment();
- const isAnnotationAtEdge = moment(domainEnd).add(60000).isAfter(now) && now.isAfter(domainEnd);
- const lineAnnotationValue = isAnnotationAtEdge ? domainEnd : now;
-
- const lineAnnotationData = [
- {
- dataValue: lineAnnotationValue,
- },
- ];
- const isDarkMode = uiSettings.get('theme:darkMode');
-
- const lineAnnotationStyle = {
- line: {
- strokeWidth: 2,
- stroke: euiThemeVars.euiColorDanger,
- opacity: 0.7,
- },
- };
-
- const rectAnnotations = [];
- if (domainStart !== domainMin) {
- rectAnnotations.push({
- coordinates: {
- x1: domainStart,
- },
- });
- }
- if (domainEnd !== domainMax) {
- rectAnnotations.push({
- coordinates: {
- x0: domainEnd,
- },
- });
- }
-
- const rectAnnotationStyle = {
- stroke: isDarkMode ? euiThemeVars.euiColorLightShade : euiThemeVars.euiColorDarkShade,
- strokeWidth: 0,
- opacity: isDarkMode ? 0.6 : 0.2,
- fill: isDarkMode ? euiThemeVars.euiColorLightShade : euiThemeVars.euiColorDarkShade,
- };
-
- const tooltipProps = {
- headerFormatter: this.renderBarTooltip(xInterval, domainStart, domainEnd),
- type: TooltipType.VerticalCursor,
- };
-
- return (
-
-
-
-
-
-
-
-
- );
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/index.js b/src/plugins/discover_legacy/public/application/angular/directives/index.js
deleted file mode 100644
index d81152164c42..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/index.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { DiscoverNoResults } from './no_results';
-import { DiscoverUninitialized } from './uninitialized';
-import { DiscoverHistogram } from './histogram';
-import { getAngularModule } from '../../../opensearch_dashboards_services';
-
-const app = getAngularModule();
-
-app.directive('discoverNoResults', (reactDirective) => reactDirective(DiscoverNoResults));
-
-app.directive('discoverUninitialized', (reactDirective) => reactDirective(DiscoverUninitialized));
-
-app.directive('discoverHistogram', (reactDirective) => reactDirective(DiscoverHistogram));
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/no_results.js b/src/plugins/discover_legacy/public/application/angular/directives/no_results.js
deleted file mode 100644
index 1495296e9dbb..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/no_results.js
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { Component, Fragment } from 'react';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-import PropTypes from 'prop-types';
-
-import {
- EuiCallOut,
- EuiCode,
- EuiDescriptionList,
- EuiFlexGroup,
- EuiFlexItem,
- EuiLink,
- EuiSpacer,
- EuiText,
-} from '@elastic/eui';
-import { getServices } from '../../../opensearch_dashboards_services';
-
-// eslint-disable-next-line react/prefer-stateless-function
-export class DiscoverNoResults extends Component {
- static propTypes = {
- timeFieldName: PropTypes.string,
- queryLanguage: PropTypes.string,
- };
-
- render() {
- const { timeFieldName, queryLanguage } = this.props;
-
- let timeFieldMessage;
-
- if (timeFieldName) {
- timeFieldMessage = (
-
-
-
-
-
-
-
-
-
-
-
-
-
- );
- }
-
- let luceneQueryMessage;
-
- if (queryLanguage === 'lucene') {
- const searchExamples = [
- {
- description: 200,
- title: (
-
-
-
-
-
- ),
- },
- {
- description: status:200,
- title: (
-
-
-
-
-
- ),
- },
- {
- description: status:[400 TO 499],
- title: (
-
-
-
-
-
- ),
- },
- {
- description: status:[400 TO 499] AND extension:PHP,
- title: (
-
-
-
-
-
- ),
- },
- {
- description: status:[400 TO 499] AND (extension:php OR extension:html),
- title: (
-
-
-
-
-
- ),
- },
- ];
-
- luceneQueryMessage = (
-
-
-
-
-
-
-
-
-
-
-
-
- ),
- }}
- />
-
-
-
-
-
-
-
-
-
- );
- }
-
- return (
-
-
-
-
-
-
-
- }
- color="warning"
- iconType="help"
- data-test-subj="discoverNoResults"
- />
- {timeFieldMessage}
- {luceneQueryMessage}
-
-
-
-
- );
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/no_results.test.js b/src/plugins/discover_legacy/public/application/angular/directives/no_results.test.js
deleted file mode 100644
index e6b1c6b73eb3..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/no_results.test.js
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { renderWithIntl } from 'test_utils/enzyme_helpers';
-
-import { DiscoverNoResults } from './no_results';
-
-jest.mock('../../../opensearch_dashboards_services', () => {
- return {
- getServices: () => ({
- docLinks: {
- links: {
- opensearch: {
- queryDSL: {
- base: 'documentation-link',
- },
- },
- },
- },
- }),
- };
-});
-
-beforeEach(() => {
- jest.clearAllMocks();
-});
-
-describe('DiscoverNoResults', () => {
- describe('props', () => {
- describe('timeFieldName', () => {
- test('renders time range feedback', () => {
- const component = renderWithIntl();
-
- expect(component).toMatchSnapshot();
- });
- });
-
- describe('queryLanguage', () => {
- test('supports lucene and renders doc link', () => {
- const component = renderWithIntl(
- 'documentation-link'} />
- );
-
- expect(component).toMatchSnapshot();
- });
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/render_complete.ts b/src/plugins/discover_legacy/public/application/angular/directives/render_complete.ts
deleted file mode 100644
index 4409910a8e5c..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/render_complete.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IScope } from 'angular';
-import { RenderCompleteListener } from '../../../../../opensearch_dashboards_utils/public';
-
-export function createRenderCompleteDirective() {
- return {
- controller($scope: IScope, $element: JQLite) {
- const el = $element[0];
- const renderCompleteListener = new RenderCompleteListener(el);
- $scope.$on('$destroy', renderCompleteListener.destroy);
- },
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/directives/uninitialized.tsx b/src/plugins/discover_legacy/public/application/angular/directives/uninitialized.tsx
deleted file mode 100644
index 9cc47b034d1e..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/directives/uninitialized.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-
-import { EuiButton, EuiEmptyPrompt, EuiPage, EuiPageBody, EuiPageContent } from '@elastic/eui';
-
-interface Props {
- onRefresh: () => void;
-}
-
-export const DiscoverUninitialized = ({ onRefresh }: Props) => {
- return (
-
-
-
-
-
-
-
- }
- body={
-
-
-
- }
- actions={
-
-
-
- }
- />
-
-
-
-
- );
-};
diff --git a/src/plugins/discover_legacy/public/application/angular/discover.js b/src/plugins/discover_legacy/public/application/angular/discover.js
deleted file mode 100644
index f8a96928784c..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/discover.js
+++ /dev/null
@@ -1,1156 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-import React from 'react';
-import { Subscription, Subject, merge } from 'rxjs';
-import { debounceTime } from 'rxjs/operators';
-import moment from 'moment';
-import dateMath from '@elastic/datemath';
-import { i18n } from '@osd/i18n';
-import { getState, splitState } from './discover_state';
-
-import { RequestAdapter } from '../../../../inspector/public';
-import {
- opensearchFilters,
- indexPatterns as indexPatternsUtils,
- connectToQueryState,
- syncQueryStateWithUrl,
-} from '../../../../data/public';
-import { SavedObjectSaveModal, showSaveModal } from '../../../../saved_objects/public';
-import { getSortArray, getSortForSearchSource } from './doc_table';
-import { createFixedScroll } from './directives/fixed_scroll';
-import * as columnActions from './doc_table/actions/columns';
-import indexTemplateLegacy from './discover_legacy.html';
-import { showOpenSearchPanel } from '../components/top_nav/show_open_search_panel';
-import { addHelpMenuToAppChrome } from '../components/help_menu/help_menu_util';
-import { discoverResponseHandler } from './response_handler';
-import {
- getRequestInspectorStats,
- getResponseInspectorStats,
- getServices,
- getHeaderActionMenuMounter,
- getUrlTracker,
- unhashUrl,
- subscribeWithScope,
- tabifyAggResponse,
- getAngularModule,
- redirectWhenMissing,
-} from '../../opensearch_dashboards_services';
-
-const {
- core,
- chrome,
- data,
- history: getHistory,
- indexPatterns,
- filterManager,
- share,
- timefilter,
- toastNotifications,
- uiSettings: config,
- visualizations,
-} = getServices();
-
-import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs';
-import { validateTimeRange } from '../helpers/validate_time_range';
-import { popularizeField } from '../helpers/popularize_field';
-import { getSwitchIndexPatternAppState } from '../helpers/get_switch_index_pattern_app_state';
-import { getIndexPatternId } from '../helpers/get_index_pattern_id';
-import { addFatalError } from '../../../../opensearch_dashboards_legacy/public';
-import {
- DEFAULT_COLUMNS_SETTING,
- SAMPLE_SIZE_SETTING,
- SORT_DEFAULT_ORDER_SETTING,
- SEARCH_ON_PAGE_LOAD_SETTING,
- DOC_HIDE_TIME_COLUMN_SETTING,
- MODIFY_COLUMNS_ON_SWITCH,
-} from '../../../common';
-import { NEW_DISCOVER_APP } from '../../../../discover/public';
-
-const fetchStatuses = {
- UNINITIALIZED: 'uninitialized',
- LOADING: 'loading',
- COMPLETE: 'complete',
-};
-
-const app = getAngularModule();
-
-app.config(($routeProvider) => {
- const defaults = {
- requireDefaultIndex: true,
- requireUICapability: 'discover.show',
- k7Breadcrumbs: ($route, $injector) =>
- $injector.invoke($route.current.params.id ? getSavedSearchBreadcrumbs : getRootBreadcrumbs),
- badge: (uiCapabilities) => {
- if (uiCapabilities.discover.save) {
- return undefined;
- }
-
- return {
- text: i18n.translate('discover.badge.readOnly.text', {
- defaultMessage: 'Read only',
- }),
- tooltip: i18n.translate('discover.badge.readOnly.tooltip', {
- defaultMessage: 'Unable to save searches',
- }),
- iconType: 'glasses',
- };
- },
- };
- const discoverRoute = {
- ...defaults,
- template: indexTemplateLegacy,
- reloadOnSearch: false,
- resolve: {
- savedObjects: function ($route, Promise) {
- const history = getHistory();
- const savedSearchId = $route.current.params.id;
- return data.indexPatterns.ensureDefaultIndexPattern(history).then(() => {
- const { appStateContainer } = getState({ history });
- const { index } = appStateContainer.getState();
- return Promise.props({
- ip: indexPatterns.getCache().then((indexPatternList) => {
- /**
- * In making the indexPattern modifiable it was placed in appState. Unfortunately,
- * the load order of AppState conflicts with the load order of many other things
- * so in order to get the name of the index we should use, and to switch to the
- * default if necessary, we parse the appState with a temporary State object and
- * then destroy it immediatly after we're done
- *
- * @type {State}
- */
- const id = getIndexPatternId(index, indexPatternList, config.get('defaultIndex'));
- return Promise.props({
- list: indexPatternList,
- loaded: indexPatterns.get(id),
- stateVal: index,
- stateValFound: !!index && id === index,
- });
- }),
- savedSearch: getServices()
- .getSavedSearchById(savedSearchId)
- .then((savedSearch) => {
- if (savedSearchId) {
- chrome.recentlyAccessed.add(
- savedSearch.getFullPath(),
- savedSearch.title,
- savedSearchId
- );
- }
- return savedSearch;
- })
- .catch(
- redirectWhenMissing({
- history,
- navigateToApp: core.application.navigateToApp,
- mapping: {
- search: '/',
- 'index-pattern': {
- app: 'management',
- path: `opensearch-dashboards/objects/savedSearches/${$route.current.params.id}`,
- },
- },
- toastNotifications,
- onBeforeRedirect() {
- getUrlTracker().setTrackedUrl('/');
- },
- })
- ),
- });
- });
- },
- },
- };
-
- $routeProvider.when('/view/:id?', discoverRoute);
- $routeProvider.when('/', discoverRoute);
-});
-
-app.directive('discoverApp', function () {
- return {
- restrict: 'E',
- controllerAs: 'discoverApp',
- controller: discoverController,
- };
-});
-
-function discoverController($element, $route, $scope, $timeout, $window, Promise, uiCapabilities) {
- const { isDefault: isDefaultType } = indexPatternsUtils;
- const subscriptions = new Subscription();
- const refetch$ = new Subject();
- let inspectorRequest;
- const savedSearch = $route.current.locals.savedObjects.savedSearch;
- $scope.searchSource = savedSearch.searchSource;
- $scope.indexPattern = resolveIndexPatternLoading();
- //used for functional testing
- $scope.fetchCounter = 0;
-
- const getTimeField = () => {
- return isDefaultType($scope.indexPattern) ? $scope.indexPattern.timeFieldName : undefined;
- };
-
- const history = getHistory();
-
- const {
- appStateContainer,
- startSync: startStateSync,
- stopSync: stopStateSync,
- setAppState,
- replaceUrlAppState,
- isAppStateDirty,
- osdUrlStateStorage,
- getPreviousAppState,
- resetInitialAppState,
- } = getState({
- defaultAppState: getStateDefaults(),
- storeInSessionStorage: config.get('state:storeInSessionStorage'),
- history,
- toasts: core.notifications.toasts,
- });
- if (appStateContainer.getState().index !== $scope.indexPattern.id) {
- //used index pattern is different than the given by url/state which is invalid
- setAppState({ index: $scope.indexPattern.id });
- }
- $scope.state = { ...appStateContainer.getState() };
-
- // syncs `_g` portion of url with query services
- const { stop: stopSyncingGlobalStateWithUrl } = syncQueryStateWithUrl(
- data.query,
- osdUrlStateStorage
- );
-
- // sync initial app filters from state to filterManager
- filterManager.setAppFilters(_.cloneDeep(appStateContainer.getState().filters));
- data.query.queryString.setQuery(appStateContainer.getState().query);
-
- const stopSyncingQueryAppStateWithStateContainer = connectToQueryState(
- data.query,
- appStateContainer,
- {
- filters: opensearchFilters.FilterStateStore.APP_STATE,
- query: true,
- }
- );
-
- const appStateUnsubscribe = appStateContainer.subscribe(async (newState) => {
- const { state: newStatePartial } = splitState(newState);
- const { state: oldStatePartial } = splitState(getPreviousAppState());
-
- if (!_.isEqual(newStatePartial, oldStatePartial)) {
- $scope.$evalAsync(async () => {
- if (oldStatePartial.index !== newStatePartial.index) {
- //in case of index switch the route has currently to be reloaded, legacy
- return;
- }
-
- $scope.state = { ...newState };
-
- // detect changes that should trigger fetching of new data
- const changes = ['interval', 'sort'].filter(
- (prop) => !_.isEqual(newStatePartial[prop], oldStatePartial[prop])
- );
-
- if (changes.length) {
- refetch$.next();
- }
- });
- }
- });
-
- // this listener is waiting for such a path http://localhost:5601/app/discover#/
- // which could be set through pressing "New" button in top nav or go to "Discover" plugin from the sidebar
- // to reload the page in a right way
- const unlistenHistoryBasePath = history.listen(({ pathname, search, hash }) => {
- if (!search && !hash && pathname === '/') {
- $route.reload();
- }
- });
-
- $scope.setIndexPattern = async (id) => {
- const nextIndexPattern = await indexPatterns.get(id);
- if (nextIndexPattern) {
- const nextAppState = getSwitchIndexPatternAppState(
- $scope.indexPattern,
- nextIndexPattern,
- $scope.state.columns,
- $scope.state.sort,
- config.get(MODIFY_COLUMNS_ON_SWITCH)
- );
- await replaceUrlAppState(nextAppState);
- $route.reload();
- }
- };
-
- // update data source when filters update
- subscriptions.add(
- subscribeWithScope(
- $scope,
- filterManager.getUpdates$(),
- {
- next: () => {
- $scope.state.filters = filterManager.getAppFilters();
- $scope.updateDataSource();
- },
- },
- (error) => addFatalError(core.fatalErrors, error)
- )
- );
-
- const inspectorAdapters = {
- requests: new RequestAdapter(),
- };
-
- $scope.timefilterUpdateHandler = (ranges) => {
- timefilter.setTime({
- from: moment(ranges.from).toISOString(),
- to: moment(ranges.to).toISOString(),
- mode: 'absolute',
- });
- };
- $scope.minimumVisibleRows = 50;
- $scope.fetchStatus = fetchStatuses.UNINITIALIZED;
- $scope.showSaveQuery = uiCapabilities.discover.saveQuery;
-
- let abortController;
- $scope.$on('$destroy', () => {
- if (abortController) abortController.abort();
- savedSearch.destroy();
- subscriptions.unsubscribe();
- appStateUnsubscribe();
- stopStateSync();
- stopSyncingGlobalStateWithUrl();
- stopSyncingQueryAppStateWithStateContainer();
- unlistenHistoryBasePath();
- });
-
- const getTopNavLinks = () => {
- const newSearch = {
- id: 'new',
- label: i18n.translate('discover.localMenu.localMenu.newSearchTitle', {
- defaultMessage: 'New',
- }),
- description: i18n.translate('discover.localMenu.newSearchDescription', {
- defaultMessage: 'New Search',
- }),
- run: function () {
- $scope.$evalAsync(() => {
- history.push('/');
- });
- },
- testId: 'discoverNewButton',
- };
-
- const saveSearch = {
- id: 'save',
- label: i18n.translate('discover.localMenu.saveTitle', {
- defaultMessage: 'Save',
- }),
- description: i18n.translate('discover.localMenu.saveSearchDescription', {
- defaultMessage: 'Save Search',
- }),
- testId: 'discoverSaveButton',
- run: async () => {
- const onSave = ({
- newTitle,
- newCopyOnSave,
- isTitleDuplicateConfirmed,
- onTitleDuplicate,
- }) => {
- const currentTitle = savedSearch.title;
- savedSearch.title = newTitle;
- savedSearch.copyOnSave = newCopyOnSave;
- const saveOptions = {
- confirmOverwrite: false,
- isTitleDuplicateConfirmed,
- onTitleDuplicate,
- };
- return saveDataSource(saveOptions).then((response) => {
- // If the save wasn't successful, put the original values back.
- if (!response.id || response.error) {
- savedSearch.title = currentTitle;
- } else {
- resetInitialAppState();
- }
- return response;
- });
- };
-
- const saveModal = (
- {}}
- title={savedSearch.title}
- showCopyOnSave={!!savedSearch.id}
- objectType="search"
- description={i18n.translate('discover.localMenu.saveSaveSearchDescription', {
- defaultMessage:
- 'Save your Discover search so you can use it in visualizations and dashboards',
- })}
- showDescription={false}
- />
- );
- showSaveModal(saveModal, core.i18n.Context);
- },
- };
-
- const openSearch = {
- id: 'open',
- label: i18n.translate('discover.localMenu.openTitle', {
- defaultMessage: 'Open',
- }),
- description: i18n.translate('discover.localMenu.openSavedSearchDescription', {
- defaultMessage: 'Open Saved Search',
- }),
- testId: 'discoverOpenButton',
- run: () => {
- showOpenSearchPanel({
- makeUrl: (searchId) => `#/view/${encodeURIComponent(searchId)}`,
- I18nContext: core.i18n.Context,
- });
- },
- };
-
- const shareSearch = {
- id: 'share',
- label: i18n.translate('discover.localMenu.shareTitle', {
- defaultMessage: 'Share',
- }),
- description: i18n.translate('discover.localMenu.shareSearchDescription', {
- defaultMessage: 'Share Search',
- }),
- testId: 'shareTopNavButton',
- run: async (anchorElement) => {
- const sharingData = await this.getSharingData();
- share.toggleShareContextMenu({
- anchorElement,
- allowEmbed: false,
- allowShortUrl: uiCapabilities.discover.createShortUrl,
- shareableUrl: unhashUrl(window.location.href),
- objectId: savedSearch.id,
- objectType: 'search',
- sharingData: {
- ...sharingData,
- title: savedSearch.title,
- },
- isDirty: !savedSearch.id || isAppStateDirty(),
- });
- },
- };
-
- const inspectSearch = {
- id: 'inspect',
- label: i18n.translate('discover.localMenu.inspectTitle', {
- defaultMessage: 'Inspect',
- }),
- description: i18n.translate('discover.localMenu.openInspectorForSearchDescription', {
- defaultMessage: 'Open Inspector for search',
- }),
- testId: 'openInspectorButton',
- run() {
- getServices().inspector.open(inspectorAdapters, {
- title: savedSearch.title,
- });
- },
- };
-
- const newDiscover = {
- id: 'discover-new',
- label: i18n.translate('discover.localMenu.newDiscoverTitle', {
- defaultMessage: 'New Discover',
- }),
- description: i18n.translate('discover.localMenu.newDiscoverDescription', {
- defaultMessage: 'New Discover Experience',
- }),
- testId: 'discoverNewButton',
- run: async function () {
- await getServices().uiSettings.set(NEW_DISCOVER_APP, true);
- window.location.reload();
- },
- type: 'toggle',
- };
-
- return [
- newDiscover,
- newSearch,
- ...(uiCapabilities.discover.save ? [saveSearch] : []),
- openSearch,
- shareSearch,
- inspectSearch,
- ];
- };
- $scope.topNavMenu = getTopNavLinks();
-
- $scope.searchSource
- .setField('index', $scope.indexPattern)
- .setField('highlightAll', true)
- .setField('version', true);
-
- // Even when searching rollups, we want to use the default strategy so that we get back a
- // document-like response.
- $scope.searchSource.setPreferredSearchStrategyId('default');
-
- // searchSource which applies time range
- const timeRangeSearchSource = savedSearch.searchSource.create();
-
- if (isDefaultType($scope.indexPattern)) {
- timeRangeSearchSource.setField('filter', () => {
- return timefilter.createFilter($scope.indexPattern);
- });
- }
-
- $scope.searchSource.setParent(timeRangeSearchSource);
-
- const pageTitleSuffix = savedSearch.id && savedSearch.title ? `: ${savedSearch.title}` : '';
- chrome.docTitle.change(`Discover${pageTitleSuffix}`);
- const discoverBreadcrumbsTitle = i18n.translate('discover.discoverBreadcrumbTitle', {
- defaultMessage: 'Discover',
- });
-
- if (savedSearch.id && savedSearch.title) {
- chrome.setBreadcrumbs([
- {
- text: discoverBreadcrumbsTitle,
- href: '#/',
- },
- { text: savedSearch.title },
- ]);
- } else {
- chrome.setBreadcrumbs([
- {
- text: discoverBreadcrumbsTitle,
- },
- ]);
- }
-
- const getFieldCounts = async () => {
- // the field counts aren't set until we have the data back,
- // so we wait for the fetch to be done before proceeding
- if ($scope.fetchStatus === fetchStatuses.COMPLETE) {
- return $scope.fieldCounts;
- }
-
- return await new Promise((resolve) => {
- const unwatch = $scope.$watch('fetchStatus', (newValue) => {
- if (newValue === fetchStatuses.COMPLETE) {
- unwatch();
- resolve($scope.fieldCounts);
- }
- });
- });
- };
-
- const getSharingDataFields = async (selectedFields, timeFieldName, hideTimeColumn) => {
- if (selectedFields.length === 1 && selectedFields[0] === '_source') {
- const fieldCounts = await getFieldCounts();
- return {
- searchFields: null,
- selectFields: _.keys(fieldCounts).sort(),
- };
- }
-
- const fields =
- timeFieldName && !hideTimeColumn ? [timeFieldName, ...selectedFields] : selectedFields;
- return {
- searchFields: fields,
- selectFields: fields,
- };
- };
-
- this.getSharingData = async () => {
- const searchSource = $scope.searchSource.createCopy();
-
- const { searchFields, selectFields } = await getSharingDataFields(
- $scope.state.columns,
- $scope.indexPattern.timeFieldName,
- config.get(DOC_HIDE_TIME_COLUMN_SETTING)
- );
- searchSource.setField('fields', searchFields);
- searchSource.setField(
- 'sort',
- getSortForSearchSource(
- $scope.state.sort,
- $scope.indexPattern,
- config.get(SORT_DEFAULT_ORDER_SETTING)
- )
- );
- searchSource.setField('highlight', null);
- searchSource.setField('highlightAll', null);
- searchSource.setField('aggs', null);
- searchSource.setField('size', null);
-
- const body = await searchSource.getSearchRequestBody();
- return {
- searchRequest: {
- index: searchSource.getField('index').title,
- body,
- },
- fields: selectFields,
- metaFields: $scope.indexPattern.metaFields,
- conflictedTypesFields: $scope.indexPattern.fields
- .filter((f) => f.type === 'conflict')
- .map((f) => f.name),
- indexPatternId: searchSource.getField('index').id,
- };
- };
-
- function getStateDefaults() {
- const query = $scope.searchSource.getField('query') || data.query.queryString.getDefaultQuery();
- return {
- query,
- sort: getSortArray(savedSearch.sort, $scope.indexPattern),
- columns:
- savedSearch.columns.length > 0
- ? savedSearch.columns
- : config.get(DEFAULT_COLUMNS_SETTING).slice(),
- index: $scope.indexPattern.id,
- interval: 'auto',
- filters: _.cloneDeep($scope.searchSource.getOwnField('filter')),
- };
- }
-
- $scope.state.index = $scope.indexPattern.id;
- $scope.state.sort = getSortArray($scope.state.sort, $scope.indexPattern);
-
- $scope.opts = {
- // number of records to fetch, then paginate through
- sampleSize: config.get(SAMPLE_SIZE_SETTING),
- timefield: getTimeField(),
- savedSearch: savedSearch,
- indexPatternList: $route.current.locals.savedObjects.ip.list,
- config: config,
- fixedScroll: createFixedScroll($scope, $timeout),
- setHeaderActionMenu: getHeaderActionMenuMounter(),
- };
-
- const shouldSearchOnPageLoad = () => {
- // A saved search is created on every page load, so we check the ID to see if we're loading a
- // previously saved search or if it is just transient
- return (
- config.get(SEARCH_ON_PAGE_LOAD_SETTING) ||
- savedSearch.id !== undefined ||
- timefilter.getRefreshInterval().pause === false
- );
- };
-
- const init = _.once(() => {
- $scope.updateDataSource().then(async () => {
- const fetch$ = merge(
- refetch$,
- filterManager.getFetches$(),
- timefilter.getFetch$(),
- timefilter.getAutoRefreshFetch$(),
- data.query.queryString.getUpdates$()
- ).pipe(debounceTime(100));
-
- subscriptions.add(
- subscribeWithScope(
- $scope,
- fetch$,
- {
- next: $scope.fetch,
- },
- (error) => addFatalError(core.fatalErrors, error)
- )
- );
- subscriptions.add(
- subscribeWithScope(
- $scope,
- timefilter.getTimeUpdate$(),
- {
- next: () => {
- $scope.updateTime();
- },
- },
- (error) => addFatalError(core.fatalErrors, error)
- )
- );
-
- $scope.changeInterval = (interval) => {
- if (interval) {
- setAppState({ interval });
- }
- };
-
- $scope.$watchMulti(
- ['rows', 'fetchStatus'],
- (function updateResultState() {
- let prev = {};
- const status = {
- UNINITIALIZED: 'uninitialized',
- LOADING: 'loading', // initial data load
- READY: 'ready', // results came back
- NO_RESULTS: 'none', // no results came back
- };
-
- function pick(rows, oldRows, fetchStatus) {
- // initial state, pretend we're already loading if we're about to execute a search so
- // that the uninitilized message doesn't flash on screen
- if (rows == null && oldRows == null && shouldSearchOnPageLoad()) {
- return status.LOADING;
- }
-
- if (fetchStatus === fetchStatuses.UNINITIALIZED) {
- return status.UNINITIALIZED;
- }
-
- const rowsEmpty = _.isEmpty(rows);
- if (rowsEmpty && fetchStatus === fetchStatuses.LOADING) return status.LOADING;
- else if (!rowsEmpty) return status.READY;
- else return status.NO_RESULTS;
- }
-
- return function () {
- const current = {
- rows: $scope.rows,
- fetchStatus: $scope.fetchStatus,
- };
-
- $scope.resultState = pick(
- current.rows,
- prev.rows,
- current.fetchStatus,
- prev.fetchStatus
- );
-
- prev = current;
- };
- })()
- );
-
- if (getTimeField()) {
- setupVisualization();
- $scope.updateTime();
- }
-
- init.complete = true;
- if (shouldSearchOnPageLoad()) {
- refetch$.next();
- }
- });
- });
-
- async function saveDataSource(saveOptions) {
- await $scope.updateDataSource();
-
- savedSearch.columns = $scope.state.columns;
- savedSearch.sort = $scope.state.sort;
-
- try {
- const id = await savedSearch.save(saveOptions);
- $scope.$evalAsync(() => {
- if (id) {
- toastNotifications.addSuccess({
- title: i18n.translate('discover.notifications.savedSearchTitle', {
- defaultMessage: `Search '{savedSearchTitle}' was saved`,
- values: {
- savedSearchTitle: savedSearch.title,
- },
- }),
- 'data-test-subj': 'saveSearchSuccess',
- });
-
- if (savedSearch.id !== $route.current.params.id) {
- history.push(`/view/${encodeURIComponent(savedSearch.id)}`);
- } else {
- // Update defaults so that "reload saved query" functions correctly
- setAppState(getStateDefaults());
- chrome.docTitle.change(savedSearch.lastSavedTitle);
- chrome.setBreadcrumbs([
- {
- text: discoverBreadcrumbsTitle,
- href: '#/',
- },
- { text: savedSearch.title },
- ]);
- }
- }
- });
- return { id };
- } catch (saveError) {
- toastNotifications.addDanger({
- title: i18n.translate('discover.notifications.notSavedSearchTitle', {
- defaultMessage: `Search '{savedSearchTitle}' was not saved.`,
- values: {
- savedSearchTitle: savedSearch.title,
- },
- }),
- text: saveError.message,
- });
- return { error: saveError };
- }
- }
-
- $scope.opts.fetch = $scope.fetch = function () {
- // ignore requests to fetch before the app inits
- if (!init.complete) return;
- $scope.fetchCounter++;
- $scope.fetchError = undefined;
- $scope.minimumVisibleRows = 50;
- if (!validateTimeRange(timefilter.getTime(), toastNotifications)) {
- $scope.resultState = 'none';
- return;
- }
-
- // Abort any in-progress requests before fetching again
- if (abortController) abortController.abort();
- abortController = new AbortController();
-
- $scope
- .updateDataSource()
- .then(setupVisualization)
- .then(function () {
- $scope.fetchStatus = fetchStatuses.LOADING;
- logInspectorRequest();
- return $scope.searchSource.fetch({
- abortSignal: abortController.signal,
- });
- })
- .then(onResults)
- .catch((error) => {
- // If the request was aborted then no need to surface this error in the UI
- if (error instanceof Error && error.name === 'AbortError') return;
-
- $scope.fetchStatus = fetchStatuses.NO_RESULTS;
- $scope.rows = [];
-
- data.search.showError(error);
- });
- };
-
- $scope.handleRefresh = function (_payload, isUpdate) {
- if (isUpdate === false) {
- refetch$.next();
- }
- };
-
- $scope.updateSavedQueryId = (newSavedQueryId) => {
- if (newSavedQueryId) {
- setAppState({ savedQuery: newSavedQueryId });
- } else {
- // remove savedQueryId from state
- const state = {
- ...appStateContainer.getState(),
- };
- delete state.savedQuery;
- appStateContainer.set(state);
- }
- };
-
- function getDimensions(aggs, timeRange) {
- const [metric, agg] = aggs;
- agg.params.timeRange = timeRange;
- const bounds = agg.params.timeRange ? timefilter.calculateBounds(agg.params.timeRange) : null;
- agg.buckets.setBounds(bounds);
-
- const { opensearchUnit, opensearchValue } = agg.buckets.getInterval();
- return {
- x: {
- accessor: 0,
- label: agg.makeLabel(),
- format: agg.toSerializedFieldFormat(),
- params: {
- date: true,
- interval: moment.duration(opensearchValue, opensearchUnit),
- intervalOpenSearchValue: opensearchValue,
- intervalOpenSearchUnit: opensearchUnit,
- format: agg.buckets.getScaledDateFormat(),
- bounds: agg.buckets.getBounds(),
- },
- },
- y: {
- accessor: 1,
- format: metric.toSerializedFieldFormat(),
- label: metric.makeLabel(),
- },
- };
- }
-
- function onResults(resp) {
- inspectorRequest.stats(getResponseInspectorStats(resp, $scope.searchSource)).ok({ json: resp });
-
- if (getTimeField()) {
- const tabifiedData = tabifyAggResponse($scope.vis.data.aggs, resp);
- $scope.searchSource.rawResponse = resp;
- $scope.histogramData = discoverResponseHandler(
- tabifiedData,
- getDimensions($scope.vis.data.aggs.aggs, $scope.timeRange)
- );
- $scope.updateTime();
- }
-
- $scope.hits = resp.hits.total;
- $scope.rows = resp.hits.hits;
-
- // if we haven't counted yet, reset the counts
- const counts = ($scope.fieldCounts = $scope.fieldCounts || {});
-
- $scope.rows.forEach((hit) => {
- const fields = Object.keys($scope.indexPattern.flattenHit(hit));
- fields.forEach((fieldName) => {
- counts[fieldName] = (counts[fieldName] || 0) + 1;
- });
- });
-
- $scope.fetchStatus = fetchStatuses.COMPLETE;
- }
-
- function logInspectorRequest() {
- inspectorAdapters.requests.reset();
- const title = i18n.translate('discover.inspectorRequestDataTitle', {
- defaultMessage: 'data',
- });
- const description = i18n.translate('discover.inspectorRequestDescription', {
- defaultMessage: 'This request queries OpenSearch to fetch the data for the search.',
- });
- inspectorRequest = inspectorAdapters.requests.start(title, { description });
- inspectorRequest.stats(getRequestInspectorStats($scope.searchSource));
- $scope.searchSource.getSearchRequestBody().then((body) => {
- inspectorRequest.json(body);
- });
- }
-
- $scope.updateTime = function () {
- const { from, to } = timefilter.getTime();
- // this is the timerange for the histogram, should be refactored
- $scope.timeRange = {
- from: dateMath.parse(from),
- to: dateMath.parse(to, { roundUp: true }),
- };
- };
-
- $scope.toMoment = function (datetime) {
- if (!datetime) {
- return;
- }
- return moment(datetime).format(config.get('dateFormat'));
- };
-
- $scope.resetQuery = function () {
- history.push(
- $route.current.params.id ? `/view/${encodeURIComponent($route.current.params.id)}` : '/'
- );
- $route.reload();
- };
-
- $scope.onSkipBottomButtonClick = function () {
- // show all the Rows
- $scope.minimumVisibleRows = $scope.hits;
-
- // delay scrolling to after the rows have been rendered
- const bottomMarker = $element.find('#discoverBottomMarker');
- $timeout(() => {
- bottomMarker.focus();
- // The anchor tag is not technically empty (it's a hack to make Safari scroll)
- // so the browser will show a highlight: remove the focus once scrolled
- $timeout(() => {
- bottomMarker.blur();
- }, 0);
- }, 0);
- };
-
- $scope.newQuery = function () {
- history.push('/');
- };
-
- $scope.updateDataSource = () => {
- const { indexPattern, searchSource } = $scope;
- searchSource
- .setField('index', $scope.indexPattern)
- .setField('size', $scope.opts.sampleSize)
- .setField(
- 'sort',
- getSortForSearchSource(
- $scope.state.sort,
- indexPattern,
- config.get(SORT_DEFAULT_ORDER_SETTING)
- )
- )
- .setField('query', data.query.queryString.getQuery() || null)
- .setField('filter', filterManager.getFilters());
- return Promise.resolve();
- };
-
- $scope.setSortOrder = function setSortOrder(sort) {
- setAppState({ sort });
- };
-
- // TODO: On array fields, negating does not negate the combination, rather all terms
- $scope.filterQuery = function (field, values, operation) {
- const { indexPattern } = $scope;
-
- popularizeField(indexPattern, field.name, indexPatterns);
- const newFilters = opensearchFilters.generateFilters(
- filterManager,
- field,
- values,
- operation,
- $scope.indexPattern.id
- );
- return filterManager.addFilters(newFilters);
- };
-
- $scope.addColumn = function addColumn(columnName) {
- if (uiCapabilities.discover.save) {
- const { indexPattern } = $scope;
- popularizeField(indexPattern, columnName, indexPatterns);
- }
- const columns = columnActions.addColumn($scope.state.columns, columnName);
- setAppState({ columns });
- };
-
- $scope.removeColumn = function removeColumn(columnName) {
- if (uiCapabilities.discover.save) {
- const { indexPattern } = $scope;
- popularizeField(indexPattern, columnName, indexPatterns);
- }
- const columns = columnActions.removeColumn($scope.state.columns, columnName);
- // The state's sort property is an array of [sortByColumn,sortDirection]
- const sort = $scope.state.sort.length
- ? $scope.state.sort.filter((subArr) => subArr[0] !== columnName)
- : [];
- setAppState({ columns, sort });
- };
-
- $scope.moveColumn = function moveColumn(columnName, newIndex) {
- const columns = columnActions.moveColumn($scope.state.columns, columnName, newIndex);
- setAppState({ columns });
- };
-
- $scope.scrollToTop = function () {
- $window.scrollTo(0, 0);
- };
-
- async function setupVisualization() {
- // If no timefield has been specified we don't create a histogram of messages
- if (!getTimeField()) return;
- const { interval: histogramInterval } = $scope.state;
-
- const visStateAggs = [
- {
- type: 'count',
- schema: 'metric',
- },
- {
- type: 'date_histogram',
- schema: 'segment',
- params: {
- field: getTimeField(),
- interval: histogramInterval,
- timeRange: timefilter.getTime(),
- },
- },
- ];
-
- $scope.vis = await visualizations.createVis('histogram', {
- title: savedSearch.title,
- params: {
- addLegend: false,
- addTimeMarker: true,
- },
- data: {
- aggs: visStateAggs,
- searchSource: $scope.searchSource.getSerializedFields(),
- },
- });
-
- $scope.searchSource.onRequestStart((searchSource, options) => {
- if (!$scope.vis) return;
- return $scope.vis.data.aggs.onSearchRequestStart(searchSource, options);
- });
-
- $scope.searchSource.setField('aggs', function () {
- if (!$scope.vis) return;
- return $scope.vis.data.aggs.toDsl();
- });
- }
-
- function getIndexPatternWarning(index) {
- return i18n.translate('discover.valueIsNotConfiguredIndexPatternIDWarningTitle', {
- defaultMessage: '{stateVal} is not a configured index pattern ID',
- values: {
- stateVal: `"${index}"`,
- },
- });
- }
-
- function resolveIndexPatternLoading() {
- const {
- loaded: loadedIndexPattern,
- stateVal,
- stateValFound,
- } = $route.current.locals.savedObjects.ip;
-
- const ownIndexPattern = $scope.searchSource.getOwnField('index');
-
- if (ownIndexPattern && !stateVal) {
- return ownIndexPattern;
- }
-
- if (stateVal && !stateValFound) {
- const warningTitle = getIndexPatternWarning();
-
- if (ownIndexPattern) {
- toastNotifications.addWarning({
- title: warningTitle,
- text: i18n.translate('discover.showingSavedIndexPatternWarningDescription', {
- defaultMessage:
- 'Showing the saved index pattern: "{ownIndexPatternTitle}" ({ownIndexPatternId})',
- values: {
- ownIndexPatternTitle: ownIndexPattern.title,
- ownIndexPatternId: ownIndexPattern.id,
- },
- }),
- });
- return ownIndexPattern;
- }
-
- toastNotifications.addWarning({
- title: warningTitle,
- text: i18n.translate('discover.showingDefaultIndexPatternWarningDescription', {
- defaultMessage:
- 'Showing the default index pattern: "{loadedIndexPatternTitle}" ({loadedIndexPatternId})',
- values: {
- loadedIndexPatternTitle: loadedIndexPattern.title,
- loadedIndexPatternId: loadedIndexPattern.id,
- },
- }),
- });
- }
-
- return loadedIndexPattern;
- }
-
- addHelpMenuToAppChrome(chrome);
-
- init();
- // Propagate current app state to url, then start syncing
- replaceUrlAppState().then(() => startStateSync());
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/discover_legacy.html b/src/plugins/discover_legacy/public/application/angular/discover_legacy.html
deleted file mode 100644
index 8582f71c0cb8..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/discover_legacy.html
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
diff --git a/src/plugins/discover_legacy/public/application/angular/discover_state.test.ts b/src/plugins/discover_legacy/public/application/angular/discover_state.test.ts
deleted file mode 100644
index 96225d4a2a53..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/discover_state.test.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getState, GetStateReturn } from './discover_state';
-import { createBrowserHistory, History } from 'history';
-
-let history: History;
-let state: GetStateReturn;
-const getCurrentUrl = () => history.createHref(history.location);
-
-describe('Test discover state', () => {
- beforeEach(async () => {
- history = createBrowserHistory();
- history.push('/');
- state = getState({
- defaultAppState: { index: 'test' },
- history,
- });
- await state.replaceUrlAppState({});
- await state.startSync();
- });
- afterEach(() => {
- state.stopSync();
- });
- test('setting app state and syncing to URL', async () => {
- state.setAppState({ index: 'modified' });
- state.flushToUrl();
- expect(getCurrentUrl()).toMatchInlineSnapshot(`"/#?_a=(index:modified)"`);
- });
-
- test('changing URL to be propagated to appState', async () => {
- history.push('/#?_a=(index:modified)');
- expect(state.appStateContainer.getState()).toMatchInlineSnapshot(`
- Object {
- "index": "modified",
- }
- `);
- });
- test('URL navigation to url without _a, state should not change', async () => {
- history.push('/#?_a=(index:modified)');
- history.push('/');
- expect(state.appStateContainer.getState()).toMatchInlineSnapshot(`
- Object {
- "index": "modified",
- }
- `);
- });
-
- test('isAppStateDirty returns whether the current state has changed', async () => {
- state.setAppState({ index: 'modified' });
- expect(state.isAppStateDirty()).toBeTruthy();
- state.resetInitialAppState();
- expect(state.isAppStateDirty()).toBeFalsy();
- });
-
- test('getPreviousAppState returns the state before the current', async () => {
- state.setAppState({ index: 'first' });
- const stateA = state.appStateContainer.getState();
- state.setAppState({ index: 'second' });
- expect(state.getPreviousAppState()).toEqual(stateA);
- });
-});
-
-describe('Test discover state with legacy migration', () => {
- test('migration of legacy query ', async () => {
- history = createBrowserHistory();
- history.push(
- "/#?_a=(query:(query_string:(analyze_wildcard:!t,query:'type:nice%20name:%22yeah%22')))"
- );
- state = getState({
- defaultAppState: { index: 'test' },
- history,
- });
- expect(state.appStateContainer.getState()).toMatchInlineSnapshot(`
- Object {
- "index": "test",
- "query": Object {
- "language": "lucene",
- "query": Object {
- "query_string": Object {
- "analyze_wildcard": true,
- "query": "type:nice name:\\"yeah\\"",
- },
- },
- },
- }
- `);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/discover_state.ts b/src/plugins/discover_legacy/public/application/angular/discover_state.ts
deleted file mode 100644
index 0570b64d24d9..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/discover_state.ts
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { isEqual } from 'lodash';
-import { History } from 'history';
-import { NotificationsStart } from 'opensearch-dashboards/public';
-import {
- createStateContainer,
- createOsdUrlStateStorage,
- syncState,
- ReduxLikeStateContainer,
- IOsdUrlStateStorage,
- withNotifyOnErrors,
-} from '../../../../opensearch_dashboards_utils/public';
-import { opensearchFilters, Filter, Query } from '../../../../data/public';
-import { migrateLegacyQuery } from '../helpers/migrate_legacy_query';
-
-export interface AppState {
- /**
- * Columns displayed in the table
- */
- columns?: string[];
- /**
- * Array of applied filters
- */
- filters?: Filter[];
- /**
- * id of the used index pattern
- */
- index?: string;
- /**
- * Used interval of the histogram
- */
- interval?: string;
- /**
- * Lucence or DQL query
- */
- query?: Query;
- /**
- * Array of the used sorting [[field,direction],...]
- */
- sort?: string[][];
- /**
- * id of the used saved query
- */
- savedQuery?: string;
-}
-
-interface GetStateParams {
- /**
- * Default state used for merging with with URL state to get the initial state
- */
- defaultAppState?: AppState;
- /**
- * Determins the use of long vs. short/hashed urls
- */
- storeInSessionStorage?: boolean;
- /**
- * Browser history
- */
- history: History;
-
- /**
- * Core's notifications.toasts service
- * In case it is passed in,
- * osdUrlStateStorage will use it notifying about inner errors
- */
- toasts?: NotificationsStart['toasts'];
-}
-
-export interface GetStateReturn {
- /**
- * osdUrlStateStorage
- */
- osdUrlStateStorage: IOsdUrlStateStorage;
- /**
- * App state, the _a part of the URL
- */
- appStateContainer: ReduxLikeStateContainer;
- /**
- * Start sync between state and URL
- */
- startSync: () => void;
- /**
- * Stop sync between state and URL
- */
- stopSync: () => void;
- /**
- * Set app state to with a partial new app state
- */
- setAppState: (newState: Partial) => void;
- /**
- * Set state in Url using history.replace
- */
- replaceUrlAppState: (newState: Partial) => Promise;
- /**
- * Sync state to URL, used for testing
- */
- flushToUrl: () => void;
- /**
- * Reset initial state to the current app state
- */
- resetInitialAppState: () => void;
- /**
- * Return the Appstate before the current app state, useful for diffing changes
- */
- getPreviousAppState: () => AppState;
- /**
- * Returns whether the current app state is different to the initial state
- */
- isAppStateDirty: () => void;
-}
-const APP_STATE_URL_KEY = '_a';
-
-/**
- * Builds and returns appState and globalState containers and helper functions
- * Used to sync URL with UI state
- */
-export function getState({
- defaultAppState = {},
- storeInSessionStorage = false,
- history,
- toasts,
-}: GetStateParams): GetStateReturn {
- const stateStorage = createOsdUrlStateStorage({
- useHash: storeInSessionStorage,
- history,
- ...(toasts && withNotifyOnErrors(toasts)),
- });
-
- const appStateFromUrl = stateStorage.get(APP_STATE_URL_KEY) as AppState;
-
- if (appStateFromUrl && appStateFromUrl.query && !appStateFromUrl.query.language) {
- appStateFromUrl.query = migrateLegacyQuery(appStateFromUrl.query);
- }
-
- let initialAppState = {
- ...defaultAppState,
- ...appStateFromUrl,
- };
- let previousAppState: AppState;
- const appStateContainer = createStateContainer(initialAppState);
-
- const appStateContainerModified = {
- ...appStateContainer,
- set: (value: AppState | null) => {
- if (value) {
- previousAppState = appStateContainer.getState();
- appStateContainer.set(value);
- }
- },
- };
-
- const { start, stop } = syncState({
- storageKey: APP_STATE_URL_KEY,
- stateContainer: appStateContainerModified,
- stateStorage,
- });
-
- return {
- osdUrlStateStorage: stateStorage,
- appStateContainer: appStateContainerModified,
- startSync: start,
- stopSync: stop,
- setAppState: (newPartial: AppState) => setState(appStateContainerModified, newPartial),
- replaceUrlAppState: async (newPartial: AppState = {}) => {
- const state = { ...appStateContainer.getState(), ...newPartial };
- await stateStorage.set(APP_STATE_URL_KEY, state, { replace: true });
- },
- resetInitialAppState: () => {
- initialAppState = appStateContainer.getState();
- },
- getPreviousAppState: () => previousAppState,
- flushToUrl: () => stateStorage.flush(),
- isAppStateDirty: () => !isEqualState(initialAppState, appStateContainer.getState()),
- };
-}
-
-/**
- * Helper function to merge a given new state with the existing state and to set the given state
- * container
- */
-export function setState(stateContainer: ReduxLikeStateContainer, newState: AppState) {
- const oldState = stateContainer.getState();
- const mergedState = { ...oldState, ...newState };
- if (!isEqualState(oldState, mergedState)) {
- stateContainer.set(mergedState);
- }
-}
-
-/**
- * Helper function to compare 2 different filter states
- */
-export function isEqualFilters(filtersA: Filter[], filtersB: Filter[]) {
- if (!filtersA && !filtersB) {
- return true;
- } else if (!filtersA || !filtersB) {
- return false;
- }
- return opensearchFilters.compareFilters(
- filtersA,
- filtersB,
- opensearchFilters.COMPARE_ALL_OPTIONS
- );
-}
-
-/**
- * helper function to extract filters of the given state
- * returns a state object without filters and an array of filters
- */
-export function splitState(state: AppState = {}) {
- const { filters = [], ...statePartial } = state;
- return { filters, state: statePartial };
-}
-
-/**
- * Helper function to compare 2 different state, is needed since comparing filters
- * works differently
- */
-export function isEqualState(stateA: AppState, stateB: AppState) {
- if (!stateA && !stateB) {
- return true;
- } else if (!stateA || !stateB) {
- return false;
- }
- const { filters: stateAFilters = [], ...stateAPartial } = stateA;
- const { filters: stateBFilters = [], ...stateBPartial } = stateB;
- return isEqual(stateAPartial, stateBPartial) && isEqualFilters(stateAFilters, stateBFilters);
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc.html b/src/plugins/discover_legacy/public/application/angular/doc.html
deleted file mode 100644
index dcd5760eff15..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
diff --git a/src/plugins/discover_legacy/public/application/angular/doc.ts b/src/plugins/discover_legacy/public/application/angular/doc.ts
deleted file mode 100644
index 584815be9342..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getAngularModule, getServices } from '../../opensearch_dashboards_services';
-// @ts-ignore
-import { getRootBreadcrumbs } from '../helpers/breadcrumbs';
-import html from './doc.html';
-import { Doc } from '../components/doc/doc';
-
-interface LazyScope extends ng.IScope {
- [key: string]: any;
-}
-
-const { timefilter } = getServices();
-const app = getAngularModule();
-app.directive('discoverDoc', function (reactDirective: any) {
- return reactDirective(
- Doc,
- [
- ['id', { watchDepth: 'value' }],
- ['index', { watchDepth: 'value' }],
- ['indexPatternId', { watchDepth: 'reference' }],
- ['indexPatternService', { watchDepth: 'reference' }],
- ],
- { restrict: 'E' }
- );
-});
-
-app.config(($routeProvider: any) => {
- $routeProvider
- .when('/doc/:indexPattern/:index/:type', {
- redirectTo: '/doc/:indexPattern/:index',
- })
- // the new route, opensearch 7 deprecated types, opensearch 8 removed them
- .when('/doc/:indexPattern/:index', {
- // have to be written as function expression, because it's not compiled in dev mode
- // eslint-disable-next-line object-shorthand
- controller: function ($scope: LazyScope, $route: any) {
- timefilter.disableAutoRefreshSelector();
- timefilter.disableTimeRangeSelector();
- $scope.id = $route.current.params.id;
- $scope.index = $route.current.params.index;
- $scope.indexPatternId = $route.current.params.indexPattern;
- $scope.indexPatternService = getServices().indexPatterns;
- },
- template: html,
- k7Breadcrumbs: ($route: any) => [
- ...getRootBreadcrumbs(),
- {
- text: `${$route.current.params.index}#${$route.current.params.id}`,
- },
- ],
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/_doc_table.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/_doc_table.scss
deleted file mode 100644
index bc75d4171004..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/_doc_table.scss
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * 1. Stack content vertically so the table can scroll when its constrained by a fixed container height.
- */
-doc-table {
- @include euiScrollBar;
-
- overflow: auto;
- flex: 1 1 100%;
- flex-direction: column; /* 1 */
-
- th {
- text-align: left;
- font-weight: bold;
- }
-
- .spinner {
- position: absolute;
- top: 40%;
- left: 0;
- right: 0;
- z-index: $euiZLevel1;
- opacity: 0.5;
- }
-}
-
-.osdDocTable__container.loading {
- opacity: 0.5;
-}
-
-.osdDocTable {
- font-size: $euiFontSizeXS;
-
- th {
- white-space: nowrap;
- padding-right: $euiSizeS;
-
- .fa {
- font-size: 1.1em;
- }
- }
-}
-
-.osd-table,
-.osdDocTable {
- /**
- * Style OpenSearch document _source in table view key:value
- * Use alpha so this will stand out against non-white backgrounds, e.g. the highlighted
- * row in the Context Log.
- */
-
- dl.source {
- margin-bottom: 0;
- line-height: 2em;
- word-break: break-word;
-
- dt,
- dd {
- display: inline;
- }
-
- dt {
- background-color: tintOrShade($euiColorPrimary, 90%, 70%);
- color: $euiTextColor;
- padding: ($euiSizeXS / 2) $euiSizeXS;
- margin-right: $euiSizeXS;
- word-break: normal;
- border-radius: $euiBorderRadius;
- }
- }
-}
-
-.osdDocTable__row {
- td {
- position: relative;
-
- &:hover {
- .osdDocTableRowFilterButton {
- opacity: 1;
- }
- }
- }
-}
-
-.osdDocTable__row--highlight {
- td,
- .osdDocTableRowFilterButton {
- background-color: tintOrShade($euiColorPrimary, 90%, 70%);
- }
-}
-
-.osdDocTable__bar {
- margin: $euiSizeXS $euiSizeXS 0;
-}
-
-.osdDocTable__bar--footer {
- position: relative;
- margin: -($euiSize * 3) $euiSizeXS 0;
-}
-
-.osdDocTable__padBottom {
- padding-bottom: $euiSizeXL;
-}
-
-.osdDocTable__error {
- display: flex;
- flex-direction: column;
- justify-content: center;
- flex: 1 0 100%;
- text-align: center;
-}
-
-.truncate-by-height {
- overflow: hidden;
-}
-
-.table {
- // Nesting
- .table {
- background-color: $euiColorEmptyShade;
- }
-}
-
-.osd-table {
- // sub tables should not have a leading border
- .table .table {
- margin-bottom: 0;
-
- tr:first-child > td {
- border-top: none;
- }
-
- td.field-name {
- font-weight: $euiFontWeightBold;
- }
- }
-}
-
-table {
- th {
- i.fa-sort {
- color: $euiColorLightShade;
- }
-
- button.fa-sort-asc,
- button.fa-sort-down,
- i.fa-sort-asc,
- i.fa-sort-down {
- color: $euiColorPrimary;
- }
-
- button.fa-sort-desc,
- button.fa-sort-up,
- i.fa-sort-desc,
- i.fa-sort-up {
- color: $euiColorPrimary;
- }
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/actions/columns.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/actions/columns.ts
deleted file mode 100644
index 877ee7db8f55..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/actions/columns.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Helper function to provide a fallback to a single _source column if the given array of columns
- * is empty, and removes _source if there are more than 1 columns given
- * @param columns
- */
-function buildColumns(columns: string[]) {
- if (columns.length > 1 && columns.indexOf('_source') !== -1) {
- return columns.filter((col) => col !== '_source');
- } else if (columns.length !== 0) {
- return columns;
- }
- return ['_source'];
-}
-
-export function addColumn(columns: string[], columnName: string) {
- if (columns.includes(columnName)) {
- return columns;
- }
- return buildColumns([...columns, columnName]);
-}
-
-export function removeColumn(columns: string[], columnName: string) {
- if (!columns.includes(columnName)) {
- return columns;
- }
- return buildColumns(columns.filter((col) => col !== columnName));
-}
-
-export function moveColumn(columns: string[], columnName: string, newIndex: number) {
- if (newIndex < 0 || newIndex >= columns.length || !columns.includes(columnName)) {
- return columns;
- }
- const modifiedColumns = [...columns];
- modifiedColumns.splice(modifiedColumns.indexOf(columnName), 1); // remove at old index
- modifiedColumns.splice(newIndex, 0, columnName); // insert before new index
- return modifiedColumns;
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/_index.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/_index.scss
deleted file mode 100644
index 25065a969b9b..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/_index.scss
+++ /dev/null
@@ -1,2 +0,0 @@
-@import "table_header";
-@import "table_row/index";
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/_table_header.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/_table_header.scss
deleted file mode 100644
index 7b4c14f6a856..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/_table_header.scss
+++ /dev/null
@@ -1,17 +0,0 @@
-.osdDocTableHeader {
- white-space: nowrap;
-}
-
-.osdDocTableHeader button {
- margin-left: $euiSizeXS;
-}
-
-.osdDocTableHeader__move,
-.osdDocTableHeader__sortChange {
- opacity: 0;
-
- &:focus,
- th:hover & {
- opacity: 1;
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap
deleted file mode 100644
index 20e503fd5ff9..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap
+++ /dev/null
@@ -1,30 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`it renders ToolBarPagerButtons 1`] = `
-
-
-
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap
deleted file mode 100644
index fe168c013cb1..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap
+++ /dev/null
@@ -1,10 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`it renders ToolBarPagerText without crashing 1`] = `
-
- 1–2 of 3
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/index.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/index.ts
deleted file mode 100644
index a0f5278d7881..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/index.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { ToolBarPagerText } from './tool_bar_pager_text';
-import { ToolBarPagerButtons } from './tool_bar_pager_buttons';
-
-export function createToolBarPagerTextDirective(reactDirective: any) {
- return reactDirective(ToolBarPagerText);
-}
-
-export function createToolBarPagerButtonsDirective(reactDirective: any) {
- return reactDirective(ToolBarPagerButtons);
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx
deleted file mode 100644
index 2ac06b2b6ebf..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
-import { ToolBarPagerButtons } from './tool_bar_pager_buttons';
-import { findTestSubject } from 'test_utils/helpers';
-
-test('it renders ToolBarPagerButtons', () => {
- const props = {
- hasPreviousPage: true,
- hasNextPage: true,
- onPageNext: jest.fn(),
- onPagePrevious: jest.fn(),
- };
- const wrapper = shallowWithIntl();
- expect(wrapper).toMatchSnapshot();
-});
-
-test('it renders ToolBarPagerButtons with clickable next and previous button', () => {
- const props = {
- hasPreviousPage: true,
- hasNextPage: true,
- onPageNext: jest.fn(),
- onPagePrevious: jest.fn(),
- };
- const wrapper = mountWithIntl();
- findTestSubject(wrapper, 'btnPrevPage').simulate('click');
- expect(props.onPagePrevious).toHaveBeenCalledTimes(1);
- findTestSubject(wrapper, 'btnNextPage').simulate('click');
- expect(props.onPageNext).toHaveBeenCalledTimes(1);
-});
-
-test('it renders ToolBarPagerButtons with disabled next and previous button', () => {
- const props = {
- hasPreviousPage: false,
- hasNextPage: false,
- onPageNext: jest.fn(),
- onPagePrevious: jest.fn(),
- };
- const wrapper = mountWithIntl();
- findTestSubject(wrapper, 'btnPrevPage').simulate('click');
- expect(props.onPagePrevious).toHaveBeenCalledTimes(0);
- findTestSubject(wrapper, 'btnNextPage').simulate('click');
- expect(props.onPageNext).toHaveBeenCalledTimes(0);
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx
deleted file mode 100644
index 04956583291c..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { i18n } from '@osd/i18n';
-
-interface Props {
- hasPreviousPage: boolean;
- hasNextPage: boolean;
- onPageNext: () => void;
- onPagePrevious: () => void;
-}
-
-export function ToolBarPagerButtons(props: Props) {
- return (
-
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx
deleted file mode 100644
index 4b13de634f04..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { renderWithIntl } from 'test_utils/enzyme_helpers';
-import { ToolBarPagerText } from './tool_bar_pager_text';
-
-test('it renders ToolBarPagerText without crashing', () => {
- const props = {
- startItem: 1,
- endItem: 2,
- totalItems: 3,
- };
- const wrapper = renderWithIntl();
- expect(wrapper).toMatchSnapshot();
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.tsx
deleted file mode 100644
index 28110891a2f9..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/pager/tool_bar_pager_text.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-
-interface Props {
- startItem: number;
- endItem: number;
- totalItems: number;
-}
-
-export function ToolBarPagerText({ startItem, endItem, totalItems }: Props) {
- return (
-
-
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/row_headers.test.js b/src/plugins/discover_legacy/public/application/angular/doc_table/components/row_headers.test.js
deleted file mode 100644
index 1b0e03653d0d..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/row_headers.test.js
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import angular from 'angular';
-import 'angular-mocks';
-import 'angular-sanitize';
-import 'angular-route';
-import _ from 'lodash';
-import sinon from 'sinon';
-import { getFakeRow } from 'fixtures/fake_row';
-import $ from 'jquery';
-import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
-import {
- setScopedHistory,
- setServices,
- setDocViewsRegistry,
- setDocViewsLinksRegistry,
-} from '../../../../opensearch_dashboards_services';
-import { coreMock } from '../../../../../../../core/public/mocks';
-import { dataPluginMock } from '../../../../../../data/public/mocks';
-import { navigationPluginMock } from '../../../../../../navigation/public/mocks';
-import { getInnerAngularModule } from '../../../../get_inner_angular';
-import { createBrowserHistory } from 'history';
-
-const fakeRowVals = {
- time: 'time_formatted',
- bytes: 'bytes_formatted',
- '@timestamp': '@timestamp_formatted',
- request_body: 'request_body_formatted',
-};
-
-describe('Doc Table', () => {
- const core = coreMock.createStart();
- const dataMock = dataPluginMock.createStartContract();
- let $parentScope;
- let $scope;
- let $elementScope;
- let timeout;
- let registry = [];
-
- // Stub out a minimal mapping of 4 fields
- let mapping;
-
- beforeAll(() => setScopedHistory(createBrowserHistory()));
- beforeEach(() => {
- angular.element.prototype.slice = jest.fn(function (index) {
- return $(this).slice(index);
- });
- angular.element.prototype.filter = jest.fn(function (condition) {
- return $(this).filter(condition);
- });
- angular.element.prototype.toggle = jest.fn(function (name) {
- return $(this).toggle(name);
- });
- angular.element.prototype.is = jest.fn(function (name) {
- return $(this).is(name);
- });
- setServices({
- uiSettings: core.uiSettings,
- filterManager: dataMock.query.filterManager,
- });
-
- setDocViewsRegistry({
- addDocView(view) {
- registry.push(view);
- },
- getDocViewsSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- });
-
- setDocViewsLinksRegistry({
- addDocViewLink(view) {
- registry.push(view);
- },
- getDocViewsLinksSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- });
-
- getInnerAngularModule(
- 'app/discover',
- core,
- {
- data: dataMock,
- navigation: navigationPluginMock.createStartContract(),
- },
- coreMock.createPluginInitializerContext()
- );
- angular.mock.module('app/discover');
- });
- beforeEach(
- angular.mock.inject(function ($rootScope, Private, $timeout) {
- $parentScope = $rootScope;
- timeout = $timeout;
- $parentScope.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
- mapping = $parentScope.indexPattern.fields;
-
- // Stub `getConverterFor` for a field in the indexPattern to return mock data.
-
- const convertFn = (value, type, options) => {
- const fieldName = _.get(options, 'field.name', null);
- return fakeRowVals[fieldName] || '';
- };
- $parentScope.indexPattern.getFormatterForField = () => ({
- convert: convertFn,
- getConverterFor: () => convertFn,
- });
- })
- );
-
- afterEach(() => {
- delete angular.element.prototype.slice;
- delete angular.element.prototype.filter;
- delete angular.element.prototype.toggle;
- delete angular.element.prototype.is;
- });
-
- // Sets up the directive, take an element, and a list of properties to attach to the parent scope.
- const init = function ($elem, props) {
- angular.mock.inject(function ($compile) {
- _.assign($parentScope, props);
- const el = $compile($elem)($parentScope);
- $elementScope = el.scope();
- el.scope().$digest();
- $scope = el.isolateScope();
- });
- };
-
- const destroy = () => {
- $scope.$destroy();
- $parentScope.$destroy();
- };
-
- // For testing column removing/adding for the header and the rows
- const columnTests = function (elemType, parentElem) {
- test('should create a time column if the timefield is defined', () => {
- const childElems = parentElem.find(elemType);
- expect(childElems.length).toBe(1);
- });
-
- test('should be able to add and remove columns', () => {
- let childElems;
-
- // Should include a column for toggling and the time column by default
- $parentScope.columns = ['bytes'];
- $elementScope.$digest();
- childElems = parentElem.find(elemType);
- expect(childElems.length).toBe(2);
- expect($(childElems[1]).text()).toContain('bytes');
-
- $parentScope.columns = ['bytes', 'request_body'];
- $elementScope.$digest();
- childElems = parentElem.find(elemType);
- expect(childElems.length).toBe(3);
- expect($(childElems[2]).text()).toContain('request_body');
-
- $parentScope.columns = ['request_body'];
- $elementScope.$digest();
- childElems = parentElem.find(elemType);
- expect(childElems.length).toBe(2);
- expect($(childElems[1]).text()).toContain('request_body');
- });
-
- test('should create only the toggle column if there is no timeField', () => {
- delete $scope.indexPattern.timeFieldName;
- $scope.$digest();
- timeout.flush();
-
- const childElems = parentElem.find(elemType);
- expect(childElems.length).toBe(0);
- });
- };
-
- describe('osdTableRow', () => {
- const $elem = $(
- '
'
- );
- let row;
-
- beforeEach(() => {
- row = getFakeRow(0, mapping);
-
- init($elem, {
- row,
- columns: [],
- sorting: [],
- filter: sinon.spy(),
- maxLength: 50,
- });
- });
- afterEach(() => {
- destroy();
- });
-
- describe('adding and removing columns', () => {
- columnTests('[data-test-subj~="docTableField"]', $elem);
- });
-
- describe('details row', () => {
- test('should be an empty tr by default', () => {
- expect($elem.next().is('tr')).toBe(true);
- expect($elem.next().text()).toBe('');
- });
-
- test('should expand the detail row when the toggle arrow is clicked', () => {
- $elem.children(':first-child').click();
- expect($elem.next().text()).not.toBe('');
- });
-
- describe('expanded', () => {
- let $details;
- beforeEach(() => {
- // Open the row
- $scope.toggleRow();
- timeout.flush();
- $details = $elem.next();
- });
- afterEach(() => {
- // Close the row
- $scope.toggleRow();
- });
-
- test('should be a tr with something in it', () => {
- expect($details.is('tr')).toBe(true);
- expect($details.text()).toBeTruthy();
- });
- });
- });
- });
-
- describe('osdTableRow meta', () => {
- const $elem = angular.element(
- '
'
- );
- let row;
-
- beforeEach(() => {
- row = getFakeRow(0, mapping);
-
- init($elem, {
- row: row,
- columns: [],
- sorting: [],
- filtering: sinon.spy(),
- maxLength: 50,
- });
-
- // Open the row
- $scope.toggleRow();
- $scope.$digest();
- timeout.flush();
- $elem.next();
- });
-
- afterEach(() => {
- destroy();
- });
-
- /** this no longer works with the new plugin approach
- test('should render even when the row source contains a field with the same name as a meta field', () => {
- setTimeout(() => {
- //this should be overridden by later changes
- }, 100);
- expect($details.find('tr').length).toBe(_.keys($parentScope.indexPattern.flattenHit($scope.row)).length);
- }); */
- });
-
- describe('row diffing', () => {
- let $row;
- let $scope;
- let $root;
- let $before;
-
- beforeEach(
- angular.mock.inject(function ($rootScope, $compile, Private) {
- $root = $rootScope;
- $root.row = getFakeRow(0, mapping);
- $root.columns = ['_source'];
- $root.sorting = [];
- $root.filtering = sinon.spy();
- $root.maxLength = 50;
- $root.mapping = mapping;
- $root.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
-
- $row = $('').attr({
- 'osd-table-row': 'row',
- columns: 'columns',
- sorting: 'sorting',
- filtering: 'filtering',
- 'index-pattern': 'indexPattern',
- });
-
- $scope = $root.$new();
- $compile($row)($scope);
- $root.$apply();
-
- $before = $row.find('td');
- expect($before).toHaveLength(3);
- expect($before.eq(0).text().trim()).toBe('');
- expect($before.eq(1).text().trim()).toMatch(/^time_formatted/);
- })
- );
-
- afterEach(() => {
- $row.remove();
- });
-
- test('handles a new column', () => {
- $root.columns.push('bytes');
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(4);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after[2].outerHTML).toBe($before[2].outerHTML);
- expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/);
- });
-
- test('handles two new columns at once', () => {
- $root.columns.push('bytes');
- $root.columns.push('request_body');
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(5);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after[2].outerHTML).toBe($before[2].outerHTML);
- expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/);
- expect($after.eq(4).text().trim()).toMatch(/^request_body_formatted/);
- });
-
- test('handles three new columns in odd places', () => {
- $root.columns = ['@timestamp', 'bytes', '_source', 'request_body'];
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(6);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after.eq(2).text().trim()).toMatch(/^@timestamp_formatted/);
- expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/);
- expect($after[4].outerHTML).toBe($before[2].outerHTML);
- expect($after.eq(5).text().trim()).toMatch(/^request_body_formatted/);
- });
-
- test('handles a removed column', () => {
- _.pull($root.columns, '_source');
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(2);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- });
-
- test('handles two removed columns', () => {
- // first add a column
- $root.columns.push('@timestamp');
- $root.$apply();
-
- const $mid = $row.find('td');
- expect($mid).toHaveLength(4);
-
- $root.columns.pop();
- $root.columns.pop();
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(2);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- });
-
- test('handles three removed random columns', () => {
- // first add two column
- $root.columns.push('@timestamp', 'bytes');
- $root.$apply();
-
- const $mid = $row.find('td');
- expect($mid).toHaveLength(5);
-
- $root.columns[0] = false; // _source
- $root.columns[2] = false; // bytes
- $root.columns = $root.columns.filter(Boolean);
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(3);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after.eq(2).text().trim()).toMatch(/^@timestamp_formatted/);
- });
-
- test('handles two columns with the same content', () => {
- const tempVal = fakeRowVals.request_body;
- fakeRowVals.request_body = 'bytes_formatted';
-
- $root.columns.length = 0;
- $root.columns.push('bytes');
- $root.columns.push('request_body');
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(4);
- expect($after.eq(2).text().trim()).toMatch(/^bytes_formatted/);
- expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/);
- fakeRowVals.request_body = tempVal;
- });
-
- test('handles two columns swapping position', () => {
- $root.columns.push('bytes');
- $root.$apply();
-
- const $mid = $row.find('td');
- expect($mid).toHaveLength(4);
-
- $root.columns.reverse();
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(4);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after[2].outerHTML).toBe($mid[3].outerHTML);
- expect($after[3].outerHTML).toBe($mid[2].outerHTML);
- });
-
- test('handles four columns all reversing position', () => {
- $root.columns.push('bytes', 'response', '@timestamp');
- $root.$apply();
-
- const $mid = $row.find('td');
- expect($mid).toHaveLength(6);
-
- $root.columns.reverse();
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(6);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after[2].outerHTML).toBe($mid[5].outerHTML);
- expect($after[3].outerHTML).toBe($mid[4].outerHTML);
- expect($after[4].outerHTML).toBe($mid[3].outerHTML);
- expect($after[5].outerHTML).toBe($mid[2].outerHTML);
- });
-
- test('handles multiple columns with the same name', () => {
- $root.columns.push('bytes', 'bytes', 'bytes');
- $root.$apply();
-
- const $after = $row.find('td');
- expect($after).toHaveLength(6);
- expect($after[0].outerHTML).toBe($before[0].outerHTML);
- expect($after[1].outerHTML).toBe($before[1].outerHTML);
- expect($after[2].outerHTML).toBe($before[2].outerHTML);
- expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/);
- expect($after.eq(4).text().trim()).toMatch(/^bytes_formatted/);
- expect($after.eq(5).text().trim()).toMatch(/^bytes_formatted/);
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header.ts
deleted file mode 100644
index 1c60685d279e..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { TableHeader } from './table_header/table_header';
-import { getServices } from '../../../../opensearch_dashboards_services';
-import { SORT_DEFAULT_ORDER_SETTING, DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../../common';
-import { UI_SETTINGS } from '../../../../../../data/public';
-
-export function createTableHeaderDirective(reactDirective: any) {
- const { uiSettings: config } = getServices();
-
- return reactDirective(
- TableHeader,
- [
- ['columns', { watchDepth: 'collection' }],
- ['hideTimeColumn', { watchDepth: 'value' }],
- ['indexPattern', { watchDepth: 'reference' }],
- ['isShortDots', { watchDepth: 'value' }],
- ['onChangeSortOrder', { watchDepth: 'reference' }],
- ['onMoveColumn', { watchDepth: 'reference' }],
- ['onRemoveColumn', { watchDepth: 'reference' }],
- ['sortOrder', { watchDepth: 'collection' }],
- ],
- { restrict: 'A' },
- {
- hideTimeColumn: config.get(DOC_HIDE_TIME_COLUMN_SETTING, false),
- isShortDots: config.get(UI_SETTINGS.SHORT_DOTS_ENABLE),
- defaultSortOrder: config.get(SORT_DEFAULT_ORDER_SETTING, 'desc'),
- }
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap
deleted file mode 100644
index 2aeb8951a60a..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap
+++ /dev/null
@@ -1,221 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`TableHeader with time column renders correctly 1`] = `
-
-`;
-
-exports[`TableHeader without time column renders correctly 1`] = `
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/helpers.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/helpers.tsx
deleted file mode 100644
index 477b72f5b199..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/helpers.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPattern } from '../../../../../opensearch_dashboards_services';
-import { shortenDottedString } from '../../../../helpers';
-
-export type SortOrder = [string, string];
-export interface ColumnProps {
- name: string;
- displayName: string;
- isSortable: boolean;
- isRemoveable: boolean;
- colLeftIdx: number;
- colRightIdx: number;
-}
-
-/**
- * Returns properties necessary to display the time column
- * If it's an IndexPattern with timefield, the time column is
- * prepended, not moveable and removeable
- * @param timeFieldName
- */
-export function getTimeColumn(timeFieldName: string): ColumnProps {
- return {
- name: timeFieldName,
- displayName: 'Time',
- isSortable: true,
- isRemoveable: false,
- colLeftIdx: -1,
- colRightIdx: -1,
- };
-}
-/**
- * A given array of column names returns an array of properties
- * necessary to display the columns. If the given indexPattern
- * has a timefield, a time column is prepended
- * @param columns
- * @param indexPattern
- * @param hideTimeField
- * @param isShortDots
- */
-export function getDisplayedColumns(
- columns: string[],
- indexPattern: IndexPattern,
- hideTimeField: boolean,
- isShortDots: boolean
-) {
- if (!Array.isArray(columns) || typeof indexPattern !== 'object' || !indexPattern.getFieldByName) {
- return [];
- }
- const columnProps = columns.map((column, idx) => {
- const field = indexPattern.getFieldByName(column);
- return {
- name: column,
- displayName: isShortDots ? shortenDottedString(column) : column,
- isSortable: field && field.sortable ? true : false,
- isRemoveable: column !== '_source' || columns.length > 1,
- colLeftIdx: idx - 1 < 0 ? -1 : idx - 1,
- colRightIdx: idx + 1 >= columns.length ? -1 : idx + 1,
- };
- });
- return !hideTimeField && indexPattern.timeFieldName
- ? [getTimeColumn(indexPattern.timeFieldName), ...columnProps]
- : columnProps;
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.test.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.test.tsx
deleted file mode 100644
index 0e8efc18efd5..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.test.tsx
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { TableHeader } from './table_header';
-import { findTestSubject } from 'test_utils/helpers';
-import { SortOrder } from './helpers';
-import { IndexPattern, IFieldType } from '../../../../../opensearch_dashboards_services';
-
-function getMockIndexPattern() {
- return ({
- id: 'test',
- title: 'Test',
- timeFieldName: 'time',
- fields: [],
- isTimeNanosBased: () => false,
- getFieldByName: (name: string) => {
- if (name === 'test1') {
- return {
- name,
- type: 'string',
- aggregatable: false,
- searchable: true,
- sortable: true,
- } as IFieldType;
- } else {
- return {
- name,
- type: 'string',
- aggregatable: false,
- searchable: true,
- sortable: false,
- } as IFieldType;
- }
- },
- } as unknown) as IndexPattern;
-}
-
-function getMockProps(props = {}) {
- const defaultProps = {
- indexPattern: getMockIndexPattern(),
- hideTimeColumn: false,
- columns: ['first', 'middle', 'last'],
- defaultSortOrder: 'desc',
- sortOrder: [['time', 'asc']] as SortOrder[],
- isShortDots: true,
- onRemoveColumn: jest.fn(),
- onChangeSortOrder: jest.fn(),
- onMoveColumn: jest.fn(),
- onPageNext: jest.fn(),
- onPagePrevious: jest.fn(),
- };
-
- return Object.assign({}, defaultProps, props);
-}
-
-describe('TableHeader with time column', () => {
- const props = getMockProps();
-
- const wrapper = mountWithIntl(
-
- );
-
- test('renders correctly', () => {
- const docTableHeader = findTestSubject(wrapper, 'docTableHeader');
- expect(docTableHeader.getDOMNode()).toMatchSnapshot();
- });
-
- test('time column is sortable with button, cycling sort direction', () => {
- findTestSubject(wrapper, 'docTableHeaderFieldSort_time').simulate('click');
- expect(props.onChangeSortOrder).toHaveBeenCalledWith([['time', 'desc']]);
- });
-
- test('time column is not removeable, no button displayed', () => {
- const removeButton = findTestSubject(wrapper, 'docTableRemoveHeader-time');
- expect(removeButton.length).toBe(0);
- });
-
- test('time column is not moveable, no button displayed', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-time');
- expect(moveButtonLeft.length).toBe(0);
- const moveButtonRight = findTestSubject(wrapper, 'docTableMoveRightHeader-time');
- expect(moveButtonRight.length).toBe(0);
- });
-
- test('first column is removeable', () => {
- const removeButton = findTestSubject(wrapper, 'docTableRemoveHeader-first');
- expect(removeButton.length).toBe(1);
- removeButton.simulate('click');
- expect(props.onRemoveColumn).toHaveBeenCalledWith('first');
- });
-
- test('first column is not moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-first');
- expect(moveButtonLeft.length).toBe(0);
- });
-
- test('first column is moveable to the right', () => {
- const moveButtonRight = findTestSubject(wrapper, 'docTableMoveRightHeader-first');
- expect(moveButtonRight.length).toBe(1);
- moveButtonRight.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('first', 1);
- });
-
- test('middle column is moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-middle');
- expect(moveButtonLeft.length).toBe(1);
- moveButtonLeft.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('middle', 0);
- });
-
- test('middle column is moveable to the right', () => {
- const moveButtonRight = findTestSubject(wrapper, 'docTableMoveRightHeader-middle');
- expect(moveButtonRight.length).toBe(1);
- moveButtonRight.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('middle', 2);
- });
-
- test('last column moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-last');
- expect(moveButtonLeft.length).toBe(1);
- moveButtonLeft.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('last', 1);
- });
-});
-
-describe('TableHeader without time column', () => {
- const props = getMockProps({ hideTimeColumn: true });
-
- const wrapper = mountWithIntl(
-
- );
-
- test('renders correctly', () => {
- const docTableHeader = findTestSubject(wrapper, 'docTableHeader');
- expect(docTableHeader.getDOMNode()).toMatchSnapshot();
- });
-
- test('first column is removeable', () => {
- const removeButton = findTestSubject(wrapper, 'docTableRemoveHeader-first');
- expect(removeButton.length).toBe(1);
- removeButton.simulate('click');
- expect(props.onRemoveColumn).toHaveBeenCalledWith('first');
- });
-
- test('first column is not moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-first');
- expect(moveButtonLeft.length).toBe(0);
- });
-
- test('first column is moveable to the right', () => {
- const moveButtonRight = findTestSubject(wrapper, 'docTableMoveRightHeader-first');
- expect(moveButtonRight.length).toBe(1);
- moveButtonRight.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('first', 1);
- });
-
- test('middle column is moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-middle');
- expect(moveButtonLeft.length).toBe(1);
- moveButtonLeft.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('middle', 0);
- });
-
- test('middle column is moveable to the right', () => {
- const moveButtonRight = findTestSubject(wrapper, 'docTableMoveRightHeader-middle');
- expect(moveButtonRight.length).toBe(1);
- moveButtonRight.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('middle', 2);
- });
-
- test('last column moveable to the left', () => {
- const moveButtonLeft = findTestSubject(wrapper, 'docTableMoveLeftHeader-last');
- expect(moveButtonLeft.length).toBe(1);
- moveButtonLeft.simulate('click');
- expect(props.onMoveColumn).toHaveBeenCalledWith('last', 1);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.tsx
deleted file mode 100644
index 6a9efdac5273..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { IndexPattern } from '../../../../../opensearch_dashboards_services';
-// @ts-ignore
-import { TableHeaderColumn } from './table_header_column';
-import { SortOrder, getDisplayedColumns } from './helpers';
-import { getDefaultSort } from '../../lib/get_default_sort';
-
-interface Props {
- columns: string[];
- defaultSortOrder: string;
- hideTimeColumn: boolean;
- indexPattern: IndexPattern;
- isShortDots: boolean;
- onChangeSortOrder?: (sortOrder: SortOrder[]) => void;
- onMoveColumn?: (name: string, index: number) => void;
- onRemoveColumn?: (name: string) => void;
- sortOrder: SortOrder[];
-}
-
-export function TableHeader({
- columns,
- defaultSortOrder,
- hideTimeColumn,
- indexPattern,
- isShortDots,
- onChangeSortOrder,
- onMoveColumn,
- onRemoveColumn,
- sortOrder,
-}: Props) {
- const displayedColumns = getDisplayedColumns(columns, indexPattern, hideTimeColumn, isShortDots);
-
- return (
-
- |
- {displayedColumns.map((col) => {
- return (
-
- );
- })}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header_column.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header_column.tsx
deleted file mode 100644
index 81dad59c6d34..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_header/table_header_column.tsx
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { i18n } from '@osd/i18n';
-import { EuiToolTip } from '@elastic/eui';
-import { SortOrder } from './helpers';
-
-interface Props {
- colLeftIdx: number; // idx of the column to the left, -1 if moving is not possible
- colRightIdx: number; // idx of the column to the right, -1 if moving is not possible
- displayName: string;
- isRemoveable: boolean;
- isSortable: boolean;
- name: string;
- onChangeSortOrder?: (sortOrder: SortOrder[]) => void;
- onMoveColumn?: (name: string, idx: number) => void;
- onRemoveColumn?: (name: string) => void;
- sortOrder: SortOrder[];
-}
-
-const sortDirectionToIcon: Record = {
- desc: 'fa fa-sort-down',
- asc: 'fa fa-sort-up',
- '': 'fa fa-sort',
-};
-
-export function TableHeaderColumn({
- colLeftIdx,
- colRightIdx,
- displayName,
- isRemoveable,
- isSortable,
- name,
- onChangeSortOrder,
- onMoveColumn,
- onRemoveColumn,
- sortOrder,
-}: Props) {
- const [, sortDirection = ''] = sortOrder.find((sortPair) => name === sortPair[0]) || [];
- const currentSortWithoutColumn = sortOrder.filter((pair) => pair[0] !== name);
- const currentColumnSort = sortOrder.find((pair) => pair[0] === name);
- const currentColumnSortDirection = (currentColumnSort && currentColumnSort[1]) || '';
-
- const btnSortIcon = sortDirectionToIcon[sortDirection];
- const btnSortClassName =
- sortDirection !== '' ? btnSortIcon : `osdDocTableHeader__sortChange ${btnSortIcon}`;
-
- const handleChangeSortOrder = () => {
- if (!onChangeSortOrder) return;
-
- // Cycle goes Unsorted -> Asc -> Desc -> Unsorted
- if (currentColumnSort === undefined) {
- onChangeSortOrder([...currentSortWithoutColumn, [name, 'asc']]);
- } else if (currentColumnSortDirection === 'asc') {
- onChangeSortOrder([...currentSortWithoutColumn, [name, 'desc']]);
- } else if (currentColumnSortDirection === 'desc' && currentSortWithoutColumn.length === 0) {
- // If we're at the end of the cycle and this is the only existing sort, we switch
- // back to ascending sort instead of removing it.
- onChangeSortOrder([[name, 'asc']]);
- } else {
- onChangeSortOrder(currentSortWithoutColumn);
- }
- };
-
- const getSortButtonAriaLabel = () => {
- const sortAscendingMessage = i18n.translate(
- 'discover.docTable.tableHeader.sortByColumnAscendingAriaLabel',
- {
- defaultMessage: 'Sort {columnName} ascending',
- values: { columnName: name },
- }
- );
- const sortDescendingMessage = i18n.translate(
- 'discover.docTable.tableHeader.sortByColumnDescendingAriaLabel',
- {
- defaultMessage: 'Sort {columnName} descending',
- values: { columnName: name },
- }
- );
- const stopSortingMessage = i18n.translate(
- 'discover.docTable.tableHeader.sortByColumnUnsortedAriaLabel',
- {
- defaultMessage: 'Stop sorting on {columnName}',
- values: { columnName: name },
- }
- );
-
- if (currentColumnSort === undefined) {
- return sortAscendingMessage;
- } else if (sortDirection === 'asc') {
- return sortDescendingMessage;
- } else if (sortDirection === 'desc' && currentSortWithoutColumn.length === 0) {
- return sortAscendingMessage;
- } else {
- return stopSortingMessage;
- }
- };
-
- // action buttons displayed on the right side of the column name
- const buttons = [
- // Sort Button
- {
- active: isSortable && typeof onChangeSortOrder === 'function',
- ariaLabel: getSortButtonAriaLabel(),
- className: btnSortClassName,
- onClick: handleChangeSortOrder,
- testSubject: `docTableHeaderFieldSort_${name}`,
- tooltip: getSortButtonAriaLabel(),
- },
- // Remove Button
- {
- active: isRemoveable && typeof onRemoveColumn === 'function',
- ariaLabel: i18n.translate('discover.docTable.tableHeader.removeColumnButtonAriaLabel', {
- defaultMessage: 'Remove {columnName} column',
- values: { columnName: name },
- }),
- className: 'fa fa-remove osdDocTableHeader__move',
- onClick: () => onRemoveColumn && onRemoveColumn(name),
- testSubject: `docTableRemoveHeader-${name}`,
- tooltip: i18n.translate('discover.docTable.tableHeader.removeColumnButtonTooltip', {
- defaultMessage: 'Remove Column',
- }),
- },
- // Move Left Button
- {
- active: colLeftIdx >= 0 && typeof onMoveColumn === 'function',
- ariaLabel: i18n.translate('discover.docTable.tableHeader.moveColumnLeftButtonAriaLabel', {
- defaultMessage: 'Move {columnName} column to the left',
- values: { columnName: name },
- }),
- className: 'fa fa-angle-double-left osdDocTableHeader__move',
- onClick: () => onMoveColumn && onMoveColumn(name, colLeftIdx),
- testSubject: `docTableMoveLeftHeader-${name}`,
- tooltip: i18n.translate('discover.docTable.tableHeader.moveColumnLeftButtonTooltip', {
- defaultMessage: 'Move column to the left',
- }),
- },
- // Move Right Button
- {
- active: colRightIdx >= 0 && typeof onMoveColumn === 'function',
- ariaLabel: i18n.translate('discover.docTable.tableHeader.moveColumnRightButtonAriaLabel', {
- defaultMessage: 'Move {columnName} column to the right',
- values: { columnName: name },
- }),
- className: 'fa fa-angle-double-right osdDocTableHeader__move',
- onClick: () => onMoveColumn && onMoveColumn(name, colRightIdx),
- testSubject: `docTableMoveRightHeader-${name}`,
- tooltip: i18n.translate('discover.docTable.tableHeader.moveColumnRightButtonTooltip', {
- defaultMessage: 'Move column to the right',
- }),
- },
- ];
-
- return (
-
-
- {displayName}
- {buttons
- .filter((button) => button.active)
- .map((button, idx) => (
-
- ))}
-
- |
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row.ts
deleted file mode 100644
index 4131798f5df3..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row.ts
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { find, template } from 'lodash';
-import { stringify } from 'query-string';
-import $ from 'jquery';
-import rison from 'rison-node';
-import '../../doc_viewer';
-
-import openRowHtml from './table_row/open.html';
-import detailsHtml from './table_row/details.html';
-
-import { dispatchRenderComplete, url } from '../../../../../../opensearch_dashboards_utils/public';
-import { DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../../common';
-import cellTemplateHtml from '../components/table_row/cell.html';
-import truncateByHeightTemplateHtml from '../components/table_row/truncate_by_height.html';
-import { opensearchFilters } from '../../../../../../data/public';
-import { getServices } from '../../../../opensearch_dashboards_services';
-
-const TAGS_WITH_WS = />\s+<');
-}
-
-// guesstimate at the minimum number of chars wide cells in the table should be
-const MIN_LINE_LENGTH = 20;
-
-interface LazyScope extends ng.IScope {
- [key: string]: any;
-}
-
-export function createTableRowDirective($compile: ng.ICompileService) {
- const cellTemplate = template(noWhiteSpace(cellTemplateHtml));
- const truncateByHeightTemplate = template(noWhiteSpace(truncateByHeightTemplateHtml));
-
- return {
- restrict: 'A',
- scope: {
- columns: '=',
- filter: '=',
- indexPattern: '=',
- row: '=osdTableRow',
- onAddColumn: '=?',
- onRemoveColumn: '=?',
- },
- link: ($scope: LazyScope, $el: JQuery) => {
- $el.after('');
- $el.empty();
-
- // when we compile the details, we use this $scope
- let $detailsScope: LazyScope;
-
- // when we compile the toggle button in the summary, we use this $scope
- let $toggleScope;
-
- // toggle display of the rows details, a full list of the fields from each row
- $scope.toggleRow = () => {
- const $detailsTr = $el.next();
-
- $scope.open = !$scope.open;
-
- ///
- // add/remove $details children
- ///
-
- $detailsTr.toggle($scope.open);
-
- if (!$scope.open) {
- // close the child scope if it exists
- $detailsScope.$destroy();
- // no need to go any further
- return;
- } else {
- $detailsScope = $scope.$new();
- }
-
- // empty the details and rebuild it
- $detailsTr.html(detailsHtml);
- $detailsScope.row = $scope.row;
- $detailsScope.hit = $scope.row;
- $detailsScope.uriEncodedId = encodeURIComponent($detailsScope.hit._id);
-
- $compile($detailsTr)($detailsScope);
- };
-
- $scope.$watchMulti(['indexPattern.timeFieldName', 'row.highlight', '[]columns'], () => {
- createSummaryRow($scope.row);
- });
-
- $scope.inlineFilter = function inlineFilter($event: any, type: string) {
- const column = $($event.currentTarget).data().column;
- const field = $scope.indexPattern.fields.getByName(column);
- $scope.filter(field, $scope.flattenedRow[column], type);
- };
-
- $scope.getContextAppHref = () => {
- const globalFilters: any = getServices().filterManager.getGlobalFilters();
- const appFilters: any = getServices().filterManager.getAppFilters();
-
- const hash = stringify(
- url.encodeQuery({
- _g: rison.encode({
- filters: globalFilters || [],
- }),
- _a: rison.encode({
- columns: $scope.columns,
- filters: (appFilters || []).map(opensearchFilters.disableFilter),
- }),
- }),
- { encode: false, sort: false }
- );
-
- return `#/context/${encodeURIComponent($scope.indexPattern.id)}/${encodeURIComponent(
- $scope.row._id
- )}?${hash}`;
- };
-
- // create a tr element that lists the value for each *column*
- function createSummaryRow(row: any) {
- const indexPattern = $scope.indexPattern;
- $scope.flattenedRow = indexPattern.flattenHit(row);
-
- // We just create a string here because its faster.
- const newHtmls = [openRowHtml];
-
- const mapping = indexPattern.fields.getByName;
- const hideTimeColumn = getServices().uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING, false);
- if (indexPattern.timeFieldName && !hideTimeColumn) {
- newHtmls.push(
- cellTemplate({
- timefield: true,
- formatted: _displayField(row, indexPattern.timeFieldName),
- filterable: mapping(indexPattern.timeFieldName).filterable && $scope.filter,
- column: indexPattern.timeFieldName,
- })
- );
- }
-
- $scope.columns.forEach(function (column: any) {
- const isFilterable = mapping(column) && mapping(column).filterable && $scope.filter;
-
- newHtmls.push(
- cellTemplate({
- timefield: false,
- sourcefield: column === '_source',
- formatted: _displayField(row, column, true),
- filterable: isFilterable,
- column,
- })
- );
- });
-
- let $cells = $el.children();
- newHtmls.forEach(function (html, i) {
- const $cell = $cells.eq(i);
- if ($cell.data('discover:html') === html) return;
-
- const reuse = find($cells.slice(i + 1), function (cell: any) {
- return $.data(cell, 'discover:html') === html;
- });
-
- const $target = reuse ? $(reuse).detach() : $(html);
- $target.data('discover:html', html);
- const $before = $cells.eq(i - 1);
- if ($before.length) {
- $before.after($target);
- } else {
- $el.append($target);
- }
-
- // rebuild cells since we modified the children
- $cells = $el.children();
-
- if (!reuse) {
- $toggleScope = $scope.$new();
- $compile($target)($toggleScope);
- }
- });
-
- if ($scope.open) {
- $detailsScope.row = row;
- }
-
- // trim off cells that were not used rest of the cells
- $cells.filter(':gt(' + (newHtmls.length - 1) + ')').remove();
- dispatchRenderComplete($el[0]);
- }
-
- /**
- * Fill an element with the value of a field
- */
- function _displayField(row: any, fieldName: string, truncate = false) {
- const indexPattern = $scope.indexPattern;
- const text = indexPattern.formatField(row, fieldName);
-
- if (truncate && text.length > MIN_LINE_LENGTH) {
- return truncateByHeightTemplate({
- body: text,
- });
- }
-
- return text;
- }
- },
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_cell.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_cell.scss
deleted file mode 100644
index 5285e09c241d..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_cell.scss
+++ /dev/null
@@ -1,34 +0,0 @@
-.osdDocTableCell__dataField {
- white-space: pre-wrap;
-}
-
-.osdDocTableCell__toggleDetails {
- padding: 4px 0 0 !important;
-}
-
-.osdDocTableCell__filter {
- position: absolute;
- white-space: nowrap;
- right: 0;
-}
-
-/**
- * 1. Align icon with text in cell.
- * 2. Use opacity to make this element accessible to screen readers and keyboard.
- * 3. Show on focus to enable keyboard accessibility.
- */
-
-.osdDocTableRowFilterButton {
- appearance: none;
- background-color: $euiColorEmptyShade;
- border: none;
- padding: 0 $euiSizeXS;
- font-size: $euiFontSizeS;
- line-height: 1; /* 1 */
- display: inline-block;
- opacity: 0; /* 2 */
-
- &:focus {
- opacity: 1; /* 3 */
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_details.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_details.scss
deleted file mode 100644
index 4014cdab62d4..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_details.scss
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 1. Visually align the actions with the tabs. We can improve this by using flexbox instead, at a later point.
- */
-.osdDocTableDetails__actions {
- float: right;
- padding-top: $euiSizeS; /* 1 */
-}
-
-// Overwrite the border on the bootstrap table
-.osdDocTableDetails__row {
- > td {
- // Offsets negative margins from an inner flex group
- padding: $euiSizeL !important;
-
- tr:hover td {
- background: tintOrShade($euiColorLightestShade, 50%, 20%);
- }
- }
-
- td {
- border-top: none !important;
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_index.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_index.scss
deleted file mode 100644
index 56530bf93330..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_index.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-@import "cell";
-@import "details";
-@import "open";
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_open.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_open.scss
deleted file mode 100644
index 0bdcee3538b0..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/_open.scss
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/**
- * 1. When switching between open and closed, the toggle changes size
- * slightly which is a problem because it forces the entire table to
- * re-render which is SLOW.
- */
-
-.osdDocTableOpen__button {
- appearance: none;
- background-color: transparent;
- padding: 0;
- border: none;
- width: 14px; /* 1 */
- height: 14px;
-}
-
-.euiButtonIcon.euiButtonIcon--open {
- box-shadow: none;
- min-height: 24px;
- min-width: 24px;
- line-height: 0;
- transition: all 250ms ease-in-out 0s;
- border: none;
- background-color: transparent;
-
- &:hover,
- &:focus {
- box-shadow: none;
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/cell.html b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/cell.html
deleted file mode 100644
index dd54c7f63205..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/cell.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<% var attributes='' ; if (timefield) { attributes='class="eui-textNoWrap" width="1%"' ; } else if (sourcefield) {
- attributes='class="eui-textBreakAll eui-textBreakWord"' ; } else {
- attributes='class="osdDocTableCell__dataField eui-textBreakAll eui-textBreakWord"' ; } %>
- data-test-subj="docTableField">
- <%= formatted %>
-
- <% if (filterable) { %>
-
-
- <% } %>
-
- |
\ No newline at end of file
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/details.html b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/details.html
deleted file mode 100644
index a28f1b9906cb..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/details.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
- |
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/open.html b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/open.html
deleted file mode 100644
index d9e15c37f02c..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/open.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- |
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/truncate_by_height.html b/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/truncate_by_height.html
deleted file mode 100644
index cf13f10e7006..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/components/table_row/truncate_by_height.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= body %>
-
\ No newline at end of file
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/create_doc_table_react.tsx b/src/plugins/discover_legacy/public/application/angular/doc_table/create_doc_table_react.tsx
deleted file mode 100644
index 8b68dc7ae466..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/create_doc_table_react.tsx
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import angular, { auto, ICompileService, IScope } from 'angular';
-import { render } from 'react-dom';
-import React, { useRef, useEffect } from 'react';
-import { getServices, IIndexPattern } from '../../../opensearch_dashboards_services';
-import { IndexPatternField } from '../../../../../data/common/index_patterns';
-export type AngularScope = IScope;
-
-export interface AngularDirective {
- template: string;
-}
-
-/**
- * Compiles and injects the give angular template into the given dom node
- * returns a function to cleanup the injected angular element
- */
-export async function injectAngularElement(
- domNode: Element,
- template: string,
- scopeProps: any,
- getInjector: () => Promise
-): Promise<() => void> {
- const $injector = await getInjector();
- const rootScope: AngularScope = $injector.get('$rootScope');
- const $compile: ICompileService = $injector.get('$compile');
- const newScope = Object.assign(rootScope.$new(), scopeProps);
-
- const $target = angular.element(domNode);
- const $element = angular.element(template);
-
- newScope.$apply(() => {
- const linkFn = $compile($element);
- $target.empty().append($element);
- linkFn(newScope);
- });
-
- return () => {
- newScope.$destroy();
- };
-}
-
-/**
- * Converts a given legacy angular directive to a render function
- * for usage in a react component. Note that the rendering is async
- */
-export function convertDirectiveToRenderFn(
- directive: AngularDirective,
- getInjector: () => Promise
-) {
- return (domNode: Element, props: any) => {
- let rejected = false;
-
- const cleanupFnPromise = injectAngularElement(domNode, directive.template, props, getInjector);
- cleanupFnPromise.catch(() => {
- rejected = true;
- render(error
, domNode);
- });
-
- return () => {
- if (!rejected) {
- // for cleanup
- cleanupFnPromise.then((cleanup) => cleanup());
- }
- };
- };
-}
-
-export interface DocTableLegacyProps {
- columns: string[];
- searchDescription?: string;
- searchTitle?: string;
- onFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
- rows: Array>;
- indexPattern: IIndexPattern;
- minimumVisibleRows: number;
- onAddColumn: (column: string) => void;
- onSort: (sort: string[][]) => void;
- onMoveColumn: (columns: string, newIdx: number) => void;
- onRemoveColumn: (column: string) => void;
- sort?: string[][];
-}
-
-export function DocTableLegacy(renderProps: DocTableLegacyProps) {
- const renderFn = convertDirectiveToRenderFn(
- {
- template: ``,
- },
- () => getServices().getEmbeddableInjector()
- );
- const ref = useRef(null);
- useEffect(() => {
- if (ref && ref.current) {
- return renderFn(ref.current, renderProps);
- }
- }, [renderFn, renderProps]);
- return ;
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.html b/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.html
deleted file mode 100644
index e7a66ce50299..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.html
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
- {{ limitedResultsWarning }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.test.js b/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.test.js
deleted file mode 100644
index bd087ac3547f..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.test.js
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import angular from 'angular';
-import _ from 'lodash';
-import 'angular-mocks';
-import 'angular-sanitize';
-import 'angular-route';
-import { createBrowserHistory } from 'history';
-import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
-import hits from 'fixtures/real_hits';
-import { coreMock } from '../../../../../../core/public/mocks';
-import { dataPluginMock } from '../../../../../data/public/mocks';
-import { navigationPluginMock } from '../../../../../navigation/public/mocks';
-import { setScopedHistory, setServices } from '../../../opensearch_dashboards_services';
-import { getInnerAngularModule } from '../../../get_inner_angular';
-
-let $parentScope;
-
-let $scope;
-
-let $timeout;
-
-let indexPattern;
-
-const init = function ($elem, props) {
- angular.mock.inject(function ($rootScope, $compile, _$timeout_) {
- $timeout = _$timeout_;
- $parentScope = $rootScope;
- _.assign($parentScope, props);
-
- $compile($elem)($parentScope);
-
- // I think the prereq requires this?
- $timeout(() => {
- $elem.scope().$digest();
- }, 0);
-
- $scope = $elem.isolateScope();
- });
-};
-
-const destroy = () => {
- $scope.$destroy();
- $parentScope.$destroy();
-};
-
-describe('docTable', () => {
- const core = coreMock.createStart();
- let $elem;
-
- beforeAll(() => setScopedHistory(createBrowserHistory()));
- beforeEach(() => {
- angular.element.prototype.slice = jest.fn(() => {
- return null;
- });
- angular.element.prototype.filter = jest.fn(() => {
- return {
- remove: jest.fn(),
- };
- });
- setServices({
- uiSettings: core.uiSettings,
- });
- getInnerAngularModule(
- 'app/discover',
- core,
- {
- data: dataPluginMock.createStartContract(),
- navigation: navigationPluginMock.createStartContract(),
- },
- coreMock.createPluginInitializerContext()
- );
- angular.mock.module('app/discover');
- });
- beforeEach(() => {
- $elem = angular.element(`
-
- `);
- angular.mock.inject(function (Private) {
- indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
- });
- init($elem, {
- indexPattern,
- hits: [...hits],
- totalHitCount: hits.length,
- columns: [],
- sorting: ['@timestamp', 'desc'],
- });
- $scope.$digest();
- });
-
- afterEach(() => {
- delete angular.element.prototype.slice;
- delete angular.element.prototype.filter;
- destroy();
- });
-
- test('should compile', () => {
- expect($elem.text()).toBeTruthy();
- });
-
- test('should have an addRows function that increases the row count', () => {
- expect($scope.addRows).toBeInstanceOf(Function);
- $scope.$digest();
- expect($scope.limit).toBe(50);
- $scope.addRows();
- expect($scope.limit).toBe(100);
- });
-
- test('should reset the row limit when results are received', () => {
- $scope.limit = 100;
- expect($scope.limit).toBe(100);
- $scope.hits = [...hits];
- $scope.$digest();
- expect($scope.limit).toBe(50);
- });
-
- test('should have a header and a table element', () => {
- $scope.$digest();
-
- expect($elem.find('thead').length).toBe(1);
- expect($elem.find('table').length).toBe(1);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.ts
deleted file mode 100644
index 2c68ad4a89ff..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import html from './doc_table.html';
-import { dispatchRenderComplete } from '../../../../../opensearch_dashboards_utils/public';
-import { SAMPLE_SIZE_SETTING } from '../../../../common';
-// @ts-ignore
-import { getLimitedSearchResultsMessage } from './doc_table_strings';
-import { getServices } from '../../../opensearch_dashboards_services';
-import './index.scss';
-
-export interface LazyScope extends ng.IScope {
- [key: string]: any;
-}
-
-export function createDocTableDirective(pagerFactory: any, $filter: any) {
- return {
- restrict: 'E',
- template: html,
- scope: {
- sorting: '=',
- columns: '=',
- hits: '=',
- totalHitCount: '=',
- indexPattern: '=',
- isLoading: '=?',
- infiniteScroll: '=?',
- filter: '=?',
- minimumVisibleRows: '=?',
- onAddColumn: '=?',
- onChangeSortOrder: '=?',
- onMoveColumn: '=?',
- onRemoveColumn: '=?',
- inspectorAdapters: '=?',
- },
- link: ($scope: LazyScope, $el: JQuery) => {
- $scope.persist = {
- sorting: $scope.sorting,
- columns: $scope.columns,
- };
-
- const limitTo = $filter('limitTo');
- const calculateItemsOnPage = () => {
- $scope.pager.setTotalItems($scope.hits.length);
- $scope.pageOfItems = limitTo($scope.hits, $scope.pager.pageSize, $scope.pager.startIndex);
- };
-
- $scope.limitedResultsWarning = getLimitedSearchResultsMessage(
- getServices().uiSettings.get(SAMPLE_SIZE_SETTING, 500)
- );
-
- $scope.addRows = function () {
- $scope.limit += 50;
- };
-
- $scope.$watch('hits', (hits: any) => {
- if (!hits) return;
-
- // Reset infinite scroll limit
- $scope.limit = $scope.minimumVisibleRows || 50;
-
- if (hits.length === 0) {
- dispatchRenderComplete($el[0]);
- }
-
- if ($scope.infiniteScroll) return;
- $scope.pager = pagerFactory.create(hits.length, 50, 1);
- calculateItemsOnPage();
- });
-
- $scope.pageOfItems = [];
- $scope.onPageNext = () => {
- $scope.pager.nextPage();
- calculateItemsOnPage();
- };
-
- $scope.onPagePrevious = () => {
- $scope.pager.previousPage();
- calculateItemsOnPage();
- };
-
- $scope.shouldShowLimitedResultsWarning = () =>
- !$scope.pager.hasNextPage && $scope.pager.totalItems < $scope.totalHitCount;
- },
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table_strings.js b/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table_strings.js
deleted file mode 100644
index 4a0457638faa..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/doc_table_strings.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-
-/**
- * A message letting the user know the results that have been retrieved is limited
- * to a certain size.
- * @param resultCount {Number}
- */
-export function getLimitedSearchResultsMessage(resultCount) {
- return i18n.translate('discover.docTable.limitedSearchResultLabel', {
- defaultMessage: 'Limited to {resultCount} results. Refine your search.',
- values: { resultCount },
- });
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/index.scss b/src/plugins/discover_legacy/public/application/angular/doc_table/index.scss
deleted file mode 100644
index 5b9dc82adb16..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/index.scss
+++ /dev/null
@@ -1,2 +0,0 @@
-@import "doc_table";
-@import "components/index";
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/index.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/index.ts
deleted file mode 100644
index c51ce33cc28f..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/index.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { createDocTableDirective } from './doc_table';
-export { getSort, getSortArray } from './lib/get_sort';
-export { getSortForSearchSource } from './lib/get_sort_for_search_source';
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/infinite_scroll.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/infinite_scroll.ts
deleted file mode 100644
index 2a59d94aa5c4..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/infinite_scroll.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import $ from 'jquery';
-
-interface LazyScope extends ng.IScope {
- [key: string]: any;
-}
-
-export function createInfiniteScrollDirective() {
- return {
- restrict: 'E',
- scope: {
- more: '=',
- },
- link: ($scope: LazyScope, $element: JQuery) => {
- const $window = $(window);
- let checkTimer: any;
-
- function onScroll() {
- if (!$scope.more) return;
-
- const winHeight = Number($window.height());
- const winBottom = Number(winHeight) + Number($window.scrollTop());
- const offset = $element.offset();
- const elTop = offset ? offset.top : 0;
- const remaining = elTop - winBottom;
-
- if (remaining <= winHeight * 0.5) {
- $scope[$scope.$$phase ? '$eval' : '$apply'](function () {
- $scope.more();
- });
- }
- }
-
- function scheduleCheck() {
- if (checkTimer) return;
- checkTimer = setTimeout(function () {
- checkTimer = null;
- onScroll();
- }, 50);
- }
-
- $window.on('scroll', scheduleCheck);
- $scope.$on('$destroy', function () {
- clearTimeout(checkTimer);
- $window.off('scroll', scheduleCheck);
- });
- scheduleCheck();
- },
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_default_sort.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_default_sort.ts
deleted file mode 100644
index d22c963d219c..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_default_sort.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPattern } from '../../../../opensearch_dashboards_services';
-// @ts-ignore
-import { isSortable } from './get_sort';
-import { SortOrder } from '../components/table_header/helpers';
-
-/**
- * use in case the user didn't manually sort.
- * the default sort is returned depending of the index pattern
- */
-export function getDefaultSort(
- indexPattern: IndexPattern,
- defaultSortOrder: string = 'desc'
-): SortOrder[] {
- if (indexPattern.timeFieldName && isSortable(indexPattern.timeFieldName, indexPattern)) {
- return [[indexPattern.timeFieldName, defaultSortOrder]];
- } else {
- return [['_score', defaultSortOrder]];
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.test.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.test.ts
deleted file mode 100644
index 30c302bccd72..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.test.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getSort, getSortArray } from './get_sort';
-// @ts-ignore
-import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
-import { IndexPattern } from '../../../../opensearch_dashboards_services';
-
-describe('docTable', function () {
- let indexPattern: IndexPattern;
-
- beforeEach(() => {
- indexPattern = FixturesStubbedLogstashIndexPatternProvider() as IndexPattern;
- });
-
- describe('getSort function', function () {
- test('should be a function', function () {
- expect(typeof getSort === 'function').toBeTruthy();
- });
-
- test('should return an array of objects', function () {
- expect(getSort([['bytes', 'desc']], indexPattern)).toEqual([{ bytes: 'desc' }]);
-
- delete indexPattern.timeFieldName;
- expect(getSort([['bytes', 'desc']], indexPattern)).toEqual([{ bytes: 'desc' }]);
- });
-
- test('should passthrough arrays of objects', () => {
- expect(getSort([{ bytes: 'desc' }], indexPattern)).toEqual([{ bytes: 'desc' }]);
- });
-
- test('should return an empty array when passed an unsortable field', function () {
- expect(getSort([['non-sortable', 'asc']], indexPattern)).toEqual([]);
- expect(getSort([['lol_nope', 'asc']], indexPattern)).toEqual([]);
-
- delete indexPattern.timeFieldName;
- expect(getSort([['non-sortable', 'asc']], indexPattern)).toEqual([]);
- });
-
- test('should return an empty array ', function () {
- expect(getSort([], indexPattern)).toEqual([]);
- expect(getSort([['foo', 'bar']], indexPattern)).toEqual([]);
- expect(getSort([{ foo: 'bar' }], indexPattern)).toEqual([]);
- });
-
- test('should convert a legacy sort to an array of objects', function () {
- expect(getSort(['foo', 'desc'], indexPattern)).toEqual([{ foo: 'desc' }]);
- expect(getSort(['foo', 'asc'], indexPattern)).toEqual([{ foo: 'asc' }]);
- });
- });
-
- describe('getSortArray function', function () {
- test('should have an array method', function () {
- expect(getSortArray).toBeInstanceOf(Function);
- });
-
- test('should return an array of arrays for sortable fields', function () {
- expect(getSortArray([['bytes', 'desc']], indexPattern)).toEqual([['bytes', 'desc']]);
- });
-
- test('should return an array of arrays from an array of elasticsearch sort objects', function () {
- expect(getSortArray([{ bytes: 'desc' }], indexPattern)).toEqual([['bytes', 'desc']]);
- });
-
- test('should sort by an empty array when an unsortable field is given', function () {
- expect(getSortArray([{ 'non-sortable': 'asc' }], indexPattern)).toEqual([]);
- expect(getSortArray([{ lol_nope: 'asc' }], indexPattern)).toEqual([]);
-
- delete indexPattern.timeFieldName;
- expect(getSortArray([{ 'non-sortable': 'asc' }], indexPattern)).toEqual([]);
- });
-
- test('should return an empty array when passed an empty sort array', () => {
- expect(getSortArray([], indexPattern)).toEqual([]);
-
- delete indexPattern.timeFieldName;
- expect(getSortArray([], indexPattern)).toEqual([]);
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.ts
deleted file mode 100644
index 2a65d7be5de1..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-import { IndexPattern } from '../../../../../../data/public';
-
-export type SortPairObj = Record;
-export type SortPairArr = [string, string];
-export type SortPair = SortPairArr | SortPairObj;
-export type SortInput = SortPair | SortPair[];
-
-export function isSortable(fieldName: string, indexPattern: IndexPattern) {
- const field = indexPattern.getFieldByName(fieldName);
- return field && field.sortable;
-}
-
-function createSortObject(
- sortPair: SortInput,
- indexPattern: IndexPattern
-): SortPairObj | undefined {
- if (
- Array.isArray(sortPair) &&
- sortPair.length === 2 &&
- isSortable(String(sortPair[0]), indexPattern)
- ) {
- const [field, direction] = sortPair as SortPairArr;
- return { [field]: direction };
- } else if (_.isPlainObject(sortPair) && isSortable(Object.keys(sortPair)[0], indexPattern)) {
- return sortPair as SortPairObj;
- }
-}
-
-export function isLegacySort(sort: SortPair[] | SortPair): sort is SortPair {
- return (
- sort.length === 2 && typeof sort[0] === 'string' && (sort[1] === 'desc' || sort[1] === 'asc')
- );
-}
-
-/**
- * Take a sorting array and make it into an object
- * @param {array} sort two dimensional array [[fieldToSort, directionToSort]]
- * or an array of objects [{fieldToSort: directionToSort}]
- * @param {object} indexPattern used for determining default sort
- * @returns Array<{object}> an array of sort objects
- */
-export function getSort(sort: SortPair[] | SortPair, indexPattern: IndexPattern): SortPairObj[] {
- if (Array.isArray(sort)) {
- if (isLegacySort(sort)) {
- // To stay compatible with legacy sort, which just supported a single sort field
- return [{ [sort[0]]: sort[1] }];
- }
- return sort
- .map((sortPair: SortPair) => createSortObject(sortPair, indexPattern))
- .filter((sortPairObj) => typeof sortPairObj === 'object') as SortPairObj[];
- }
- return [];
-}
-
-/**
- * compared to getSort it doesn't return an array of objects, it returns an array of arrays
- * [[fieldToSort: directionToSort]]
- */
-export function getSortArray(sort: SortPair[], indexPattern: IndexPattern) {
- return getSort(sort, indexPattern).map((sortPair) => Object.entries(sortPair).pop());
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort_for_search_source.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort_for_search_source.ts
deleted file mode 100644
index f83c764565c5..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/get_sort_for_search_source.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { OpenSearchQuerySortValue, IndexPattern } from '../../../../opensearch_dashboards_services';
-import { SortOrder } from '../components/table_header/helpers';
-import { getSort } from './get_sort';
-import { getDefaultSort } from './get_default_sort';
-
-/**
- * Prepares sort for search source, that's sending the request to OpenSearch
- * - Adds default sort if necessary
- * - Handles the special case when there's sorting by date_nanos typed fields
- * the addon of the numeric_type guarantees the right sort order
- * when there are indices with date and indices with date_nanos field
- */
-export function getSortForSearchSource(
- sort?: SortOrder[],
- indexPattern?: IndexPattern,
- defaultDirection: string = 'desc'
-): OpenSearchQuerySortValue[] {
- if (!sort || !indexPattern) {
- return [];
- } else if (Array.isArray(sort) && sort.length === 0) {
- sort = getDefaultSort(indexPattern, defaultDirection);
- }
- const { timeFieldName } = indexPattern;
- return getSort(sort, indexPattern).map((sortPair: Record) => {
- if (indexPattern.isTimeNanosBased() && timeFieldName && sortPair[timeFieldName]) {
- return {
- [timeFieldName]: {
- order: sortPair[timeFieldName],
- numeric_type: 'date_nanos',
- },
- } as OpenSearchQuerySortValue;
- }
- return sortPair as OpenSearchQuerySortValue;
- });
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/index.js b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/index.js
deleted file mode 100644
index e400b3b52226..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/index.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import './pager_factory';
-export { Pager } from './pager';
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager.js b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager.js
deleted file mode 100644
index 55b8c670317a..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager.js
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-function clamp(val, min, max) {
- return Math.min(Math.max(min, val), max);
-}
-
-export class Pager {
- constructor(totalItems, pageSize, startingPage) {
- this.currentPage = startingPage;
- this.totalItems = totalItems;
- this.pageSize = pageSize;
- this.startIndex = 0;
- this.updateMeta();
- }
-
- get pageCount() {
- return Math.ceil(this.totalItems / this.pageSize);
- }
-
- get hasNextPage() {
- return this.currentPage < this.totalPages;
- }
-
- get hasPreviousPage() {
- return this.currentPage > 1;
- }
-
- nextPage() {
- this.currentPage += 1;
- this.updateMeta();
- }
-
- previousPage() {
- this.currentPage -= 1;
- this.updateMeta();
- }
-
- setTotalItems(count) {
- this.totalItems = count;
- this.updateMeta();
- }
-
- setPageSize(count) {
- this.pageSize = count;
- this.updateMeta();
- }
-
- updateMeta() {
- this.totalPages = Math.ceil(this.totalItems / this.pageSize);
- this.currentPage = clamp(this.currentPage, 1, this.totalPages);
-
- this.startItem = (this.currentPage - 1) * this.pageSize + 1;
- this.startItem = clamp(this.startItem, 0, this.totalItems);
-
- this.endItem = this.startItem - 1 + this.pageSize;
- this.endItem = clamp(this.endItem, 0, this.totalItems);
-
- this.startIndex = this.startItem - 1;
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager_factory.ts b/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager_factory.ts
deleted file mode 100644
index febb6428e53b..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_table/lib/pager/pager_factory.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// @ts-ignore
-import { Pager } from './pager';
-
-export function createPagerFactory() {
- return {
- create(...args: unknown[]) {
- return new Pager(...args);
- },
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_viewer.tsx b/src/plugins/discover_legacy/public/application/angular/doc_viewer.tsx
deleted file mode 100644
index 9072594bf478..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_viewer.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { DocViewer } from '../components/doc_viewer/doc_viewer';
-
-export function createDocViewerDirective(reactDirective: any) {
- return reactDirective(
- (props: any) => {
- return ;
- },
- [
- 'hit',
- ['indexPattern', { watchDepth: 'reference' }],
- ['filter', { watchDepth: 'reference' }],
- ['columns', { watchDepth: 'collection' }],
- ['onAddColumn', { watchDepth: 'reference' }],
- ['onRemoveColumn', { watchDepth: 'reference' }],
- ],
- {
- restrict: 'E',
- scope: {
- hit: '=',
- indexPattern: '=',
- filter: '=?',
- columns: '=?',
- onAddColumn: '=?',
- onRemoveColumn: '=?',
- },
- }
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/doc_viewer_links.tsx b/src/plugins/discover_legacy/public/application/angular/doc_viewer_links.tsx
deleted file mode 100644
index 763a75e51300..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/doc_viewer_links.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import React from 'react';
-import { DocViewerLinks } from '../components/doc_viewer_links/doc_viewer_links';
-
-export function createDocViewerLinksDirective(reactDirective: any) {
- return reactDirective(
- (props: any) => {
- return ;
- },
- [
- 'hit',
- ['indexPattern', { watchDepth: 'reference' }],
- ['columns', { watchDepth: 'collection' }],
- ],
- {
- restrict: 'E',
- scope: {
- hit: '=',
- indexPattern: '=',
- columns: '=?',
- },
- }
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/angular/helpers/index.ts b/src/plugins/discover_legacy/public/application/angular/helpers/index.ts
deleted file mode 100644
index eb569f6985d6..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/helpers/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { buildPointSeriesData } from './point_series';
diff --git a/src/plugins/discover_legacy/public/application/angular/helpers/point_series.ts b/src/plugins/discover_legacy/public/application/angular/helpers/point_series.ts
deleted file mode 100644
index 34b35453cb55..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/helpers/point_series.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { uniq } from 'lodash';
-import { Duration, Moment } from 'moment';
-import { Unit } from '@elastic/datemath';
-
-import { SerializedFieldFormat } from '../../../../../expressions/common/types';
-
-export interface Column {
- id: string;
- name: string;
-}
-
-export interface Row {
- [key: string]: number | 'NaN';
-}
-
-export interface Table {
- columns: Column[];
- rows: Row[];
-}
-
-interface HistogramParams {
- date: true;
- interval: Duration;
- intervalOpenSearchValue: number;
- intervalOpenSearchUnit: Unit;
- format: string;
- bounds: {
- min: Moment;
- max: Moment;
- };
-}
-export interface Dimension {
- accessor: 0 | 1;
- format: SerializedFieldFormat<{ pattern: string }>;
-}
-
-export interface Dimensions {
- x: Dimension & { params: HistogramParams };
- y: Dimension;
-}
-
-interface Ordered {
- date: true;
- interval: Duration;
- intervalOpenSearchUnit: string;
- intervalOpenSearchValue: number;
- min: Moment;
- max: Moment;
-}
-export interface Chart {
- values: Array<{
- x: number;
- y: number;
- }>;
- xAxisOrderedValues: number[];
- xAxisFormat: Dimension['format'];
- xAxisLabel: Column['name'];
- yAxisLabel?: Column['name'];
- ordered: Ordered;
-}
-
-export const buildPointSeriesData = (table: Table, dimensions: Dimensions) => {
- const { x, y } = dimensions;
- const xAccessor = table.columns[x.accessor].id;
- const yAccessor = table.columns[y.accessor].id;
- const chart = {} as Chart;
-
- chart.xAxisOrderedValues = uniq(table.rows.map((r) => r[xAccessor] as number));
- chart.xAxisFormat = x.format;
- chart.xAxisLabel = table.columns[x.accessor].name;
-
- const { intervalOpenSearchUnit, intervalOpenSearchValue, interval, bounds } = x.params;
- chart.ordered = {
- date: true,
- interval,
- intervalOpenSearchUnit,
- intervalOpenSearchValue,
- min: bounds.min,
- max: bounds.max,
- };
-
- chart.yAxisLabel = table.columns[y.accessor].name;
-
- chart.values = table.rows
- .filter((row) => row && row[yAccessor] !== 'NaN')
- .map((row) => ({
- x: row[xAccessor] as number,
- y: row[yAccessor] as number,
- }));
-
- return chart;
-};
diff --git a/src/plugins/discover_legacy/public/application/angular/index.ts b/src/plugins/discover_legacy/public/application/angular/index.ts
deleted file mode 100644
index f9b905759c06..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/index.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// required for i18nIdDirective
-import 'angular-sanitize';
-// required for ngRoute
-import 'angular-route';
-
-import './discover';
-import './doc';
-import './context';
-import './doc_viewer';
-import './redirect';
-import './directives';
diff --git a/src/plugins/discover_legacy/public/application/angular/redirect.ts b/src/plugins/discover_legacy/public/application/angular/redirect.ts
deleted file mode 100644
index d8c03e42abb7..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/redirect.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getAngularModule, getServices, getUrlTracker } from '../../opensearch_dashboards_services';
-
-getAngularModule().config(($routeProvider: any) => {
- $routeProvider.otherwise({
- resolveRedirectTo: ($rootScope: any) => {
- const path = window.location.hash.substr(1);
- getUrlTracker().restorePreviousUrl();
- $rootScope.$applyAsync(() => {
- const { urlForwarding } = getServices();
- const { navigated } = urlForwarding.navigateToLegacyOpenSearchDashboardsUrl(path);
- if (!navigated) {
- urlForwarding.navigateToDefaultApp();
- }
- });
- // prevent angular from completing the navigation
- return new Promise(() => {});
- },
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/angular/response_handler.js b/src/plugins/discover_legacy/public/application/angular/response_handler.js
deleted file mode 100644
index 853de0086168..000000000000
--- a/src/plugins/discover_legacy/public/application/angular/response_handler.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getServices } from '../../opensearch_dashboards_services';
-import { buildPointSeriesData } from './helpers';
-
-function tableResponseHandler(table, dimensions) {
- const converted = { tables: [] };
- const split = dimensions.splitColumn || dimensions.splitRow;
-
- if (split) {
- converted.direction = dimensions.splitRow ? 'row' : 'column';
- const splitColumnIndex = split[0].accessor;
- const splitColumnFormatter = getServices().data.fieldFormats.deserialize(split[0].format);
- const splitColumn = table.columns[splitColumnIndex];
- const splitMap = {};
- let splitIndex = 0;
-
- table.rows.forEach((row, rowIndex) => {
- const splitValue = row[splitColumn.id];
-
- if (!splitMap.hasOwnProperty(splitValue)) {
- splitMap[splitValue] = splitIndex++;
- const tableGroup = {
- $parent: converted,
- title: `${splitColumnFormatter.convert(splitValue)}: ${splitColumn.name}`,
- name: splitColumn.name,
- key: splitValue,
- column: splitColumnIndex,
- row: rowIndex,
- table,
- tables: [],
- };
- tableGroup.tables.push({
- $parent: tableGroup,
- columns: table.columns,
- rows: [],
- });
-
- converted.tables.push(tableGroup);
- }
-
- const tableIndex = splitMap[splitValue];
- converted.tables[tableIndex].tables[0].rows.push(row);
- });
- } else {
- converted.tables.push({
- columns: table.columns,
- rows: table.rows,
- });
- }
-
- return converted;
-}
-
-function convertTableGroup(tableGroup, convertTable) {
- const tables = tableGroup.tables;
-
- if (!tables.length) return;
-
- const firstChild = tables[0];
- if (firstChild.columns) {
- const chart = convertTable(firstChild);
- // if chart is within a split, assign group title to its label
- if (tableGroup.$parent) {
- chart.label = tableGroup.title;
- }
- return chart;
- }
-
- const out = {};
- let outList;
-
- tables.forEach(function (table) {
- if (!outList) {
- const direction = tableGroup.direction === 'row' ? 'rows' : 'columns';
- outList = out[direction] = [];
- }
-
- let output;
- if ((output = convertTableGroup(table, convertTable))) {
- outList.push(output);
- }
- });
-
- return out;
-}
-
-export const discoverResponseHandler = (response, dimensions) => {
- const tableGroup = tableResponseHandler(response, dimensions);
-
- let converted = convertTableGroup(tableGroup, (table) => {
- return buildPointSeriesData(table, dimensions);
- });
- if (!converted) {
- // mimic a row of tables that doesn't have any tables
- // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/7bfb68cd24ed42b1b257682f93c50cd8d73e2520/src/kibana/components/vislib/components/zero_injection/inject_zeros.js#L32
- converted = { rows: [] };
- }
-
- converted.hits = response.rows.length;
-
- return converted;
-};
diff --git a/src/plugins/discover_legacy/public/application/application.ts b/src/plugins/discover_legacy/public/application/application.ts
deleted file mode 100644
index 49fd743d76ef..000000000000
--- a/src/plugins/discover_legacy/public/application/application.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import './index.scss';
-import angular from 'angular';
-import { getServices } from '../opensearch_dashboards_services';
-
-/**
- * Here's where Discover's inner angular is mounted and rendered
- */
-export async function renderApp(moduleName: string, element: HTMLElement) {
- // do not wait for fontawesome
- getServices().opensearchDashboardsLegacy.loadFontAwesome();
- await import('./angular');
- const $injector = mountDiscoverApp(moduleName, element);
- return () => $injector.get('$rootScope').$destroy();
-}
-
-function mountDiscoverApp(moduleName: string, element: HTMLElement) {
- const mountpoint = document.createElement('div');
- const appWrapper = document.createElement('div');
- appWrapper.setAttribute('ng-view', '');
- mountpoint.appendChild(appWrapper);
- // bootstrap angular into detached element and attach it later to
- // make angular-within-angular possible
- const $injector = angular.bootstrap(mountpoint, [moduleName]);
- element.appendChild(mountpoint);
- return $injector;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.test.tsx b/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.test.tsx
deleted file mode 100644
index a1ef06b81cf2..000000000000
--- a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.test.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { ContextErrorMessage } from './context_error_message';
-// @ts-ignore
-import { FAILURE_REASONS, LOADING_STATUS } from '../../angular/context/query';
-import { findTestSubject } from 'test_utils/helpers';
-
-describe('loading spinner', function () {
- let component: ReactWrapper;
-
- it('ContextErrorMessage does not render on loading', () => {
- component = mountWithIntl();
- expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(0);
- });
-
- it('ContextErrorMessage does not render on success loading', () => {
- component = mountWithIntl();
- expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(0);
- });
-
- it('ContextErrorMessage renders just the title if the reason is not specifically handled', () => {
- component = mountWithIntl();
- expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1);
- expect(findTestSubject(component, 'contextErrorMessageBody').text()).toBe('');
- });
-
- it('ContextErrorMessage renders the reason for unknown errors', () => {
- component = mountWithIntl(
-
- );
- expect(findTestSubject(component, 'contextErrorMessageTitle').length).toBe(1);
- expect(findTestSubject(component, 'contextErrorMessageBody').length).toBe(1);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.tsx b/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.tsx
deleted file mode 100644
index 8fe36f592275..000000000000
--- a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiCallOut, EuiText } from '@elastic/eui';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-// @ts-ignore
-import { FAILURE_REASONS, LOADING_STATUS } from '../../angular/context/query';
-
-export interface ContextErrorMessageProps {
- /**
- * the status of the loading action
- */
- status: string;
- /**
- * the reason of the error
- */
- reason?: string;
-}
-
-export function ContextErrorMessage({ status, reason }: ContextErrorMessageProps) {
- if (status !== LOADING_STATUS.FAILED) {
- return null;
- }
- return (
-
-
- }
- color="danger"
- iconType="alert"
- data-test-subj="contextErrorMessageTitle"
- >
-
- {reason === FAILURE_REASONS.UNKNOWN && (
-
- )}
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message_directive.ts b/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message_directive.ts
deleted file mode 100644
index 077682c67d06..000000000000
--- a/src/plugins/discover_legacy/public/application/components/context_error_message/context_error_message_directive.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { ContextErrorMessage } from './context_error_message';
-
-export function createContextErrorMessageDirective(reactDirective: any) {
- return reactDirective(ContextErrorMessage, [
- ['status', { watchDepth: 'reference' }],
- ['reason', { watchDepth: 'reference' }],
- ]);
-}
diff --git a/src/plugins/discover_legacy/public/application/components/context_error_message/index.ts b/src/plugins/discover_legacy/public/application/components/context_error_message/index.ts
deleted file mode 100644
index 99cd662ecca3..000000000000
--- a/src/plugins/discover_legacy/public/application/components/context_error_message/index.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { ContextErrorMessage } from './context_error_message';
-export { createContextErrorMessageDirective } from './context_error_message_directive';
diff --git a/src/plugins/discover_legacy/public/application/components/create_discover_legacy_directive.ts b/src/plugins/discover_legacy/public/application/components/create_discover_legacy_directive.ts
deleted file mode 100644
index 09cc33964862..000000000000
--- a/src/plugins/discover_legacy/public/application/components/create_discover_legacy_directive.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { DiscoverLegacy } from './discover_legacy';
-
-export function createDiscoverLegacyDirective(reactDirective: any) {
- return reactDirective(DiscoverLegacy, [
- ['addColumn', { watchDepth: 'reference' }],
- ['fetch', { watchDepth: 'reference' }],
- ['fetchCounter', { watchDepth: 'reference' }],
- ['fetchError', { watchDepth: 'reference' }],
- ['fieldCounts', { watchDepth: 'reference' }],
- ['histogramData', { watchDepth: 'reference' }],
- ['hits', { watchDepth: 'reference' }],
- ['indexPattern', { watchDepth: 'reference' }],
- ['minimumVisibleRows', { watchDepth: 'reference' }],
- ['onAddFilter', { watchDepth: 'reference' }],
- ['onChangeInterval', { watchDepth: 'reference' }],
- ['onMoveColumn', { watchDepth: 'reference' }],
- ['onRemoveColumn', { watchDepth: 'reference' }],
- ['onSetColumns', { watchDepth: 'reference' }],
- ['onSkipBottomButtonClick', { watchDepth: 'reference' }],
- ['onSort', { watchDepth: 'reference' }],
- ['opts', { watchDepth: 'reference' }],
- ['resetQuery', { watchDepth: 'reference' }],
- ['resultState', { watchDepth: 'reference' }],
- ['rows', { watchDepth: 'reference' }],
- ['savedSearch', { watchDepth: 'reference' }],
- ['searchSource', { watchDepth: 'reference' }],
- ['setIndexPattern', { watchDepth: 'reference' }],
- ['showSaveQuery', { watchDepth: 'reference' }],
- ['state', { watchDepth: 'reference' }],
- ['timefilterUpdateHandler', { watchDepth: 'reference' }],
- ['timeRange', { watchDepth: 'reference' }],
- ['topNavMenu', { watchDepth: 'reference' }],
- ['updateQuery', { watchDepth: 'reference' }],
- ['updateSavedQueryId', { watchDepth: 'reference' }],
- ['vis', { watchDepth: 'reference' }],
- ]);
-}
diff --git a/src/plugins/discover_legacy/public/application/components/discover_legacy.tsx b/src/plugins/discover_legacy/public/application/components/discover_legacy.tsx
deleted file mode 100644
index d3bf5b6ffeb8..000000000000
--- a/src/plugins/discover_legacy/public/application/components/discover_legacy.tsx
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState, useCallback, useEffect } from 'react';
-import classNames from 'classnames';
-import { EuiButtonEmpty, EuiButtonIcon, EuiCallOut, EuiLink } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-import { IUiSettingsClient, MountPoint } from 'opensearch-dashboards/public';
-import { HitsCounter } from './hits_counter';
-import { TimechartHeader } from './timechart_header';
-import { DiscoverSidebar } from './sidebar';
-import { getServices, IndexPattern } from '../../opensearch_dashboards_services';
-// @ts-ignore
-import { DiscoverNoResults } from '../angular/directives/no_results';
-import { DiscoverUninitialized } from '../angular/directives/uninitialized';
-import { DiscoverHistogram } from '../angular/directives/histogram';
-import { LoadingSpinner } from './loading_spinner/loading_spinner';
-import { DocTableLegacy } from '../angular/doc_table/create_doc_table_react';
-import { SkipBottomButton } from './skip_bottom_button';
-import {
- IndexPatternField,
- search,
- ISearchSource,
- TimeRange,
- Query,
- IndexPatternAttributes,
-} from '../../../../data/public';
-import { Chart } from '../angular/helpers/point_series';
-import { AppState } from '../angular/discover_state';
-import { SavedSearch } from '../../saved_searches';
-
-import { SavedObject } from '../../../../../core/types';
-import { Vis } from '../../../../visualizations/public';
-import { TopNavMenuData } from '../../../../navigation/public';
-
-export interface DiscoverLegacyProps {
- addColumn: (column: string) => void;
- fetch: () => void;
- fetchCounter: number;
- fieldCounts: Record;
- histogramData: Chart;
- hits: number;
- indexPattern: IndexPattern;
- minimumVisibleRows: number;
- onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
- onChangeInterval: (interval: string) => void;
- onMoveColumn: (columns: string, newIdx: number) => void;
- onRemoveColumn: (column: string) => void;
- onSetColumns: (columns: string[]) => void;
- onSkipBottomButtonClick: () => void;
- onSort: (sort: string[][]) => void;
- opts: {
- savedSearch: SavedSearch;
- config: IUiSettingsClient;
- indexPatternList: Array>;
- timefield: string;
- sampleSize: number;
- fixedScroll: (el: HTMLElement) => void;
- setHeaderActionMenu: (menuMount: MountPoint | undefined) => void;
- };
- resetQuery: () => void;
- resultState: string;
- rows: Array>;
- searchSource: ISearchSource;
- setIndexPattern: (id: string) => void;
- showSaveQuery: boolean;
- state: AppState;
- timefilterUpdateHandler: (ranges: { from: number; to: number }) => void;
- timeRange?: { from: string; to: string };
- topNavMenu: TopNavMenuData[];
- updateQuery: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void;
- updateSavedQueryId: (savedQueryId?: string) => void;
- vis?: Vis;
-}
-
-export function DiscoverLegacy({
- addColumn,
- fetch,
- fetchCounter,
- fieldCounts,
- histogramData,
- hits,
- indexPattern,
- minimumVisibleRows,
- onAddFilter,
- onChangeInterval,
- onMoveColumn,
- onRemoveColumn,
- onSkipBottomButtonClick,
- onSort,
- opts,
- resetQuery,
- resultState,
- rows,
- searchSource,
- setIndexPattern,
- showSaveQuery,
- state,
- timefilterUpdateHandler,
- timeRange,
- topNavMenu,
- updateQuery,
- updateSavedQueryId,
- vis,
-}: DiscoverLegacyProps) {
- const [isSidebarClosed, setIsSidebarClosed] = useState(false);
- const [isCallOutVisible, setIsCallOutVisible] = useState(true);
- const { TopNavMenu } = getServices().navigation.ui;
- const { savedSearch, indexPatternList } = opts;
- const bucketAggConfig = vis?.data?.aggs?.aggs[1];
- const bucketInterval =
- bucketAggConfig && search.aggs.isDateHistogramBucketAggConfig(bucketAggConfig)
- ? bucketAggConfig.buckets?.getInterval()
- : undefined;
- const [fixedScrollEl, setFixedScrollEl] = useState();
-
- const closeCallOut = () => setIsCallOutVisible(false);
-
- let callOut;
-
- if (isCallOutVisible) {
- callOut = (
-
-
-
- To provide feedback,{' '}
-
- open an issue
-
- .
-
-
-
- );
- }
-
- useEffect(() => (fixedScrollEl ? opts.fixedScroll(fixedScrollEl) : undefined), [
- fixedScrollEl,
- opts,
- ]);
- const fixedScrollRef = useCallback(
- (node: HTMLElement) => {
- if (node !== null) {
- setFixedScrollEl(node);
- }
- },
- [setFixedScrollEl]
- );
- const sidebarClassName = classNames({
- closed: isSidebarClosed,
- });
-
- const mainSectionClassName = classNames({
- 'col-md-10': !isSidebarClosed,
- 'col-md-12': isSidebarClosed,
- });
-
- return (
-
-
-
{savedSearch.title}
-
-
-
-
-
-
-
- {callOut}
- {resultState === 'none' && (
-
- )}
- {resultState === 'uninitialized' &&
}
- {/* @TODO: Solved in the Angular way to satisfy functional test - should be improved*/}
-
-
-
-
-
- {resultState === 'ready' && (
-
-
-
0 ? hits : 0}
- showResetButton={!!(savedSearch && savedSearch.id)}
- onResetQuery={resetQuery}
- />
- {opts.timefield && (
-
- )}
-
- {opts.timefield && (
-
- {vis && rows.length !== 0 && (
-
-
-
- )}
-
- )}
-
-
-
-
-
-
- {rows && rows.length && (
-
-
-
-
-
- {rows.length === opts.sampleSize && (
-
-
-
- window.scrollTo(0, 0)}>
-
-
-
- )}
-
- )}
-
-
-
- )}
-
-
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc/doc.test.tsx b/src/plugins/discover_legacy/public/application/components/doc/doc.test.tsx
deleted file mode 100644
index 4a3fb740492a..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc/doc.test.tsx
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { throwError, of } from 'rxjs';
-import React from 'react';
-import { act } from 'react-dom/test-utils';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { findTestSubject } from 'test_utils/helpers';
-import { Doc, DocProps } from './doc';
-
-const mockSearchApi = jest.fn();
-
-jest.mock('../../../opensearch_dashboards_services', () => {
- let registry: any[] = [];
-
- return {
- getServices: () => ({
- metadata: {
- branch: 'test',
- },
- data: {
- search: {
- search: mockSearchApi,
- },
- },
- }),
- getDocViewsRegistry: () => ({
- addDocView(view: any) {
- registry.push(view);
- },
- getDocViewsSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- }),
- getDocViewsLinksRegistry: () => ({
- addDocViewLink(view: any) {
- registry.push(view);
- },
- getDocViewsLinksSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- }),
- };
-});
-
-beforeEach(() => {
- jest.clearAllMocks();
-});
-
-const waitForPromises = async () =>
- act(async () => {
- await new Promise((resolve) => setTimeout(resolve));
- });
-
-/**
- * this works but logs ugly error messages until we're using React 16.9
- * should be adapted when we upgrade
- */
-async function mountDoc(update = false, indexPatternGetter: any = null) {
- const indexPattern = {
- getComputedFields: () => [],
- };
- const indexPatternService = {
- get: indexPatternGetter ? indexPatternGetter : jest.fn(() => Promise.resolve(indexPattern)),
- } as any;
-
- const props = {
- id: '1',
- index: 'index1',
- indexPatternId: 'xyz',
- indexPatternService,
- } as DocProps;
- let comp!: ReactWrapper;
- await act(async () => {
- comp = mountWithIntl();
- if (update) comp.update();
- });
- if (update) {
- await waitForPromises();
- comp.update();
- }
- return comp;
-}
-
-describe('Test of of Discover', () => {
- test('renders loading msg', async () => {
- const comp = await mountDoc();
- expect(findTestSubject(comp, 'doc-msg-loading').length).toBe(1);
- });
-
- test('renders IndexPattern notFound msg', async () => {
- const indexPatternGetter = jest.fn(() => Promise.reject({ savedObjectId: '007' }));
- const comp = await mountDoc(true, indexPatternGetter);
- expect(findTestSubject(comp, 'doc-msg-notFoundIndexPattern').length).toBe(1);
- });
-
- test('renders notFound msg', async () => {
- mockSearchApi.mockImplementation(() => throwError({ status: 404 }));
- const comp = await mountDoc(true);
- expect(findTestSubject(comp, 'doc-msg-notFound').length).toBe(1);
- });
-
- test('renders error msg', async () => {
- mockSearchApi.mockImplementation(() => throwError({ error: 'something else' }));
- const comp = await mountDoc(true);
- expect(findTestSubject(comp, 'doc-msg-error').length).toBe(1);
- });
-
- test('renders opensearch hit ', async () => {
- mockSearchApi.mockImplementation(() =>
- of({ rawResponse: { hits: { total: 1, hits: [{ _id: 1, _source: { test: 1 } }] } } })
- );
- const comp = await mountDoc(true);
- expect(findTestSubject(comp, 'doc-hit').length).toBe(1);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/doc/doc.tsx b/src/plugins/discover_legacy/public/application/components/doc/doc.tsx
deleted file mode 100644
index 204a16d64757..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc/doc.tsx
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-import { EuiCallOut, EuiLink, EuiLoadingSpinner, EuiPageContent } from '@elastic/eui';
-import { IndexPatternsContract } from 'src/plugins/data/public';
-import { OpenSearchRequestState, useOpenSearchDocSearch } from './use_opensearch_doc_search';
-import { DocViewer } from '../doc_viewer/doc_viewer';
-
-export interface DocProps {
- /**
- * Id of the doc in OpenSearch
- */
- id: string;
- /**
- * Index in OpenSearch to query
- */
- index: string;
- /**
- * IndexPattern ID used to get IndexPattern entity
- * that's used for adding additional fields (stored_fields, script_fields, docvalue_fields)
- */
- indexPatternId: string;
- /**
- * IndexPatternService to get a given index pattern by ID
- */
- indexPatternService: IndexPatternsContract;
-}
-
-export function Doc(props: DocProps) {
- const [reqState, hit, indexPattern] = useOpenSearchDocSearch(props);
- return (
-
-
- {reqState === OpenSearchRequestState.NotFoundIndexPattern && (
-
- }
- />
- )}
- {reqState === OpenSearchRequestState.NotFound && (
-
- }
- >
-
-
- )}
-
- {reqState === OpenSearchRequestState.Error && (
-
- }
- >
- {' '}
-
-
-
-
- )}
-
- {reqState === OpenSearchRequestState.Loading && (
-
- {' '}
-
-
- )}
-
- {reqState === OpenSearchRequestState.Found && hit !== null && indexPattern && (
-
-
-
- )}
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.test.tsx b/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.test.tsx
deleted file mode 100644
index cb716a4f17cb..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.test.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { renderHook, act } from '@testing-library/react-hooks';
-import {
- buildSearchBody,
- useOpenSearchDocSearch,
- OpenSearchRequestState,
-} from './use_opensearch_doc_search';
-import { DocProps } from './doc';
-import { Observable } from 'rxjs';
-
-const mockSearchResult = new Observable();
-
-jest.mock('../../../opensearch_dashboards_services', () => ({
- getServices: () => ({
- data: {
- search: {
- search: jest.fn(() => {
- return mockSearchResult;
- }),
- },
- },
- }),
-}));
-
-describe('Test of helper / hook', () => {
- test('buildSearchBody', () => {
- const indexPattern = {
- getComputedFields: () => ({ storedFields: [], scriptFields: [], docvalueFields: [] }),
- } as any;
- const actual = buildSearchBody('1', indexPattern);
- expect(actual).toMatchInlineSnapshot(`
- Object {
- "_source": true,
- "docvalue_fields": Array [],
- "query": Object {
- "ids": Object {
- "values": Array [
- "1",
- ],
- },
- },
- "script_fields": Array [],
- "stored_fields": Array [],
- }
- `);
- });
-
- test('useOpenSearchDocSearch', async () => {
- const indexPattern = {
- getComputedFields: () => [],
- };
- const indexPatternService = {
- get: jest.fn(() => Promise.resolve(indexPattern)),
- } as any;
- const props = {
- id: '1',
- index: 'index1',
- indexPatternId: 'xyz',
- indexPatternService,
- } as DocProps;
- let hook;
- await act(async () => {
- hook = renderHook((p: DocProps) => useOpenSearchDocSearch(p), { initialProps: props });
- });
- // @ts-ignore
- expect(hook.result.current).toEqual([OpenSearchRequestState.Loading, null, indexPattern]);
- expect(indexPatternService.get).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.ts b/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.ts
deleted file mode 100644
index b5ca9fec1c2f..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc/use_opensearch_doc_search.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { useEffect, useState } from 'react';
-import { IndexPattern, getServices } from '../../../opensearch_dashboards_services';
-import { DocProps } from './doc';
-import { OpenSearchSearchHit } from '../../doc_views/doc_views_types';
-
-export enum OpenSearchRequestState {
- Loading,
- NotFound,
- Found,
- Error,
- NotFoundIndexPattern,
-}
-
-/**
- * helper function to build a query body for OpenSearch
- * https://opensearch.org/docs/latest/opensearch/query-dsl/index/
- */
-export function buildSearchBody(id: string, indexPattern: IndexPattern): Record {
- const computedFields = indexPattern.getComputedFields();
-
- return {
- query: {
- ids: {
- values: [id],
- },
- },
- stored_fields: computedFields.storedFields,
- _source: true,
- script_fields: computedFields.scriptFields,
- docvalue_fields: computedFields.docvalueFields,
- };
-}
-
-/**
- * Custom react hook for querying a single doc in OpenSearch
- */
-export function useOpenSearchDocSearch({
- id,
- index,
- indexPatternId,
- indexPatternService,
-}: DocProps): [OpenSearchRequestState, OpenSearchSearchHit | null, IndexPattern | null] {
- const [indexPattern, setIndexPattern] = useState(null);
- const [status, setStatus] = useState(OpenSearchRequestState.Loading);
- const [hit, setHit] = useState(null);
-
- useEffect(() => {
- async function requestData() {
- try {
- const indexPatternEntity = await indexPatternService.get(indexPatternId);
- setIndexPattern(indexPatternEntity);
-
- const { rawResponse } = await getServices()
- .data.search.search({
- dataSourceId: indexPatternEntity.dataSourceRef?.id,
- params: {
- index,
- body: buildSearchBody(id, indexPatternEntity),
- },
- })
- .toPromise();
-
- const hits = rawResponse.hits;
-
- if (hits?.hits?.[0]) {
- setStatus(OpenSearchRequestState.Found);
- setHit(hits.hits[0]);
- } else {
- setStatus(OpenSearchRequestState.NotFound);
- }
- } catch (err) {
- if (err.savedObjectId) {
- setStatus(OpenSearchRequestState.NotFoundIndexPattern);
- } else if (err.status === 404) {
- setStatus(OpenSearchRequestState.NotFound);
- } else {
- setStatus(OpenSearchRequestState.Error);
- }
- }
- }
- requestData();
- }, [id, index, indexPatternId, indexPatternService]);
- return [status, hit, indexPattern];
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap
deleted file mode 100644
index cc1647fe264e..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap
+++ /dev/null
@@ -1,56 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Render with 3 different tabs 1`] = `
-
- ,
- "id": "osd_doc_viewer_tab_0",
- "name": "Render function",
- },
- Object {
- "content": ,
- "id": "osd_doc_viewer_tab_1",
- "name": "React component",
- },
- Object {
- "content": ,
- "id": "osd_doc_viewer_tab_2",
- "name": "Invalid doc view",
- },
- ]
- }
- />
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap
deleted file mode 100644
index 31509659ce41..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap
+++ /dev/null
@@ -1,20 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Mounting and unmounting DocViewerRenderTab 1`] = `
-[MockFunction] {
- "calls": Array [
- Array [
- ,
- Object {
- "hit": Object {},
- },
- ],
- ],
- "results": Array [
- Object {
- "type": "return",
- "value": [MockFunction],
- },
- ],
-}
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.scss b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.scss
deleted file mode 100644
index 91b66fc84297..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.scss
+++ /dev/null
@@ -1,72 +0,0 @@
-.osdDocViewerTable {
- margin-top: $euiSizeS;
-}
-
-.osdDocViewer {
- pre,
- .osdDocViewer__value {
- display: inline-block;
- word-break: break-all;
- word-wrap: break-word;
- white-space: pre-wrap;
- color: $euiColorFullShade;
- vertical-align: top;
- padding-top: 2px;
- }
-
- .osdDocViewer__field {
- padding-top: 8px;
- }
-
- .dscFieldName {
- color: $euiColorDarkShade;
- }
-
- td,
- pre {
- font-family: $euiCodeFontFamily;
- }
-
- tr:first-child td {
- border-top-color: transparent;
- }
-
- tr:hover {
- .osdDocViewer__actionButton {
- opacity: 1;
- }
- }
-}
-
-.osdDocViewer__buttons,
-.osdDocViewer__field {
- white-space: nowrap;
-}
-
-.osdDocViewer__buttons {
- width: 60px;
-
- // Show all icons if one is focused,
- // IE doesn't support, but the fallback is just the focused button becomes visible
- &:focus-within {
- .osdDocViewer__actionButton {
- opacity: 1;
- }
- }
-}
-
-.osdDocViewer__field {
- width: 160px;
-}
-
-.osdDocViewer__actionButton {
- opacity: 0;
-
- &:focus {
- opacity: 1;
- }
-}
-
-.osdDocViewer__warning {
- margin-right: $euiSizeS;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.test.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.test.tsx
deleted file mode 100644
index ccab0be41ed2..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.test.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mount, shallow } from 'enzyme';
-import { DocViewer } from './doc_viewer';
-import { findTestSubject } from 'test_utils/helpers';
-import { getDocViewsRegistry } from '../../../opensearch_dashboards_services';
-import { DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-jest.mock('../../../opensearch_dashboards_services', () => {
- let registry: any[] = [];
- return {
- getDocViewsRegistry: () => ({
- addDocView(view: any) {
- registry.push(view);
- },
- getDocViewsSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- }),
- };
-});
-
-beforeEach(() => {
- (getDocViewsRegistry() as any).resetRegistry();
- jest.clearAllMocks();
-});
-
-test('Render with 3 different tabs', () => {
- const registry = getDocViewsRegistry();
- registry.addDocView({ order: 10, title: 'Render function', render: jest.fn() });
- registry.addDocView({ order: 20, title: 'React component', component: () => test
});
- registry.addDocView({ order: 30, title: 'Invalid doc view' });
-
- const renderProps = { hit: {} } as DocViewRenderProps;
-
- const wrapper = shallow();
-
- expect(wrapper).toMatchSnapshot();
-});
-
-test('Render with 1 tab displaying error message', () => {
- function SomeComponent() {
- // this is just a placeholder
- return null;
- }
-
- const registry = getDocViewsRegistry();
- registry.addDocView({
- order: 10,
- title: 'React component',
- component: SomeComponent,
- });
-
- const renderProps = { hit: {} } as DocViewRenderProps;
- const errorMsg = 'Catch me if you can!';
-
- const wrapper = mount();
- const error = new Error(errorMsg);
- wrapper.find(SomeComponent).simulateError(error);
- const errorMsgComponent = findTestSubject(wrapper, 'docViewerError');
- expect(errorMsgComponent.text()).toMatch(new RegExp(`${errorMsg}`));
-});
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.tsx
deleted file mode 100644
index d165c9bd05b8..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import './doc_viewer.scss';
-import React from 'react';
-import { EuiTabbedContent } from '@elastic/eui';
-import { getDocViewsRegistry } from '../../../opensearch_dashboards_services';
-import { DocViewerTab } from './doc_viewer_tab';
-import { DocView, DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-/**
- * Rendering tabs with different views of 1 OpenSearch hit in Discover.
- * The tabs are provided by the `docs_views` registry.
- * A view can contain a React `component`, or any JS framework by using
- * a `render` function.
- */
-export function DocViewer(renderProps: DocViewRenderProps) {
- const docViewsRegistry = getDocViewsRegistry();
- const tabs = docViewsRegistry
- .getDocViewsSorted(renderProps.hit)
- .map(({ title, render, component }: DocView, idx: number) => {
- return {
- id: `osd_doc_viewer_tab_${idx}`,
- name: title,
- content: (
-
- ),
- };
- });
-
- if (!tabs.length) {
- // There there's a minimum of 2 tabs active in Discover.
- // This condition takes care of unit tests with 0 tabs.
- return null;
- }
-
- return (
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_error.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_error.tsx
deleted file mode 100644
index 1cb14d191a57..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_error.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiCallOut, EuiCodeBlock } from '@elastic/eui';
-import { formatMsg, formatStack } from '../../../../../opensearch_dashboards_legacy/public';
-
-interface Props {
- error: Error | string;
-}
-
-export function DocViewerError({ error }: Props) {
- const errMsg = formatMsg(error);
- const errStack = typeof error === 'object' ? formatStack(error) : '';
-
- return (
-
- {errStack && {errStack}}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.test.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.test.tsx
deleted file mode 100644
index 83d857b24fc5..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.test.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mount } from 'enzyme';
-import { DocViewRenderTab } from './doc_viewer_render_tab';
-import { DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-test('Mounting and unmounting DocViewerRenderTab', () => {
- const unmountFn = jest.fn();
- const renderFn = jest.fn(() => unmountFn);
- const renderProps = {
- hit: {},
- };
-
- const wrapper = mount(
-
- );
-
- expect(renderFn).toMatchSnapshot();
-
- wrapper.unmount();
-
- expect(unmountFn).toBeCalled();
-});
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.tsx
deleted file mode 100644
index edc7f40c5e43..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_render_tab.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useRef, useEffect } from 'react';
-import { DocViewRenderFn, DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-interface Props {
- render: DocViewRenderFn;
- renderProps: DocViewRenderProps;
-}
-/**
- * Responsible for rendering a tab provided by a render function.
- * So any other framework can be used (E.g. legacy Angular 3rd party plugin code)
- * The provided `render` function is called with a reference to the
- * component's `HTMLDivElement` as 1st arg and `renderProps` as 2nd arg
- */
-export function DocViewRenderTab({ render, renderProps }: Props) {
- const ref = useRef(null);
- useEffect(() => {
- if (ref && ref.current) {
- return render(ref.current, renderProps);
- }
- }, [render, renderProps]);
- return ;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_tab.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_tab.tsx
deleted file mode 100644
index 6e7a5f1ac434..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer_tab.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { I18nProvider } from '@osd/i18n/react';
-import { DocViewRenderTab } from './doc_viewer_render_tab';
-import { DocViewerError } from './doc_viewer_render_error';
-import { DocViewRenderFn, DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-interface Props {
- component?: React.ComponentType;
- id: number;
- render?: DocViewRenderFn;
- renderProps: DocViewRenderProps;
- title: string;
-}
-
-interface State {
- error: Error | string;
- hasError: boolean;
-}
-/**
- * Renders the tab content of a doc view.
- * Displays an error message when it encounters exceptions, thanks to
- * Error Boundaries.
- */
-export class DocViewerTab extends React.Component {
- state = {
- hasError: false,
- error: '',
- };
-
- static getDerivedStateFromError(error: unknown) {
- // Update state so the next render will show the fallback UI.
- return { hasError: true, error };
- }
-
- shouldComponentUpdate(nextProps: Props, nextState: State) {
- return (
- nextProps.renderProps.hit._id !== this.props.renderProps.hit._id ||
- nextProps.id !== this.props.id ||
- nextState.hasError
- );
- }
-
- render() {
- const { component, render, renderProps, title } = this.props;
- const { hasError, error } = this.state;
-
- if (hasError && error) {
- return ;
- } else if (!render && !component) {
- return (
-
- );
- }
-
- if (render) {
- // doc view is provided by a render function, e.g. for legacy Angular code
- return ;
- }
-
- // doc view is provided by a react component
-
- const Component = component as any;
- return (
-
-
-
- );
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap
deleted file mode 100644
index 95fb0c377180..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap
+++ /dev/null
@@ -1,34 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Dont Render if generateCb.hide 1`] = `
-
-`;
-
-exports[`Render with 2 different links 1`] = `
-
-
-
-
-
-
-
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.test.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.test.tsx
deleted file mode 100644
index 8aba555b3a37..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.test.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import React from 'react';
-import { shallow } from 'enzyme';
-import { DocViewerLinks } from './doc_viewer_links';
-import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services';
-import { DocViewLinkRenderProps } from '../../doc_views_links/doc_views_links_types';
-
-jest.mock('../../../opensearch_dashboards_services', () => {
- let registry: any[] = [];
- return {
- getDocViewsLinksRegistry: () => ({
- addDocViewLink(view: any) {
- registry.push(view);
- },
- getDocViewsLinksSorted() {
- return registry;
- },
- resetRegistry: () => {
- registry = [];
- },
- }),
- };
-});
-
-beforeEach(() => {
- (getDocViewsLinksRegistry() as any).resetRegistry();
- jest.clearAllMocks();
-});
-
-test('Render with 2 different links', () => {
- const registry = getDocViewsLinksRegistry();
- registry.addDocViewLink({
- order: 10,
- label: 'generateCb link',
- generateCb: () => ({
- url: 'aaa',
- }),
- });
- registry.addDocViewLink({ order: 20, label: 'href link', href: 'bbb' });
-
- const renderProps = { hit: {} } as DocViewLinkRenderProps;
-
- const wrapper = shallow();
-
- expect(wrapper).toMatchSnapshot();
-});
-
-test('Dont Render if generateCb.hide', () => {
- const registry = getDocViewsLinksRegistry();
- registry.addDocViewLink({
- order: 10,
- label: 'generateCb link',
- generateCb: () => ({
- url: 'aaa',
- hide: true,
- }),
- });
-
- const renderProps = { hit: {} } as DocViewLinkRenderProps;
-
- const wrapper = shallow();
-
- expect(wrapper).toMatchSnapshot();
-});
diff --git a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.tsx b/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.tsx
deleted file mode 100644
index 9efb0693fde6..000000000000
--- a/src/plugins/discover_legacy/public/application/components/doc_viewer_links/doc_viewer_links.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import React from 'react';
-import { EuiFlexGroup, EuiFlexItem, EuiListGroupItem, EuiListGroupItemProps } from '@elastic/eui';
-import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services';
-import { DocViewLinkRenderProps } from '../../doc_views_links/doc_views_links_types';
-
-export function DocViewerLinks(renderProps: DocViewLinkRenderProps) {
- const listItems = getDocViewsLinksRegistry()
- .getDocViewsLinksSorted()
- .filter((item) => !(item.generateCb && item.generateCb(renderProps)?.hide))
- .map((item) => {
- const { generateCb, href, ...props } = item;
- const listItem: EuiListGroupItemProps = {
- 'data-test-subj': 'docTableRowAction',
- ...props,
- href: generateCb ? generateCb(renderProps).url : href,
- };
-
- return listItem;
- });
-
- return (
-
- {listItems.map((item, index) => (
-
-
-
- ))}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/field_name/__snapshots__/field_name.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/field_name/__snapshots__/field_name.test.tsx.snap
deleted file mode 100644
index cfd81a66acae..000000000000
--- a/src/plugins/discover_legacy/public/application/components/field_name/__snapshots__/field_name.test.tsx.snap
+++ /dev/null
@@ -1,94 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`FieldName renders a geo field, useShortDots is set to true 1`] = `
-
-
-
-
-
-
-
-
-
- t.t.test
-
-
-
-
-`;
-
-exports[`FieldName renders a number field by providing a field record, useShortDots is set to false 1`] = `
-
-
-
-
-
-
-
-
-
- test.test.test
-
-
-
-
-`;
-
-exports[`FieldName renders a string field by providing fieldType and fieldName 1`] = `
-
-
-
-
-
-
-
-
-
- test
-
-
-
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/field_name/field_name.test.tsx b/src/plugins/discover_legacy/public/application/components/field_name/field_name.test.tsx
deleted file mode 100644
index 54dc902837d0..000000000000
--- a/src/plugins/discover_legacy/public/application/components/field_name/field_name.test.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { render } from 'enzyme';
-import { FieldName } from './field_name';
-
-// Note that it currently provides just 2 basic tests, there should be more, but
-// the components involved will soon change
-test('FieldName renders a string field by providing fieldType and fieldName', () => {
- const component = render();
- expect(component).toMatchSnapshot();
-});
-
-test('FieldName renders a number field by providing a field record, useShortDots is set to false', () => {
- const component = render();
- expect(component).toMatchSnapshot();
-});
-
-test('FieldName renders a geo field, useShortDots is set to true', () => {
- const component = render(
-
- );
- expect(component).toMatchSnapshot();
-});
diff --git a/src/plugins/discover_legacy/public/application/components/field_name/field_name.tsx b/src/plugins/discover_legacy/public/application/components/field_name/field_name.tsx
deleted file mode 100644
index bbd9ab79d0fb..000000000000
--- a/src/plugins/discover_legacy/public/application/components/field_name/field_name.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
-
-import { FieldIcon, FieldIconProps } from '../../../../../opensearch_dashboards_react/public';
-import { shortenDottedString } from '../../helpers';
-import { getFieldTypeName } from './field_type_name';
-
-// properties fieldType and fieldName are provided in osd_doc_view
-// this should be changed when both components are deangularized
-interface Props {
- fieldName: string;
- fieldType: string;
- useShortDots?: boolean;
- fieldIconProps?: Omit;
- scripted?: boolean;
-}
-
-export function FieldName({
- fieldName,
- fieldType,
- useShortDots,
- fieldIconProps,
- scripted = false,
-}: Props) {
- const typeName = getFieldTypeName(fieldType);
- const displayName = useShortDots ? shortenDottedString(fieldName) : fieldName;
-
- return (
-
-
-
-
-
-
- {displayName}
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/field_name/field_type_name.ts b/src/plugins/discover_legacy/public/application/components/field_name/field_type_name.ts
deleted file mode 100644
index 38b18792d3e4..000000000000
--- a/src/plugins/discover_legacy/public/application/components/field_name/field_type_name.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-
-export function getFieldTypeName(type: string) {
- switch (type) {
- case 'boolean':
- return i18n.translate('discover.fieldNameIcons.booleanAriaLabel', {
- defaultMessage: 'Boolean field',
- });
- case 'conflict':
- return i18n.translate('discover.fieldNameIcons.conflictFieldAriaLabel', {
- defaultMessage: 'Conflicting field',
- });
- case 'date':
- return i18n.translate('discover.fieldNameIcons.dateFieldAriaLabel', {
- defaultMessage: 'Date field',
- });
- case 'geo_point':
- return i18n.translate('discover.fieldNameIcons.geoPointFieldAriaLabel', {
- defaultMessage: 'Geo point field',
- });
- case 'geo_shape':
- return i18n.translate('discover.fieldNameIcons.geoShapeFieldAriaLabel', {
- defaultMessage: 'Geo shape field',
- });
- case 'ip':
- return i18n.translate('discover.fieldNameIcons.ipAddressFieldAriaLabel', {
- defaultMessage: 'IP address field',
- });
- case 'murmur3':
- return i18n.translate('discover.fieldNameIcons.murmur3FieldAriaLabel', {
- defaultMessage: 'Murmur3 field',
- });
- case 'number':
- return i18n.translate('discover.fieldNameIcons.numberFieldAriaLabel', {
- defaultMessage: 'Number field',
- });
- case 'source':
- // Note that this type is currently not provided, type for _source is undefined
- return i18n.translate('discover.fieldNameIcons.sourceFieldAriaLabel', {
- defaultMessage: 'Source field',
- });
- case 'string':
- return i18n.translate('discover.fieldNameIcons.stringFieldAriaLabel', {
- defaultMessage: 'String field',
- });
- case 'nested':
- return i18n.translate('discover.fieldNameIcons.nestedFieldAriaLabel', {
- defaultMessage: 'Nested field',
- });
- default:
- return i18n.translate('discover.fieldNameIcons.unknownFieldAriaLabel', {
- defaultMessage: 'Unknown field',
- });
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/components/help_menu/help_menu_util.js b/src/plugins/discover_legacy/public/application/components/help_menu/help_menu_util.js
deleted file mode 100644
index 39ea94046d7c..000000000000
--- a/src/plugins/discover_legacy/public/application/components/help_menu/help_menu_util.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-import { getServices } from '../../../opensearch_dashboards_services';
-const { docLinks } = getServices();
-
-export function addHelpMenuToAppChrome(chrome) {
- chrome.setHelpExtension({
- appName: i18n.translate('discover.helpMenu.appName', {
- defaultMessage: 'Discover',
- }),
- links: [
- {
- linkType: 'documentation',
- href: `${docLinks.links.opensearchDashboards.introduction}`,
- },
- ],
- });
-}
diff --git a/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.test.tsx b/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.test.tsx
deleted file mode 100644
index 998ababbc47f..000000000000
--- a/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.test.tsx
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { HitsCounter, HitsCounterProps } from './hits_counter';
-import { findTestSubject } from 'test_utils/helpers';
-
-describe('hits counter', function () {
- let props: HitsCounterProps;
- let component: ReactWrapper;
-
- beforeAll(() => {
- props = {
- onResetQuery: jest.fn(),
- showResetButton: true,
- hits: 2,
- };
- });
-
- it('HitsCounter renders a button by providing the showResetButton property', () => {
- component = mountWithIntl();
- expect(findTestSubject(component, 'resetSavedSearch').length).toBe(1);
- });
-
- it('HitsCounter not renders a button when the showResetButton property is false', () => {
- component = mountWithIntl(
-
- );
- expect(findTestSubject(component, 'resetSavedSearch').length).toBe(0);
- });
-
- it('expect to render the number of hits', function () {
- component = mountWithIntl();
- const hits = findTestSubject(component, 'discoverQueryHits');
- expect(hits.text()).toBe('2');
- });
-
- it('expect to render 1,899 hits if 1899 hits given', function () {
- component = mountWithIntl(
-
- );
- const hits = findTestSubject(component, 'discoverQueryHits');
- expect(hits.text()).toBe('1,899');
- });
-
- it('should reset query', function () {
- component = mountWithIntl();
- findTestSubject(component, 'resetSavedSearch').simulate('click');
- expect(props.onResetQuery).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.tsx b/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.tsx
deleted file mode 100644
index 3355b733202b..000000000000
--- a/src/plugins/discover_legacy/public/application/components/hits_counter/hits_counter.tsx
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-import { i18n } from '@osd/i18n';
-import { formatNumWithCommas } from '../../helpers';
-
-export interface HitsCounterProps {
- /**
- * the number of query hits
- */
- hits: number;
- /**
- * displays the reset button
- */
- showResetButton: boolean;
- /**
- * resets the query
- */
- onResetQuery: () => void;
-}
-
-export function HitsCounter({ hits, showResetButton, onResetQuery }: HitsCounterProps) {
- return (
-
-
-
-
- {formatNumWithCommas(hits)}{' '}
-
-
-
- {showResetButton && (
-
-
-
-
-
- )}
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/hits_counter/index.ts b/src/plugins/discover_legacy/public/application/components/hits_counter/index.ts
deleted file mode 100644
index 213cf96e0cc8..000000000000
--- a/src/plugins/discover_legacy/public/application/components/hits_counter/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { HitsCounter } from './hits_counter';
diff --git a/src/plugins/discover_legacy/public/application/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap
deleted file mode 100644
index 3897e22c50f1..000000000000
--- a/src/plugins/discover_legacy/public/application/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap
+++ /dev/null
@@ -1,20 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`returns the \`JsonCodeEditor\` component 1`] = `
-
- {
- "_index": "test",
- "_type": "doc",
- "_id": "foo",
- "_score": 1,
- "_source": {
- "test": 123
- }
-}
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.test.tsx b/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.test.tsx
deleted file mode 100644
index 2cb700b4d2ac..000000000000
--- a/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.test.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { shallow } from 'enzyme';
-import { JsonCodeBlock } from './json_code_block';
-import { IndexPattern } from '../../../../../data/public';
-
-it('returns the `JsonCodeEditor` component', () => {
- const props = {
- hit: { _index: 'test', _type: 'doc', _id: 'foo', _score: 1, _source: { test: 123 } },
- columns: [],
- indexPattern: {} as IndexPattern,
- filter: jest.fn(),
- onAddColumn: jest.fn(),
- onRemoveColumn: jest.fn(),
- };
- expect(shallow()).toMatchSnapshot();
-});
diff --git a/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.tsx b/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.tsx
deleted file mode 100644
index f33cae438cb2..000000000000
--- a/src/plugins/discover_legacy/public/application/components/json_code_block/json_code_block.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiCodeBlock } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-import { DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-export function JsonCodeBlock({ hit }: DocViewRenderProps) {
- const label = i18n.translate('discover.docViews.json.codeEditorAriaLabel', {
- defaultMessage: 'Read only JSON view of an opensearch document',
- });
- return (
-
- {JSON.stringify(hit, null, 2)}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.test.tsx b/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.test.tsx
deleted file mode 100644
index fbc98e2550e0..000000000000
--- a/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.test.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { LoadingSpinner } from './loading_spinner';
-import { findTestSubject } from 'test_utils/helpers';
-
-describe('loading spinner', function () {
- let component: ReactWrapper;
-
- it('LoadingSpinner renders a Searching text and a spinner', () => {
- component = mountWithIntl();
- expect(findTestSubject(component, 'loadingSpinnerText').text()).toBe('Searching');
- expect(findTestSubject(component, 'loadingSpinner').length).toBe(1);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.tsx b/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.tsx
deleted file mode 100644
index 697c7a136d60..000000000000
--- a/src/plugins/discover_legacy/public/application/components/loading_spinner/loading_spinner.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiLoadingSpinner, EuiTitle, EuiSpacer } from '@elastic/eui';
-import { FormattedMessage } from '@osd/i18n/react';
-
-export function LoadingSpinner() {
- return (
- <>
-
-
-
-
-
-
-
- >
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/__snapshots__/discover_index_pattern.test.tsx.snap b/src/plugins/discover_legacy/public/application/components/sidebar/__snapshots__/discover_index_pattern.test.tsx.snap
deleted file mode 100644
index 42c11152e263..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/__snapshots__/discover_index_pattern.test.tsx.snap
+++ /dev/null
@@ -1,3 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`DiscoverIndexPattern Invalid props dont cause an exception: "" 1`] = `""`;
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/change_indexpattern.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/change_indexpattern.tsx
deleted file mode 100644
index 553031f06721..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/change_indexpattern.tsx
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-import React, { useState } from 'react';
-import {
- EuiButtonEmpty,
- EuiPopover,
- EuiPopoverTitle,
- EuiSelectable,
- EuiButtonEmptyProps,
-} from '@elastic/eui';
-import { EuiSelectableProps } from '@elastic/eui/src/components/selectable/selectable';
-import { IndexPatternRef } from './types';
-
-export type ChangeIndexPatternTriggerProps = EuiButtonEmptyProps & {
- label: string;
- title?: string;
-};
-
-export function ChangeIndexPattern({
- indexPatternRefs,
- indexPatternId,
- onChangeIndexPattern,
- trigger,
- selectableProps,
-}: {
- trigger: ChangeIndexPatternTriggerProps;
- indexPatternRefs: IndexPatternRef[];
- onChangeIndexPattern: (newId: string) => void;
- indexPatternId?: string;
- selectableProps?: EuiSelectableProps;
-}) {
- const [isPopoverOpen, setPopoverIsOpen] = useState(false);
-
- const createTrigger = function () {
- const { label, title, ...rest } = trigger;
- return (
- setPopoverIsOpen(!isPopoverOpen)}
- {...rest}
- >
- {label}
-
- );
- };
-
- return (
- setPopoverIsOpen(false)}
- className="eui-textTruncate"
- anchorClassName="eui-textTruncate"
- display="block"
- panelPaddingSize="s"
- ownFocus
- >
-
-
- {i18n.translate('discover.fieldChooser.indexPattern.changeIndexPatternTitle', {
- defaultMessage: 'Change index pattern',
- })}
-
- ({
- label: title,
- key: id,
- value: id,
- checked: id === indexPatternId ? 'on' : undefined,
- }))}
- onChange={(choices) => {
- const choice = (choices.find(({ checked }) => checked) as unknown) as {
- value: string;
- };
- onChangeIndexPattern(choice.value);
- setPopoverIsOpen(false);
- }}
- searchProps={{
- compressed: true,
- ...(selectableProps ? selectableProps.searchProps : undefined),
- }}
- >
- {(list, search) => (
- <>
- {search}
- {list}
- >
- )}
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.scss b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.scss
deleted file mode 100644
index 8e1dd41f66ab..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-.dscSidebarItem__fieldPopoverPanel {
- min-width: 260px;
- max-width: 300px;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.test.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.test.tsx
deleted file mode 100644
index 1b384a4b5550..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.test.tsx
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-// @ts-ignore
-import { findTestSubject } from '@elastic/eui/lib/test';
-// @ts-ignore
-import stubbedLogstashFields from 'fixtures/logstash_fields';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { DiscoverField } from './discover_field';
-import { coreMock } from '../../../../../../core/public/mocks';
-import { IndexPatternField } from '../../../../../data/public';
-import { getStubIndexPattern } from '../../../../../data/public/test_utils';
-
-jest.mock('../../../opensearch_dashboards_services', () => ({
- getServices: () => ({
- history: () => ({
- location: {
- search: '',
- },
- }),
- capabilities: {
- visualize: {
- show: true,
- },
- },
- uiSettings: {
- get: (key: string) => {
- if (key === 'fields:popularLimit') {
- return 5;
- } else if (key === 'shortDots:enable') {
- return false;
- }
- },
- },
- }),
-}));
-
-function getComponent({
- selected = false,
- showDetails = false,
- useShortDots = false,
- field,
-}: {
- selected?: boolean;
- showDetails?: boolean;
- useShortDots?: boolean;
- field?: IndexPatternField;
-}) {
- const indexPattern = getStubIndexPattern(
- 'logstash-*',
- (cfg: any) => cfg,
- 'time',
- stubbedLogstashFields(),
- coreMock.createSetup()
- );
-
- const finalField =
- field ??
- new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
-
- const props = {
- indexPattern,
- columns: [],
- field: finalField,
- getDetails: jest.fn(() => ({ buckets: [], error: '', exists: 1, total: 1 })),
- onAddFilter: jest.fn(),
- onAddField: jest.fn(),
- onRemoveField: jest.fn(),
- showDetails,
- selected,
- useShortDots,
- };
- const comp = mountWithIntl();
- return { comp, props };
-}
-
-describe('discover sidebar field', function () {
- it('should allow selecting fields', function () {
- const { comp, props } = getComponent({});
- findTestSubject(comp, 'fieldToggle-bytes').simulate('click');
- expect(props.onAddField).toHaveBeenCalledWith('bytes');
- });
- it('should allow deselecting fields', function () {
- const { comp, props } = getComponent({ selected: true });
- findTestSubject(comp, 'fieldToggle-bytes').simulate('click');
- expect(props.onRemoveField).toHaveBeenCalledWith('bytes');
- });
- it('should trigger getDetails', function () {
- const { comp, props } = getComponent({ selected: true });
- findTestSubject(comp, 'field-bytes-showDetails').simulate('click');
- expect(props.getDetails).toHaveBeenCalledWith(props.field);
- });
- it('should not allow clicking on _source', function () {
- const field = new IndexPatternField(
- {
- name: '_source',
- type: '_source',
- esTypes: ['_source'],
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- '_source'
- );
- const { comp, props } = getComponent({
- selected: true,
- field,
- });
- findTestSubject(comp, 'field-_source-showDetails').simulate('click');
- expect(props.getDetails).not.toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.tsx
deleted file mode 100644
index e807267435eb..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field.tsx
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState } from 'react';
-import { EuiPopover, EuiPopoverTitle, EuiButtonIcon, EuiToolTip } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-import { DiscoverFieldDetails } from './discover_field_details';
-import { FieldIcon, FieldButton } from '../../../../../opensearch_dashboards_react/public';
-import { FieldDetails } from './types';
-import { IndexPatternField, IndexPattern } from '../../../../../data/public';
-import { shortenDottedString } from '../../helpers';
-import { getFieldTypeName } from './lib/get_field_type_name';
-import './discover_field.scss';
-
-export interface DiscoverFieldProps {
- /**
- * the selected columns displayed in the doc table in discover
- */
- columns: string[];
- /**
- * The displayed field
- */
- field: IndexPatternField;
- /**
- * The currently selected index pattern
- */
- indexPattern: IndexPattern;
- /**
- * Callback to add/select the field
- */
- onAddField: (fieldName: string) => void;
- /**
- * Callback to add a filter to filter bar
- */
- onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
- /**
- * Callback to remove/deselect a the field
- * @param fieldName
- */
- onRemoveField: (fieldName: string) => void;
- /**
- * Retrieve details data for the field
- */
- getDetails: (field: IndexPatternField) => FieldDetails;
- /**
- * Determines whether the field is selected
- */
- selected?: boolean;
- /**
- * Determines whether the field name is shortened test.sub1.sub2 = t.s.sub2
- */
- useShortDots?: boolean;
-}
-
-export function DiscoverField({
- columns,
- field,
- indexPattern,
- onAddField,
- onRemoveField,
- onAddFilter,
- getDetails,
- selected,
- useShortDots,
-}: DiscoverFieldProps) {
- const addLabelAria = i18n.translate('discover.fieldChooser.discoverField.addButtonAriaLabel', {
- defaultMessage: 'Add {field} to table',
- values: { field: field.name },
- });
- const removeLabelAria = i18n.translate(
- 'discover.fieldChooser.discoverField.removeButtonAriaLabel',
- {
- defaultMessage: 'Remove {field} from table',
- values: { field: field.name },
- }
- );
-
- const [infoIsOpen, setOpen] = useState(false);
-
- const toggleDisplay = (f: IndexPatternField) => {
- if (selected) {
- onRemoveField(f.name);
- } else {
- onAddField(f.name);
- }
- };
-
- function togglePopover() {
- setOpen(!infoIsOpen);
- }
-
- function wrapOnDot(str?: string) {
- // u200B is a non-width white-space character, which allows
- // the browser to efficiently word-wrap right after the dot
- // without us having to draw a lot of extra DOM elements, etc
- return str ? str.replace(/\./g, '.\u200B') : '';
- }
-
- const dscFieldIcon = (
-
- );
-
- const fieldName = (
-
- {useShortDots ? wrapOnDot(shortenDottedString(field.name)) : wrapOnDot(field.displayName)}
-
- );
-
- let actionButton;
- if (field.name !== '_source' && !selected) {
- actionButton = (
-
- ) => {
- if (ev.type === 'click') {
- ev.currentTarget.focus();
- }
- ev.preventDefault();
- ev.stopPropagation();
- toggleDisplay(field);
- }}
- data-test-subj={`fieldToggle-${field.name}`}
- aria-label={addLabelAria}
- />
-
- );
- } else if (field.name !== '_source' && selected) {
- actionButton = (
-
- ) => {
- if (ev.type === 'click') {
- ev.currentTarget.focus();
- }
- ev.preventDefault();
- ev.stopPropagation();
- toggleDisplay(field);
- }}
- data-test-subj={`fieldToggle-${field.name}`}
- aria-label={removeLabelAria}
- />
-
- );
- }
-
- if (field.type === '_source') {
- return (
-
- );
- }
-
- return (
- {
- togglePopover();
- }}
- dataTestSubj={`field-${field.name}-showDetails`}
- fieldIcon={dscFieldIcon}
- fieldAction={actionButton}
- fieldName={fieldName}
- />
- }
- isOpen={infoIsOpen}
- closePopover={() => setOpen(false)}
- anchorPosition="rightUp"
- panelClassName="dscSidebarItem__fieldPopoverPanel"
- >
-
- {' '}
- {i18n.translate('discover.fieldChooser.discoverField.fieldTopValuesLabel', {
- defaultMessage: 'Top 5 values',
- })}
-
- {infoIsOpen && (
-
- )}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.scss b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.scss
deleted file mode 100644
index 90b645f70084..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-.dscFieldDetails__barContainer {
- // Constrains value to the flex item, and allows for truncation when necessary
- min-width: 0;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.tsx
deleted file mode 100644
index 6a4dbe295e50..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_bucket.tsx
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiText, EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-import { StringFieldProgressBar } from './string_progress_bar';
-import { Bucket } from './types';
-import { IndexPatternField } from '../../../../../data/public';
-import './discover_field_bucket.scss';
-
-interface Props {
- bucket: Bucket;
- field: IndexPatternField;
- onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
-}
-
-export function DiscoverFieldBucket({ field, bucket, onAddFilter }: Props) {
- const emptyTxt = i18n.translate('discover.fieldChooser.detailViews.emptyStringText', {
- defaultMessage: 'Empty string',
- });
- const addLabel = i18n.translate('discover.fieldChooser.detailViews.filterValueButtonAriaLabel', {
- defaultMessage: 'Filter for {field}: "{value}"',
- values: { value: bucket.value, field: field.name },
- });
- const removeLabel = i18n.translate(
- 'discover.fieldChooser.detailViews.filterOutValueButtonAriaLabel',
- {
- defaultMessage: 'Filter out {field}: "{value}"',
- values: { value: bucket.value, field: field.name },
- }
- );
-
- return (
- <>
-
-
-
-
-
- {bucket.display === '' ? emptyTxt : bucket.display}
-
-
-
-
- {bucket.percent.toFixed(1)}%
-
-
-
-
-
- {field.filterable && (
-
-
- onAddFilter(field, bucket.value, '+')}
- aria-label={addLabel}
- data-test-subj={`plus-${field.name}-${bucket.value}`}
- style={{
- minHeight: 'auto',
- minWidth: 'auto',
- paddingRight: 2,
- paddingLeft: 2,
- paddingTop: 0,
- paddingBottom: 0,
- }}
- className={'euiButtonIcon--auto'}
- />
- onAddFilter(field, bucket.value, '-')}
- aria-label={removeLabel}
- data-test-subj={`minus-${field.name}-${bucket.value}`}
- style={{
- minHeight: 'auto',
- minWidth: 'auto',
- paddingTop: 0,
- paddingBottom: 0,
- paddingRight: 2,
- paddingLeft: 2,
- }}
- className={'euiButtonIcon--auto'}
- />
-
-
- )}
-
-
- >
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.scss b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.scss
deleted file mode 100644
index 7bf0892d0148..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.scss
+++ /dev/null
@@ -1,6 +0,0 @@
-.dscFieldDetails__visualizeBtn {
- @include euiFontSizeXS;
-
- height: $euiSizeL !important;
- min-width: $euiSize * 4;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.test.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.test.tsx
deleted file mode 100644
index 63d5c7ace303..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.test.tsx
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-// @ts-ignore
-import { findTestSubject } from '@elastic/eui/lib/test';
-import { act } from '@testing-library/react';
-// @ts-ignore
-import stubbedLogstashFields from 'fixtures/logstash_fields';
-import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
-import { DiscoverFieldDetails } from './discover_field_details';
-import { coreMock } from '../../../../../../core/public/mocks';
-import { IndexPatternField } from '../../../../../data/public';
-import { getStubIndexPattern } from '../../../../../data/public/test_utils';
-
-const mockGetHref = jest.fn();
-const mockGetTriggerCompatibleActions = jest.fn();
-
-jest.mock('../../../opensearch_dashboards_services', () => ({
- getUiActions: () => ({
- getTriggerCompatibleActions: mockGetTriggerCompatibleActions,
- }),
-}));
-
-const indexPattern = getStubIndexPattern(
- 'logstash-*',
- (cfg: any) => cfg,
- 'time',
- stubbedLogstashFields(),
- coreMock.createSetup()
-);
-
-describe('discover sidebar field details', function () {
- const defaultProps = {
- columns: [],
- details: { buckets: [], error: '', exists: 1, total: 1 },
- indexPattern,
- onAddFilter: jest.fn(),
- };
-
- beforeEach(() => {
- mockGetHref.mockReturnValue('/foo/bar');
- mockGetTriggerCompatibleActions.mockReturnValue([
- {
- getHref: mockGetHref,
- },
- ]);
- });
-
- function mountComponent(field: IndexPatternField, props?: Record) {
- const compProps = { ...defaultProps, ...props, field };
- return mountWithIntl();
- }
-
- it('should render buckets if they exist', async function () {
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const buckets = [1, 2, 3].map((n) => ({
- display: `display-${n}`,
- value: `value-${n}`,
- percent: 25,
- count: 100,
- }));
- const comp = mountComponent(visualizableField, {
- details: { ...defaultProps.details, buckets },
- });
- expect(findTestSubject(comp, 'fieldVisualizeError').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').children().length).toBe(
- buckets.length
- );
- // Visualize link should not be rendered until async hook update
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(0);
-
- // Complete async hook
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualizeError').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').children().length).toBe(
- buckets.length
- );
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(1);
- });
-
- it('should only render buckets if they exist', async function () {
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const comp = mountComponent(visualizableField);
- expect(findTestSubject(comp, 'fieldVisualizeContainer').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeError').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(0);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
-
- expect(findTestSubject(comp, 'fieldVisualizeContainer').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeError').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(1);
- });
-
- it('should render a details error', async function () {
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const errText = 'Some error';
- const comp = mountComponent(visualizableField, {
- details: { ...defaultProps.details, error: errText },
- });
- expect(findTestSubject(comp, 'fieldVisualizeContainer').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeBucketContainer').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualizeError').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualizeError').text()).toBe(errText);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(1);
- });
-
- it('should handle promise rejection from isFieldVisualizable', async function () {
- mockGetTriggerCompatibleActions.mockRejectedValue(new Error('Async error'));
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const comp = mountComponent(visualizableField);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(0);
- });
-
- it('should handle promise rejection from getVisualizeHref', async function () {
- mockGetHref.mockRejectedValue(new Error('Async error'));
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const comp = mountComponent(visualizableField);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(0);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(0);
- });
-
- it('should enable the visualize link for a number field', async function () {
- const visualizableField = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
- const comp = mountComponent(visualizableField);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualizeLink').length).toBe(1);
- expect(findTestSubject(comp, 'fieldVisualize-bytes').length).toBe(1);
- });
-
- it('should disable the visualize link for an _id field', async function () {
- expect.assertions(1);
- const conflictField = new IndexPatternField(
- {
- name: '_id',
- type: 'string',
- esTypes: ['_id'],
- count: 0,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'test'
- );
- const comp = mountComponent(conflictField);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualize-_id').length).toBe(0);
- });
-
- it('should disable the visualize link for an unknown field', async function () {
- const unknownField = new IndexPatternField(
- {
- name: 'test',
- type: 'unknown',
- esTypes: ['double'],
- count: 0,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'test'
- );
- const comp = mountComponent(unknownField);
-
- await act(async () => {
- await nextTick();
- comp.update();
- });
- expect(findTestSubject(comp, 'fieldVisualize-test').length).toBe(0);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.tsx
deleted file mode 100644
index 906c173ed07d..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_details.tsx
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState, useEffect } from 'react';
-import { EuiLink, EuiIconTip, EuiText, EuiPopoverFooter, EuiButton, EuiSpacer } from '@elastic/eui';
-import { FormattedMessage } from '@osd/i18n/react';
-import { DiscoverFieldBucket } from './discover_field_bucket';
-import { getWarnings } from './lib/get_warnings';
-import {
- triggerVisualizeActions,
- isFieldVisualizable,
- getVisualizeHref,
-} from './lib/visualize_trigger_utils';
-import { Bucket, FieldDetails } from './types';
-import { IndexPatternField, IndexPattern } from '../../../../../data/public';
-import './discover_field_details.scss';
-
-interface DiscoverFieldDetailsProps {
- columns: string[];
- details: FieldDetails;
- field: IndexPatternField;
- indexPattern: IndexPattern;
- onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
-}
-
-export function DiscoverFieldDetails({
- columns,
- details,
- field,
- indexPattern,
- onAddFilter,
-}: DiscoverFieldDetailsProps) {
- const warnings = getWarnings(field);
- const [showVisualizeLink, setShowVisualizeLink] = useState(false);
- const [visualizeLink, setVisualizeLink] = useState('');
-
- useEffect(() => {
- const checkIfVisualizable = async () => {
- const visualizable = await isFieldVisualizable(field, indexPattern.id, columns).catch(
- () => false
- );
-
- setShowVisualizeLink(visualizable);
- if (visualizable) {
- const href = await getVisualizeHref(field, indexPattern.id, columns).catch(() => '');
- setVisualizeLink(href || '');
- }
- };
- checkIfVisualizable();
- }, [field, indexPattern.id, columns]);
-
- const handleVisualizeLinkClick = (event: React.MouseEvent) => {
- // regular link click. let the uiActions code handle the navigation and show popup if needed
- event.preventDefault();
- triggerVisualizeActions(field, indexPattern.id, columns);
- };
-
- return (
- <>
-
- {details.error && (
-
- {details.error}
-
- )}
-
- {!details.error && details.buckets.length > 0 && (
-
- {details.buckets.map((bucket: Bucket, idx: number) => (
-
- ))}
-
- )}
-
- {showVisualizeLink && visualizeLink && (
-
-
- {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
- handleVisualizeLinkClick(e)}
- href={visualizeLink}
- size="s"
- className="dscFieldDetails__visualizeBtn"
- data-test-subj={`fieldVisualize-${field.name}`}
- >
-
-
- {warnings.length > 0 && (
-
- )}
-
- )}
-
- {!details.error && (
-
-
- {!indexPattern.metaFields.includes(field.name) && !field.scripted ? (
- onAddFilter('_exists_', field.name, '+')}>
- {' '}
- {details.exists}
-
- ) : (
- {details.exists}
- )}{' '}
- / {details.total}{' '}
-
-
-
- )}
- >
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.test.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.test.tsx
deleted file mode 100644
index f78505e11f1e..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.test.tsx
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { act } from 'react-dom/test-utils';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { findTestSubject } from 'test_utils/helpers';
-import { DiscoverFieldSearch, Props } from './discover_field_search';
-import { EuiButtonGroupProps, EuiPopover } from '@elastic/eui';
-import { ReactWrapper } from 'enzyme';
-
-describe('DiscoverFieldSearch', () => {
- const defaultProps = {
- onChange: jest.fn(),
- value: 'test',
- types: ['any', 'string', '_source'],
- };
-
- function mountComponent(props?: Props) {
- const compProps = props || defaultProps;
- return mountWithIntl();
- }
-
- function findButtonGroup(component: ReactWrapper, id: string) {
- return component.find(`[data-test-subj="${id}ButtonGroup"]`).first();
- }
-
- test('enter value', () => {
- const component = mountComponent();
- const input = findTestSubject(component, 'fieldFilterSearchInput');
- input.simulate('change', { target: { value: 'new filter' } });
- expect(defaultProps.onChange).toBeCalledTimes(1);
- });
-
- test('change in active filters should change facet selection and call onChange', () => {
- const onChange = jest.fn();
- const component = mountComponent({ ...defaultProps, ...{ onChange } });
- let btn = findTestSubject(component, 'toggleFieldFilterButton');
- expect(btn.hasClass('euiFacetButton--isSelected')).toBeFalsy();
- btn.simulate('click');
- const aggregatableButtonGroup = findButtonGroup(component, 'aggregatable');
- act(() => {
- // @ts-ignore
- (aggregatableButtonGroup.props() as EuiButtonGroupProps).onChange('aggregatable-true', null);
- });
- component.update();
- btn = findTestSubject(component, 'toggleFieldFilterButton');
- expect(btn.hasClass('euiFacetButton--isSelected')).toBe(true);
- expect(onChange).toBeCalledWith('aggregatable', true);
- });
-
- test('change in active filters should change filters count', () => {
- const component = mountComponent();
- let btn = findTestSubject(component, 'toggleFieldFilterButton');
- btn.simulate('click');
- btn = findTestSubject(component, 'toggleFieldFilterButton');
- const badge = btn.find('.euiNotificationBadge');
- // no active filters
- expect(badge.text()).toEqual('0');
- // change value of aggregatable select
- const aggregatableButtonGroup = findButtonGroup(component, 'aggregatable');
- act(() => {
- // @ts-ignore
- (aggregatableButtonGroup.props() as EuiButtonGroupProps).onChange('aggregatable-true', null);
- });
- component.update();
- expect(badge.text()).toEqual('1');
- // change value of searchable select
- const searchableButtonGroup = findButtonGroup(component, 'searchable');
- act(() => {
- // @ts-ignore
- (searchableButtonGroup.props() as EuiButtonGroupProps).onChange('searchable-true', null);
- });
- component.update();
- expect(badge.text()).toEqual('2');
- // change value of searchable select
- act(() => {
- // @ts-ignore
- (searchableButtonGroup.props() as EuiButtonGroupProps).onChange('searchable-any', null);
- });
- component.update();
- expect(badge.text()).toEqual('1');
- });
-
- test('change in missing fields switch should not change filter count', () => {
- const component = mountComponent();
- const btn = findTestSubject(component, 'toggleFieldFilterButton');
- btn.simulate('click');
- const badge = btn.find('.euiNotificationBadge');
- expect(badge.text()).toEqual('0');
- const missingSwitch = findTestSubject(component, 'missingSwitch');
- missingSwitch.simulate('change', { target: { value: false } });
- expect(badge.text()).toEqual('0');
- });
-
- test('change in filters triggers onChange', () => {
- const onChange = jest.fn();
- const component = mountComponent({ ...defaultProps, ...{ onChange } });
- const btn = findTestSubject(component, 'toggleFieldFilterButton');
- btn.simulate('click');
- const aggregtableButtonGroup = findButtonGroup(component, 'aggregatable');
- const missingSwitch = findTestSubject(component, 'missingSwitch');
- act(() => {
- // @ts-ignore
- (aggregtableButtonGroup.props() as EuiButtonGroupProps).onChange('aggregatable-true', null);
- });
- missingSwitch.simulate('click');
- expect(onChange).toBeCalledTimes(2);
- });
-
- test('change in type filters triggers onChange with appropriate value', () => {
- const onChange = jest.fn();
- const component = mountComponent({ ...defaultProps, ...{ onChange } });
- const btn = findTestSubject(component, 'toggleFieldFilterButton');
- btn.simulate('click');
- const typeSelector = findTestSubject(component, 'typeSelect');
- typeSelector.simulate('change', { target: { value: 'string' } });
- expect(onChange).toBeCalledWith('type', 'string');
- typeSelector.simulate('change', { target: { value: 'any' } });
- expect(onChange).toBeCalledWith('type', 'any');
- });
-
- test('click on filter button should open and close popover', () => {
- const component = mountComponent();
- const btn = findTestSubject(component, 'toggleFieldFilterButton');
- btn.simulate('click');
- let popover = component.find(EuiPopover);
- expect(popover.prop('isOpen')).toBe(true);
- btn.simulate('click');
- popover = component.find(EuiPopover);
- expect(popover.prop('isOpen')).toBe(false);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.tsx
deleted file mode 100644
index 4a1390cb1955..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_field_search.tsx
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { OptionHTMLAttributes, ReactNode, useState } from 'react';
-import { i18n } from '@osd/i18n';
-import {
- EuiFacetButton,
- EuiFieldSearch,
- EuiFlexGroup,
- EuiFlexItem,
- EuiIcon,
- EuiPopover,
- EuiPopoverFooter,
- EuiPopoverTitle,
- EuiSelect,
- EuiSwitch,
- EuiSwitchEvent,
- EuiForm,
- EuiFormRow,
- EuiButtonGroup,
- EuiOutsideClickDetector,
-} from '@elastic/eui';
-import { FormattedMessage } from '@osd/i18n/react';
-
-export interface State {
- searchable: string;
- aggregatable: string;
- type: string;
- missing: boolean;
- [index: string]: string | boolean;
-}
-
-export interface Props {
- /**
- * triggered on input of user into search field
- */
- onChange: (field: string, value: string | boolean | undefined) => void;
-
- /**
- * the input value of the user
- */
- value?: string;
-
- /**
- * types for the type filter
- */
- types: string[];
-}
-
-/**
- * Component is Discover's side bar to search of available fields
- * Additionally there's a button displayed that allows the user to show/hide more filter fields
- */
-export function DiscoverFieldSearch({ onChange, value, types }: Props) {
- const searchPlaceholder = i18n.translate('discover.fieldChooser.searchPlaceHolder', {
- defaultMessage: 'Search field names',
- });
- const aggregatableLabel = i18n.translate('discover.fieldChooser.filter.aggregatableLabel', {
- defaultMessage: 'Aggregatable',
- });
- const searchableLabel = i18n.translate('discover.fieldChooser.filter.searchableLabel', {
- defaultMessage: 'Searchable',
- });
- const typeLabel = i18n.translate('discover.fieldChooser.filter.typeLabel', {
- defaultMessage: 'Type',
- });
- const typeOptions = types
- ? types.map((type) => {
- return { value: type, text: type };
- })
- : [{ value: 'any', text: 'any' }];
-
- const [activeFiltersCount, setActiveFiltersCount] = useState(0);
- const [isPopoverOpen, setPopoverOpen] = useState(false);
- const [values, setValues] = useState({
- searchable: 'any',
- aggregatable: 'any',
- type: 'any',
- missing: true,
- });
-
- if (typeof value !== 'string') {
- // at initial rendering value is undefined (angular related), this catches the warning
- // should be removed once all is react
- return null;
- }
-
- const filterBtnAriaLabel = isPopoverOpen
- ? i18n.translate('discover.fieldChooser.toggleFieldFilterButtonHideAriaLabel', {
- defaultMessage: 'Hide field filter settings',
- })
- : i18n.translate('discover.fieldChooser.toggleFieldFilterButtonShowAriaLabel', {
- defaultMessage: 'Show field filter settings',
- });
-
- const handleFacetButtonClicked = () => {
- setPopoverOpen(!isPopoverOpen);
- };
-
- const applyFilterValue = (id: string, filterValue: string | boolean) => {
- switch (filterValue) {
- case 'any':
- if (id !== 'type') {
- onChange(id, undefined);
- } else {
- onChange(id, filterValue);
- }
- break;
- case 'true':
- onChange(id, true);
- break;
- case 'false':
- onChange(id, false);
- break;
- default:
- onChange(id, filterValue);
- }
- };
-
- const isFilterActive = (name: string, filterValue: string | boolean) => {
- return name !== 'missing' && filterValue !== 'any';
- };
-
- const handleValueChange = (name: string, filterValue: string | boolean) => {
- const previousValue = values[name];
- updateFilterCount(name, previousValue, filterValue);
- const updatedValues = { ...values };
- updatedValues[name] = filterValue;
- setValues(updatedValues);
- applyFilterValue(name, filterValue);
- };
-
- const updateFilterCount = (
- name: string,
- previousValue: string | boolean,
- currentValue: string | boolean
- ) => {
- const previouslyFilterActive = isFilterActive(name, previousValue);
- const filterActive = isFilterActive(name, currentValue);
- const diff = Number(filterActive) - Number(previouslyFilterActive);
- setActiveFiltersCount(activeFiltersCount + diff);
- };
-
- const handleMissingChange = (e: EuiSwitchEvent) => {
- const missingValue = e.target.checked;
- handleValueChange('missing', missingValue);
- };
-
- const buttonContent = (
- }
- isSelected={activeFiltersCount > 0}
- quantity={activeFiltersCount}
- onClick={handleFacetButtonClicked}
- >
-
-
- );
-
- const select = (
- id: string,
- selectOptions: Array<{ text: ReactNode } & OptionHTMLAttributes>,
- selectValue: string
- ) => {
- return (
- ) =>
- handleValueChange(id, e.target.value)
- }
- aria-label={i18n.translate('discover.fieldChooser.filter.fieldSelectorLabel', {
- defaultMessage: 'Selection of {id} filter options',
- values: { id },
- })}
- data-test-subj={`${id}Select`}
- compressed
- />
- );
- };
-
- const toggleButtons = (id: string) => {
- return [
- {
- id: `${id}-any`,
- label: 'any',
- },
- {
- id: `${id}-true`,
- label: 'yes',
- },
- {
- id: `${id}-false`,
- label: 'no',
- },
- ];
- };
-
- const buttonGroup = (id: string, legend: string) => {
- return (
- handleValueChange(id, optionId.replace(`${id}-`, ''))}
- buttonSize="compressed"
- isFullWidth
- data-test-subj={`${id}ButtonGroup`}
- />
- );
- };
-
- const selectionPanel = (
-
-
-
- {buttonGroup('aggregatable', aggregatableLabel)}
-
-
- {buttonGroup('searchable', searchableLabel)}
-
-
- {select('type', typeOptions, values.type)}
-
-
-
- );
-
- return (
-
-
-
- onChange('name', event.currentTarget.value)}
- placeholder={searchPlaceholder}
- value={value}
- />
-
-
-
- {}} isDisabled={!isPopoverOpen}>
- {
- setPopoverOpen(false);
- }}
- button={buttonContent}
- >
-
- {i18n.translate('discover.fieldChooser.filter.filterByTypeLabel', {
- defaultMessage: 'Filter by type',
- })}
-
- {selectionPanel}
-
-
-
-
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.test.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.test.tsx
deleted file mode 100644
index 9298aef92cf0..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.test.tsx
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { shallowWithIntl as shallow } from 'test_utils/enzyme_helpers';
-
-// @ts-ignore
-import { ShallowWrapper } from 'enzyme';
-import { ChangeIndexPattern } from './change_indexpattern';
-import { SavedObject } from 'opensearch-dashboards/server';
-import { DiscoverIndexPattern } from './discover_index_pattern';
-import { EuiSelectable } from '@elastic/eui';
-import { IIndexPattern } from 'src/plugins/data/public';
-
-const indexPattern = {
- id: 'test1',
- title: 'test1 title',
-} as IIndexPattern;
-
-const indexPattern1 = {
- id: 'test1',
- attributes: {
- title: 'test1 titleToDisplay',
- },
-} as SavedObject;
-
-const indexPattern2 = {
- id: 'test2',
- attributes: {
- title: 'test2 titleToDisplay',
- },
-} as SavedObject;
-
-const defaultProps = {
- indexPatternList: [indexPattern1, indexPattern2],
- selectedIndexPattern: indexPattern,
- setIndexPattern: jest.fn(async () => {}),
-};
-
-function getIndexPatternPickerList(instance: ShallowWrapper) {
- return instance.find(ChangeIndexPattern).first().dive().find(EuiSelectable);
-}
-
-function getIndexPatternPickerOptions(instance: ShallowWrapper) {
- return getIndexPatternPickerList(instance).prop('options');
-}
-
-function selectIndexPatternPickerOption(instance: ShallowWrapper, selectedLabel: string) {
- const options: Array<{ label: string; checked?: 'on' | 'off' }> = getIndexPatternPickerOptions(
- instance
- ).map((option: any) =>
- option.label === selectedLabel
- ? { ...option, checked: 'on' }
- : { ...option, checked: undefined }
- );
- return getIndexPatternPickerList(instance).prop('onChange')!(options);
-}
-
-describe('DiscoverIndexPattern', () => {
- test('Invalid props dont cause an exception', () => {
- const props = {
- indexPatternList: null,
- selectedIndexPattern: null,
- setIndexPattern: jest.fn(),
- } as any;
-
- expect(shallow()).toMatchSnapshot(`""`);
- });
- test('should list all index patterns', () => {
- const instance = shallow();
-
- expect(getIndexPatternPickerOptions(instance)!.map((option: any) => option.label)).toEqual([
- 'test1 titleToDisplay',
- 'test2 titleToDisplay',
- ]);
- });
-
- test('should switch data panel to target index pattern', () => {
- const instance = shallow();
-
- selectIndexPatternPickerOption(instance, 'test2 titleToDisplay');
- expect(defaultProps.setIndexPattern).toHaveBeenCalledWith('test2');
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.tsx
deleted file mode 100644
index 95154bec1939..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState, useEffect } from 'react';
-import { SavedObject } from 'opensearch-dashboards/public';
-import { IIndexPattern, IndexPatternAttributes } from 'src/plugins/data/public';
-import { I18nProvider } from '@osd/i18n/react';
-
-import { IndexPatternRef } from './types';
-import { ChangeIndexPattern } from './change_indexpattern';
-export interface DiscoverIndexPatternProps {
- /**
- * list of available index patterns, if length > 1, component offers a "change" link
- */
- indexPatternList: Array>;
- /**
- * currently selected index pattern, due to angular issues it's undefined at first rendering
- */
- selectedIndexPattern: IIndexPattern;
- /**
- * triggered when user selects a new index pattern
- */
- setIndexPattern: (id: string) => void;
-}
-
-/**
- * Component allows you to select an index pattern in discovers side bar
- */
-export function DiscoverIndexPattern({
- indexPatternList,
- selectedIndexPattern,
- setIndexPattern,
-}: DiscoverIndexPatternProps) {
- const options: IndexPatternRef[] = (indexPatternList || []).map((entity) => ({
- id: entity.id,
- title: entity.attributes!.title,
- }));
- const { id: selectedId, title: selectedTitle } = selectedIndexPattern || {};
-
- const [selected, setSelected] = useState({
- id: selectedId,
- title: selectedTitle || '',
- });
- useEffect(() => {
- const { id, title } = selectedIndexPattern;
- const indexPattern = indexPatternList.find((pattern) => pattern.id === id);
- const titleToDisplay = indexPattern ? indexPattern.attributes!.title : title;
- setSelected({ id, title: titleToDisplay });
- }, [indexPatternList, selectedIndexPattern]);
- if (!selectedId) {
- return null;
- }
-
- return (
-
-
- {
- const indexPattern = options.find((pattern) => pattern.id === id);
- if (indexPattern) {
- setIndexPattern(id);
- setSelected(indexPattern);
- }
- }}
- />
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern_title.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern_title.tsx
deleted file mode 100644
index 30b50a9006c8..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_index_pattern_title.tsx
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiToolTip, EuiFlexItem, EuiFlexGroup, EuiTitle, EuiButtonEmpty } from '@elastic/eui';
-
-import { FormattedMessage } from '@osd/i18n/react';
-import { i18n } from '@osd/i18n';
-export interface DiscoverIndexPatternTitleProps {
- /**
- * determines whether the change link is displayed
- */
- isChangeable: boolean;
- /**
- * function triggered when the change link is clicked
- */
- onChange: () => void;
- /**
- * title of the current index pattern
- */
- title: string;
-}
-
-/**
- * Component displaying the title of the current selected index pattern
- * and if changeable is true, a link is provided to change the index pattern
- */
-export function DiscoverIndexPatternTitle({
- isChangeable,
- onChange,
- title,
-}: DiscoverIndexPatternTitleProps) {
- return (
-
-
-
-
- {title}
-
-
-
- {isChangeable && (
-
-
- }
- >
- onChange()}
- iconSide="right"
- iconType="arrowDown"
- color="text"
- />
-
-
- )}
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.scss b/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.scss
deleted file mode 100644
index 9c80e0afa600..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.scss
+++ /dev/null
@@ -1,99 +0,0 @@
-.dscSidebar__container {
- padding-left: 0 !important;
- padding-right: 0 !important;
- background-color: transparent;
- border-right-color: transparent;
- border-bottom-color: transparent;
-}
-
-.dscIndexPattern__container {
- display: flex;
- align-items: center;
- height: $euiSize * 3;
- margin-top: -$euiSizeS;
-}
-
-.dscIndexPattern__triggerButton {
- @include euiTitle("xs");
-
- line-height: $euiSizeXXL;
-}
-
-.dscFieldList {
- list-style: none;
- margin-bottom: 0;
-}
-
-.dscFieldListHeader {
- padding: $euiSizeS $euiSizeS 0 $euiSizeS;
- background-color: lightOrDarkTheme(tint($euiColorPrimary, 90%), $euiColorLightShade);
-}
-
-.dscFieldList--popular {
- background-color: lightOrDarkTheme(tint($euiColorPrimary, 90%), $euiColorLightShade);
-}
-
-.dscFieldChooser {
- padding-left: $euiSize;
-}
-
-.dscFieldChooser__toggle {
- color: $euiColorMediumShade;
- margin-left: $euiSizeS !important;
-}
-
-.dscSidebarItem {
- &:hover,
- &:focus-within,
- &[class*="-isActive"] {
- .dscSidebarItem__action {
- opacity: 1;
- }
- }
-}
-
-/**
- * 1. Only visually hide the action, so that it's still accessible to screen readers.
- * 2. When tabbed to, this element needs to be visible for keyboard accessibility.
- */
-.dscSidebarItem__action {
- opacity: 0; /* 1 */
- transition: none;
-
- &:focus {
- opacity: 1; /* 2 */
- }
-
- font-size: $euiFontSizeXS;
- padding: 2px 6px !important;
- height: 22px !important;
- min-width: auto !important;
-
- .euiButton__content {
- padding: 0 4px;
- }
-}
-
-.dscFieldSearch {
- padding: $euiSizeS;
-}
-
-.dscFieldSearch__toggleButton {
- width: calc(100% - #{$euiSizeS});
- color: $euiColorPrimary;
- padding-left: $euiSizeXS;
- margin-left: $euiSizeXS;
-}
-
-.dscFieldSearch__filterWrapper {
- flex-grow: 0;
-}
-
-.dscFieldSearch__formWrapper {
- padding: $euiSizeM;
-}
-
-.dscFieldDetails {
- color: $euiTextColor;
- margin-bottom: $euiSizeS;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.test.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.test.tsx
deleted file mode 100644
index fa692ca22b5b..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.test.tsx
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-import { ReactWrapper } from 'enzyme';
-import { findTestSubject } from 'test_utils/helpers';
-// @ts-ignore
-import realHits from 'fixtures/real_hits.js';
-// @ts-ignore
-import stubbedLogstashFields from 'fixtures/logstash_fields';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import React from 'react';
-import { DiscoverSidebar, DiscoverSidebarProps } from './discover_sidebar';
-import { coreMock } from '../../../../../../core/public/mocks';
-import { IndexPatternAttributes } from '../../../../../data/common';
-import { getStubIndexPattern } from '../../../../../data/public/test_utils';
-import { SavedObject } from '../../../../../../core/types';
-
-jest.mock('../../../opensearch_dashboards_services', () => ({
- getServices: () => ({
- history: () => ({
- location: {
- search: '',
- },
- }),
- capabilities: {
- visualize: {
- show: true,
- },
- discover: {
- save: false,
- },
- },
- uiSettings: {
- get: (key: string) => {
- if (key === 'fields:popularLimit') {
- return 5;
- } else if (key === 'shortDots:enable') {
- return false;
- }
- },
- },
- }),
-}));
-
-jest.mock('./lib/get_index_pattern_field_list', () => ({
- getIndexPatternFieldList: jest.fn((indexPattern) => indexPattern.fields),
-}));
-
-function getCompProps() {
- const indexPattern = getStubIndexPattern(
- 'logstash-*',
- (cfg: any) => cfg,
- 'time',
- stubbedLogstashFields(),
- coreMock.createSetup()
- );
-
- // @ts-expect-error _.each() is passing additional args to flattenHit
- const hits = _.each(_.cloneDeep(realHits), indexPattern.flattenHit) as Array<
- Record
- >;
-
- const indexPatternList = [
- { id: '0', attributes: { title: 'b' } } as SavedObject,
- { id: '1', attributes: { title: 'a' } } as SavedObject,
- { id: '2', attributes: { title: 'c' } } as SavedObject,
- ];
-
- const fieldCounts: Record = {};
-
- for (const hit of hits) {
- for (const key of Object.keys(indexPattern.flattenHit(hit))) {
- fieldCounts[key] = (fieldCounts[key] || 0) + 1;
- }
- }
- return {
- columns: ['extension'],
- fieldCounts,
- hits,
- indexPatternList,
- onAddFilter: jest.fn(),
- onAddField: jest.fn(),
- onRemoveField: jest.fn(),
- selectedIndexPattern: indexPattern,
- setIndexPattern: jest.fn(),
- state: {},
- };
-}
-
-describe('discover sidebar', function () {
- let props: DiscoverSidebarProps;
- let comp: ReactWrapper;
-
- beforeAll(() => {
- props = getCompProps();
- comp = mountWithIntl();
- });
-
- it('should have Selected Fields and Available Fields with Popular Fields sections', function () {
- const popular = findTestSubject(comp, 'fieldList-popular');
- const selected = findTestSubject(comp, 'fieldList-selected');
- const unpopular = findTestSubject(comp, 'fieldList-unpopular');
- expect(popular.children().length).toBe(1);
- expect(unpopular.children().length).toBe(7);
- expect(selected.children().length).toBe(1);
- });
- it('should allow selecting fields', function () {
- findTestSubject(comp, 'fieldToggle-bytes').simulate('click');
- expect(props.onAddField).toHaveBeenCalledWith('bytes');
- });
- it('should allow deselecting fields', function () {
- findTestSubject(comp, 'fieldToggle-extension').simulate('click');
- expect(props.onRemoveField).toHaveBeenCalledWith('extension');
- });
- it('should allow adding filters', function () {
- findTestSubject(comp, 'field-extension-showDetails').simulate('click');
- findTestSubject(comp, 'plus-extension-gif').simulate('click');
- expect(props.onAddFilter).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.tsx
deleted file mode 100644
index 865aff590286..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/discover_sidebar.tsx
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import './discover_sidebar.scss';
-import React, { useCallback, useEffect, useState, useMemo } from 'react';
-import { i18n } from '@osd/i18n';
-import { EuiButtonIcon, EuiTitle, EuiSpacer } from '@elastic/eui';
-import { sortBy } from 'lodash';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-import { DiscoverField } from './discover_field';
-import { DiscoverIndexPattern } from './discover_index_pattern';
-import { DiscoverFieldSearch } from './discover_field_search';
-import { IndexPatternAttributes } from '../../../../../data/common';
-import { SavedObject } from '../../../../../../core/types';
-import { FIELDS_LIMIT_SETTING } from '../../../../common';
-import { groupFields } from './lib/group_fields';
-import { IndexPatternField, IndexPattern, UI_SETTINGS } from '../../../../../data/public';
-import { getDetails } from './lib/get_details';
-import { getDefaultFieldFilter, setFieldFilterProp } from './lib/field_filter';
-import { getIndexPatternFieldList } from './lib/get_index_pattern_field_list';
-import { getServices } from '../../../opensearch_dashboards_services';
-
-export interface DiscoverSidebarProps {
- /**
- * the selected columns displayed in the doc table in discover
- */
- columns: string[];
- /**
- * a statistics of the distribution of fields in the given hits
- */
- fieldCounts: Record;
- /**
- * hits fetched from OpenSearch, displayed in the doc table
- */
- hits: Array>;
- /**
- * List of available index patterns
- */
- indexPatternList: Array>;
- /**
- * Callback function when selecting a field
- */
- onAddField: (fieldName: string) => void;
- /**
- * Callback function when adding a filter from sidebar
- */
- onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
- /**
- * Callback function when removing a field
- * @param fieldName
- */
- onRemoveField: (fieldName: string) => void;
- /**
- * Currently selected index pattern
- */
- selectedIndexPattern?: IndexPattern;
- /**
- * Callback function to select another index pattern
- */
- setIndexPattern: (id: string) => void;
-}
-
-export function DiscoverSidebar({
- columns,
- fieldCounts,
- hits,
- indexPatternList,
- onAddField,
- onAddFilter,
- onRemoveField,
- selectedIndexPattern,
- setIndexPattern,
-}: DiscoverSidebarProps) {
- const [showFields, setShowFields] = useState(false);
- const [fields, setFields] = useState(null);
- const [fieldFilterState, setFieldFilterState] = useState(getDefaultFieldFilter());
- const services = useMemo(() => getServices(), []);
-
- useEffect(() => {
- const newFields = getIndexPatternFieldList(selectedIndexPattern, fieldCounts);
- setFields(newFields);
- }, [selectedIndexPattern, fieldCounts, hits, services]);
-
- const onChangeFieldSearch = useCallback(
- (field: string, value: string | boolean | undefined) => {
- const newState = setFieldFilterProp(fieldFilterState, field, value);
- setFieldFilterState(newState);
- },
- [fieldFilterState]
- );
-
- const getDetailsByField = useCallback(
- (ipField: IndexPatternField) => getDetails(ipField, hits, selectedIndexPattern),
- [hits, selectedIndexPattern]
- );
-
- const popularLimit = services.uiSettings.get(FIELDS_LIMIT_SETTING);
- const useShortDots = services.uiSettings.get(UI_SETTINGS.SHORT_DOTS_ENABLE);
-
- const {
- selected: selectedFields,
- popular: popularFields,
- unpopular: unpopularFields,
- } = useMemo(() => groupFields(fields, columns, popularLimit, fieldCounts, fieldFilterState), [
- fields,
- columns,
- popularLimit,
- fieldCounts,
- fieldFilterState,
- ]);
-
- const fieldTypes = useMemo(() => {
- const result = ['any'];
- if (Array.isArray(fields)) {
- for (const field of fields) {
- if (result.indexOf(field.type) === -1) {
- result.push(field.type);
- }
- }
- }
- return result;
- }, [fields]);
-
- if (!selectedIndexPattern || !fields) {
- return null;
- }
-
- return (
-
-
- o.attributes.title)}
- />
-
-
-
-
- {fields.length > 0 && (
- <>
-
-
-
-
-
-
-
- {selectedFields.map((field: IndexPatternField) => {
- return (
- -
-
-
- );
- })}
-
-
-
-
-
-
-
-
- setShowFields(!showFields)}
- aria-label={
- showFields
- ? i18n.translate(
- 'discover.fieldChooser.filter.indexAndFieldsSectionHideAriaLabel',
- {
- defaultMessage: 'Hide fields',
- }
- )
- : i18n.translate(
- 'discover.fieldChooser.filter.indexAndFieldsSectionShowAriaLabel',
- {
- defaultMessage: 'Show fields',
- }
- )
- }
- />
-
-
- >
- )}
- {popularFields.length > 0 && (
-
-
-
-
-
-
-
- {popularFields.map((field: IndexPatternField) => {
- return (
- -
-
-
- );
- })}
-
-
- )}
-
-
- {unpopularFields.map((field: IndexPatternField) => {
- return (
- -
-
-
- );
- })}
-
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/index.ts b/src/plugins/discover_legacy/public/application/components/sidebar/index.ts
deleted file mode 100644
index 2799d47da83f..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { DiscoverSidebar } from './discover_sidebar';
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.test.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.test.ts
deleted file mode 100644
index d580f7ae228a..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.test.ts
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-// @ts-ignore
-import realHits from 'fixtures/real_hits.js';
-// @ts-ignore
-import stubbedLogstashFields from 'fixtures/logstash_fields';
-import { coreMock } from '../../../../../../../core/public/mocks';
-import { IndexPattern, IndexPatternField } from '../../../../../../data/public';
-import { getStubIndexPattern } from '../../../../../../data/public/test_utils';
-import {
- groupValues,
- getFieldValues,
- getFieldValueCounts,
- FieldValueCountsParams,
-} from './field_calculator';
-import { Bucket } from '../types';
-
-let indexPattern: IndexPattern;
-
-describe('field_calculator', function () {
- beforeEach(function () {
- indexPattern = getStubIndexPattern(
- 'logstash-*',
- (cfg: any) => cfg,
- 'time',
- stubbedLogstashFields(),
- coreMock.createSetup()
- );
- });
-
- describe('groupValues', function () {
- let groups: Record;
- let grouped: boolean;
- let values: any[];
- beforeEach(function () {
- values = [
- ['foo', 'bar'],
- 'foo',
- 'foo',
- undefined,
- ['foo', 'bar'],
- 'bar',
- 'baz',
- null,
- null,
- null,
- 'foo',
- undefined,
- ];
- groups = groupValues(values, grouped);
- });
-
- it('should return an object values', function () {
- expect(groups).toBeInstanceOf(Object);
- });
-
- it('should throw an error if any value is a plain object', function () {
- expect(function () {
- groupValues([{}, true, false], grouped);
- }).toThrowError();
- });
-
- it('should handle values with dots in them', function () {
- values = ['0', '0.........', '0.......,.....'];
- groups = groupValues(values, grouped);
- expect(groups[values[0]].count).toBe(1);
- expect(groups[values[1]].count).toBe(1);
- expect(groups[values[2]].count).toBe(1);
- });
-
- it('should have a key for value in the array when not grouping array terms', function () {
- expect(_.keys(groups).length).toBe(3);
- expect(groups.foo).toBeInstanceOf(Object);
- expect(groups.bar).toBeInstanceOf(Object);
- expect(groups.baz).toBeInstanceOf(Object);
- });
-
- it('should count array terms independently', function () {
- expect(groups['foo,bar']).toBeUndefined();
- expect(groups.foo.count).toBe(5);
- expect(groups.bar.count).toBe(3);
- expect(groups.baz.count).toBe(1);
- });
-
- describe('grouped array terms', function () {
- beforeEach(function () {
- grouped = true;
- groups = groupValues(values, grouped);
- });
-
- it('should group array terms when grouped is true', function () {
- expect(_.keys(groups).length).toBe(4);
- expect(groups['foo,bar']).toBeInstanceOf(Object);
- });
-
- it('should contain the original array as the value', function () {
- expect(groups['foo,bar'].value).toEqual(['foo', 'bar']);
- });
-
- it('should count the pairs separately from the values they contain', function () {
- expect(groups['foo,bar'].count).toBe(2);
- expect(groups.foo.count).toBe(3);
- expect(groups.bar.count).toBe(1);
- });
- });
- });
-
- describe('getFieldValues', function () {
- let hits: any;
-
- beforeEach(function () {
- hits = _.each(_.cloneDeep(realHits), (hit) => indexPattern.flattenHit(hit));
- });
-
- it('should return an array of values for _source fields', function () {
- const extensions = getFieldValues({
- hits,
- field: indexPattern.fields.getByName('extension') as IndexPatternField,
- indexPattern,
- });
- expect(extensions).toBeInstanceOf(Array);
- expect(
- _.filter(extensions, function (v) {
- return v === 'html';
- }).length
- ).toBe(8);
- expect(_.uniq(_.clone(extensions)).sort()).toEqual(['gif', 'html', 'php', 'png']);
- });
-
- it('should return an array of values for core meta fields', function () {
- const types = getFieldValues({
- hits,
- field: indexPattern.fields.getByName('_type') as IndexPatternField,
- indexPattern,
- });
- expect(types).toBeInstanceOf(Array);
- expect(
- _.filter(types, function (v) {
- return v === 'apache';
- }).length
- ).toBe(18);
- expect(_.uniq(_.clone(types)).sort()).toEqual(['apache', 'nginx']);
- });
- });
-
- describe('getFieldValueCounts', function () {
- let params: FieldValueCountsParams;
- beforeEach(function () {
- params = {
- hits: _.cloneDeep(realHits),
- field: indexPattern.fields.getByName('extension') as IndexPatternField,
- count: 3,
- indexPattern,
- };
- });
-
- it('counts the top 5 values by default', function () {
- params.hits = params.hits.map((hit: Record, i) => ({
- ...hit,
- _source: {
- extension: `${hit._source.extension}-${i}`,
- },
- }));
- params.count = undefined;
- const extensions = getFieldValueCounts(params);
- expect(extensions).toBeInstanceOf(Object);
- expect(extensions.buckets).toBeInstanceOf(Array);
- const buckets = extensions.buckets as Bucket[];
- expect(buckets.length).toBe(5);
- expect(extensions.error).toBeUndefined();
- });
-
- it('counts only distinct values if less than default', function () {
- params.count = undefined;
- const extensions = getFieldValueCounts(params);
- expect(extensions).toBeInstanceOf(Object);
- expect(extensions.buckets).toBeInstanceOf(Array);
- const buckets = extensions.buckets as Bucket[];
- expect(buckets.length).toBe(4);
- expect(extensions.error).toBeUndefined();
- });
-
- it('counts only distinct values if less than specified count', function () {
- params.count = 10;
- const extensions = getFieldValueCounts(params);
- expect(extensions).toBeInstanceOf(Object);
- expect(extensions.buckets).toBeInstanceOf(Array);
- const buckets = extensions.buckets as Bucket[];
- expect(buckets.length).toBe(4);
- expect(extensions.error).toBeUndefined();
- });
-
- it('counts the top 3 values', function () {
- const extensions = getFieldValueCounts(params);
- expect(extensions).toBeInstanceOf(Object);
- expect(extensions.buckets).toBeInstanceOf(Array);
- const buckets = extensions.buckets as Bucket[];
- expect(buckets.length).toBe(3);
- expect(_.map(buckets, 'value')).toEqual(['html', 'gif', 'php']);
- expect(extensions.error).toBeUndefined();
- });
-
- it('fails to analyze geo and attachment types', function () {
- params.field = indexPattern.fields.getByName('point') as IndexPatternField;
- expect(getFieldValueCounts(params).error).not.toBeUndefined();
-
- params.field = indexPattern.fields.getByName('area') as IndexPatternField;
- expect(getFieldValueCounts(params).error).not.toBeUndefined();
-
- params.field = indexPattern.fields.getByName('request_body') as IndexPatternField;
- expect(getFieldValueCounts(params).error).not.toBeUndefined();
- });
-
- it('fails to analyze fields that are in the mapping, but not the hits', function () {
- params.field = indexPattern.fields.getByName('ip') as IndexPatternField;
- expect(getFieldValueCounts(params).error).not.toBeUndefined();
- });
-
- it('counts the total hits', function () {
- expect(getFieldValueCounts(params).total).toBe(params.hits.length);
- });
-
- it('counts the hits the field exists in', function () {
- params.field = indexPattern.fields.getByName('phpmemory') as IndexPatternField;
- expect(getFieldValueCounts(params).exists).toBe(5);
- });
-
- it('catches and returns errors', function () {
- params.hits = params.hits.map((hit: Record) => ({
- ...hit,
- _source: {
- extension: { foo: hit._source.extension },
- },
- }));
- params.grouped = true;
- expect(typeof getFieldValueCounts(params).error).toBe('string');
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.ts
deleted file mode 100644
index 54f8832fa1fc..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_calculator.ts
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-import { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
-import { FieldValueCounts } from '../types';
-
-const NO_ANALYSIS_TYPES = ['geo_point', 'geo_shape', 'attachment'];
-
-interface FieldValuesParams {
- hits: Array>;
- field: IndexPatternField;
- indexPattern: IndexPattern;
-}
-
-interface FieldValueCountsParams extends FieldValuesParams {
- count?: number;
- grouped?: boolean;
-}
-
-const getFieldValues = ({ hits, field, indexPattern }: FieldValuesParams) => {
- const name = field.name;
- const flattenHit = indexPattern.flattenHit;
- return hits.map((hit) => flattenHit(hit)[name]);
-};
-
-const getFieldValueCounts = (params: FieldValueCountsParams): FieldValueCounts => {
- const { hits, field, indexPattern, count = 5, grouped = false } = params;
- const { type: fieldType } = field;
-
- if (NO_ANALYSIS_TYPES.includes(fieldType)) {
- return {
- error: i18n.translate(
- 'discover.fieldChooser.fieldCalculator.analysisIsNotAvailableForGeoFieldsErrorMessage',
- {
- defaultMessage: 'Analysis is not available for {fieldType} fields.',
- values: {
- fieldType,
- },
- }
- ),
- };
- }
-
- const allValues = getFieldValues({ hits, field, indexPattern });
- const missing = allValues.filter((v) => v === undefined || v === null).length;
-
- try {
- const groups = groupValues(allValues, grouped);
- const counts = Object.keys(groups)
- .sort((a, b) => groups[b].count - groups[a].count)
- .slice(0, count)
- .map((key) => ({
- value: groups[key].value,
- count: groups[key].count,
- percent: (groups[key].count / (hits.length - missing)) * 100,
- display: indexPattern.getFormatterForField(field).convert(groups[key].value),
- }));
-
- if (hits.length === missing) {
- return {
- error: i18n.translate(
- 'discover.fieldChooser.fieldCalculator.fieldIsNotPresentInDocumentsErrorMessage',
- {
- defaultMessage:
- 'This field is present in your OpenSearch mapping but not in the {hitsLength} documents shown in the doc table. You may still be able to visualize or search on it.',
- values: {
- hitsLength: hits.length,
- },
- }
- ),
- };
- }
-
- return {
- total: hits.length,
- exists: hits.length - missing,
- missing,
- buckets: counts,
- };
- } catch (e) {
- return {
- error: e instanceof Error ? e.message : String(e),
- };
- }
-};
-
-const groupValues = (
- allValues: any[],
- grouped?: boolean
-): Record => {
- const values = grouped ? allValues : allValues.flat();
-
- return values
- .filter((v) => {
- if (v instanceof Object && !Array.isArray(v)) {
- throw new Error(
- i18n.translate(
- 'discover.fieldChooser.fieldCalculator.analysisIsNotAvailableForObjectFieldsErrorMessage',
- {
- defaultMessage: 'Analysis is not available for object fields.',
- }
- )
- );
- }
- return v !== undefined && v !== null;
- })
- .reduce((groups, value) => {
- if (groups.hasOwnProperty(value)) {
- groups[value].count++;
- } else {
- groups[value] = {
- value,
- count: 1,
- };
- }
- return groups;
- }, {});
-};
-
-export { FieldValueCountsParams, groupValues, getFieldValues, getFieldValueCounts };
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.test.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.test.ts
deleted file mode 100644
index a21d93cb5bc4..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.test.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getDefaultFieldFilter, setFieldFilterProp, isFieldFiltered } from './field_filter';
-import { IndexPatternField } from '../../../../../../data/public';
-
-describe('field_filter', function () {
- it('getDefaultFieldFilter should return default filter state', function () {
- expect(getDefaultFieldFilter()).toMatchInlineSnapshot(`
- Object {
- "aggregatable": null,
- "missing": true,
- "name": "",
- "searchable": null,
- "type": "any",
- }
- `);
- });
- it('setFieldFilterProp should return allow filter changes', function () {
- const state = getDefaultFieldFilter();
- const targetState = {
- aggregatable: true,
- missing: true,
- name: 'test',
- searchable: true,
- type: 'string',
- };
- const actualState = Object.entries(targetState).reduce((acc, kv) => {
- return setFieldFilterProp(acc, kv[0], kv[1]);
- }, state);
- expect(actualState).toMatchInlineSnapshot(`
- Object {
- "aggregatable": true,
- "missing": true,
- "name": "test",
- "searchable": true,
- "type": "string",
- }
- `);
- });
- it('filters a given list', () => {
- const defaultState = getDefaultFieldFilter();
- const fieldList = [
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: false,
- aggregatable: false,
- },
- {
- name: 'extension',
- type: 'string',
- esTypes: ['text'],
- count: 10,
- scripted: true,
- searchable: true,
- aggregatable: true,
- },
- ] as IndexPatternField[];
-
- [
- { filter: {}, result: ['bytes', 'extension'] },
- { filter: { name: 'by' }, result: ['bytes'] },
- { filter: { aggregatable: true }, result: ['extension'] },
- { filter: { aggregatable: true, searchable: false }, result: [] },
- { filter: { type: 'string' }, result: ['extension'] },
- ].forEach((test) => {
- const filtered = fieldList
- .filter((field) =>
- isFieldFiltered(field, { ...defaultState, ...test.filter }, { bytes: 1, extension: 1 })
- )
- .map((field) => field.name);
-
- expect(filtered).toEqual(test.result);
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.ts
deleted file mode 100644
index d72af29b43e0..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/field_filter.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPatternField } from '../../../../../../data/public';
-
-export interface FieldFilterState {
- missing: boolean;
- type: string;
- name: string;
- aggregatable: null | boolean;
- searchable: null | boolean;
-}
-
-export function getDefaultFieldFilter(): FieldFilterState {
- return {
- missing: true,
- type: 'any',
- name: '',
- aggregatable: null,
- searchable: null,
- };
-}
-
-export function setFieldFilterProp(
- state: FieldFilterState,
- name: string,
- value: string | boolean | null | undefined
-): FieldFilterState {
- const newState = { ...state };
- if (name === 'missing') {
- newState.missing = Boolean(value);
- } else if (name === 'aggregatable') {
- newState.aggregatable = typeof value !== 'boolean' ? null : value;
- } else if (name === 'searchable') {
- newState.searchable = typeof value !== 'boolean' ? null : value;
- } else if (name === 'name') {
- newState.name = String(value);
- } else if (name === 'type') {
- newState.type = String(value);
- }
- return newState;
-}
-
-export function isFieldFiltered(
- field: IndexPatternField,
- filterState: FieldFilterState,
- fieldCounts: Record
-): boolean {
- const matchFilter = filterState.type === 'any' || field.type === filterState.type;
- const isAggregatable =
- filterState.aggregatable === null || field.aggregatable === filterState.aggregatable;
- const isSearchable =
- filterState.searchable === null || field.searchable === filterState.searchable;
- const scriptedOrMissing =
- !filterState.missing ||
- field.type === '_source' ||
- field.scripted ||
- fieldCounts[field.name] > 0;
- const matchName = !filterState.name || field.name.indexOf(filterState.name) !== -1;
-
- return matchFilter && isAggregatable && isSearchable && scriptedOrMissing && matchName;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_details.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_details.ts
deleted file mode 100644
index 823cbde9ba72..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_details.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// @ts-ignore
-import { i18n } from '@osd/i18n';
-import { getFieldValueCounts } from './field_calculator';
-import { IndexPattern, IndexPatternField } from '../../../../../../data/public';
-
-export function getDetails(
- field: IndexPatternField,
- hits: Array>,
- indexPattern?: IndexPattern
-) {
- const defaultDetails = {
- error: '',
- exists: 0,
- total: 0,
- buckets: [],
- };
- if (!indexPattern) {
- return {
- ...defaultDetails,
- error: i18n.translate('discover.fieldChooser.noIndexPatternSelectedErrorMessage', {
- defaultMessage: 'Index pattern not specified.',
- }),
- };
- }
- const details = {
- ...defaultDetails,
- ...getFieldValueCounts({
- hits,
- field,
- indexPattern,
- count: 5,
- grouped: false,
- }),
- };
- if (details.buckets) {
- for (const bucket of details.buckets) {
- bucket.display = indexPattern.getFormatterForField(field).convert(bucket.value);
- }
- }
- return details;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_field_type_name.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_field_type_name.ts
deleted file mode 100644
index 38b18792d3e4..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_field_type_name.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-
-export function getFieldTypeName(type: string) {
- switch (type) {
- case 'boolean':
- return i18n.translate('discover.fieldNameIcons.booleanAriaLabel', {
- defaultMessage: 'Boolean field',
- });
- case 'conflict':
- return i18n.translate('discover.fieldNameIcons.conflictFieldAriaLabel', {
- defaultMessage: 'Conflicting field',
- });
- case 'date':
- return i18n.translate('discover.fieldNameIcons.dateFieldAriaLabel', {
- defaultMessage: 'Date field',
- });
- case 'geo_point':
- return i18n.translate('discover.fieldNameIcons.geoPointFieldAriaLabel', {
- defaultMessage: 'Geo point field',
- });
- case 'geo_shape':
- return i18n.translate('discover.fieldNameIcons.geoShapeFieldAriaLabel', {
- defaultMessage: 'Geo shape field',
- });
- case 'ip':
- return i18n.translate('discover.fieldNameIcons.ipAddressFieldAriaLabel', {
- defaultMessage: 'IP address field',
- });
- case 'murmur3':
- return i18n.translate('discover.fieldNameIcons.murmur3FieldAriaLabel', {
- defaultMessage: 'Murmur3 field',
- });
- case 'number':
- return i18n.translate('discover.fieldNameIcons.numberFieldAriaLabel', {
- defaultMessage: 'Number field',
- });
- case 'source':
- // Note that this type is currently not provided, type for _source is undefined
- return i18n.translate('discover.fieldNameIcons.sourceFieldAriaLabel', {
- defaultMessage: 'Source field',
- });
- case 'string':
- return i18n.translate('discover.fieldNameIcons.stringFieldAriaLabel', {
- defaultMessage: 'String field',
- });
- case 'nested':
- return i18n.translate('discover.fieldNameIcons.nestedFieldAriaLabel', {
- defaultMessage: 'Nested field',
- });
- default:
- return i18n.translate('discover.fieldNameIcons.unknownFieldAriaLabel', {
- defaultMessage: 'Unknown field',
- });
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_index_pattern_field_list.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_index_pattern_field_list.ts
deleted file mode 100644
index b3a8ff5cd8d9..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_index_pattern_field_list.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { difference } from 'lodash';
-import { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
-
-export function getIndexPatternFieldList(
- indexPattern?: IndexPattern,
- fieldCounts?: Record
-) {
- if (!indexPattern || !fieldCounts) return [];
-
- const fieldNamesInDocs = Object.keys(fieldCounts);
- const fieldNamesInIndexPattern = indexPattern.fields.getAll().map((fld) => fld.name);
- const unknownTypes: IndexPatternField[] = [];
-
- difference(fieldNamesInDocs, fieldNamesInIndexPattern).forEach((unknownFieldName) => {
- unknownTypes.push({
- displayName: String(unknownFieldName),
- name: String(unknownFieldName),
- type: 'unknown',
- } as IndexPatternField);
- });
-
- return [...indexPattern.fields.getAll(), ...unknownTypes];
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_warnings.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_warnings.ts
deleted file mode 100644
index 770a0ce664e4..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/get_warnings.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-import { IndexPatternField } from '../../../../../../data/public';
-
-export function getWarnings(field: IndexPatternField) {
- let warnings = [];
-
- if (field.scripted) {
- warnings.push(
- i18n.translate(
- 'discover.fieldChooser.discoverField.scriptedFieldsTakeLongExecuteDescription',
- {
- defaultMessage: 'Scripted fields can take a long time to execute.',
- }
- )
- );
- }
-
- if (warnings.length > 1) {
- warnings = warnings.map(function (warning, i) {
- return (i > 0 ? '\n' : '') + (i + 1) + ' - ' + warning;
- });
- }
-
- return warnings;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.test.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.test.ts
deleted file mode 100644
index 7301ce3a4c96..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.test.ts
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { groupFields } from './group_fields';
-import { getDefaultFieldFilter } from './field_filter';
-
-describe('group_fields', function () {
- it('should group fields in selected, popular, unpopular group', function () {
- const fields = [
- {
- name: 'category',
- type: 'string',
- esTypes: ['text'],
- count: 1,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- {
- name: 'currency',
- type: 'string',
- esTypes: ['keyword'],
- count: 0,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- {
- name: 'customer_birth_date',
- type: 'date',
- esTypes: ['date'],
- count: 0,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- ];
-
- const fieldCounts = {
- category: 1,
- currency: 1,
- customer_birth_date: 1,
- };
-
- const fieldFilterState = getDefaultFieldFilter();
-
- const actual = groupFields(fields as any, ['currency'], 5, fieldCounts, fieldFilterState);
- expect(actual).toMatchInlineSnapshot(`
- Object {
- "popular": Array [
- Object {
- "aggregatable": true,
- "count": 1,
- "esTypes": Array [
- "text",
- ],
- "name": "category",
- "readFromDocValues": true,
- "scripted": false,
- "searchable": true,
- "type": "string",
- },
- ],
- "selected": Array [
- Object {
- "aggregatable": true,
- "count": 0,
- "esTypes": Array [
- "keyword",
- ],
- "name": "currency",
- "readFromDocValues": true,
- "scripted": false,
- "searchable": true,
- "type": "string",
- },
- ],
- "unpopular": Array [
- Object {
- "aggregatable": true,
- "count": 0,
- "esTypes": Array [
- "date",
- ],
- "name": "customer_birth_date",
- "readFromDocValues": true,
- "scripted": false,
- "searchable": true,
- "type": "date",
- },
- ],
- }
- `);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.tsx
deleted file mode 100644
index fad1db402467..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/group_fields.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPatternField } from 'src/plugins/data/public';
-import { FieldFilterState, isFieldFiltered } from './field_filter';
-
-interface GroupedFields {
- selected: IndexPatternField[];
- popular: IndexPatternField[];
- unpopular: IndexPatternField[];
-}
-
-/**
- * group the fields into selected, popular and unpopular, filter by fieldFilterState
- */
-export function groupFields(
- fields: IndexPatternField[] | null,
- columns: string[],
- popularLimit: number,
- fieldCounts: Record,
- fieldFilterState: FieldFilterState
-): GroupedFields {
- const result: GroupedFields = {
- selected: [],
- popular: [],
- unpopular: [],
- };
- if (!Array.isArray(fields) || !Array.isArray(columns) || typeof fieldCounts !== 'object') {
- return result;
- }
-
- const popular = fields
- .filter((field) => !columns.includes(field.name) && field.count)
- .sort((a: IndexPatternField, b: IndexPatternField) => (b.count || 0) - (a.count || 0))
- .map((field) => field.name)
- .slice(0, popularLimit);
-
- const compareFn = (a: IndexPatternField, b: IndexPatternField) => {
- if (!a.displayName) {
- return 0;
- }
- return a.displayName.localeCompare(b.displayName || '');
- };
- const fieldsSorted = fields.sort(compareFn);
-
- for (const field of fieldsSorted) {
- if (!isFieldFiltered(field, fieldFilterState, fieldCounts)) {
- continue;
- }
- if (columns.includes(field.name)) {
- result.selected.push(field);
- } else if (popular.includes(field.name) && field.type !== '_source') {
- result.popular.push(field);
- } else if (field.type !== '_source') {
- result.unpopular.push(field);
- }
- }
-
- return result;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/lib/visualize_trigger_utils.ts b/src/plugins/discover_legacy/public/application/components/sidebar/lib/visualize_trigger_utils.ts
deleted file mode 100644
index 36a6bcf2e329..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/lib/visualize_trigger_utils.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- VISUALIZE_FIELD_TRIGGER,
- VISUALIZE_GEO_FIELD_TRIGGER,
- visualizeFieldTrigger,
- visualizeGeoFieldTrigger,
-} from '../../../../../../ui_actions/public';
-import { getUiActions } from '../../../../opensearch_dashboards_services';
-import { IndexPatternField, OSD_FIELD_TYPES } from '../../../../../../data/public';
-
-function getTriggerConstant(type: string) {
- return type === OSD_FIELD_TYPES.GEO_POINT || type === OSD_FIELD_TYPES.GEO_SHAPE
- ? VISUALIZE_GEO_FIELD_TRIGGER
- : VISUALIZE_FIELD_TRIGGER;
-}
-
-function getTrigger(type: string) {
- return type === OSD_FIELD_TYPES.GEO_POINT || type === OSD_FIELD_TYPES.GEO_SHAPE
- ? visualizeGeoFieldTrigger
- : visualizeFieldTrigger;
-}
-
-async function getCompatibleActions(
- fieldName: string,
- indexPatternId: string,
- contextualFields: string[],
- trigger: typeof VISUALIZE_FIELD_TRIGGER | typeof VISUALIZE_GEO_FIELD_TRIGGER
-) {
- const compatibleActions = await getUiActions().getTriggerCompatibleActions(trigger, {
- indexPatternId,
- fieldName,
- contextualFields,
- });
- return compatibleActions;
-}
-
-export async function getVisualizeHref(
- field: IndexPatternField,
- indexPatternId: string | undefined,
- contextualFields: string[]
-) {
- if (!indexPatternId) return undefined;
- const triggerOptions = {
- indexPatternId,
- fieldName: field.name,
- contextualFields,
- trigger: getTrigger(field.type),
- };
- const compatibleActions = await getCompatibleActions(
- field.name,
- indexPatternId,
- contextualFields,
- getTriggerConstant(field.type)
- );
- // enable the link only if only one action is registered
- return compatibleActions.length === 1
- ? compatibleActions[0].getHref?.(triggerOptions)
- : undefined;
-}
-
-export function triggerVisualizeActions(
- field: IndexPatternField,
- indexPatternId: string | undefined,
- contextualFields: string[]
-) {
- if (!indexPatternId) return;
- const trigger = getTriggerConstant(field.type);
- const triggerOptions = {
- indexPatternId,
- fieldName: field.name,
- contextualFields,
- };
- getUiActions().getTrigger(trigger).exec(triggerOptions);
-}
-
-export async function isFieldVisualizable(
- field: IndexPatternField,
- indexPatternId: string | undefined,
- contextualFields: string[]
-) {
- if (field.name === '_id' || !indexPatternId) {
- // for first condition you'd get a 'Fielddata access on the _id field is disallowed' error on OpenSearch side.
- return false;
- }
- const trigger = getTriggerConstant(field.type);
- const compatibleActions = await getCompatibleActions(
- field.name,
- indexPatternId,
- contextualFields,
- trigger
- );
- return compatibleActions.length > 0 && field.visualizable;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/string_progress_bar.tsx b/src/plugins/discover_legacy/public/application/components/sidebar/string_progress_bar.tsx
deleted file mode 100644
index dba087d0f9ed..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/string_progress_bar.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiProgress } from '@elastic/eui';
-
-interface Props {
- percent: number;
- count: number;
- value: string;
-}
-
-export function StringFieldProgressBar({ value, percent, count }: Props) {
- const ariaLabel = `${value}: ${count} (${percent}%)`;
-
- return (
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/sidebar/types.ts b/src/plugins/discover_legacy/public/application/components/sidebar/types.ts
deleted file mode 100644
index a43120b28e96..000000000000
--- a/src/plugins/discover_legacy/public/application/components/sidebar/types.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export interface IndexPatternRef {
- id: string;
- title: string;
-}
-
-export interface FieldDetails {
- error: string;
- exists: number;
- total: number;
- buckets: Bucket[];
-}
-
-export interface FieldValueCounts extends Partial {
- missing?: number;
-}
-
-export interface Bucket {
- display: string;
- value: string;
- percent: number;
- count: number;
-}
diff --git a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/index.ts b/src/plugins/discover_legacy/public/application/components/skip_bottom_button/index.ts
deleted file mode 100644
index 094d8e286875..000000000000
--- a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { SkipBottomButton } from './skip_bottom_button';
diff --git a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx b/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx
deleted file mode 100644
index 28ffef9dae86..000000000000
--- a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.test.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { SkipBottomButton, SkipBottomButtonProps } from './skip_bottom_button';
-
-describe('Skip to Bottom Button', function () {
- let props: SkipBottomButtonProps;
- let component: ReactWrapper;
-
- beforeAll(() => {
- props = {
- onClick: jest.fn(),
- };
- });
-
- it('should be clickable', function () {
- component = mountWithIntl();
- component.simulate('click');
- expect(props.onClick).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.tsx b/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.tsx
deleted file mode 100644
index a1e5754cb312..000000000000
--- a/src/plugins/discover_legacy/public/application/components/skip_bottom_button/skip_bottom_button.tsx
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiSkipLink } from '@elastic/eui';
-import { FormattedMessage, I18nProvider } from '@osd/i18n/react';
-
-export interface SkipBottomButtonProps {
- /**
- * Action to perform on click
- */
- onClick: () => void;
-}
-
-export function SkipBottomButton({ onClick }: SkipBottomButtonProps) {
- return (
-
- {
- // prevent the anchor to reload the page on click
- event.preventDefault();
- // The destinationId prop cannot be leveraged here as the table needs
- // to be updated first (angular logic)
- onClick();
- }}
- className="dscSkipButton"
- destinationId=""
- data-test-subj="discoverSkipTableButton"
- >
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table.test.tsx b/src/plugins/discover_legacy/public/application/components/table/table.test.tsx
deleted file mode 100644
index 220ac57feae2..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table.test.tsx
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mount } from 'enzyme';
-import { findTestSubject } from 'test_utils/helpers';
-import { DocViewTable } from './table';
-import { indexPatterns, IndexPattern } from '../../../../../data/public';
-
-const indexPattern = ({
- fields: {
- getAll: () => [
- {
- name: '_index',
- type: 'string',
- scripted: false,
- filterable: true,
- },
- {
- name: 'message',
- type: 'string',
- scripted: false,
- filterable: false,
- },
- {
- name: 'extension',
- type: 'string',
- scripted: false,
- filterable: true,
- },
- {
- name: 'bytes',
- type: 'number',
- scripted: false,
- filterable: true,
- },
- {
- name: 'scripted',
- type: 'number',
- scripted: true,
- filterable: false,
- },
- ],
- },
- metaFields: ['_index', '_score'],
- flattenHit: undefined,
- formatHit: jest.fn((hit) => hit._source),
-} as unknown) as IndexPattern;
-
-indexPattern.fields.getByName = (name: string) => {
- return indexPattern.fields.getAll().find((field) => field.name === name);
-};
-
-indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);
-
-describe('DocViewTable at Discover', () => {
- // At Discover's main view, all buttons are rendered
- // check for existence of action buttons and warnings
-
- const hit = {
- _index: 'logstash-2014.09.09',
- _type: 'doc',
- _id: 'id123',
- _score: 1,
- _source: {
- message:
- 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
- Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus \
- et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, \
- ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. \
- Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, \
- rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. \
- Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. \
- Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut',
- extension: 'html',
- not_mapped: 'yes',
- bytes: 100,
- objectArray: [{ foo: true }],
- relatedContent: {
- test: 1,
- },
- scripted: 123,
- _underscore: 123,
- },
- };
-
- const props = {
- hit,
- columns: ['extension'],
- indexPattern,
- filter: jest.fn(),
- onAddColumn: jest.fn(),
- onRemoveColumn: jest.fn(),
- };
- const component = mount();
- [
- {
- _property: '_index',
- addInclusiveFilterButton: true,
- collapseBtn: false,
- noMappingWarning: false,
- toggleColumnButton: true,
- underscoreWarning: false,
- },
- {
- _property: 'message',
- addInclusiveFilterButton: false,
- collapseBtn: true,
- noMappingWarning: false,
- toggleColumnButton: true,
- underscoreWarning: false,
- },
- {
- _property: '_underscore',
- addInclusiveFilterButton: false,
- collapseBtn: false,
- noMappingWarning: false,
- toggleColumnButton: true,
- underScoreWarning: true,
- },
- {
- _property: 'scripted',
- addInclusiveFilterButton: false,
- collapseBtn: false,
- noMappingWarning: false,
- toggleColumnButton: true,
- underScoreWarning: false,
- },
- {
- _property: 'not_mapped',
- addInclusiveFilterButton: false,
- collapseBtn: false,
- noMappingWarning: true,
- toggleColumnButton: true,
- underScoreWarning: false,
- },
- ].forEach((check) => {
- const rowComponent = findTestSubject(component, `tableDocViewRow-${check._property}`);
-
- it(`renders row for ${check._property}`, () => {
- expect(rowComponent.length).toBe(1);
- });
-
- ([
- 'addInclusiveFilterButton',
- 'collapseBtn',
- 'toggleColumnButton',
- 'underscoreWarning',
- ] as const).forEach((element) => {
- const elementExist = check[element];
-
- if (typeof elementExist === 'boolean') {
- const btn = findTestSubject(rowComponent, element);
-
- it(`renders ${element} for '${check._property}' correctly`, () => {
- const disabled = btn.length ? btn.props().disabled : true;
- const clickAble = btn.length && !disabled ? true : false;
- expect(clickAble).toBe(elementExist);
- });
- }
- });
-
- (['noMappingWarning'] as const).forEach((element) => {
- const elementExist = check[element];
-
- if (typeof elementExist === 'boolean') {
- const el = findTestSubject(rowComponent, element);
-
- it(`renders ${element} for '${check._property}' correctly`, () => {
- expect(el.length).toBe(elementExist ? 1 : 0);
- });
- }
- });
- });
-});
-
-describe('DocViewTable at Discover Doc', () => {
- const hit = {
- _index: 'logstash-2014.09.09',
- _score: 1,
- _type: 'doc',
- _id: 'id123',
- _source: {
- extension: 'html',
- not_mapped: 'yes',
- },
- };
- // here no action buttons are rendered
- const props = {
- hit,
- indexPattern,
- };
- const component = mount();
- const foundLength = findTestSubject(component, 'addInclusiveFilterButton').length;
-
- it(`renders no action buttons`, () => {
- expect(foundLength).toBe(0);
- });
-});
-
-describe('DocViewTable at Discover Context', () => {
- // here no toggleColumnButtons are rendered
- const hit = {
- _index: 'logstash-2014.09.09',
- _type: 'doc',
- _id: 'id123',
- _score: 1,
- _source: {
- message:
- 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
- Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus \
- et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, \
- ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. \
- Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, \
- rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. \
- Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. \
- Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut',
- },
- };
- const props = {
- hit,
- columns: ['extension'],
- indexPattern,
- filter: jest.fn(),
- };
-
- const component = mount();
-
- it(`renders no toggleColumnButton`, () => {
- const foundLength = findTestSubject(component, 'toggleColumnButtons').length;
- expect(foundLength).toBe(0);
- });
-
- it(`renders addInclusiveFilterButton`, () => {
- const row = findTestSubject(component, `tableDocViewRow-_index`);
- const btn = findTestSubject(row, 'addInclusiveFilterButton');
- expect(btn.length).toBe(1);
- btn.simulate('click');
- expect(props.filter).toBeCalled();
- });
-
- it(`renders functional collapse button`, () => {
- const btn = findTestSubject(component, `collapseBtn`);
- const html = component.html();
-
- expect(component.html()).toContain('truncate-by-height');
-
- expect(btn.length).toBe(1);
- btn.simulate('click');
- expect(component.html() !== html).toBeTruthy();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/table/table.tsx b/src/plugins/discover_legacy/public/application/components/table/table.tsx
deleted file mode 100644
index 90167a515985..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table.tsx
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState } from 'react';
-import { escapeRegExp } from 'lodash';
-import { DocViewTableRow } from './table_row';
-import { arrayContainsObjects, trimAngularSpan } from './table_helper';
-import { DocViewRenderProps } from '../../doc_views/doc_views_types';
-
-const COLLAPSE_LINE_LENGTH = 350;
-
-export function DocViewTable({
- hit,
- indexPattern,
- filter,
- columns,
- onAddColumn,
- onRemoveColumn,
-}: DocViewRenderProps) {
- const mapping = indexPattern.fields.getByName;
- const flattened = indexPattern.flattenHit(hit);
- const formatted = indexPattern.formatHit(hit, 'html');
- const [fieldRowOpen, setFieldRowOpen] = useState({} as Record);
-
- function toggleValueCollapse(field: string) {
- fieldRowOpen[field] = fieldRowOpen[field] !== true;
- setFieldRowOpen({ ...fieldRowOpen });
- }
-
- return (
-
-
- {Object.keys(flattened)
- .sort()
- .map((field) => {
- const valueRaw = flattened[field];
- const value = trimAngularSpan(String(formatted[field]));
-
- const isCollapsible = value.length > COLLAPSE_LINE_LENGTH;
- const isCollapsed = isCollapsible && !fieldRowOpen[field];
- const toggleColumn =
- onRemoveColumn && onAddColumn && Array.isArray(columns)
- ? () => {
- if (columns.includes(field)) {
- onRemoveColumn(field);
- } else {
- onAddColumn(field);
- }
- }
- : undefined;
- const isArrayOfObjects =
- Array.isArray(flattened[field]) && arrayContainsObjects(flattened[field]);
- const displayUnderscoreWarning = !mapping(field) && field.indexOf('_') === 0;
- const displayNoMappingWarning =
- !mapping(field) && !displayUnderscoreWarning && !isArrayOfObjects;
-
- // Discover doesn't flatten arrays of objects, so for documents with an `object` or `nested` field that
- // contains an array, Discover will only detect the top level root field. We want to detect when those
- // root fields are `nested` so that we can display the proper icon and label. However, those root
- // `nested` fields are not a part of the index pattern. Their children are though, and contain nested path
- // info. So to detect nested fields we look through the index pattern for nested children
- // whose path begins with the current field. There are edge cases where
- // this could incorrectly identify a plain `object` field as `nested`. Say we had the following document
- // where `foo` is a plain object field and `bar` is a nested field.
- // {
- // "foo": [
- // {
- // "bar": [
- // {
- // "baz": "qux"
- // }
- // ]
- // },
- // {
- // "bar": [
- // {
- // "baz": "qux"
- // }
- // ]
- // }
- // ]
- // }
- //
- // The following code will search for `foo`, find it at the beginning of the path to the nested child field
- // `foo.bar.baz` and incorrectly mark `foo` as nested. Any time we're searching for the name of a plain object
- // field that happens to match a segment of a nested path, we'll get a false positive.
- // We're aware of this issue and we'll have to live with
- // it in the short term. The long term fix will be to add info about the `nested` and `object` root fields
- // to the index pattern, but that has its own complications which you can read more about in the following
- // issue: https://github.com/elastic/kibana/issues/54957
- const isNestedField =
- !indexPattern.fields.getByName(field) &&
- !!indexPattern.fields.getAll().find((patternField) => {
- // We only want to match a full path segment
- const nestedRootRegex = new RegExp(escapeRegExp(field) + '(\\.|$)');
- return nestedRootRegex.test(patternField.subType?.nested?.path ?? '');
- });
- const fieldType = isNestedField ? 'nested' : indexPattern.fields.getByName(field)?.type;
-
- return (
- toggleValueCollapse(field)}
- onToggleColumn={toggleColumn}
- value={value}
- valueRaw={valueRaw}
- />
- );
- })}
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_helper.test.ts b/src/plugins/discover_legacy/public/application/components/table/table_helper.test.ts
deleted file mode 100644
index 20c1092ef86d..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_helper.test.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { arrayContainsObjects } from './table_helper';
-
-describe('arrayContainsObjects', () => {
- it(`returns false for an array of primitives`, () => {
- const actual = arrayContainsObjects(['test', 'test']);
- expect(actual).toBeFalsy();
- });
-
- it(`returns true for an array of objects`, () => {
- const actual = arrayContainsObjects([{}, {}]);
- expect(actual).toBeTruthy();
- });
-
- it(`returns true for an array of objects and primitves`, () => {
- const actual = arrayContainsObjects([{}, 'sdf']);
- expect(actual).toBeTruthy();
- });
-
- it(`returns false for an array of null values`, () => {
- const actual = arrayContainsObjects([null, null]);
- expect(actual).toBeFalsy();
- });
-
- it(`returns false if no array is given`, () => {
- const actual = arrayContainsObjects([null, null]);
- expect(actual).toBeFalsy();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_helper.tsx b/src/plugins/discover_legacy/public/application/components/table/table_helper.tsx
deleted file mode 100644
index 2e63b43b8310..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_helper.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Returns true if the given array contains at least 1 object
- */
-export function arrayContainsObjects(value: unknown[]): boolean {
- return Array.isArray(value) && value.some((v) => typeof v === 'object' && v !== null);
-}
-
-/**
- * Removes markup added by OpenSearch Dashboards fields html formatter
- */
-export function trimAngularSpan(text: string): string {
- return text.replace(/^/, '').replace(/<\/span>$/, '');
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row.tsx
deleted file mode 100644
index 95ba38106e3e..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row.tsx
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import classNames from 'classnames';
-import React, { ReactNode } from 'react';
-import { FieldMapping, DocViewFilterFn } from '../../doc_views/doc_views_types';
-import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add';
-import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove';
-import { DocViewTableRowBtnToggleColumn } from './table_row_btn_toggle_column';
-import { DocViewTableRowBtnCollapse } from './table_row_btn_collapse';
-import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists';
-import { DocViewTableRowIconNoMapping } from './table_row_icon_no_mapping';
-import { DocViewTableRowIconUnderscore } from './table_row_icon_underscore';
-import { FieldName } from '../field_name/field_name';
-
-export interface Props {
- field: string;
- fieldMapping?: FieldMapping;
- fieldType: string;
- displayNoMappingWarning: boolean;
- displayUnderscoreWarning: boolean;
- isCollapsible: boolean;
- isColumnActive: boolean;
- isCollapsed: boolean;
- onToggleCollapse: () => void;
- onFilter?: DocViewFilterFn;
- onToggleColumn?: () => void;
- value: string | ReactNode;
- valueRaw: unknown;
-}
-
-export function DocViewTableRow({
- field,
- fieldMapping,
- fieldType,
- displayNoMappingWarning,
- displayUnderscoreWarning,
- isCollapsible,
- isCollapsed,
- isColumnActive,
- onFilter,
- onToggleCollapse,
- onToggleColumn,
- value,
- valueRaw,
-}: Props) {
- const valueClassName = classNames({
- // eslint-disable-next-line @typescript-eslint/naming-convention
- osdDocViewer__value: true,
- 'truncate-by-height': isCollapsible && isCollapsed,
- });
-
- return (
-
- {typeof onFilter === 'function' && (
-
- onFilter(fieldMapping, valueRaw, '+')}
- />
- onFilter(fieldMapping, valueRaw, '-')}
- />
- {typeof onToggleColumn === 'function' && (
-
- )}
- onFilter('_exists_', field, '+')}
- scripted={fieldMapping && fieldMapping.scripted}
- />
- |
- )}
-
-
- |
-
- {isCollapsible && (
-
- )}
- {displayUnderscoreWarning && }
- {displayNoMappingWarning && }
-
- |
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_collapse.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_btn_collapse.tsx
deleted file mode 100644
index de25c73e9c95..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_collapse.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { i18n } from '@osd/i18n';
-import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
-
-export interface Props {
- onClick: () => void;
- isCollapsed: boolean;
-}
-
-export function DocViewTableRowBtnCollapse({ onClick, isCollapsed }: Props) {
- const label = i18n.translate('discover.docViews.table.toggleFieldDetails', {
- defaultMessage: 'Toggle field details',
- });
- return (
-
- onClick()}
- iconType={isCollapsed ? 'arrowRight' : 'arrowDown'}
- iconSize={'s'}
- />
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_add.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_add.tsx
deleted file mode 100644
index 1707861faf28..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_add.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage } from '@osd/i18n/react';
-import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export interface Props {
- onClick: () => void;
- disabled: boolean;
-}
-
-export function DocViewTableRowBtnFilterAdd({ onClick, disabled = false }: Props) {
- const tooltipContent = disabled ? (
-
- ) : (
-
- );
-
- return (
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_exists.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_exists.tsx
deleted file mode 100644
index d4f401282e14..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_exists.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage } from '@osd/i18n/react';
-import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export interface Props {
- onClick: () => void;
- disabled?: boolean;
- scripted?: boolean;
-}
-
-export function DocViewTableRowBtnFilterExists({
- onClick,
- disabled = false,
- scripted = false,
-}: Props) {
- const tooltipContent = disabled ? (
- scripted ? (
-
- ) : (
-
- )
- ) : (
-
- );
-
- return (
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_remove.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_remove.tsx
deleted file mode 100644
index 3b58fbfdc282..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_filter_remove.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage } from '@osd/i18n/react';
-import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export interface Props {
- onClick: () => void;
- disabled?: boolean;
-}
-
-export function DocViewTableRowBtnFilterRemove({ onClick, disabled = false }: Props) {
- const tooltipContent = disabled ? (
-
- ) : (
-
- );
-
- return (
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_toggle_column.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_btn_toggle_column.tsx
deleted file mode 100644
index 74f0972fa0ee..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_btn_toggle_column.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { FormattedMessage } from '@osd/i18n/react';
-import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export interface Props {
- active: boolean;
- disabled?: boolean;
- onClick: () => void;
-}
-
-export function DocViewTableRowBtnToggleColumn({ onClick, active, disabled = false }: Props) {
- if (disabled) {
- return (
-
- );
- }
- return (
-
- }
- >
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_icon_no_mapping.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_icon_no_mapping.tsx
deleted file mode 100644
index edc4bea91bd8..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_icon_no_mapping.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiIconTip } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export function DocViewTableRowIconNoMapping() {
- const ariaLabel = i18n.translate('discover.docViews.table.noCachedMappingForThisFieldAriaLabel', {
- defaultMessage: 'Warning',
- });
- const tooltipContent = i18n.translate(
- 'discover.docViews.table.noCachedMappingForThisFieldTooltip',
- {
- defaultMessage:
- 'No cached mapping for this field. Refresh field list from the Management > Index Patterns page',
- }
- );
- return (
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/table/table_row_icon_underscore.tsx b/src/plugins/discover_legacy/public/application/components/table/table_row_icon_underscore.tsx
deleted file mode 100644
index f1d09e2c8d44..000000000000
--- a/src/plugins/discover_legacy/public/application/components/table/table_row_icon_underscore.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { EuiIconTip } from '@elastic/eui';
-import { i18n } from '@osd/i18n';
-
-export function DocViewTableRowIconUnderscore() {
- const ariaLabel = i18n.translate(
- 'discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel',
- {
- defaultMessage: 'Warning',
- }
- );
- const tooltipContent = i18n.translate(
- 'discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip',
- {
- defaultMessage: 'Field names beginning with {underscoreSign} are not supported',
- values: { underscoreSign: '_' },
- }
- );
-
- return (
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/timechart_header/index.ts b/src/plugins/discover_legacy/public/application/components/timechart_header/index.ts
deleted file mode 100644
index 880610ac57e9..000000000000
--- a/src/plugins/discover_legacy/public/application/components/timechart_header/index.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { TimechartHeader } from './timechart_header';
diff --git a/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.test.tsx b/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.test.tsx
deleted file mode 100644
index 9011c38a6acb..000000000000
--- a/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.test.tsx
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { mountWithIntl } from 'test_utils/enzyme_helpers';
-import { ReactWrapper } from 'enzyme';
-import { TimechartHeader, TimechartHeaderProps } from './timechart_header';
-import { EuiIconTip } from '@elastic/eui';
-import { findTestSubject } from 'test_utils/helpers';
-
-describe('timechart header', function () {
- let props: TimechartHeaderProps;
- let component: ReactWrapper;
-
- beforeAll(() => {
- props = {
- timeRange: {
- from: 'May 14, 2020 @ 11:05:13.590',
- to: 'May 14, 2020 @ 11:20:13.590',
- },
- stateInterval: 's',
- options: [
- {
- display: 'Auto',
- val: 'auto',
- },
- {
- display: 'Millisecond',
- val: 'ms',
- },
- {
- display: 'Second',
- val: 's',
- },
- ],
- onChangeInterval: jest.fn(),
- bucketInterval: {
- scaled: undefined,
- description: 'second',
- scale: undefined,
- },
- };
- });
-
- it('TimechartHeader not renders an info text when the showScaledInfo property is not provided', () => {
- component = mountWithIntl();
- expect(component.find(EuiIconTip).length).toBe(0);
- });
-
- it('TimechartHeader renders an info when bucketInterval.scale is set to true', () => {
- props.bucketInterval!.scaled = true;
- component = mountWithIntl();
- expect(component.find(EuiIconTip).length).toBe(1);
- });
-
- it('expect to render the date range', function () {
- component = mountWithIntl();
- const datetimeRangeText = findTestSubject(component, 'discoverIntervalDateRange');
- expect(datetimeRangeText.text()).toBe(
- 'May 14, 2020 @ 11:05:13.590 - May 14, 2020 @ 11:20:13.590 per'
- );
- });
-
- it('expects to render a dropdown with the interval options', () => {
- component = mountWithIntl();
- const dropdown = findTestSubject(component, 'discoverIntervalSelect');
- expect(dropdown.length).toBe(1);
- // @ts-ignore
- const values = dropdown.find('option').map((option) => option.prop('value'));
- expect(values).toEqual(['auto', 'ms', 's']);
- // @ts-ignore
- const labels = dropdown.find('option').map((option) => option.text());
- expect(labels).toEqual(['Auto', 'Millisecond', 'Second']);
- });
-
- it('should change the interval', function () {
- component = mountWithIntl();
- findTestSubject(component, 'discoverIntervalSelect').simulate('change', {
- target: { value: 'ms' },
- });
- expect(props.onChangeInterval).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.tsx b/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.tsx
deleted file mode 100644
index b73e8b162570..000000000000
--- a/src/plugins/discover_legacy/public/application/components/timechart_header/timechart_header.tsx
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React, { useState, useEffect, useCallback } from 'react';
-import {
- EuiFlexGroup,
- EuiFlexItem,
- EuiToolTip,
- EuiText,
- EuiSelect,
- EuiIconTip,
-} from '@elastic/eui';
-import { I18nProvider } from '@osd/i18n/react';
-import { i18n } from '@osd/i18n';
-import moment from 'moment';
-
-export interface TimechartHeaderProps {
- /**
- * Format of date to be displayed
- */
- dateFormat?: string;
- /**
- * Interval for the buckets of the recent request
- */
- bucketInterval?: {
- scaled?: boolean;
- description?: string;
- scale?: number;
- };
- /**
- * Range of dates to be displayed
- */
- timeRange?: {
- from: string;
- to: string;
- };
- /**
- * Interval Options
- */
- options: Array<{ display: string; val: string }>;
- /**
- * changes the interval
- */
- onChangeInterval: (interval: string) => void;
- /**
- * selected interval
- */
- stateInterval: string;
-}
-
-export function TimechartHeader({
- bucketInterval,
- dateFormat,
- timeRange,
- options,
- onChangeInterval,
- stateInterval,
-}: TimechartHeaderProps) {
- const [interval, setInterval] = useState(stateInterval);
- const toMoment = useCallback(
- (datetime: string) => {
- if (!datetime) {
- return '';
- }
- if (!dateFormat) {
- return datetime;
- }
- return moment(datetime).format(dateFormat);
- },
- [dateFormat]
- );
-
- useEffect(() => {
- setInterval(stateInterval);
- }, [stateInterval]);
-
- const handleIntervalChange = (e: React.ChangeEvent) => {
- setInterval(e.target.value);
- onChangeInterval(e.target.value);
- };
-
- if (!timeRange || !bucketInterval) {
- return null;
- }
-
- return (
-
-
-
-
-
- {`${toMoment(timeRange.from)} - ${toMoment(timeRange.to)} ${
- interval !== 'auto'
- ? i18n.translate('discover.timechartHeader.timeIntervalSelect.per', {
- defaultMessage: 'per',
- })
- : ''
- }`}
-
-
-
-
- val !== 'custom')
- .map(({ display, val }) => {
- return {
- text: display,
- value: val,
- label: display,
- };
- })}
- value={interval}
- onChange={handleIntervalChange}
- append={
- bucketInterval.scaled ? (
- 1
- ? i18n.translate('discover.bucketIntervalTooltip.tooLargeBucketsText', {
- defaultMessage: 'buckets that are too large',
- })
- : i18n.translate('discover.bucketIntervalTooltip.tooManyBucketsText', {
- defaultMessage: 'too many buckets',
- }),
- bucketIntervalDescription: bucketInterval.description,
- },
- })}
- color="warning"
- size="s"
- type="alert"
- />
- ) : undefined
- }
- />
-
-
-
- );
-}
diff --git a/src/plugins/discover_legacy/public/application/components/top_nav/__snapshots__/open_search_panel.test.js.snap b/src/plugins/discover_legacy/public/application/components/top_nav/__snapshots__/open_search_panel.test.js.snap
deleted file mode 100644
index 342dea206c30..000000000000
--- a/src/plugins/discover_legacy/public/application/components/top_nav/__snapshots__/open_search_panel.test.js.snap
+++ /dev/null
@@ -1,69 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`render 1`] = `
-
-
-
-
-
-
-
-
-
-
- }
- onChoose={[Function]}
- savedObjectMetaData={
- Array [
- Object {
- "getIconForSavedObject": [Function],
- "name": "Saved search",
- "type": "search",
- },
- ]
- }
- savedObjects={Object {}}
- uiSettings={Object {}}
- />
-
-
-
-
-
-
-
-
-
-
-
-`;
diff --git a/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.js b/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.js
deleted file mode 100644
index f575b8dee625..000000000000
--- a/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import PropTypes from 'prop-types';
-import rison from 'rison-node';
-import { i18n } from '@osd/i18n';
-import { FormattedMessage } from '@osd/i18n/react';
-import {
- EuiButton,
- EuiFlexGroup,
- EuiFlexItem,
- EuiFlyout,
- EuiFlyoutHeader,
- EuiFlyoutFooter,
- EuiFlyoutBody,
- EuiTitle,
-} from '@elastic/eui';
-import { SavedObjectFinderUi } from '../../../../../saved_objects/public';
-import { getServices } from '../../../opensearch_dashboards_services';
-
-const SEARCH_OBJECT_TYPE = 'search';
-
-export function OpenSearchPanel(props) {
- const {
- core: { uiSettings, savedObjects },
- addBasePath,
- } = getServices();
-
- return (
-
-
-
-
-
-
-
-
-
-
- }
- savedObjectMetaData={[
- {
- type: SEARCH_OBJECT_TYPE,
- getIconForSavedObject: () => 'search',
- name: i18n.translate('discover.savedSearch.savedObjectName', {
- defaultMessage: 'Saved search',
- }),
- },
- ]}
- onChoose={(id) => {
- window.location.assign(props.makeUrl(id));
- props.onClose();
- }}
- uiSettings={uiSettings}
- savedObjects={savedObjects}
- />
-
-
-
-
- {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
-
-
-
-
-
-
-
- );
-}
-
-OpenSearchPanel.propTypes = {
- onClose: PropTypes.func.isRequired,
- makeUrl: PropTypes.func.isRequired,
-};
diff --git a/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.test.js b/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.test.js
deleted file mode 100644
index 6316471e9a40..000000000000
--- a/src/plugins/discover_legacy/public/application/components/top_nav/open_search_panel.test.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import { shallow } from 'enzyme';
-
-jest.mock('../../../opensearch_dashboards_services', () => {
- return {
- getServices: () => ({
- core: { uiSettings: {}, savedObjects: {} },
- addBasePath: (path) => path,
- }),
- };
-});
-
-import { OpenSearchPanel } from './open_search_panel';
-
-test('render', () => {
- const component = shallow( {}} makeUrl={() => {}} />);
- expect(component).toMatchSnapshot();
-});
diff --git a/src/plugins/discover_legacy/public/application/components/top_nav/show_open_search_panel.js b/src/plugins/discover_legacy/public/application/components/top_nav/show_open_search_panel.js
deleted file mode 100644
index 8cb550f49f16..000000000000
--- a/src/plugins/discover_legacy/public/application/components/top_nav/show_open_search_panel.js
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import React from 'react';
-import ReactDOM from 'react-dom';
-import { OpenSearchPanel } from './open_search_panel';
-
-let isOpen = false;
-
-export function showOpenSearchPanel({ makeUrl, I18nContext }) {
- if (isOpen) {
- return;
- }
-
- isOpen = true;
- const container = document.createElement('div');
- const onClose = () => {
- ReactDOM.unmountComponentAtNode(container);
- document.body.removeChild(container);
- isOpen = false;
- };
-
- document.body.appendChild(container);
- const element = (
-
-
-
- );
- ReactDOM.render(element, container);
-}
diff --git a/src/plugins/discover_legacy/public/application/doc_views/doc_views_helpers.tsx b/src/plugins/discover_legacy/public/application/doc_views/doc_views_helpers.tsx
deleted file mode 100644
index e113f6961fc3..000000000000
--- a/src/plugins/discover_legacy/public/application/doc_views/doc_views_helpers.tsx
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { auto, IController } from 'angular';
-import React from 'react';
-import { render } from 'react-dom';
-import angular, { ICompileService } from 'angular';
-import { DocViewRenderProps, AngularScope, AngularDirective } from './doc_views_types';
-import { DocViewerError } from '../components/doc_viewer/doc_viewer_render_error';
-
-/**
- * Compiles and injects the give angular template into the given dom node
- * returns a function to cleanup the injected angular element
- */
-export async function injectAngularElement(
- domNode: Element,
- template: string,
- scopeProps: DocViewRenderProps,
- Controller: IController,
- getInjector: () => Promise
-): Promise<() => void> {
- const $injector = await getInjector();
- const rootScope: AngularScope = $injector.get('$rootScope');
- const $compile: ICompileService = $injector.get('$compile');
- const newScope = Object.assign(rootScope.$new(), scopeProps);
-
- if (typeof Controller === 'function') {
- // when a controller is defined, expose the value it produces to the view as `$ctrl`
- // see: https://docs.angularjs.org/api/ng/provider/$compileProvider#component
- (newScope as any).$ctrl = $injector.instantiate(Controller, {
- $scope: newScope,
- });
- }
-
- const $target = angular.element(domNode);
- const $element = angular.element(template);
-
- newScope.$apply(() => {
- const linkFn = $compile($element);
- $target.empty().append($element);
- linkFn(newScope);
- });
-
- return () => {
- newScope.$destroy();
- };
-}
-/**
- * Converts a given legacy angular directive to a render function
- * for usage in a react component. Note that the rendering is async
- */
-export function convertDirectiveToRenderFn(
- directive: AngularDirective,
- getInjector: () => Promise
-) {
- return (domNode: Element, props: DocViewRenderProps) => {
- let rejected = false;
-
- const cleanupFnPromise = injectAngularElement(
- domNode,
- directive.template,
- props,
- directive.controller,
- getInjector
- );
- cleanupFnPromise.catch((e) => {
- rejected = true;
- render(, domNode);
- });
-
- return () => {
- if (!rejected) {
- // for cleanup
- cleanupFnPromise.then((cleanup) => cleanup());
- }
- };
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/doc_views/doc_views_registry.ts b/src/plugins/discover_legacy/public/application/doc_views/doc_views_registry.ts
deleted file mode 100644
index 56f167b5f2cc..000000000000
--- a/src/plugins/discover_legacy/public/application/doc_views/doc_views_registry.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { auto } from 'angular';
-import { convertDirectiveToRenderFn } from './doc_views_helpers';
-import { DocView, DocViewInput, OpenSearchSearchHit, DocViewInputFn } from './doc_views_types';
-
-export class DocViewsRegistry {
- private docViews: DocView[] = [];
- private angularInjectorGetter: (() => Promise) | null = null;
-
- setAngularInjectorGetter = (injectorGetter: () => Promise) => {
- this.angularInjectorGetter = injectorGetter;
- };
-
- /**
- * Extends and adds the given doc view to the registry array
- */
- addDocView(docViewRaw: DocViewInput | DocViewInputFn) {
- const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw;
- if (docView.directive) {
- // convert angular directive to render function for backwards compatibility
- docView.render = convertDirectiveToRenderFn(docView.directive, () => {
- if (!this.angularInjectorGetter) {
- throw new Error('Angular was not initialized');
- }
- return this.angularInjectorGetter();
- });
- }
- if (typeof docView.shouldShow !== 'function') {
- docView.shouldShow = () => true;
- }
- this.docViews.push(docView as DocView);
- }
- /**
- * Returns a sorted array of doc_views for rendering tabs
- */
- getDocViewsSorted(hit: OpenSearchSearchHit) {
- return this.docViews
- .filter((docView) => docView.shouldShow(hit))
- .sort((a, b) => (Number(a.order) > Number(b.order) ? 1 : -1));
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/doc_views/doc_views_types.ts b/src/plugins/discover_legacy/public/application/doc_views/doc_views_types.ts
deleted file mode 100644
index 961fc98516f6..000000000000
--- a/src/plugins/discover_legacy/public/application/doc_views/doc_views_types.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { ComponentType } from 'react';
-import { IScope } from 'angular';
-import { SearchResponse } from 'elasticsearch';
-import { IndexPattern } from '../../../../data/public';
-
-export interface AngularDirective {
- controller: (...injectedServices: any[]) => void;
- template: string;
-}
-
-export type AngularScope = IScope;
-
-export type OpenSearchSearchHit = SearchResponse['hits']['hits'][number];
-
-export interface FieldMapping {
- filterable?: boolean;
- scripted?: boolean;
- rowCount?: number;
- type: string;
- name: string;
-}
-
-export type DocViewFilterFn = (
- mapping: FieldMapping | string | undefined,
- value: unknown,
- mode: '+' | '-'
-) => void;
-
-export interface DocViewRenderProps {
- columns?: string[];
- filter?: DocViewFilterFn;
- hit: OpenSearchSearchHit;
- indexPattern: IndexPattern;
- onAddColumn?: (columnName: string) => void;
- onRemoveColumn?: (columnName: string) => void;
-}
-export type DocViewerComponent = ComponentType;
-export type DocViewRenderFn = (
- domeNode: HTMLDivElement,
- renderProps: DocViewRenderProps
-) => () => void;
-
-export interface DocViewInput {
- component?: DocViewerComponent;
- directive?: AngularDirective;
- order: number;
- render?: DocViewRenderFn;
- shouldShow?: (hit: OpenSearchSearchHit) => boolean;
- title: string;
-}
-
-export interface DocView extends DocViewInput {
- shouldShow: (hit: OpenSearchSearchHit) => boolean;
-}
-
-export type DocViewInputFn = () => DocViewInput;
diff --git a/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_registry.ts b/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_registry.ts
deleted file mode 100644
index 16653f5d5377..000000000000
--- a/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_registry.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import { DocViewLink } from './doc_views_links_types';
-
-export class DocViewsLinksRegistry {
- private docViewsLinks: DocViewLink[] = [];
-
- addDocViewLink(docViewLink: DocViewLink) {
- this.docViewsLinks.push(docViewLink);
- }
-
- getDocViewsLinksSorted() {
- return this.docViewsLinks.sort((a, b) => (Number(a.order) > Number(b.order) ? 1 : -1));
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_types.ts b/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_types.ts
deleted file mode 100644
index bbc5caadafcd..000000000000
--- a/src/plugins/discover_legacy/public/application/doc_views_links/doc_views_links_types.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import { EuiListGroupItemProps } from '@elastic/eui';
-import { OpenSearchSearchHit } from '../doc_views/doc_views_types';
-import { IndexPattern } from '../../../../data/public';
-
-export interface DocViewLink extends EuiListGroupItemProps {
- href?: string;
- order: number;
- generateCb?(
- renderProps: any
- ): {
- url: string;
- hide?: boolean;
- };
-}
-
-export interface DocViewLinkRenderProps {
- columns?: string[];
- hit: OpenSearchSearchHit;
- indexPattern: IndexPattern;
-}
diff --git a/src/plugins/discover_legacy/public/application/embeddable/constants.ts b/src/plugins/discover_legacy/public/application/embeddable/constants.ts
deleted file mode 100644
index 82f428ea4e4b..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/constants.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export const SEARCH_EMBEDDABLE_TYPE = 'search';
diff --git a/src/plugins/discover_legacy/public/application/embeddable/index.ts b/src/plugins/discover_legacy/public/application/embeddable/index.ts
deleted file mode 100644
index ecb5e98f43c1..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/index.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { SEARCH_EMBEDDABLE_TYPE } from './constants';
-export * from './types';
-export * from './search_embeddable_factory';
diff --git a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.scss b/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.scss
deleted file mode 100644
index e953968495e7..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.scss
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * 1. We want the osdDocTable__container to scroll only when embedded in an embeddable panel
- * 2. Force a better looking scrollbar
- */
-.embPanel {
- .osdDocTable__container {
- @include euiScrollBar; /* 2 */
-
- flex: 1 1 0; /* 1 */
- overflow: auto; /* 1 */
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.ts b/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.ts
deleted file mode 100644
index 933f807f8153..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable.ts
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import './search_embeddable.scss';
-import angular from 'angular';
-import _ from 'lodash';
-import * as Rx from 'rxjs';
-import { Subscription } from 'rxjs';
-import { i18n } from '@osd/i18n';
-import { UiActionsStart, APPLY_FILTER_TRIGGER } from '../../../../ui_actions/public';
-import { RequestAdapter, Adapters } from '../../../../inspector/public';
-import {
- opensearchFilters,
- Filter,
- TimeRange,
- FilterManager,
- getTime,
- Query,
- IFieldType,
-} from '../../../../data/public';
-import { Container, Embeddable } from '../../../../embeddable/public';
-import * as columnActions from '../angular/doc_table/actions/columns';
-import searchTemplate from './search_template.html';
-import { ISearchEmbeddable, SearchInput, SearchOutput } from './types';
-import { SortOrder } from '../angular/doc_table/components/table_header/helpers';
-import { getSortForSearchSource } from '../angular/doc_table';
-import {
- getRequestInspectorStats,
- getResponseInspectorStats,
- getServices,
- IndexPattern,
- ISearchSource,
-} from '../../opensearch_dashboards_services';
-import { SEARCH_EMBEDDABLE_TYPE } from './constants';
-import { SavedSearch } from '../..';
-import { SAMPLE_SIZE_SETTING, SORT_DEFAULT_ORDER_SETTING } from '../../../common';
-
-interface SearchScope extends ng.IScope {
- columns?: string[];
- description?: string;
- sort?: SortOrder[];
- sharedItemTitle?: string;
- inspectorAdapters?: Adapters;
- setSortOrder?: (sortPair: SortOrder[]) => void;
- removeColumn?: (column: string) => void;
- addColumn?: (column: string) => void;
- moveColumn?: (column: string, index: number) => void;
- filter?: (field: IFieldType, value: string[], operator: string) => void;
- hits?: any[];
- indexPattern?: IndexPattern;
- totalHitCount?: number;
- isLoading?: boolean;
-}
-
-interface SearchEmbeddableConfig {
- $rootScope: ng.IRootScopeService;
- $compile: ng.ICompileService;
- savedSearch: SavedSearch;
- editUrl: string;
- editPath: string;
- indexPatterns?: IndexPattern[];
- editable: boolean;
- filterManager: FilterManager;
-}
-
-export class SearchEmbeddable
- extends Embeddable
- implements ISearchEmbeddable {
- private readonly savedSearch: SavedSearch;
- private $rootScope: ng.IRootScopeService;
- private $compile: ng.ICompileService;
- private inspectorAdaptors: Adapters;
- private searchScope?: SearchScope;
- private panelTitle: string = '';
- private filtersSearchSource?: ISearchSource;
- private searchInstance?: JQLite;
- private autoRefreshFetchSubscription?: Subscription;
- private subscription?: Subscription;
- public readonly type = SEARCH_EMBEDDABLE_TYPE;
- private filterManager: FilterManager;
- private abortController?: AbortController;
-
- private prevTimeRange?: TimeRange;
- private prevFilters?: Filter[];
- private prevQuery?: Query;
-
- constructor(
- {
- $rootScope,
- $compile,
- savedSearch,
- editUrl,
- editPath,
- indexPatterns,
- editable,
- filterManager,
- }: SearchEmbeddableConfig,
- initialInput: SearchInput,
- private readonly executeTriggerActions: UiActionsStart['executeTriggerActions'],
- parent?: Container
- ) {
- super(
- initialInput,
- {
- defaultTitle: savedSearch.title,
- editUrl,
- editPath,
- editApp: 'discover',
- indexPatterns,
- editable,
- },
- parent
- );
-
- this.filterManager = filterManager;
- this.savedSearch = savedSearch;
- this.$rootScope = $rootScope;
- this.$compile = $compile;
- this.inspectorAdaptors = {
- requests: new RequestAdapter(),
- };
- this.initializeSearchScope();
-
- this.autoRefreshFetchSubscription = getServices()
- .timefilter.getAutoRefreshFetch$()
- .subscribe(this.fetch);
-
- this.subscription = Rx.merge(this.getOutput$(), this.getInput$()).subscribe(() => {
- this.panelTitle = this.output.title || '';
-
- if (this.searchScope) {
- this.pushContainerStateParamsToScope(this.searchScope);
- }
- });
- }
-
- public getInspectorAdapters() {
- return this.inspectorAdaptors;
- }
-
- public getSavedSearch() {
- return this.savedSearch;
- }
-
- /**
- *
- * @param {Element} domNode
- */
- public render(domNode: HTMLElement) {
- if (!this.searchScope) {
- throw new Error('Search scope not defined');
- }
- this.searchInstance = this.$compile(searchTemplate)(this.searchScope);
- const rootNode = angular.element(domNode);
- rootNode.append(this.searchInstance);
-
- this.pushContainerStateParamsToScope(this.searchScope);
- }
-
- public destroy() {
- super.destroy();
- this.savedSearch.destroy();
- if (this.searchInstance) {
- this.searchInstance.remove();
- }
- if (this.searchScope) {
- this.searchScope.$destroy();
- delete this.searchScope;
- }
- if (this.subscription) {
- this.subscription.unsubscribe();
- }
- if (this.autoRefreshFetchSubscription) {
- this.autoRefreshFetchSubscription.unsubscribe();
- }
- if (this.abortController) this.abortController.abort();
- }
-
- private initializeSearchScope() {
- const searchScope: SearchScope = (this.searchScope = this.$rootScope.$new());
-
- searchScope.description = this.savedSearch.description;
- searchScope.inspectorAdapters = this.inspectorAdaptors;
-
- const { searchSource } = this.savedSearch;
- const indexPattern = (searchScope.indexPattern = searchSource.getField('index'))!;
-
- const timeRangeSearchSource = searchSource.create();
- timeRangeSearchSource.setField('filter', () => {
- if (!this.searchScope || !this.input.timeRange) return;
- return getTime(indexPattern, this.input.timeRange);
- });
-
- this.filtersSearchSource = searchSource.create();
- this.filtersSearchSource.setParent(timeRangeSearchSource);
-
- searchSource.setParent(this.filtersSearchSource);
-
- this.pushContainerStateParamsToScope(searchScope);
-
- searchScope.setSortOrder = (sort) => {
- this.updateInput({ sort });
- };
-
- searchScope.addColumn = (columnName: string) => {
- if (!searchScope.columns) {
- return;
- }
- const columns = columnActions.addColumn(searchScope.columns, columnName);
- this.updateInput({ columns });
- };
-
- searchScope.removeColumn = (columnName: string) => {
- if (!searchScope.columns) {
- return;
- }
- const columns = columnActions.removeColumn(searchScope.columns, columnName);
- this.updateInput({ columns });
- };
-
- searchScope.moveColumn = (columnName, newIndex: number) => {
- if (!searchScope.columns) {
- return;
- }
- const columns = columnActions.moveColumn(searchScope.columns, columnName, newIndex);
- this.updateInput({ columns });
- };
-
- searchScope.filter = async (field, value, operator) => {
- let filters = opensearchFilters.generateFilters(
- this.filterManager,
- field,
- value,
- operator,
- indexPattern.id!
- );
- filters = filters.map((filter) => ({
- ...filter,
- $state: { store: opensearchFilters.FilterStateStore.APP_STATE },
- }));
-
- await this.executeTriggerActions(APPLY_FILTER_TRIGGER, {
- embeddable: this,
- filters,
- });
- };
- }
-
- public reload() {
- this.fetch();
- }
-
- private fetch = async () => {
- if (!this.searchScope) return;
-
- const { searchSource } = this.savedSearch;
-
- // Abort any in-progress requests
- if (this.abortController) this.abortController.abort();
- this.abortController = new AbortController();
-
- searchSource.setField('size', getServices().uiSettings.get(SAMPLE_SIZE_SETTING));
- searchSource.setField(
- 'sort',
- getSortForSearchSource(
- this.searchScope.sort,
- this.searchScope.indexPattern,
- getServices().uiSettings.get(SORT_DEFAULT_ORDER_SETTING)
- )
- );
-
- // Log request to inspector
- this.inspectorAdaptors.requests.reset();
- const title = i18n.translate('discover.embeddable.inspectorRequestDataTitle', {
- defaultMessage: 'Data',
- });
- const description = i18n.translate('discover.embeddable.inspectorRequestDescription', {
- defaultMessage: 'This request queries OpenSearch to fetch the data for the search.',
- });
- const inspectorRequest = this.inspectorAdaptors.requests.start(title, { description });
- inspectorRequest.stats(getRequestInspectorStats(searchSource));
- searchSource.getSearchRequestBody().then((body: Record) => {
- inspectorRequest.json(body);
- });
- this.updateOutput({ loading: true, error: undefined });
-
- try {
- // Make the request
- const resp = await searchSource.fetch({
- abortSignal: this.abortController.signal,
- });
- this.updateOutput({ loading: false, error: undefined });
-
- // Log response to inspector
- inspectorRequest.stats(getResponseInspectorStats(resp, searchSource)).ok({ json: resp });
-
- // Apply the changes to the angular scope
- this.searchScope.$apply(() => {
- this.searchScope!.hits = resp.hits.hits;
- this.searchScope!.totalHitCount = resp.hits.total;
- });
- } catch (error) {
- this.updateOutput({ loading: false, error });
- }
- };
-
- private pushContainerStateParamsToScope(searchScope: SearchScope) {
- const isFetchRequired =
- !opensearchFilters.onlyDisabledFiltersChanged(this.input.filters, this.prevFilters) ||
- !_.isEqual(this.prevQuery, this.input.query) ||
- !_.isEqual(this.prevTimeRange, this.input.timeRange) ||
- !_.isEqual(searchScope.sort, this.input.sort || this.savedSearch.sort);
-
- // If there is column or sort data on the panel, that means the original columns or sort settings have
- // been overridden in a dashboard.
- searchScope.columns = this.input.columns || this.savedSearch.columns;
- searchScope.sort = this.input.sort || this.savedSearch.sort;
- searchScope.sharedItemTitle = this.panelTitle;
-
- if (isFetchRequired) {
- this.filtersSearchSource!.setField('filter', this.input.filters);
- this.filtersSearchSource!.setField('query', this.input.query);
-
- this.fetch();
-
- this.prevFilters = this.input.filters;
- this.prevQuery = this.input.query;
- this.prevTimeRange = this.input.timeRange;
- } else if (this.searchScope) {
- // trigger a digest cycle to make sure non-fetch relevant changes are propagated
- this.searchScope.$applyAsync();
- }
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable_factory.ts b/src/plugins/discover_legacy/public/application/embeddable/search_embeddable_factory.ts
deleted file mode 100644
index 9b8c540713ce..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/search_embeddable_factory.ts
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { auto } from 'angular';
-import { i18n } from '@osd/i18n';
-import { UiActionsStart } from 'src/plugins/ui_actions/public';
-import { getServices } from '../../opensearch_dashboards_services';
-import {
- EmbeddableFactoryDefinition,
- Container,
- ErrorEmbeddable,
-} from '../../../../embeddable/public';
-
-import { TimeRange } from '../../../../data/public';
-
-import { SearchInput, SearchOutput, SearchEmbeddable } from './types';
-import { SEARCH_EMBEDDABLE_TYPE } from './constants';
-
-interface StartServices {
- executeTriggerActions: UiActionsStart['executeTriggerActions'];
- isEditable: () => boolean;
-}
-
-export class SearchEmbeddableFactory
- implements EmbeddableFactoryDefinition {
- public readonly type = SEARCH_EMBEDDABLE_TYPE;
- private $injector: auto.IInjectorService | null;
- private getInjector: () => Promise | null;
- public readonly savedObjectMetaData = {
- name: i18n.translate('discover.savedSearch.savedObjectName', {
- defaultMessage: 'Saved search',
- }),
- type: 'search',
- getIconForSavedObject: () => 'search',
- };
-
- constructor(
- private getStartServices: () => Promise,
- getInjector: () => Promise
- ) {
- this.$injector = null;
- this.getInjector = getInjector;
- }
-
- public canCreateNew() {
- return false;
- }
-
- public isEditable = async () => {
- return (await this.getStartServices()).isEditable();
- };
-
- public getDisplayName() {
- return i18n.translate('discover.embeddable.search.displayName', {
- defaultMessage: 'search',
- });
- }
-
- public createFromSavedObject = async (
- savedObjectId: string,
- input: Partial & { id: string; timeRange: TimeRange },
- parent?: Container
- ): Promise => {
- if (!this.$injector) {
- this.$injector = await this.getInjector();
- }
- const $injector = this.$injector as auto.IInjectorService;
-
- const $compile = $injector.get('$compile');
- const $rootScope = $injector.get('$rootScope');
- const filterManager = getServices().filterManager;
-
- const url = await getServices().getSavedSearchUrlById(savedObjectId);
- const editUrl = getServices().addBasePath(`/app/discover${url}`);
- try {
- const savedObject = await getServices().getSavedSearchById(savedObjectId);
- const indexPattern = savedObject.searchSource.getField('index');
- const { executeTriggerActions } = await this.getStartServices();
- const { SearchEmbeddable: SearchEmbeddableClass } = await import('./search_embeddable');
- return new SearchEmbeddableClass(
- {
- savedSearch: savedObject,
- $rootScope,
- $compile,
- editUrl,
- editPath: url,
- filterManager,
- editable: getServices().capabilities.discover.save as boolean,
- indexPatterns: indexPattern ? [indexPattern] : [],
- },
- input,
- executeTriggerActions,
- parent
- );
- } catch (e) {
- console.error(e); // eslint-disable-line no-console
- return new ErrorEmbeddable(e, input, parent);
- }
- };
-
- public async create(input: SearchInput) {
- return new ErrorEmbeddable('Saved searches can only be created from a saved object', input);
- }
-}
diff --git a/src/plugins/discover_legacy/public/application/embeddable/search_template.html b/src/plugins/discover_legacy/public/application/embeddable/search_template.html
deleted file mode 100644
index e188d230ea30..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/search_template.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
diff --git a/src/plugins/discover_legacy/public/application/embeddable/types.ts b/src/plugins/discover_legacy/public/application/embeddable/types.ts
deleted file mode 100644
index 864f954588dd..000000000000
--- a/src/plugins/discover_legacy/public/application/embeddable/types.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- Embeddable,
- EmbeddableInput,
- EmbeddableOutput,
- IEmbeddable,
-} from 'src/plugins/embeddable/public';
-import { SortOrder } from '../angular/doc_table/components/table_header/helpers';
-import { Filter, IIndexPattern, TimeRange, Query } from '../../../../data/public';
-import { SavedSearch } from '../..';
-
-export interface SearchInput extends EmbeddableInput {
- timeRange: TimeRange;
- query?: Query;
- filters?: Filter[];
- hidePanelTitles?: boolean;
- columns?: string[];
- sort?: SortOrder[];
-}
-
-export interface SearchOutput extends EmbeddableOutput {
- editUrl: string;
- indexPatterns?: IIndexPattern[];
- editable: boolean;
-}
-
-export interface ISearchEmbeddable extends IEmbeddable {
- getSavedSearch(): SavedSearch;
-}
-
-export interface SearchEmbeddable extends Embeddable {
- type: string;
-}
diff --git a/src/plugins/discover_legacy/public/application/helpers/breadcrumbs.ts b/src/plugins/discover_legacy/public/application/helpers/breadcrumbs.ts
deleted file mode 100644
index e30f50206aef..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/breadcrumbs.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-
-export function getRootBreadcrumbs() {
- return [
- {
- text: i18n.translate('discover.rootBreadcrumb', {
- defaultMessage: 'Discover',
- }),
- href: '#/',
- },
- ];
-}
-
-export function getSavedSearchBreadcrumbs($route: any) {
- return [
- ...getRootBreadcrumbs(),
- {
- text: $route.current.locals.savedObjects.savedSearch.id,
- },
- ];
-}
diff --git a/src/plugins/discover_legacy/public/application/helpers/format_number_with_commas.ts b/src/plugins/discover_legacy/public/application/helpers/format_number_with_commas.ts
deleted file mode 100644
index b1b3c96e0958..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/format_number_with_commas.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-const COMMA_SEPARATOR_RE = /(\d)(?=(\d{3})+(?!\d))/g;
-
-/**
- * Converts a number to a string and adds commas
- * as thousands separators
- */
-export const formatNumWithCommas = (input: number) =>
- String(input).replace(COMMA_SEPARATOR_RE, '$1,');
diff --git a/src/plugins/discover_legacy/public/application/helpers/get_index_pattern_id.ts b/src/plugins/discover_legacy/public/application/helpers/get_index_pattern_id.ts
deleted file mode 100644
index dfb02c0b0740..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/get_index_pattern_id.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IIndexPattern } from '../../../../data/common/index_patterns';
-
-export function findIndexPatternById(
- indexPatterns: IIndexPattern[],
- id: string
-): IIndexPattern | undefined {
- if (!Array.isArray(indexPatterns) || !id) {
- return;
- }
- return indexPatterns.find((o) => o.id === id);
-}
-
-/**
- * Checks if the given defaultIndex exists and returns
- * the first available index pattern id if not
- */
-export function getFallbackIndexPatternId(
- indexPatterns: IIndexPattern[],
- defaultIndex: string = ''
-): string {
- if (defaultIndex && findIndexPatternById(indexPatterns, defaultIndex)) {
- return defaultIndex;
- }
- return !indexPatterns || !indexPatterns.length || !indexPatterns[0].id ? '' : indexPatterns[0].id;
-}
-
-/**
- * A given index pattern id is checked for existence and a fallback is provided if it doesn't exist
- * The provided defaultIndex is usually configured in Advanced Settings, if it's also invalid
- * the first entry of the given list of Indexpatterns is used
- */
-export function getIndexPatternId(
- id: string = '',
- indexPatterns: IIndexPattern[],
- defaultIndex: string = ''
-): string {
- if (!id || !findIndexPatternById(indexPatterns, id)) {
- return getFallbackIndexPatternId(indexPatterns, defaultIndex);
- }
- return id;
-}
diff --git a/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.test.ts b/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.test.ts
deleted file mode 100644
index c1a8acb04ac3..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.test.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getSwitchIndexPatternAppState } from './get_switch_index_pattern_app_state';
-import { IIndexPatternFieldList, IndexPattern } from '../../../../data/common/index_patterns';
-
-const currentIndexPattern: IndexPattern = {
- id: 'prev',
- getFieldByName(name) {
- return this.fields.getByName(name);
- },
- fields: {
- getByName: (name: string) => {
- const fields = [
- { name: 'category', sortable: true },
- { name: 'name', sortable: true },
- ] as IIndexPatternFieldList;
- return fields.find((field) => field.name === name);
- },
- },
-} as IndexPattern;
-
-const nextIndexPattern = {
- id: 'next',
- getFieldByName(name) {
- return this.fields.getByName(name);
- },
- fields: {
- getByName: (name: string) => {
- const fields = [{ name: 'category', sortable: true }] as IIndexPatternFieldList;
- return fields.find((field) => field.name === name);
- },
- },
-} as IndexPattern;
-
-describe('Discover getSwitchIndexPatternAppState', () => {
- test('removing fields that are not part of the next index pattern, keeping unknown fields ', async () => {
- const result = getSwitchIndexPatternAppState(
- currentIndexPattern,
- nextIndexPattern,
- ['category', 'name', 'unknown'],
- [['category', 'desc']]
- );
- expect(result.columns).toEqual(['category', 'unknown']);
- expect(result.sort).toEqual([['category', 'desc']]);
- });
- test('removing sorted by fields that are not part of the next index pattern', async () => {
- const result = getSwitchIndexPatternAppState(
- currentIndexPattern,
- nextIndexPattern,
- ['name'],
- [
- ['category', 'desc'],
- ['name', 'asc'],
- ]
- );
- expect(result.columns).toEqual(['_source']);
- expect(result.sort).toEqual([['category', 'desc']]);
- });
- test('removing sorted by fields that without modifying columns', async () => {
- const result = getSwitchIndexPatternAppState(
- currentIndexPattern,
- nextIndexPattern,
- ['name'],
- [
- ['category', 'desc'],
- ['name', 'asc'],
- ],
- false
- );
- expect(result.columns).toEqual(['name']);
- expect(result.sort).toEqual([['category', 'desc']]);
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.ts b/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.ts
deleted file mode 100644
index 51835910a402..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/get_switch_index_pattern_app_state.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { getSortArray } from '../angular/doc_table';
-import { SortPairArr } from '../angular/doc_table/lib/get_sort';
-import { IndexPattern } from '../../opensearch_dashboards_services';
-
-/**
- * Helper function to remove or adapt the currently selected columns/sort to be valid with the next
- * index pattern, returns a new state object
- */
-export function getSwitchIndexPatternAppState(
- currentIndexPattern: IndexPattern,
- nextIndexPattern: IndexPattern,
- currentColumns: string[],
- currentSort: SortPairArr[],
- modifyColumns: boolean = true
-) {
- const nextColumns = modifyColumns
- ? currentColumns.filter(
- (column) =>
- nextIndexPattern.fields.getByName(column) || !currentIndexPattern.fields.getByName(column)
- )
- : currentColumns;
- const nextSort = getSortArray(currentSort, nextIndexPattern);
- return {
- index: nextIndexPattern.id,
- columns: nextColumns.length ? nextColumns : ['_source'],
- sort: nextSort,
- };
-}
diff --git a/src/plugins/discover_legacy/public/application/helpers/index.ts b/src/plugins/discover_legacy/public/application/helpers/index.ts
deleted file mode 100644
index d765fdf60cee..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/index.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { shortenDottedString } from './shorten_dotted_string';
-export { formatNumWithCommas } from './format_number_with_commas';
diff --git a/src/plugins/discover_legacy/public/application/helpers/migrate_legacy_query.ts b/src/plugins/discover_legacy/public/application/helpers/migrate_legacy_query.ts
deleted file mode 100644
index 90458c135b98..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/migrate_legacy_query.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { has } from 'lodash';
-import { Query } from 'src/plugins/data/public';
-
-/**
- * Creates a standardized query object from old queries that were either strings or pure OpenSearch query DSL
- *
- * @param query - a legacy query, what used to be stored in SearchSource's query property
- * @return Object
- */
-
-export function migrateLegacyQuery(query: Query | { [key: string]: any } | string): Query {
- // Lucene was the only option before, so language-less queries are all lucene
- if (!has(query, 'language')) {
- return { query, language: 'lucene' };
- }
-
- return query as Query;
-}
diff --git a/src/plugins/discover_legacy/public/application/helpers/popularize_field.test.ts b/src/plugins/discover_legacy/public/application/helpers/popularize_field.test.ts
deleted file mode 100644
index cdd49c0f77f1..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/popularize_field.test.ts
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPattern, IndexPatternsService } from '../../../../data/public';
-import { popularizeField } from './popularize_field';
-
-describe('Popularize field', () => {
- test('returns undefined if index pattern lacks id', async () => {
- const indexPattern = ({} as unknown) as IndexPattern;
- const fieldName = '@timestamp';
- const indexPatternsService = ({} as unknown) as IndexPatternsService;
- const result = await popularizeField(indexPattern, fieldName, indexPatternsService);
- expect(result).toBeUndefined();
- });
-
- test('returns undefined if field not found', async () => {
- const indexPattern = ({
- fields: {
- getByName: () => {},
- },
- } as unknown) as IndexPattern;
- const fieldName = '@timestamp';
- const indexPatternsService = ({} as unknown) as IndexPatternsService;
- const result = await popularizeField(indexPattern, fieldName, indexPatternsService);
- expect(result).toBeUndefined();
- });
-
- test('returns undefined if successful', async () => {
- const field = {
- count: 0,
- };
- const indexPattern = ({
- id: 'id',
- fields: {
- getByName: () => field,
- },
- } as unknown) as IndexPattern;
- const fieldName = '@timestamp';
- const indexPatternsService = ({
- updateSavedObject: async () => {},
- } as unknown) as IndexPatternsService;
- const result = await popularizeField(indexPattern, fieldName, indexPatternsService);
- expect(result).toBeUndefined();
- expect(field.count).toEqual(1);
- });
-
- test('hides errors', async () => {
- const field = {
- count: 0,
- };
- const indexPattern = ({
- id: 'id',
- fields: {
- getByName: () => field,
- },
- } as unknown) as IndexPattern;
- const fieldName = '@timestamp';
- const indexPatternsService = ({
- updateSavedObject: async () => {
- throw new Error('unknown error');
- },
- } as unknown) as IndexPatternsService;
- const result = await popularizeField(indexPattern, fieldName, indexPatternsService);
- expect(result).toBeUndefined();
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/helpers/popularize_field.ts b/src/plugins/discover_legacy/public/application/helpers/popularize_field.ts
deleted file mode 100644
index e7c4b900fa19..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/popularize_field.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IndexPattern, IndexPatternsService } from '../../../../data/public';
-
-async function popularizeField(
- indexPattern: IndexPattern,
- fieldName: string,
- indexPatternsService: IndexPatternsService
-) {
- if (!indexPattern.id) return;
- const field = indexPattern.fields.getByName(fieldName);
- if (!field) {
- return;
- }
-
- field.count++;
- // Catch 409 errors caused by user adding columns in a higher frequency that the changes can be persisted to OpenSearch
- try {
- await indexPatternsService.updateSavedObject(indexPattern, 0, true);
- // eslint-disable-next-line no-empty
- } catch {}
-}
-
-export { popularizeField };
diff --git a/src/plugins/discover_legacy/public/application/helpers/shorten_dotted_string.ts b/src/plugins/discover_legacy/public/application/helpers/shorten_dotted_string.ts
deleted file mode 100644
index 39450f8c82c0..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/shorten_dotted_string.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-const DOT_PREFIX_RE = /(.).+?\./g;
-
-/**
- * Convert a dot.notated.string into a short
- * version (d.n.string)
- */
-export const shortenDottedString = (input: string) => input.replace(DOT_PREFIX_RE, '$1.');
diff --git a/src/plugins/discover_legacy/public/application/helpers/validate_time_range.test.ts b/src/plugins/discover_legacy/public/application/helpers/validate_time_range.test.ts
deleted file mode 100644
index 902f3d8a4b62..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/validate_time_range.test.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { validateTimeRange } from './validate_time_range';
-import { notificationServiceMock } from '../../../../../core/public/mocks';
-
-describe('Discover validateTimeRange', () => {
- test('validates given time ranges correctly', async () => {
- const { toasts } = notificationServiceMock.createStartContract();
- [
- { from: '', to: '', result: false },
- { from: 'now', to: 'now+1h', result: true },
- { from: 'now', to: 'lala+1h', result: false },
- { from: '', to: 'now', result: false },
- { from: 'now', to: '', result: false },
- { from: ' 2020-06-02T13:36:13.689Z', to: 'now', result: true },
- { from: ' 2020-06-02T13:36:13.689Z', to: '2020-06-02T13:36:13.690Z', result: true },
- ].map((test) => {
- expect(validateTimeRange({ from: test.from, to: test.to }, toasts)).toEqual(test.result);
- });
- });
-
- test('displays a toast when invalid data is entered', async () => {
- const { toasts } = notificationServiceMock.createStartContract();
- expect(validateTimeRange({ from: 'now', to: 'null' }, toasts)).toEqual(false);
- expect(toasts.addDanger).toHaveBeenCalledWith({
- title: 'Invalid time range',
- text: "The provided time range is invalid. (from: 'now', to: 'null')",
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/application/helpers/validate_time_range.ts b/src/plugins/discover_legacy/public/application/helpers/validate_time_range.ts
deleted file mode 100644
index d23a84aabb14..000000000000
--- a/src/plugins/discover_legacy/public/application/helpers/validate_time_range.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import dateMath from '@elastic/datemath';
-import { i18n } from '@osd/i18n';
-import { ToastsStart } from 'opensearch-dashboards/public';
-
-/**
- * Validates a given time filter range, provided by URL or UI
- * Unless valid, it returns false and displays a notification
- */
-export function validateTimeRange(
- { from, to }: { from: string; to: string },
- toastNotifications: ToastsStart
-): boolean {
- const fromMoment = dateMath.parse(from);
- const toMoment = dateMath.parse(to);
- if (!fromMoment || !toMoment || !fromMoment.isValid() || !toMoment.isValid()) {
- toastNotifications.addDanger({
- title: i18n.translate('discover.notifications.invalidTimeRangeTitle', {
- defaultMessage: `Invalid time range`,
- }),
- text: i18n.translate('discover.notifications.invalidTimeRangeText', {
- defaultMessage: `The provided time range is invalid. (from: '{from}', to: '{to}')`,
- values: {
- from,
- to,
- },
- }),
- });
- return false;
- }
- return true;
-}
diff --git a/src/plugins/discover_legacy/public/application/index.scss b/src/plugins/discover_legacy/public/application/index.scss
deleted file mode 100644
index b9f191ac6d69..000000000000
--- a/src/plugins/discover_legacy/public/application/index.scss
+++ /dev/null
@@ -1,2 +0,0 @@
-@import "angular/index";
-@import "discover";
diff --git a/src/plugins/discover_legacy/public/build_services.ts b/src/plugins/discover_legacy/public/build_services.ts
deleted file mode 100644
index 3fdafcff0c40..000000000000
--- a/src/plugins/discover_legacy/public/build_services.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { History } from 'history';
-
-import {
- Capabilities,
- ChromeStart,
- CoreStart,
- DocLinksStart,
- ToastsStart,
- IUiSettingsClient,
- PluginInitializerContext,
-} from 'opensearch-dashboards/public';
-import {
- FilterManager,
- TimefilterContract,
- IndexPatternsContract,
- DataPublicPluginStart,
-} from 'src/plugins/data/public';
-import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/public';
-import { SharePluginStart } from 'src/plugins/share/public';
-import { ChartsPluginStart } from 'src/plugins/charts/public';
-import { VisualizationsStart } from 'src/plugins/visualizations/public';
-import { SavedObjectOpenSearchDashboardsServices } from 'src/plugins/saved_objects/public';
-
-import { DiscoverStartPlugins } from './plugin';
-import { createSavedSearchesLoader, SavedSearch } from './saved_searches';
-import { getHistory } from './opensearch_dashboards_services';
-import { OpenSearchDashboardsLegacyStart } from '../../opensearch_dashboards_legacy/public';
-import { UrlForwardingStart } from '../../url_forwarding/public';
-import { NavigationPublicPluginStart } from '../../navigation/public';
-
-export interface DiscoverServices {
- addBasePath: (path: string) => string;
- capabilities: Capabilities;
- chrome: ChromeStart;
- core: CoreStart;
- data: DataPublicPluginStart;
- docLinks: DocLinksStart;
- history: () => History;
- theme: ChartsPluginStart['theme'];
- filterManager: FilterManager;
- indexPatterns: IndexPatternsContract;
- inspector: InspectorPublicPluginStart;
- metadata: { branch: string };
- navigation: NavigationPublicPluginStart;
- share?: SharePluginStart;
- opensearchDashboardsLegacy: OpenSearchDashboardsLegacyStart;
- urlForwarding: UrlForwardingStart;
- timefilter: TimefilterContract;
- toastNotifications: ToastsStart;
- getSavedSearchById: (id: string) => Promise;
- getSavedSearchUrlById: (id: string) => Promise;
- getEmbeddableInjector: any;
- uiSettings: IUiSettingsClient;
- visualizations: VisualizationsStart;
-}
-
-export async function buildServices(
- core: CoreStart,
- plugins: DiscoverStartPlugins,
- context: PluginInitializerContext,
- getEmbeddableInjector: any
-): Promise {
- const services: SavedObjectOpenSearchDashboardsServices = {
- savedObjectsClient: core.savedObjects.client,
- indexPatterns: plugins.data.indexPatterns,
- search: plugins.data.search,
- chrome: core.chrome,
- overlays: core.overlays,
- };
- const savedObjectService = createSavedSearchesLoader(services);
-
- return {
- addBasePath: core.http.basePath.prepend,
- capabilities: core.application.capabilities,
- chrome: core.chrome,
- core,
- data: plugins.data,
- docLinks: core.docLinks,
- theme: plugins.charts.theme,
- filterManager: plugins.data.query.filterManager,
- getEmbeddableInjector,
- getSavedSearchById: async (id: string) => savedObjectService.get(id),
- getSavedSearchUrlById: async (id: string) => savedObjectService.urlFor(id),
- history: getHistory,
- indexPatterns: plugins.data.indexPatterns,
- inspector: plugins.inspector,
- metadata: {
- branch: context.env.packageInfo.branch,
- },
- navigation: plugins.navigation,
- share: plugins.share,
- opensearchDashboardsLegacy: plugins.opensearchDashboardsLegacy,
- urlForwarding: plugins.urlForwarding,
- timefilter: plugins.data.query.timefilter.timefilter,
- toastNotifications: core.notifications.toasts,
- uiSettings: core.uiSettings,
- visualizations: plugins.visualizations,
- };
-}
diff --git a/src/plugins/discover_legacy/public/get_inner_angular.ts b/src/plugins/discover_legacy/public/get_inner_angular.ts
deleted file mode 100644
index b4a7a17357ab..000000000000
--- a/src/plugins/discover_legacy/public/get_inner_angular.ts
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// inner angular imports
-// these are necessary to bootstrap the local angular.
-// They can stay even after NP cutover
-import './application/index.scss';
-import angular from 'angular';
-// required for `ngSanitize` angular module
-import 'angular-sanitize';
-import { EuiIcon } from '@elastic/eui';
-import { i18nDirective, i18nFilter, I18nProvider } from '@osd/i18n/angular';
-import { CoreStart, PluginInitializerContext } from 'opensearch-dashboards/public';
-import { DataPublicPluginStart } from '../../data/public';
-import { Storage } from '../../opensearch_dashboards_utils/public';
-import { NavigationPublicPluginStart as NavigationStart } from '../../navigation/public';
-import { createDocTableDirective } from './application/angular/doc_table';
-import { createTableHeaderDirective } from './application/angular/doc_table/components/table_header';
-import {
- createToolBarPagerButtonsDirective,
- createToolBarPagerTextDirective,
-} from './application/angular/doc_table/components/pager';
-import { createTableRowDirective } from './application/angular/doc_table/components/table_row';
-import { createPagerFactory } from './application/angular/doc_table/lib/pager/pager_factory';
-import { createInfiniteScrollDirective } from './application/angular/doc_table/infinite_scroll';
-import { createDocViewerDirective } from './application/angular/doc_viewer';
-import { createDocViewerLinksDirective } from './application/angular/doc_viewer_links';
-import { createRenderCompleteDirective } from './application/angular/directives/render_complete';
-import {
- initAngularBootstrap,
- configureAppAngularModule,
- PrivateProvider,
- PromiseServiceCreator,
- registerListenEventListener,
- watchMultiDecorator,
- createTopNavDirective,
- createTopNavHelper,
-} from '../../opensearch_dashboards_legacy/public';
-import { createContextErrorMessageDirective } from './application/components/context_error_message';
-import { DiscoverStartPlugins } from './plugin';
-import { getScopedHistory } from './opensearch_dashboards_services';
-import { createDiscoverLegacyDirective } from './application/components/create_discover_legacy_directive';
-
-/**
- * returns the main inner angular module, it contains all the parts of Angular Discover
- * needs to render, so in the end the current 'opensearchDashboards' angular module is no longer necessary
- */
-export function getInnerAngularModule(
- name: string,
- core: CoreStart,
- deps: DiscoverStartPlugins,
- context: PluginInitializerContext
-) {
- initAngularBootstrap();
- const module = initializeInnerAngularModule(name, core, deps.navigation, deps.data);
- configureAppAngularModule(module, { core, env: context.env }, true, getScopedHistory);
- return module;
-}
-
-/**
- * returns a slimmer inner angular module for embeddable rendering
- */
-export function getInnerAngularModuleEmbeddable(
- name: string,
- core: CoreStart,
- deps: DiscoverStartPlugins
-) {
- return initializeInnerAngularModule(name, core, deps.navigation, deps.data, true);
-}
-
-let initialized = false;
-
-export function initializeInnerAngularModule(
- name = 'app/discover',
- core: CoreStart,
- navigation: NavigationStart,
- data: DataPublicPluginStart,
- embeddable = false
-) {
- if (!initialized) {
- createLocalI18nModule();
- createLocalPrivateModule();
- createLocalPromiseModule();
- createLocalTopNavModule(navigation);
- createLocalStorageModule();
- createPagerFactoryModule();
- createDocTableModule();
- initialized = true;
- }
-
- if (embeddable) {
- return angular
- .module(name, [
- 'ngSanitize',
- 'react',
- 'ui.bootstrap',
- 'discoverI18n',
- 'discoverPrivate',
- 'discoverDocTable',
- 'discoverPagerFactory',
- 'discoverPromise',
- ])
- .config(watchMultiDecorator)
- .directive('icon', (reactDirective) => reactDirective(EuiIcon))
- .directive('renderComplete', createRenderCompleteDirective);
- }
-
- return angular
- .module(name, [
- 'ngSanitize',
- 'ngRoute',
- 'react',
- 'ui.bootstrap',
- 'discoverI18n',
- 'discoverPrivate',
- 'discoverPromise',
- 'discoverTopNav',
- 'discoverLocalStorageProvider',
- 'discoverDocTable',
- 'discoverPagerFactory',
- ])
- .config(watchMultiDecorator)
- .run(registerListenEventListener)
- .directive('icon', (reactDirective) => reactDirective(EuiIcon))
- .directive('renderComplete', createRenderCompleteDirective)
- .directive('discoverLegacy', createDiscoverLegacyDirective)
- .directive('contextErrorMessage', createContextErrorMessageDirective);
-}
-
-function createLocalPromiseModule() {
- angular.module('discoverPromise', []).service('Promise', PromiseServiceCreator);
-}
-
-function createLocalPrivateModule() {
- angular.module('discoverPrivate', []).provider('Private', PrivateProvider);
-}
-
-function createLocalTopNavModule(navigation: NavigationStart) {
- angular
- .module('discoverTopNav', ['react'])
- .directive('osdTopNav', createTopNavDirective)
- .directive('osdTopNavHelper', createTopNavHelper(navigation.ui));
-}
-
-function createLocalI18nModule() {
- angular
- .module('discoverI18n', [])
- .provider('i18n', I18nProvider)
- .filter('i18n', i18nFilter)
- .directive('i18nId', i18nDirective);
-}
-
-function createLocalStorageModule() {
- angular
- .module('discoverLocalStorageProvider', ['discoverPrivate'])
- .service('localStorage', createLocalStorageService('localStorage'))
- .service('sessionStorage', createLocalStorageService('sessionStorage'));
-}
-
-const createLocalStorageService = function (type: string) {
- return function ($window: any) {
- return new Storage($window[type]);
- };
-};
-
-function createPagerFactoryModule() {
- angular.module('discoverPagerFactory', []).factory('pagerFactory', createPagerFactory);
-}
-
-function createDocTableModule() {
- angular
- .module('discoverDocTable', ['discoverPagerFactory', 'react'])
- .directive('docTable', createDocTableDirective)
- .directive('osdTableHeader', createTableHeaderDirective)
- .directive('toolBarPagerText', createToolBarPagerTextDirective)
- .directive('osdTableRow', createTableRowDirective)
- .directive('toolBarPagerButtons', createToolBarPagerButtonsDirective)
- .directive('osdInfiniteScroll', createInfiniteScrollDirective)
- .directive('docViewer', createDocViewerDirective)
- .directive('docViewerLinks', createDocViewerLinksDirective);
-}
diff --git a/src/plugins/discover_legacy/public/index.ts b/src/plugins/discover_legacy/public/index.ts
deleted file mode 100644
index 6c9ab46b656e..000000000000
--- a/src/plugins/discover_legacy/public/index.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { PluginInitializerContext } from 'opensearch-dashboards/public';
-import { DiscoverPlugin } from './plugin';
-
-export { DiscoverSetup, DiscoverStart } from './plugin';
-export function plugin(initializerContext: PluginInitializerContext) {
- return new DiscoverPlugin(initializerContext);
-}
-
-export { SavedSearch, SavedSearchLoader, createSavedSearchesLoader } from './saved_searches';
-export { ISearchEmbeddable, SEARCH_EMBEDDABLE_TYPE, SearchInput } from './application/embeddable';
-export { DISCOVER_APP_URL_GENERATOR, DiscoverUrlGeneratorState } from './url_generator';
diff --git a/src/plugins/discover_legacy/public/mocks.ts b/src/plugins/discover_legacy/public/mocks.ts
deleted file mode 100644
index 4724ced290ff..000000000000
--- a/src/plugins/discover_legacy/public/mocks.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { DiscoverSetup, DiscoverStart } from '.';
-
-export type Setup = jest.Mocked;
-export type Start = jest.Mocked;
-
-const createSetupContract = (): Setup => {
- const setupContract: Setup = {
- docViews: {
- addDocView: jest.fn(),
- },
- docViewsLinks: {
- addDocViewLink: jest.fn(),
- },
- };
- return setupContract;
-};
-
-const createStartContract = (): Start => {
- const startContract: Start = {
- savedSearchLoader: {} as any,
- urlGenerator: {
- createUrl: jest.fn(),
- } as any,
- };
- return startContract;
-};
-
-export const discoverPluginMock = {
- createSetupContract,
- createStartContract,
-};
diff --git a/src/plugins/discover_legacy/public/opensearch_dashboards_services.ts b/src/plugins/discover_legacy/public/opensearch_dashboards_services.ts
deleted file mode 100644
index 8531564e0cc7..000000000000
--- a/src/plugins/discover_legacy/public/opensearch_dashboards_services.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-import { createHashHistory } from 'history';
-import { ScopedHistory, AppMountParameters } from 'opensearch-dashboards/public';
-import { UiActionsStart } from 'src/plugins/ui_actions/public';
-import { DiscoverServices } from './build_services';
-import { createGetterSetter } from '../../opensearch_dashboards_utils/public';
-import { search } from '../../data/public';
-import { DocViewsRegistry } from './application/doc_views/doc_views_registry';
-import { DocViewsLinksRegistry } from './application/doc_views_links/doc_views_links_registry';
-
-let angularModule: any = null;
-let services: DiscoverServices | null = null;
-let uiActions: UiActionsStart;
-
-/**
- * set bootstrapped inner angular module
- */
-export function setAngularModule(module: any) {
- angularModule = module;
-}
-
-/**
- * get boostrapped inner angular module
- */
-export function getAngularModule() {
- return angularModule;
-}
-
-export function getServices(): DiscoverServices {
- if (!services) {
- throw new Error('Discover services are not yet available');
- }
- return services;
-}
-
-export function setServices(newServices: any) {
- services = newServices;
-}
-
-export const setUiActions = (pluginUiActions: UiActionsStart) => (uiActions = pluginUiActions);
-export const getUiActions = () => uiActions;
-
-export const [getHeaderActionMenuMounter, setHeaderActionMenuMounter] = createGetterSetter<
- AppMountParameters['setHeaderActionMenu']
->('headerActionMenuMounter');
-
-export const [getUrlTracker, setUrlTracker] = createGetterSetter<{
- setTrackedUrl: (url: string) => void;
- restorePreviousUrl: () => void;
-}>('urlTracker');
-
-export const [getDocViewsRegistry, setDocViewsRegistry] = createGetterSetter(
- 'DocViewsRegistry'
-);
-
-export const [getDocViewsLinksRegistry, setDocViewsLinksRegistry] = createGetterSetter<
- DocViewsLinksRegistry
->('DocViewsLinksRegistry');
-/**
- * Makes sure discover and context are using one instance of history.
- */
-export const getHistory = _.once(() => createHashHistory());
-
-/**
- * Discover currently uses two `history` instances: one from OpenSearch Dashboards Platform and
- * another from `history` package. Below function is used every time Discover
- * app is loaded to synchronize both instances.
- *
- * This helper is temporary until https://github.com/elastic/kibana/issues/65161 is resolved.
- */
-export const syncHistoryLocations = () => {
- const h = getHistory();
- Object.assign(h.location, createHashHistory().location);
- return h;
-};
-
-export const [getScopedHistory, setScopedHistory] = createGetterSetter(
- 'scopedHistory'
-);
-
-export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggResponse } = search;
-export { unhashUrl, redirectWhenMissing } from '../../opensearch_dashboards_utils/public';
-export {
- formatMsg,
- formatStack,
- subscribeWithScope,
-} from '../../opensearch_dashboards_legacy/public';
-
-// EXPORT types
-export {
- IndexPatternsContract,
- IIndexPattern,
- IndexPattern,
- indexPatterns,
- IFieldType,
- ISearchSource,
- OpenSearchQuerySortValue,
- SortDirection,
-} from '../../data/public';
diff --git a/src/plugins/discover_legacy/public/plugin.ts b/src/plugins/discover_legacy/public/plugin.ts
deleted file mode 100644
index 7e855b707891..000000000000
--- a/src/plugins/discover_legacy/public/plugin.ts
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { i18n } from '@osd/i18n';
-import angular, { auto } from 'angular';
-import { BehaviorSubject } from 'rxjs';
-import { filter, map } from 'rxjs/operators';
-
-import {
- AppMountParameters,
- AppUpdater,
- CoreSetup,
- CoreStart,
- Plugin,
- PluginInitializerContext,
-} from 'opensearch-dashboards/public';
-import { UiActionsStart, UiActionsSetup } from 'src/plugins/ui_actions/public';
-import { EmbeddableStart, EmbeddableSetup } from 'src/plugins/embeddable/public';
-import { ChartsPluginStart } from 'src/plugins/charts/public';
-import { NavigationPublicPluginStart as NavigationStart } from 'src/plugins/navigation/public';
-import { SharePluginStart, SharePluginSetup, UrlGeneratorContract } from 'src/plugins/share/public';
-import { VisualizationsStart, VisualizationsSetup } from 'src/plugins/visualizations/public';
-import {
- OpenSearchDashboardsLegacySetup,
- OpenSearchDashboardsLegacyStart,
-} from 'src/plugins/opensearch_dashboards_legacy/public';
-import { UrlForwardingSetup, UrlForwardingStart } from 'src/plugins/url_forwarding/public';
-import { HomePublicPluginSetup } from 'src/plugins/home/public';
-import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/public';
-import { stringify } from 'query-string';
-import rison from 'rison-node';
-import { NEW_DISCOVER_APP } from '../../discover/public';
-import { DataPublicPluginStart, DataPublicPluginSetup, opensearchFilters } from '../../data/public';
-import { SavedObjectLoader } from '../../saved_objects/public';
-import { createOsdUrlTracker, url } from '../../opensearch_dashboards_utils/public';
-import { UrlGeneratorState } from '../../share/public';
-import { DocViewInput, DocViewInputFn } from './application/doc_views/doc_views_types';
-import { DocViewLink } from './application/doc_views_links/doc_views_links_types';
-import { DocViewsRegistry } from './application/doc_views/doc_views_registry';
-import { DocViewsLinksRegistry } from './application/doc_views_links/doc_views_links_registry';
-import { DocViewTable } from './application/components/table/table';
-import { JsonCodeBlock } from './application/components/json_code_block/json_code_block';
-import {
- setDocViewsRegistry,
- setDocViewsLinksRegistry,
- setUrlTracker,
- setAngularModule,
- setServices,
- setHeaderActionMenuMounter,
- setUiActions,
- setScopedHistory,
- getScopedHistory,
- syncHistoryLocations,
- getServices,
-} from './opensearch_dashboards_services';
-import { createSavedSearchesLoader } from './saved_searches';
-import { buildServices } from './build_services';
-import {
- DiscoverUrlGeneratorState,
- DISCOVER_APP_URL_GENERATOR,
- DiscoverUrlGenerator,
-} from './url_generator';
-import { SearchEmbeddableFactory } from './application/embeddable';
-import { AppNavLinkStatus } from '../../../core/public';
-import { ViewRedirectParams } from '../../data_explorer/public';
-
-declare module '../../share/public' {
- export interface UrlGeneratorStateMapping {
- [DISCOVER_APP_URL_GENERATOR]: UrlGeneratorState;
- }
-}
-
-/**
- * @public
- */
-export interface DiscoverSetup {
- docViews: {
- /**
- * Add new doc view shown along with table view and json view in the details of each document in Discover.
- * Both react and angular doc views are supported.
- * @param docViewRaw
- */
- addDocView(docViewRaw: DocViewInput | DocViewInputFn): void;
- };
-
- docViewsLinks: {
- addDocViewLink(docViewLinkRaw: DocViewLink): void;
- };
-}
-
-export interface DiscoverStart {
- savedSearchLoader: SavedObjectLoader;
-
- /**
- * `share` plugin URL generator for Discover app. Use it to generate links into
- * Discover application, example:
- *
- * ```ts
- * const url = await plugins.discover.urlGenerator.createUrl({
- * savedSearchId: '571aaf70-4c88-11e8-b3d7-01146121b73d',
- * indexPatternId: 'c367b774-a4c2-11ea-bb37-0242ac130002',
- * timeRange: {
- * to: 'now',
- * from: 'now-15m',
- * mode: 'relative',
- * },
- * });
- * ```
- */
- readonly urlGenerator: undefined | UrlGeneratorContract<'DISCOVER_APP_URL_GENERATOR'>;
-}
-
-/**
- * @internal
- */
-export interface DiscoverSetupPlugins {
- share?: SharePluginSetup;
- uiActions: UiActionsSetup;
- embeddable: EmbeddableSetup;
- opensearchDashboardsLegacy: OpenSearchDashboardsLegacySetup;
- urlForwarding: UrlForwardingSetup;
- home?: HomePublicPluginSetup;
- visualizations: VisualizationsSetup;
- data: DataPublicPluginSetup;
-}
-
-/**
- * @internal
- */
-export interface DiscoverStartPlugins {
- uiActions: UiActionsStart;
- embeddable: EmbeddableStart;
- navigation: NavigationStart;
- charts: ChartsPluginStart;
- data: DataPublicPluginStart;
- share?: SharePluginStart;
- opensearchDashboardsLegacy: OpenSearchDashboardsLegacyStart;
- urlForwarding: UrlForwardingStart;
- inspector: InspectorPublicPluginStart;
- visualizations: VisualizationsStart;
-}
-
-const innerAngularName = 'app/discover';
-const embeddableAngularName = 'app/discoverEmbeddable';
-
-/**
- * Contains Discover, one of the oldest parts of OpenSearch Dashboards
- * There are 2 kinds of Angular bootstrapped for rendering, additionally to the main Angular
- * Discover provides embeddables, those contain a slimmer Angular
- */
-export class DiscoverPlugin
- implements Plugin {
- constructor(private readonly initializerContext: PluginInitializerContext) {}
-
- private appStateUpdater = new BehaviorSubject(() => ({}));
- private docViewsRegistry: DocViewsRegistry | null = null;
- private docViewsLinksRegistry: DocViewsLinksRegistry | null = null;
- private embeddableInjector: auto.IInjectorService | null = null;
- private stopUrlTracking: (() => void) | undefined = undefined;
- private servicesInitialized: boolean = false;
- private innerAngularInitialized: boolean = false;
- private urlGenerator?: DiscoverStart['urlGenerator'];
-
- /**
- * why are those functions public? they are needed for some mocha tests
- * can be removed once all is Jest
- */
- public initializeInnerAngular?: () => void;
- public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>;
-
- setup(core: CoreSetup, plugins: DiscoverSetupPlugins) {
- const baseUrl = core.http.basePath.prepend('/app/discover');
-
- if (plugins.share) {
- this.urlGenerator = plugins.share.urlGenerators.registerUrlGenerator(
- new DiscoverUrlGenerator({
- appBasePath: baseUrl,
- useHash: core.uiSettings.get('state:storeInSessionStorage'),
- })
- );
- }
-
- this.docViewsRegistry = new DocViewsRegistry();
- setDocViewsRegistry(this.docViewsRegistry);
- this.docViewsRegistry.addDocView({
- title: i18n.translate('discover.docViews.table.tableTitle', {
- defaultMessage: 'Table',
- }),
- order: 10,
- component: DocViewTable,
- });
-
- this.docViewsRegistry.addDocView({
- title: i18n.translate('discover.docViews.json.jsonTitle', {
- defaultMessage: 'JSON',
- }),
- order: 20,
- component: JsonCodeBlock,
- });
-
- this.docViewsLinksRegistry = new DocViewsLinksRegistry();
- setDocViewsLinksRegistry(this.docViewsLinksRegistry);
-
- this.docViewsLinksRegistry.addDocViewLink({
- label: i18n.translate('discover.docTable.tableRow.viewSurroundingDocumentsLinkText', {
- defaultMessage: 'View surrounding documents',
- }),
- generateCb: (renderProps: any) => {
- const globalFilters: any = getServices().filterManager.getGlobalFilters();
- const appFilters: any = getServices().filterManager.getAppFilters();
-
- const hash = stringify(
- url.encodeQuery({
- _g: rison.encode({
- filters: globalFilters || [],
- }),
- _a: rison.encode({
- columns: renderProps.columns,
- filters: (appFilters || []).map(opensearchFilters.disableFilter),
- }),
- }),
- { encode: false, sort: false }
- );
-
- return {
- url: `#/context/${encodeURIComponent(renderProps.indexPattern.id)}/${encodeURIComponent(
- renderProps.hit._id
- )}?${hash}`,
- hide: !renderProps.indexPattern.isTimeBased(),
- };
- },
- order: 1,
- });
-
- this.docViewsLinksRegistry.addDocViewLink({
- label: i18n.translate('discover.docTable.tableRow.viewSingleDocumentLinkText', {
- defaultMessage: 'View single document',
- }),
- generateCb: (renderProps) => ({
- url: `#/doc/${renderProps.indexPattern.id}/${
- renderProps.hit._index
- }?id=${encodeURIComponent(renderProps.hit._id)}`,
- }),
- order: 2,
- });
-
- const {
- appMounted,
- appUnMounted,
- stop: stopUrlTracker,
- setActiveUrl: setTrackedUrl,
- restorePreviousUrl,
- } = createOsdUrlTracker({
- // we pass getter here instead of plain `history`,
- // so history is lazily created (when app is mounted)
- // this prevents redundant `#` when not in discover app
- getHistory: getScopedHistory,
- baseUrl,
- defaultSubUrl: '#/',
- storageKey: `lastUrl:${core.http.basePath.get()}:discover_legacy`,
- navLinkUpdater$: this.appStateUpdater,
- toastNotifications: core.notifications.toasts,
- stateParams: [
- {
- osdUrlKey: '_g',
- stateUpdate$: plugins.data.query.state$.pipe(
- filter(
- ({ changes }) => !!(changes.globalFilters || changes.time || changes.refreshInterval)
- ),
- map(({ state }) => ({
- ...state,
- filters: state.filters?.filter(opensearchFilters.isFilterPinned),
- }))
- ),
- },
- ],
- });
- setUrlTracker({ setTrackedUrl, restorePreviousUrl });
- this.stopUrlTracking = () => {
- stopUrlTracker();
- };
-
- this.docViewsRegistry.setAngularInjectorGetter(this.getEmbeddableInjector);
- core.application.register({
- id: 'discoverLegacy',
- title: 'Discover Legacy',
- defaultPath: '#/',
- navLinkStatus: AppNavLinkStatus.hidden,
- mount: async (params: AppMountParameters) => {
- if (!this.initializeServices) {
- throw Error('Discover plugin method initializeServices is undefined');
- }
- if (!this.initializeInnerAngular) {
- throw Error('Discover plugin method initializeInnerAngular is undefined');
- }
-
- // If a user explicitly tries to access the legacy app URL
- const {
- core: {
- application: { navigateToApp },
- },
- } = await this.initializeServices();
- const path = window.location.hash;
-
- const v2Enabled = core.uiSettings.get(NEW_DISCOVER_APP);
- if (v2Enabled) {
- navigateToApp('discover', {
- replace: true,
- path,
- });
- }
- setScopedHistory(params.history);
- setHeaderActionMenuMounter(params.setHeaderActionMenu);
- syncHistoryLocations();
- appMounted();
- const {
- plugins: { data: dataStart },
- } = await this.initializeServices();
- await this.initializeInnerAngular();
-
- // make sure the index pattern list is up to date
- await dataStart.indexPatterns.clearCache();
- const { renderApp } = await import('./application/application');
- params.element.classList.add('dscAppWrapper');
- const unmount = await renderApp(innerAngularName, params.element);
- return () => {
- params.element.classList.remove('dscAppWrapper');
- unmount();
- appUnMounted();
- };
- },
- });
-
- plugins.urlForwarding.forwardApp('doc', 'discoverLegacy', (path) => {
- return `#${path}`;
- });
- plugins.urlForwarding.forwardApp('context', 'discoverLegacy', (path) => {
- const urlParts = path.split('/');
- // take care of urls containing legacy url, those split in the following way
- // ["", "context", indexPatternId, _type, id + params]
- if (urlParts[4]) {
- // remove _type part
- const newPath = [...urlParts.slice(0, 3), ...urlParts.slice(4)].join('/');
- return `#${newPath}`;
- }
- return `#${path}`;
- });
- plugins.urlForwarding.forwardApp('discover', 'discoverLegacy', (path) => {
- const [, id, tail] = /discover\/([^\?]+)(.*)/.exec(path) || [];
- if (!id) {
- return `#${path.replace('/discover', '') || '/'}`;
- }
- return `#/view/${id}${tail || ''}`;
- });
-
- this.registerEmbeddable(core, plugins);
-
- return {
- docViews: {
- addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry),
- },
- docViewsLinks: {
- addDocViewLink: this.docViewsLinksRegistry.addDocViewLink.bind(this.docViewsLinksRegistry),
- },
- };
- }
-
- start(core: CoreStart, plugins: DiscoverStartPlugins) {
- // we need to register the application service at setup, but to render it
- // there are some start dependencies necessary, for this reason
- // initializeInnerAngular + initializeServices are assigned at start and used
- // when the application/embeddable is mounted
- this.initializeInnerAngular = async () => {
- if (this.innerAngularInitialized) {
- return;
- }
- // this is used by application mount and tests
- const { getInnerAngularModule } = await import('./get_inner_angular');
- const module = getInnerAngularModule(
- innerAngularName,
- core,
- plugins,
- this.initializerContext
- );
- setAngularModule(module);
- this.innerAngularInitialized = true;
- };
-
- setUiActions(plugins.uiActions);
-
- this.initializeServices = async () => {
- if (this.servicesInitialized) {
- return { core, plugins };
- }
- const services = await buildServices(
- core,
- plugins,
- this.initializerContext,
- this.getEmbeddableInjector
- );
- setServices(services);
- this.servicesInitialized = true;
-
- return { core, plugins };
- };
-
- return {
- urlGenerator: this.urlGenerator,
- savedSearchLoader: createSavedSearchesLoader({
- savedObjectsClient: core.savedObjects.client,
- indexPatterns: plugins.data.indexPatterns,
- search: plugins.data.search,
- chrome: core.chrome,
- overlays: core.overlays,
- }),
- };
- }
-
- stop() {
- if (this.stopUrlTracking) {
- this.stopUrlTracking();
- }
- }
-
- /**
- * register embeddable with a slimmer embeddable version of inner angular
- */
- private registerEmbeddable(core: CoreSetup, plugins: DiscoverSetupPlugins) {
- if (!this.getEmbeddableInjector) {
- throw Error('Discover plugin method getEmbeddableInjector is undefined');
- }
-
- const getStartServices = async () => {
- const [coreStart, deps] = await core.getStartServices();
- return {
- executeTriggerActions: deps.uiActions.executeTriggerActions,
- isEditable: () => coreStart.application.capabilities.discover.save as boolean,
- };
- };
-
- const factory = new SearchEmbeddableFactory(getStartServices, this.getEmbeddableInjector);
- plugins.embeddable.registerEmbeddableFactory(factory.type, factory);
- }
-
- private getEmbeddableInjector = async () => {
- if (!this.embeddableInjector) {
- if (!this.initializeServices) {
- throw Error('Discover plugin getEmbeddableInjector: initializeServices is undefined');
- }
- const { core, plugins } = await this.initializeServices();
- getServices().opensearchDashboardsLegacy.loadFontAwesome();
- const { getInnerAngularModuleEmbeddable } = await import('./get_inner_angular');
- getInnerAngularModuleEmbeddable(embeddableAngularName, core, plugins);
- const mountpoint = document.createElement('div');
- this.embeddableInjector = angular.bootstrap(mountpoint, [embeddableAngularName]);
- }
-
- return this.embeddableInjector;
- };
-}
diff --git a/src/plugins/discover_legacy/public/saved_searches/_saved_search.ts b/src/plugins/discover_legacy/public/saved_searches/_saved_search.ts
deleted file mode 100644
index 55cd59104ecb..000000000000
--- a/src/plugins/discover_legacy/public/saved_searches/_saved_search.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- createSavedObjectClass,
- SavedObject,
- SavedObjectOpenSearchDashboardsServices,
-} from '../../../saved_objects/public';
-
-export function createSavedSearchClass(services: SavedObjectOpenSearchDashboardsServices) {
- const SavedObjectClass = createSavedObjectClass(services);
-
- class SavedSearch extends SavedObjectClass {
- public static type: string = 'search';
- public static mapping = {
- title: 'text',
- description: 'text',
- hits: 'integer',
- columns: 'keyword',
- sort: 'keyword',
- version: 'integer',
- };
- // Order these fields to the top, the rest are alphabetical
- public static fieldOrder = ['title', 'description'];
- public static searchSource = true;
-
- public id: string;
- public showInRecentlyAccessed: boolean;
-
- constructor(id: string) {
- super({
- id,
- type: 'search',
- mapping: {
- title: 'text',
- description: 'text',
- hits: 'integer',
- columns: 'keyword',
- sort: 'keyword',
- version: 'integer',
- },
- searchSource: true,
- defaults: {
- title: '',
- description: '',
- columns: [],
- hits: 0,
- sort: [],
- version: 1,
- },
- });
- this.showInRecentlyAccessed = true;
- this.id = id;
- this.getFullPath = () => `/app/discover#/view/${String(id)}`;
- }
- }
-
- return SavedSearch as new (id: string) => SavedObject;
-}
diff --git a/src/plugins/discover_legacy/public/saved_searches/index.ts b/src/plugins/discover_legacy/public/saved_searches/index.ts
deleted file mode 100644
index f576a9a9377a..000000000000
--- a/src/plugins/discover_legacy/public/saved_searches/index.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-export { createSavedSearchesLoader } from './saved_searches';
-export { SavedSearch, SavedSearchLoader } from './types';
diff --git a/src/plugins/discover_legacy/public/saved_searches/saved_searches.ts b/src/plugins/discover_legacy/public/saved_searches/saved_searches.ts
deleted file mode 100644
index dd3243568159..000000000000
--- a/src/plugins/discover_legacy/public/saved_searches/saved_searches.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- SavedObjectLoader,
- SavedObjectOpenSearchDashboardsServices,
-} from '../../../saved_objects/public';
-import { createSavedSearchClass } from './_saved_search';
-
-export function createSavedSearchesLoader(services: SavedObjectOpenSearchDashboardsServices) {
- const SavedSearchClass = createSavedSearchClass(services);
- const savedSearchLoader = new SavedObjectLoader(SavedSearchClass, services.savedObjectsClient);
- // Customize loader properties since adding an 's' on type doesn't work for type 'search' .
- savedSearchLoader.loaderProperties = {
- name: 'searches',
- noun: 'Saved Search',
- nouns: 'saved searches',
- };
-
- savedSearchLoader.urlFor = (id: string) => (id ? `#/view/${encodeURIComponent(id)}` : '#/');
-
- return savedSearchLoader;
-}
diff --git a/src/plugins/discover_legacy/public/saved_searches/types.ts b/src/plugins/discover_legacy/public/saved_searches/types.ts
deleted file mode 100644
index e02fd65e6899..000000000000
--- a/src/plugins/discover_legacy/public/saved_searches/types.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { ISearchSource } from '../../../data/public';
-
-export type SortOrder = [string, string];
-export interface SavedSearch {
- readonly id: string;
- title: string;
- searchSource: ISearchSource;
- description?: string;
- columns: string[];
- sort: SortOrder[];
- destroy: () => void;
- lastSavedTitle?: string;
-}
-export interface SavedSearchLoader {
- get: (id: string) => Promise;
- urlFor: (id: string) => string;
-}
diff --git a/src/plugins/discover_legacy/public/url_generator.test.ts b/src/plugins/discover_legacy/public/url_generator.test.ts
deleted file mode 100644
index c352dd5133a4..000000000000
--- a/src/plugins/discover_legacy/public/url_generator.test.ts
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { DiscoverUrlGenerator } from './url_generator';
-import { hashedItemStore, getStatesFromOsdUrl } from '../../opensearch_dashboards_utils/public';
-import { mockStorage } from '../../opensearch_dashboards_utils/public/storage/hashed_item_store/mock';
-import { FilterStateStore } from '../../data/common';
-
-const appBasePath: string = 'xyz/app/discover';
-const indexPatternId: string = 'c367b774-a4c2-11ea-bb37-0242ac130002';
-const savedSearchId: string = '571aaf70-4c88-11e8-b3d7-01146121b73d';
-
-interface SetupParams {
- useHash?: boolean;
-}
-
-const setup = async ({ useHash = false }: SetupParams = {}) => {
- const generator = new DiscoverUrlGenerator({
- appBasePath,
- useHash,
- });
-
- return {
- generator,
- };
-};
-
-beforeEach(() => {
- // @ts-ignore
- hashedItemStore.storage = mockStorage;
-});
-
-describe('Discover url generator', () => {
- test('can create a link to Discover with no state and no saved search', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({});
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(url.startsWith(appBasePath)).toBe(true);
- expect(_a).toEqual({});
- expect(_g).toEqual({});
- });
-
- test('can create a link to a saved search in Discover', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({ savedSearchId });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(url.startsWith(`${appBasePath}#/${savedSearchId}`)).toBe(true);
- expect(_a).toEqual({});
- expect(_g).toEqual({});
- });
-
- test('can specify specific index pattern', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- indexPatternId,
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({
- index: indexPatternId,
- });
- expect(_g).toEqual({});
- });
-
- test('can specify specific time range', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- timeRange: { to: 'now', from: 'now-15m', mode: 'relative' },
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({});
- expect(_g).toEqual({
- time: {
- from: 'now-15m',
- mode: 'relative',
- to: 'now',
- },
- });
- });
-
- test('can specify query', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- query: {
- language: 'kuery',
- query: 'foo',
- },
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({
- query: {
- language: 'kuery',
- query: 'foo',
- },
- });
- expect(_g).toEqual({});
- });
-
- test('can specify local and global filters', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- filters: [
- {
- meta: {
- alias: 'foo',
- disabled: false,
- negate: false,
- },
- $state: {
- store: FilterStateStore.APP_STATE,
- },
- },
- {
- meta: {
- alias: 'bar',
- disabled: false,
- negate: false,
- },
- $state: {
- store: FilterStateStore.GLOBAL_STATE,
- },
- },
- ],
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({
- filters: [
- {
- $state: {
- store: 'appState',
- },
- meta: {
- alias: 'foo',
- disabled: false,
- negate: false,
- },
- },
- ],
- });
- expect(_g).toEqual({
- filters: [
- {
- $state: {
- store: 'globalState',
- },
- meta: {
- alias: 'bar',
- disabled: false,
- negate: false,
- },
- },
- ],
- });
- });
-
- test('can set refresh interval', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- refreshInterval: {
- pause: false,
- value: 666,
- },
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({});
- expect(_g).toEqual({
- refreshInterval: {
- pause: false,
- value: 666,
- },
- });
- });
-
- test('can set time range', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- timeRange: {
- from: 'now-3h',
- to: 'now',
- },
- });
- const { _a, _g } = getStatesFromOsdUrl(url, ['_a', '_g']);
-
- expect(_a).toEqual({});
- expect(_g).toEqual({
- time: {
- from: 'now-3h',
- to: 'now',
- },
- });
- });
-
- describe('useHash property', () => {
- describe('when default useHash is set to false', () => {
- test('when using default, sets index pattern ID in the generated URL', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- indexPatternId,
- });
-
- expect(url.indexOf(indexPatternId) > -1).toBe(true);
- });
-
- test('when enabling useHash, does not set index pattern ID in the generated URL', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- useHash: true,
- indexPatternId,
- });
-
- expect(url.indexOf(indexPatternId) > -1).toBe(false);
- });
- });
-
- describe('when default useHash is set to true', () => {
- test('when using default, does not set index pattern ID in the generated URL', async () => {
- const { generator } = await setup({ useHash: true });
- const url = await generator.createUrl({
- indexPatternId,
- });
-
- expect(url.indexOf(indexPatternId) > -1).toBe(false);
- });
-
- test('when disabling useHash, sets index pattern ID in the generated URL', async () => {
- const { generator } = await setup();
- const url = await generator.createUrl({
- useHash: false,
- indexPatternId,
- });
-
- expect(url.indexOf(indexPatternId) > -1).toBe(true);
- });
- });
- });
-});
diff --git a/src/plugins/discover_legacy/public/url_generator.ts b/src/plugins/discover_legacy/public/url_generator.ts
deleted file mode 100644
index 25e8517c8c9d..000000000000
--- a/src/plugins/discover_legacy/public/url_generator.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- TimeRange,
- Filter,
- Query,
- opensearchFilters,
- QueryState,
- RefreshInterval,
-} from '../../data/public';
-import { setStateToOsdUrl } from '../../opensearch_dashboards_utils/public';
-import { UrlGeneratorsDefinition } from '../../share/public';
-
-export const DISCOVER_APP_URL_GENERATOR = 'DISCOVER_APP_URL_GENERATOR';
-
-export interface DiscoverUrlGeneratorState {
- /**
- * Optionally set saved search ID.
- */
- savedSearchId?: string;
-
- /**
- * Optionally set index pattern ID.
- */
- indexPatternId?: string;
-
- /**
- * Optionally set the time range in the time picker.
- */
- timeRange?: TimeRange;
-
- /**
- * Optionally set the refresh interval.
- */
- refreshInterval?: RefreshInterval;
-
- /**
- * Optionally apply filers.
- */
- filters?: Filter[];
-
- /**
- * Optionally set a query. NOTE: if given and used in conjunction with `dashboardId`, and the
- * saved dashboard has a query saved with it, this will _replace_ that query.
- */
- query?: Query;
-
- /**
- * If not given, will use the uiSettings configuration for `storeInSessionStorage`. useHash determines
- * whether to hash the data in the url to avoid url length issues.
- */
- useHash?: boolean;
-}
-
-interface Params {
- appBasePath: string;
- useHash: boolean;
-}
-
-export class DiscoverUrlGenerator
- implements UrlGeneratorsDefinition {
- constructor(private readonly params: Params) {}
-
- public readonly id = DISCOVER_APP_URL_GENERATOR;
-
- public readonly createUrl = async ({
- filters,
- indexPatternId,
- query,
- refreshInterval,
- savedSearchId,
- timeRange,
- useHash = this.params.useHash,
- }: DiscoverUrlGeneratorState): Promise => {
- const savedSearchPath = savedSearchId ? encodeURIComponent(savedSearchId) : '';
- const appState: {
- query?: Query;
- filters?: Filter[];
- index?: string;
- } = {};
- const queryState: QueryState = {};
-
- if (query) appState.query = query;
- if (filters && filters.length)
- appState.filters = filters?.filter((f) => !opensearchFilters.isFilterPinned(f));
- if (indexPatternId) appState.index = indexPatternId;
-
- if (timeRange) queryState.time = timeRange;
- if (filters && filters.length)
- queryState.filters = filters?.filter((f) => opensearchFilters.isFilterPinned(f));
- if (refreshInterval) queryState.refreshInterval = refreshInterval;
-
- let url = `${this.params.appBasePath}#/${savedSearchPath}`;
- url = setStateToOsdUrl('_g', queryState, { useHash }, url);
- url = setStateToOsdUrl('_a', appState, { useHash }, url);
-
- return url;
- };
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/angular_config.tsx b/src/plugins/opensearch_dashboards_legacy/public/angular/angular_config.tsx
deleted file mode 100644
index fbe36a289d70..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/angular_config.tsx
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import {
- ICompileProvider,
- IHttpProvider,
- IHttpService,
- ILocationProvider,
- IModule,
- IRootScopeService,
-} from 'angular';
-import $ from 'jquery';
-import { set } from '@elastic/safer-lodash-set';
-import { get } from 'lodash';
-import * as Rx from 'rxjs';
-import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'opensearch-dashboards/public';
-import { History } from 'history';
-
-import { CoreStart } from 'opensearch-dashboards/public';
-import { isSystemApiRequest } from '../utils';
-import { formatAngularHttpError, isAngularHttpError } from '../notify/lib';
-
-export interface RouteConfiguration {
- controller?: string | ((...args: any[]) => void);
- redirectTo?: string;
- resolveRedirectTo?: (...args: any[]) => void;
- reloadOnSearch?: boolean;
- reloadOnUrl?: boolean;
- outerAngularWrapperRoute?: boolean;
- resolve?: object;
- template?: string;
- k7Breadcrumbs?: (...args: any[]) => ChromeBreadcrumb[];
- requireUICapability?: string;
-}
-
-/**
- * Detects whether a given angular route is a dummy route that doesn't
- * require any action. There are two ways this can happen:
- * If `outerAngularWrapperRoute` is set on the route config object,
- * it means the local application service set up this route on the outer angular
- * and the internal routes will handle the hooks.
- *
- * If angular did not detect a route and it is the local angular, we are currently
- * navigating away from a URL controlled by a local angular router and the
- * application will get unmounted. In this case the outer router will handle
- * the hooks.
- * @param $route Injected $route dependency
- * @param isLocalAngular Flag whether this is the local angular router
- */
-function isDummyRoute($route: any, isLocalAngular: boolean) {
- return (
- ($route.current && $route.current.$$route && $route.current.$$route.outerAngularWrapperRoute) ||
- (!$route.current && isLocalAngular)
- );
-}
-
-export const configureAppAngularModule = (
- angularModule: IModule,
- newPlatform: {
- core: CoreStart;
- readonly env: {
- mode: Readonly;
- packageInfo: Readonly;
- };
- },
- isLocalAngular: boolean,
- getHistory?: () => History
-) => {
- const core = 'core' in newPlatform ? newPlatform.core : newPlatform;
- const packageInfo = newPlatform.env.packageInfo;
-
- angularModule
- .value('osdVersion', packageInfo.version)
- .value('buildNum', packageInfo.buildNum)
- .value('buildSha', packageInfo.buildSha)
- .value('opensearchUrl', getOpenSearchUrl(core))
- .value('uiCapabilities', core.application.capabilities)
- .config(setupCompileProvider(newPlatform.env.mode.dev))
- .config(setupLocationProvider())
- .config($setupXsrfRequestInterceptor(packageInfo.version))
- .run(capture$httpLoadingCount(core))
- .run(digestOnHashChange(getHistory))
- .run($setupBreadcrumbsAutoClear(core, isLocalAngular))
- .run($setupBadgeAutoClear(core, isLocalAngular))
- .run($setupHelpExtensionAutoClear(core, isLocalAngular))
- .run($setupUICapabilityRedirect(core));
-};
-
-const getOpenSearchUrl = (newPlatform: CoreStart) => {
- const a = document.createElement('a');
- a.href = newPlatform.http.basePath.prepend('/opensearch');
- const protocolPort = /https/.test(a.protocol) ? 443 : 80;
- const port = a.port || protocolPort;
- return {
- host: a.hostname,
- port,
- protocol: a.protocol,
- pathname: a.pathname,
- };
-};
-
-const digestOnHashChange = (getHistory?: () => History) => ($rootScope: IRootScopeService) => {
- if (!getHistory) return;
- const unlisten = getHistory().listen(() => {
- // dispatch synthetic hash change event to update hash history objects and angular routing
- // this is necessary because hash updates triggered by using popState won't trigger this event naturally.
- // this has to happen in the next tick to not change the existing timing of angular digest cycles.
- setTimeout(() => {
- window.dispatchEvent(new HashChangeEvent('hashchange'));
- }, 0);
- });
- $rootScope.$on('$destroy', unlisten);
-};
-
-const setupCompileProvider = (devMode: boolean) => ($compileProvider: ICompileProvider) => {
- if (!devMode) {
- $compileProvider.debugInfoEnabled(false);
- }
-};
-
-const setupLocationProvider = () => ($locationProvider: ILocationProvider) => {
- $locationProvider.html5Mode({
- enabled: false,
- requireBase: false,
- rewriteLinks: false,
- });
-
- $locationProvider.hashPrefix('');
-};
-
-export const $setupXsrfRequestInterceptor = (version: string) => {
- // Configure jQuery prefilter
- $.ajaxPrefilter(({ osdXsrfToken = true }: any, originalOptions, jqXHR) => {
- if (osdXsrfToken) {
- jqXHR.setRequestHeader('osd-xsrf', 'osd-legacy');
- // ToDo: Remove next; `osd-version` incorrectly used for satisfying XSRF protection
- jqXHR.setRequestHeader('osd-version', version);
- }
- });
-
- return ($httpProvider: IHttpProvider) => {
- // Configure $httpProvider interceptor
- $httpProvider.interceptors.push(() => {
- return {
- request(opts) {
- const { osdXsrfToken = true } = opts as any;
- if (osdXsrfToken) {
- set(opts, ['headers', 'osd-xsrf'], 'osd-legacy');
- // ToDo: Remove next; `osd-version` incorrectly used for satisfying XSRF protection
- set(opts, ['headers', 'osd-version'], version);
- }
- return opts;
- },
- };
- });
- };
-};
-
-/**
- * Injected into angular module by ui/chrome angular integration
- * and adds a root-level watcher that will capture the count of
- * active $http requests on each digest loop and expose the count to
- * the core.loadingCount api
- */
-const capture$httpLoadingCount = (newPlatform: CoreStart) => (
- $rootScope: IRootScopeService,
- $http: IHttpService
-) => {
- newPlatform.http.addLoadingCountSource(
- new Rx.Observable((observer) => {
- const unwatch = $rootScope.$watch(() => {
- const reqs = $http.pendingRequests || [];
- observer.next(reqs.filter((req) => !isSystemApiRequest(req)).length);
- });
-
- return unwatch;
- })
- );
-};
-
-/**
- * integrates with angular to automatically redirect to home if required
- * capability is not met
- */
-const $setupUICapabilityRedirect = (newPlatform: CoreStart) => (
- $rootScope: IRootScopeService,
- $injector: any
-) => {
- const isOpenSearchDashboardsAppRoute = window.location.pathname.endsWith(
- '/app/opensearch-dashboards'
- );
- // this feature only works within opensearch dashboards app for now after everything is
- // switched to the application service, this can be changed to handle all
- // apps.
- if (!isOpenSearchDashboardsAppRoute) {
- return;
- }
- $rootScope.$on(
- '$routeChangeStart',
- (event, { $$route: route }: { $$route?: RouteConfiguration } = {}) => {
- if (!route || !route.requireUICapability) {
- return;
- }
-
- if (!get(newPlatform.application.capabilities, route.requireUICapability)) {
- $injector.get('$location').url('/home');
- event.preventDefault();
- }
- }
- );
-};
-
-/**
- * internal angular run function that will be called when angular bootstraps and
- * lets us integrate with the angular router so that we can automatically clear
- * the breadcrumbs if we switch to a OpenSearch Dashboards app that does not use breadcrumbs correctly
- */
-const $setupBreadcrumbsAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
- $rootScope: IRootScopeService,
- $injector: any
-) => {
- // A flag used to determine if we should automatically
- // clear the breadcrumbs between angular route changes.
- let breadcrumbSetSinceRouteChange = false;
- const $route = $injector.has('$route') ? $injector.get('$route') : {};
-
- // reset breadcrumbSetSinceRouteChange any time the breadcrumbs change, even
- // if it was done directly through the new platform
- newPlatform.chrome.getBreadcrumbs$().subscribe({
- next() {
- breadcrumbSetSinceRouteChange = true;
- },
- });
-
- $rootScope.$on('$routeChangeStart', () => {
- breadcrumbSetSinceRouteChange = false;
- });
-
- $rootScope.$on('$routeChangeSuccess', () => {
- if (isDummyRoute($route, isLocalAngular)) {
- return;
- }
- const current = $route.current || {};
-
- if (breadcrumbSetSinceRouteChange || (current.$$route && current.$$route.redirectTo)) {
- return;
- }
-
- const k7BreadcrumbsProvider = current.k7Breadcrumbs;
- if (!k7BreadcrumbsProvider) {
- newPlatform.chrome.setBreadcrumbs([]);
- return;
- }
-
- try {
- newPlatform.chrome.setBreadcrumbs($injector.invoke(k7BreadcrumbsProvider));
- } catch (error) {
- if (isAngularHttpError(error)) {
- error = formatAngularHttpError(error);
- }
- newPlatform.fatalErrors.add(error, 'location');
- }
- });
-};
-
-/**
- * internal angular run function that will be called when angular bootstraps and
- * lets us integrate with the angular router so that we can automatically clear
- * the badge if we switch to a OpenSearch Dashboards app that does not use the badge correctly
- */
-const $setupBadgeAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
- $rootScope: IRootScopeService,
- $injector: any
-) => {
- // A flag used to determine if we should automatically
- // clear the badge between angular route changes.
- let badgeSetSinceRouteChange = false;
- const $route = $injector.has('$route') ? $injector.get('$route') : {};
-
- $rootScope.$on('$routeChangeStart', () => {
- badgeSetSinceRouteChange = false;
- });
-
- $rootScope.$on('$routeChangeSuccess', () => {
- if (isDummyRoute($route, isLocalAngular)) {
- return;
- }
- const current = $route.current || {};
-
- if (badgeSetSinceRouteChange || (current.$$route && current.$$route.redirectTo)) {
- return;
- }
-
- const badgeProvider = current.badge;
- if (!badgeProvider) {
- newPlatform.chrome.setBadge(undefined);
- return;
- }
-
- try {
- newPlatform.chrome.setBadge($injector.invoke(badgeProvider));
- } catch (error) {
- if (isAngularHttpError(error)) {
- error = formatAngularHttpError(error);
- }
- newPlatform.fatalErrors.add(error, 'location');
- }
- });
-};
-
-/**
- * internal angular run function that will be called when angular bootstraps and
- * lets us integrate with the angular router so that we can automatically clear
- * the helpExtension if we switch to a OpenSearch Dashboards app that does not set its own
- * helpExtension
- */
-const $setupHelpExtensionAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
- $rootScope: IRootScopeService,
- $injector: any
-) => {
- /**
- * reset helpExtensionSetSinceRouteChange any time the helpExtension changes, even
- * if it was done directly through the new platform
- */
- let helpExtensionSetSinceRouteChange = false;
- newPlatform.chrome.getHelpExtension$().subscribe({
- next() {
- helpExtensionSetSinceRouteChange = true;
- },
- });
-
- const $route = $injector.has('$route') ? $injector.get('$route') : {};
-
- $rootScope.$on('$routeChangeStart', () => {
- if (isDummyRoute($route, isLocalAngular)) {
- return;
- }
- helpExtensionSetSinceRouteChange = false;
- });
-
- $rootScope.$on('$routeChangeSuccess', () => {
- if (isDummyRoute($route, isLocalAngular)) {
- return;
- }
- const current = $route.current || {};
-
- if (helpExtensionSetSinceRouteChange || (current.$$route && current.$$route.redirectTo)) {
- return;
- }
-
- newPlatform.chrome.setHelpExtension(current.helpExtension);
- });
-};
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/index.ts b/src/plugins/opensearch_dashboards_legacy/public/angular/index.ts
deleted file mode 100644
index c492de510093..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/index.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// @ts-ignore
-export { PromiseServiceCreator } from './promises';
-// @ts-ignore
-export { watchMultiDecorator } from './watch_multi';
-export * from './angular_config';
-// @ts-ignore
-export { createTopNavDirective, createTopNavHelper, loadOsdTopNavDirectives } from './osd_top_nav';
-export { subscribeWithScope } from './subscribe_with_scope';
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/osd_top_nav.js b/src/plugins/opensearch_dashboards_legacy/public/angular/osd_top_nav.js
deleted file mode 100644
index 11835005b60c..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/osd_top_nav.js
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import angular from 'angular';
-import 'ngreact';
-
-export function createTopNavDirective() {
- return {
- restrict: 'E',
- template: '',
- compile: (elem) => {
- const child = document.createElement('osd-top-nav-helper');
-
- // Copy attributes to the child directive
- for (const attr of elem[0].attributes) {
- child.setAttribute(attr.name, attr.value);
- }
-
- // Add a special attribute that will change every time that one
- // of the config array's disableButton function return value changes.
- child.setAttribute('disabled-buttons', 'disabledButtons');
-
- // Append helper directive
- elem.append(child);
-
- const linkFn = ($scope, _, $attr) => {
- // Watch config changes
- $scope.$watch(
- () => {
- const config = $scope.$eval($attr.config) || [];
- return config.map((item) => {
- // Copy key into id, as it's a reserved react propery.
- // This is done for Angular directive backward compatibility.
- // In React only id is recognized.
- if (item.key && !item.id) {
- item.id = item.key;
- }
-
- // Watch the disableButton functions
- if (typeof item.disableButton === 'function') {
- return item.disableButton();
- }
- return item.disableButton;
- });
- },
- (newVal) => {
- $scope.disabledButtons = newVal;
- },
- true
- );
- };
-
- return linkFn;
- },
- };
-}
-
-export const createTopNavHelper = ({ TopNavMenu }) => (reactDirective) => {
- return reactDirective(TopNavMenu, [
- ['config', { watchDepth: 'value' }],
- ['setMenuMountPoint', { watchDepth: 'reference' }],
- ['disabledButtons', { watchDepth: 'reference' }],
-
- ['query', { watchDepth: 'reference' }],
- ['savedQuery', { watchDepth: 'reference' }],
- ['intl', { watchDepth: 'reference' }],
-
- ['onQuerySubmit', { watchDepth: 'reference' }],
- ['onFiltersUpdated', { watchDepth: 'reference' }],
- ['onRefreshChange', { watchDepth: 'reference' }],
- ['onClearSavedQuery', { watchDepth: 'reference' }],
- ['onSaved', { watchDepth: 'reference' }],
- ['onSavedQueryUpdated', { watchDepth: 'reference' }],
- ['onSavedQueryIdChange', { watchDepth: 'reference' }],
-
- ['indexPatterns', { watchDepth: 'collection' }],
- ['filters', { watchDepth: 'collection' }],
-
- // All modifiers default to true.
- // Set to false to hide subcomponents.
- 'showSearchBar',
- 'showQueryBar',
- 'showQueryInput',
- 'showSaveQuery',
- 'showDatePicker',
- 'showFilterBar',
-
- 'appName',
- 'screenTitle',
- 'dateRangeFrom',
- 'dateRangeTo',
- 'savedQueryId',
- 'isRefreshPaused',
- 'refreshInterval',
- 'disableAutoFocus',
- 'showAutoRefreshOnly',
-
- // temporary flag to use the stateful components
- 'useDefaultBehaviors',
- ]);
-};
-
-let isLoaded = false;
-
-export function loadOsdTopNavDirectives(navUi) {
- if (!isLoaded) {
- isLoaded = true;
- angular
- .module('opensearchDashboards')
- .directive('osdTopNav', createTopNavDirective)
- .directive('osdTopNavHelper', createTopNavHelper(navUi));
- }
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/promises.js b/src/plugins/opensearch_dashboards_legacy/public/angular/promises.js
deleted file mode 100644
index 690bc5489d10..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/promises.js
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-
-export function PromiseServiceCreator($q, $timeout) {
- function Promise(fn) {
- if (typeof this === 'undefined')
- throw new Error('Promise constructor must be called with "new"');
-
- const defer = $q.defer();
- try {
- fn(defer.resolve, defer.reject);
- } catch (e) {
- defer.reject(e);
- }
- return defer.promise;
- }
-
- Promise.all = Promise.props = $q.all;
- Promise.resolve = function (val) {
- const defer = $q.defer();
- defer.resolve(val);
- return defer.promise;
- };
- Promise.reject = function (reason) {
- const defer = $q.defer();
- defer.reject(reason);
- return defer.promise;
- };
- Promise.cast = $q.when;
- Promise.delay = function (ms) {
- return $timeout(_.noop, ms);
- };
- Promise.method = function (fn) {
- return function () {
- const args = Array.prototype.slice.call(arguments);
- return Promise.try(fn, args, this);
- };
- };
- Promise.nodeify = function (promise, cb) {
- promise.then(function (val) {
- cb(void 0, val);
- }, cb);
- };
- Promise.map = function (arr, fn) {
- return Promise.all(
- arr.map(function (i, el, list) {
- return Promise.try(fn, [i, el, list]);
- })
- );
- };
- Promise.each = function (arr, fn) {
- const queue = arr.slice(0);
- let i = 0;
- return (function next() {
- if (!queue.length) return arr;
- return Promise.try(fn, [arr.shift(), i++]).then(next);
- })();
- };
- Promise.is = function (obj) {
- // $q doesn't create instances of any constructor, promises are just objects with a then function
- // https://github.com/angular/angular.js/blob/58f5da86645990ef984353418cd1ed83213b111e/src/ng/q.js#L335
- return obj && typeof obj.then === 'function';
- };
- Promise.halt = _.once(function () {
- const promise = new Promise(() => {});
- promise.then = _.constant(promise);
- promise.catch = _.constant(promise);
- return promise;
- });
- Promise.try = function (fn, args, ctx) {
- if (typeof fn !== 'function') {
- return Promise.reject(new TypeError('fn must be a function'));
- }
-
- let value;
-
- if (Array.isArray(args)) {
- try {
- value = fn.apply(ctx, args);
- } catch (e) {
- return Promise.reject(e);
- }
- } else {
- try {
- value = fn.call(ctx, args);
- } catch (e) {
- return Promise.reject(e);
- }
- }
-
- return Promise.resolve(value);
- };
- Promise.fromNode = function (takesCbFn) {
- return new Promise(function (resolve, reject) {
- takesCbFn(function (err, ...results) {
- if (err) reject(err);
- else if (results.length > 1) resolve(results);
- else resolve(results[0]);
- });
- });
- };
- Promise.race = function (iterable) {
- return new Promise((resolve, reject) => {
- for (const i of iterable) {
- Promise.resolve(i).then(resolve, reject);
- }
- });
- };
-
- return Promise;
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.test.ts b/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.test.ts
deleted file mode 100644
index 3784988fc818..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.test.ts
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import * as Rx from 'rxjs';
-import { subscribeWithScope } from './subscribe_with_scope';
-
-// eslint-disable-next-line prefer-const
-let $rootScope: Scope;
-
-class Scope {
- public $$phase?: string;
- public $root = $rootScope;
- public $apply = jest.fn((fn: () => void) => fn());
-}
-
-$rootScope = new Scope();
-
-afterEach(() => {
- jest.clearAllMocks();
-});
-
-it('subscribes to the passed observable, returns subscription', () => {
- const $scope = new Scope();
-
- const unsubSpy = jest.fn();
- const subSpy = jest.fn(() => unsubSpy);
- const observable = new Rx.Observable(subSpy);
-
- const subscription = subscribeWithScope($scope as any, observable);
- expect(subSpy).toHaveBeenCalledTimes(1);
- expect(unsubSpy).not.toHaveBeenCalled();
-
- subscription.unsubscribe();
-
- expect(subSpy).toHaveBeenCalledTimes(1);
- expect(unsubSpy).toHaveBeenCalledTimes(1);
-});
-
-it('calls observer.next() if already in a digest cycle, wraps in $scope.$apply if not', () => {
- const subject = new Rx.Subject();
- const nextSpy = jest.fn();
- const $scope = new Scope();
-
- subscribeWithScope($scope as any, subject, { next: nextSpy });
-
- subject.next();
- expect($scope.$apply).toHaveBeenCalledTimes(1);
- expect(nextSpy).toHaveBeenCalledTimes(1);
-
- jest.clearAllMocks();
-
- $rootScope.$$phase = '$digest';
- subject.next();
- expect($scope.$apply).not.toHaveBeenCalled();
- expect(nextSpy).toHaveBeenCalledTimes(1);
-});
-
-it('reports fatalError if observer.next() throws', () => {
- const fatalError = jest.fn();
- const $scope = new Scope();
- subscribeWithScope(
- $scope as any,
- Rx.of(undefined),
- {
- next() {
- throw new Error('foo bar');
- },
- },
- fatalError
- );
-
- expect(fatalError.mock.calls).toMatchInlineSnapshot(`
-Array [
- Array [
- [Error: foo bar],
- ],
-]
-`);
-});
-
-it('reports fatal error if observer.error is not defined and observable errors', () => {
- const fatalError = jest.fn();
- const $scope = new Scope();
- const error = new Error('foo');
- error.stack = `${error.message}\n---stack trace ---`;
- subscribeWithScope($scope as any, Rx.throwError(error), undefined, fatalError);
-
- expect(fatalError.mock.calls).toMatchInlineSnapshot(`
-Array [
- Array [
- [Error: Uncaught error in subscribeWithScope(): foo
----stack trace ---],
- ],
-]
-`);
-});
-
-it('reports fatal error if observer.error throws', () => {
- const fatalError = jest.fn();
- const $scope = new Scope();
- subscribeWithScope(
- $scope as any,
- Rx.throwError(new Error('foo')),
- {
- error: () => {
- throw new Error('foo');
- },
- },
- fatalError
- );
-
- expect(fatalError.mock.calls).toMatchInlineSnapshot(`
-Array [
- Array [
- [Error: foo],
- ],
-]
-`);
-});
-
-it('does not report fatal error if observer.error handles the error', () => {
- const fatalError = jest.fn();
- const $scope = new Scope();
- subscribeWithScope(
- $scope as any,
- Rx.throwError(new Error('foo')),
- {
- error: () => {
- // noop, swallow error
- },
- },
- fatalError
- );
-
- expect(fatalError.mock.calls).toEqual([]);
-});
-
-it('reports fatal error if observer.complete throws', () => {
- const fatalError = jest.fn();
- const $scope = new Scope();
- subscribeWithScope(
- $scope as any,
- Rx.EMPTY,
- {
- complete: () => {
- throw new Error('foo');
- },
- },
- fatalError
- );
-
- expect(fatalError.mock.calls).toMatchInlineSnapshot(`
-Array [
- Array [
- [Error: foo],
- ],
-]
-`);
-});
-
-it('preserves the context of the observer functions', () => {
- const $scope = new Scope();
- const observer = {
- next() {
- expect(this).toBe(observer);
- },
- complete() {
- expect(this).toBe(observer);
- },
- };
-
- subscribeWithScope($scope as any, Rx.of([1, 2, 3]), observer);
-
- const observer2 = {
- error() {
- expect(this).toBe(observer);
- },
- };
-
- subscribeWithScope($scope as any, Rx.throwError(new Error('foo')), observer2);
-});
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.ts b/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.ts
deleted file mode 100644
index f8cb102379b6..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/subscribe_with_scope.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { IScope } from 'angular';
-import * as Rx from 'rxjs';
-import { AngularHttpError } from '../notify/lib';
-
-type FatalErrorFn = (error: AngularHttpError | Error | string, location?: string) => void;
-
-function callInDigest($scope: IScope, fn: () => void, fatalError?: FatalErrorFn) {
- try {
- // this is terrible, but necessary to synchronously deliver subscription values
- // to angular scopes. This is required by some APIs, like the `config` service,
- // and beneficial for root level directives where additional digest cycles make
- // opensearch dashboards sluggish to load.
- //
- // If you copy this code elsewhere you better have a good reason :)
- if ($scope.$root.$$phase) {
- fn();
- } else {
- $scope.$apply(() => fn());
- }
- } catch (error) {
- if (fatalError) {
- fatalError(error);
- }
- }
-}
-
-/**
- * Subscribe to an observable at a $scope, ensuring that the digest cycle
- * is run for subscriber hooks and routing errors to fatalError if not handled.
- */
-export function subscribeWithScope(
- $scope: IScope,
- observable: Rx.Observable,
- observer?: Rx.PartialObserver,
- fatalError?: FatalErrorFn
-) {
- return observable.subscribe({
- next(value) {
- if (observer && observer.next) {
- callInDigest($scope, () => observer.next!(value), fatalError);
- }
- },
- error(error) {
- callInDigest(
- $scope,
- () => {
- if (observer && observer.error) {
- observer.error(error);
- } else {
- throw new Error(
- `Uncaught error in subscribeWithScope(): ${
- error ? error.stack || error.message : error
- }`
- );
- }
- },
- fatalError
- );
- },
- complete() {
- if (observer && observer.complete) {
- callInDigest($scope, () => observer.complete!(), fatalError);
- }
- },
- });
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular/watch_multi.js b/src/plugins/opensearch_dashboards_legacy/public/angular/watch_multi.js
deleted file mode 100644
index 8dfcb0f59420..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular/watch_multi.js
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/*
- * Licensed to Elasticsearch B.V. under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch B.V. licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import _ from 'lodash';
-
-export function watchMultiDecorator($provide) {
- $provide.decorator('$rootScope', function ($delegate) {
- /**
- * Watch multiple expressions with a single callback. Along
- * with making code simpler it also merges all of the watcher
- * handlers within a single tick.
- *
- * # expression format
- * expressions can be specified in one of the following ways:
- * 1. string that evaluates to a value on scope. Creates a regular $watch
- * expression.
- * 'someScopeValue.prop' === $scope.$watch('someScopeValue.prop', fn);
- *
- * 2. #1 prefixed with '[]', which uses $watchCollection rather than $watch.
- * '[]expr' === $scope.$watchCollection('expr', fn);
- *
- * 3. #1 prefixed with '=', which uses $watch with objectEquality turned on
- * '=expr' === $scope.$watch('expr', fn, true);
- *
- * 4. a function that will be called, like a normal function water
- *
- * 5. an object with any of the properties:
- * `get`: the getter called on each iteration
- * `deep`: a flag to turn on objectEquality in $watch
- * `fn`: the watch registration function ($scope.$watch or $scope.$watchCollection)
- *
- * @param {array[string|function|obj]} expressions - the list of expressions to $watch
- * @param {Function} fn - the callback function
- * @return {Function} - an unwatch function, just like the return value of $watch
- */
- $delegate.constructor.prototype.$watchMulti = function (expressions, fn) {
- if (!Array.isArray(expressions)) {
- throw new TypeError('expected an array of expressions to watch');
- }
-
- if (!_.isFunction(fn)) {
- throw new TypeError('expected a function that is triggered on each watch');
- }
- const $scope = this;
- const vals = new Array(expressions.length);
- const prev = new Array(expressions.length);
- let fire = false;
- let init = 0;
- const neededInits = expressions.length;
-
- // first, register all of the multi-watchers
- const unwatchers = expressions.map(function (expr, i) {
- expr = normalizeExpression($scope, expr);
- if (!expr) return;
-
- return expr.fn.call(
- $scope,
- expr.get,
- function (newVal, oldVal) {
- if (newVal === oldVal) {
- init += 1;
- }
-
- vals[i] = newVal;
- prev[i] = oldVal;
- fire = true;
- },
- expr.deep
- );
- });
-
- // then, the watcher that checks to see if any of
- // the other watchers triggered this cycle
- let flip = false;
- unwatchers.push(
- $scope.$watch(
- function () {
- if (init < neededInits) return init;
-
- if (fire) {
- fire = false;
- flip = !flip;
- }
- return flip;
- },
- function () {
- if (init < neededInits) return false;
-
- fn(vals.slice(0), prev.slice(0));
- vals.forEach(function (v, i) {
- prev[i] = v;
- });
- }
- )
- );
-
- return function () {
- unwatchers.forEach((listener) => listener());
- };
- };
-
- function normalizeExpression($scope, expr) {
- if (!expr) return;
- const norm = {
- fn: $scope.$watch,
- deep: false,
- };
-
- if (_.isFunction(expr)) return _.assign(norm, { get: expr });
- if (_.isObject(expr)) return _.assign(norm, expr);
- if (!_.isString(expr)) return;
-
- if (expr.substr(0, 2) === '[]') {
- return _.assign(norm, {
- fn: $scope.$watchCollection,
- get: expr.substr(2),
- });
- }
-
- if (expr.charAt(0) === '=') {
- return _.assign(norm, {
- deep: true,
- get: expr.substr(1),
- });
- }
-
- return _.assign(norm, { get: expr });
- }
-
- return $delegate;
- });
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/bind_html/bind_html.js b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/bind_html/bind_html.js
deleted file mode 100755
index 5e6f2edea608..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/bind_html/bind_html.js
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/* eslint-disable */
-
-import angular from 'angular';
-
-export function initBindHtml() {
- angular
- .module('ui.bootstrap.bindHtml', [])
-
- .directive('bindHtmlUnsafe', function() {
- return function(scope, element, attr) {
- element.addClass('ng-binding').data('$binding', attr.bindHtmlUnsafe);
- scope.$watch(attr.bindHtmlUnsafe, function bindHtmlUnsafeWatchAction(value) {
- element.html(value || '');
- });
- };
- });
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/index.ts b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/index.ts
deleted file mode 100644
index 63b0431ebb29..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/index.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/* eslint-disable */
-
-import { once } from 'lodash';
-import angular from 'angular';
-
-// @ts-ignore
-import { initBindHtml } from './bind_html/bind_html';
-// @ts-ignore
-import { initBootstrapTooltip } from './tooltip/tooltip';
-
-import tooltipPopup from './tooltip/tooltip_popup.html';
-
-import tooltipUnsafePopup from './tooltip/tooltip_html_unsafe_popup.html';
-
-export const initAngularBootstrap = once(() => {
- /*
- * angular-ui-bootstrap
- * http://angular-ui.github.io/bootstrap/
-
- * Version: 0.12.1 - 2015-02-20
- * License: MIT
- */
- angular.module('ui.bootstrap', [
- 'ui.bootstrap.tpls',
- 'ui.bootstrap.bindHtml',
- 'ui.bootstrap.tooltip',
- ]);
-
- angular.module('ui.bootstrap.tpls', [
- 'template/tooltip/tooltip-html-unsafe-popup.html',
- 'template/tooltip/tooltip-popup.html',
- ]);
-
- initBindHtml();
- initBootstrapTooltip();
-
- angular.module('template/tooltip/tooltip-html-unsafe-popup.html', []).run([
- '$templateCache',
- function($templateCache: any) {
- $templateCache.put('template/tooltip/tooltip-html-unsafe-popup.html', tooltipUnsafePopup);
- },
- ]);
-
- angular.module('template/tooltip/tooltip-popup.html', []).run([
- '$templateCache',
- function($templateCache: any) {
- $templateCache.put('template/tooltip/tooltip-popup.html', tooltipPopup);
- },
- ]);
-});
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/position.js b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/position.js
deleted file mode 100755
index 2f322e2b42e2..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/position.js
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/* eslint-disable */
-
-import angular from 'angular';
-
-export function initBootstrapPosition() {
- angular
- .module('ui.bootstrap.position', [])
-
- /**
- * A set of utility methods that can be use to retrieve position of DOM elements.
- * It is meant to be used where we need to absolute-position DOM elements in
- * relation to other, existing elements (this is the case for tooltips, popovers,
- * typeahead suggestions etc.).
- */
- .factory('$position', [
- '$document',
- '$window',
- function($document, $window) {
- function getStyle(el, cssprop) {
- if (el.currentStyle) {
- //IE
- return el.currentStyle[cssprop];
- } else if ($window.getComputedStyle) {
- return $window.getComputedStyle(el)[cssprop];
- }
- // finally try and get inline style
- return el.style[cssprop];
- }
-
- /**
- * Checks if a given element is statically positioned
- * @param element - raw DOM element
- */
- function isStaticPositioned(element) {
- return (getStyle(element, 'position') || 'static') === 'static';
- }
-
- /**
- * returns the closest, non-statically positioned parentOffset of a given element
- * @param element
- */
- const parentOffsetEl = function(element) {
- const docDomEl = $document[0];
- let offsetParent = element.offsetParent || docDomEl;
- while (offsetParent && offsetParent !== docDomEl && isStaticPositioned(offsetParent)) {
- offsetParent = offsetParent.offsetParent;
- }
- return offsetParent || docDomEl;
- };
-
- return {
- /**
- * Provides read-only equivalent of jQuery's position function:
- * http://api.jquery.com/position/
- */
- position: function(element) {
- const elBCR = this.offset(element);
- let offsetParentBCR = { top: 0, left: 0 };
- const offsetParentEl = parentOffsetEl(element[0]);
- if (offsetParentEl != $document[0]) {
- offsetParentBCR = this.offset(angular.element(offsetParentEl));
- offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop;
- offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft;
- }
-
- const boundingClientRect = element[0].getBoundingClientRect();
- return {
- width: boundingClientRect.width || element.prop('offsetWidth'),
- height: boundingClientRect.height || element.prop('offsetHeight'),
- top: elBCR.top - offsetParentBCR.top,
- left: elBCR.left - offsetParentBCR.left,
- };
- },
-
- /**
- * Provides read-only equivalent of jQuery's offset function:
- * http://api.jquery.com/offset/
- */
- offset: function(element) {
- const boundingClientRect = element[0].getBoundingClientRect();
- return {
- width: boundingClientRect.width || element.prop('offsetWidth'),
- height: boundingClientRect.height || element.prop('offsetHeight'),
- top:
- boundingClientRect.top +
- ($window.pageYOffset || $document[0].documentElement.scrollTop),
- left:
- boundingClientRect.left +
- ($window.pageXOffset || $document[0].documentElement.scrollLeft),
- };
- },
-
- /**
- * Provides coordinates for the targetEl in relation to hostEl
- */
- positionElements: function(hostEl, targetEl, positionStr, appendToBody) {
- const positionStrParts = positionStr.split('-');
- const pos0 = positionStrParts[0];
- const pos1 = positionStrParts[1] || 'center';
-
- let hostElPos;
- let targetElWidth;
- let targetElHeight;
- let targetElPos;
-
- hostElPos = appendToBody ? this.offset(hostEl) : this.position(hostEl);
-
- targetElWidth = targetEl.prop('offsetWidth');
- targetElHeight = targetEl.prop('offsetHeight');
-
- const shiftWidth = {
- center: function() {
- return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2;
- },
- left: function() {
- return hostElPos.left;
- },
- right: function() {
- return hostElPos.left + hostElPos.width;
- },
- };
-
- const shiftHeight = {
- center: function() {
- return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2;
- },
- top: function() {
- return hostElPos.top;
- },
- bottom: function() {
- return hostElPos.top + hostElPos.height;
- },
- };
-
- switch (pos0) {
- case 'right':
- targetElPos = {
- top: shiftHeight[pos1](),
- left: shiftWidth[pos0](),
- };
- break;
- case 'left':
- targetElPos = {
- top: shiftHeight[pos1](),
- left: hostElPos.left - targetElWidth,
- };
- break;
- case 'bottom':
- targetElPos = {
- top: shiftHeight[pos0](),
- left: shiftWidth[pos1](),
- };
- break;
- default:
- targetElPos = {
- top: hostElPos.top - targetElHeight,
- left: shiftWidth[pos1](),
- };
- break;
- }
-
- return targetElPos;
- },
- };
- },
- ]);
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip.js b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip.js
deleted file mode 100755
index 086fa6a7d6df..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip.js
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * SPDX-License-Identifier: Apache-2.0
- *
- * The OpenSearch Contributors require contributions made to
- * this file be licensed under the Apache-2.0 license or a
- * compatible open source license.
- *
- * Any modifications Copyright OpenSearch Contributors. See
- * GitHub history for details.
- */
-
-/* eslint-disable */
-
-import angular from 'angular';
-
-import { initBootstrapPosition } from './position';
-
-export function initBootstrapTooltip() {
- initBootstrapPosition();
- /**
- * The following features are still outstanding: animation as a
- * function, placement as a function, inside, support for more triggers than
- * just mouse enter/leave, html tooltips, and selector delegation.
- */
- angular
- .module('ui.bootstrap.tooltip', ['ui.bootstrap.position'])
-
- /**
- * The $tooltip service creates tooltip- and popover-like directives as well as
- * houses global options for them.
- */
- .provider('$tooltip', function() {
- // The default options tooltip and popover.
- const defaultOptions = {
- placement: 'top',
- animation: true,
- popupDelay: 0,
- };
-
- // Default hide triggers for each show trigger
- const triggerMap = {
- mouseenter: 'mouseleave',
- click: 'click',
- focus: 'blur',
- };
-
- // The options specified to the provider globally.
- const globalOptions = {};
-
- /**
- * `options({})` allows global configuration of all tooltips in the
- * application.
- *
- * var app = angular.module( 'App', ['ui.bootstrap.tooltip'], function( $tooltipProvider ) {
- * // place tooltips left instead of top by default
- * $tooltipProvider.options( { placement: 'left' } );
- * });
- */
- this.options = function(value) {
- angular.extend(globalOptions, value);
- };
-
- /**
- * This allows you to extend the set of trigger mappings available. E.g.:
- *
- * $tooltipProvider.setTriggers( 'openTrigger': 'closeTrigger' );
- */
- this.setTriggers = function setTriggers(triggers) {
- angular.extend(triggerMap, triggers);
- };
-
- /**
- * This is a helper function for translating camel-case to snake-case.
- */
- function snake_case(name) {
- const regexp = /[A-Z]/g;
- const separator = '-';
- return name.replace(regexp, function(letter, pos) {
- return (pos ? separator : '') + letter.toLowerCase();
- });
- }
-
- /**
- * Returns the actual instance of the $tooltip service.
- * TODO support multiple triggers
- */
- this.$get = [
- '$window',
- '$compile',
- '$timeout',
- '$document',
- '$position',
- '$interpolate',
- function($window, $compile, $timeout, $document, $position, $interpolate) {
- return function $tooltip(type, prefix, defaultTriggerShow) {
- const options = angular.extend({}, defaultOptions, globalOptions);
-
- /**
- * Returns an object of show and hide triggers.
- *
- * If a trigger is supplied,
- * it is used to show the tooltip; otherwise, it will use the `trigger`
- * option passed to the `$tooltipProvider.options` method; else it will
- * default to the trigger supplied to this directive factory.
- *
- * The hide trigger is based on the show trigger. If the `trigger` option
- * was passed to the `$tooltipProvider.options` method, it will use the
- * mapped trigger from `triggerMap` or the passed trigger if the map is
- * undefined; otherwise, it uses the `triggerMap` value of the show
- * trigger; else it will just use the show trigger.
- */
- function getTriggers(trigger) {
- const show = trigger || options.trigger || defaultTriggerShow;
- const hide = triggerMap[show] || show;
- return {
- show: show,
- hide: hide,
- };
- }
-
- const directiveName = snake_case(type);
-
- const startSym = $interpolate.startSymbol();
- const endSym = $interpolate.endSymbol();
- const template =
- '' +
- '
';
-
- return {
- restrict: 'EA',
- compile: function(tElem, tAttrs) {
- const tooltipLinker = $compile(template);
-
- return function link(scope, element, attrs) {
- let tooltip;
- let tooltipLinkedScope;
- let transitionTimeout;
- let popupTimeout;
- let appendToBody = angular.isDefined(options.appendToBody)
- ? options.appendToBody
- : false;
- let triggers = getTriggers(undefined);
- const hasEnableExp = angular.isDefined(attrs[prefix + 'Enable']);
- let ttScope = scope.$new(true);
-
- const positionTooltip = function() {
- const ttPosition = $position.positionElements(
- element,
- tooltip,
- ttScope.placement,
- appendToBody
- );
- ttPosition.top += 'px';
- ttPosition.left += 'px';
-
- // Now set the calculated positioning.
- tooltip.css(ttPosition);
- };
-
- // By default, the tooltip is not open.
- // TODO add ability to start tooltip opened
- ttScope.isOpen = false;
-
- function toggleTooltipBind() {
- if (!ttScope.isOpen) {
- showTooltipBind();
- } else {
- hideTooltipBind();
- }
- }
-
- // Show the tooltip with delay if specified, otherwise show it immediately
- function showTooltipBind() {
- if (hasEnableExp && !scope.$eval(attrs[prefix + 'Enable'])) {
- return;
- }
-
- prepareTooltip();
-
- if (ttScope.popupDelay) {
- // Do nothing if the tooltip was already scheduled to pop-up.
- // This happens if show is triggered multiple times before any hide is triggered.
- if (!popupTimeout) {
- popupTimeout = $timeout(show, ttScope.popupDelay, false);
- popupTimeout
- .then(reposition => reposition())
- .catch(error => {
- // if the timeout is canceled then the string `canceled` is thrown. To prevent
- // this from triggering an 'unhandled promise rejection' in angular 1.5+ the
- // $timeout service explicitly tells $q that the promise it generated is "handled"
- // but that does not include down chain promises like the one created by calling
- // `popupTimeout.then()`. Because of this we need to ignore the "canceled" string
- // and only propagate real errors
- if (error !== 'canceled') {
- throw error;
- }
- });
- }
- } else {
- show()();
- }
- }
-
- function hideTooltipBind() {
- scope.$evalAsync(function() {
- hide();
- });
- }
-
- // Show the tooltip popup element.
- function show() {
- popupTimeout = null;
-
- // If there is a pending remove transition, we must cancel it, lest the
- // tooltip be mysteriously removed.
- if (transitionTimeout) {
- $timeout.cancel(transitionTimeout);
- transitionTimeout = null;
- }
-
- // Don't show empty tooltips.
- if (!ttScope.content) {
- return angular.noop;
- }
-
- createTooltip();
-
- // Set the initial positioning.
- tooltip.css({ top: 0, left: 0, display: 'block' });
- ttScope.$digest();
-
- positionTooltip();
-
- // And show the tooltip.
- ttScope.isOpen = true;
- ttScope.$digest(); // digest required as $apply is not called
-
- // Return positioning function as promise callback for correct
- // positioning after draw.
- return positionTooltip;
- }
-
- // Hide the tooltip popup element.
- function hide() {
- // First things first: we don't show it anymore.
- ttScope.isOpen = false;
-
- //if tooltip is going to be shown after delay, we must cancel this
- $timeout.cancel(popupTimeout);
- popupTimeout = null;
-
- // And now we remove it from the DOM. However, if we have animation, we
- // need to wait for it to expire beforehand.
- // FIXME: this is a placeholder for a port of the transitions library.
- if (ttScope.animation) {
- if (!transitionTimeout) {
- transitionTimeout = $timeout(removeTooltip, 500);
- }
- } else {
- removeTooltip();
- }
- }
-
- function createTooltip() {
- // There can only be one tooltip element per directive shown at once.
- if (tooltip) {
- removeTooltip();
- }
- tooltipLinkedScope = ttScope.$new();
- tooltip = tooltipLinker(tooltipLinkedScope, function(tooltip) {
- if (appendToBody) {
- $document.find('body').append(tooltip);
- } else {
- element.after(tooltip);
- }
- });
- }
-
- function removeTooltip() {
- transitionTimeout = null;
- if (tooltip) {
- tooltip.remove();
- tooltip = null;
- }
- if (tooltipLinkedScope) {
- tooltipLinkedScope.$destroy();
- tooltipLinkedScope = null;
- }
- }
-
- function prepareTooltip() {
- prepPlacement();
- prepPopupDelay();
- }
-
- /**
- * Observe the relevant attributes.
- */
- attrs.$observe(type, function(val) {
- ttScope.content = val;
-
- if (!val && ttScope.isOpen) {
- hide();
- }
- });
-
- attrs.$observe(prefix + 'Title', function(val) {
- ttScope.title = val;
- });
-
- function prepPlacement() {
- const val = attrs[prefix + 'Placement'];
- ttScope.placement = angular.isDefined(val) ? val : options.placement;
- }
-
- function prepPopupDelay() {
- const val = attrs[prefix + 'PopupDelay'];
- const delay = parseInt(val, 10);
- ttScope.popupDelay = !isNaN(delay) ? delay : options.popupDelay;
- }
-
- const unregisterTriggers = function() {
- element.unbind(triggers.show, showTooltipBind);
- element.unbind(triggers.hide, hideTooltipBind);
- };
-
- function prepTriggers() {
- const val = attrs[prefix + 'Trigger'];
- unregisterTriggers();
-
- triggers = getTriggers(val);
-
- if (triggers.show === triggers.hide) {
- element.bind(triggers.show, toggleTooltipBind);
- } else {
- element.bind(triggers.show, showTooltipBind);
- element.bind(triggers.hide, hideTooltipBind);
- }
- }
-
- prepTriggers();
-
- const animation = scope.$eval(attrs[prefix + 'Animation']);
- ttScope.animation = angular.isDefined(animation)
- ? !!animation
- : options.animation;
-
- const appendToBodyVal = scope.$eval(attrs[prefix + 'AppendToBody']);
- appendToBody = angular.isDefined(appendToBodyVal)
- ? appendToBodyVal
- : appendToBody;
-
- // if a tooltip is attached to we need to remove it on
- // location change as its parent scope will probably not be destroyed
- // by the change.
- if (appendToBody) {
- scope.$on(
- '$locationChangeSuccess',
- function closeTooltipOnLocationChangeSuccess() {
- if (ttScope.isOpen) {
- hide();
- }
- }
- );
- }
-
- // Make sure tooltip is destroyed and removed.
- scope.$on('$destroy', function onDestroyTooltip() {
- $timeout.cancel(transitionTimeout);
- $timeout.cancel(popupTimeout);
- unregisterTriggers();
- removeTooltip();
- ttScope = null;
- });
- };
- },
- };
- };
- },
- ];
- })
-
- .directive('tooltip', [
- '$tooltip',
- function($tooltip) {
- return $tooltip('tooltip', 'tooltip', 'mouseenter');
- },
- ])
-
- .directive('tooltipPopup', function() {
- return {
- restrict: 'EA',
- replace: true,
- scope: { content: '@', placement: '@', animation: '&', isOpen: '&' },
- templateUrl: 'template/tooltip/tooltip-popup.html',
- };
- })
-
- .directive('tooltipHtmlUnsafe', [
- '$tooltip',
- function($tooltip) {
- return $tooltip('tooltipHtmlUnsafe', 'tooltip', 'mouseenter');
- },
- ])
-
- .directive('tooltipHtmlUnsafePopup', function() {
- return {
- restrict: 'EA',
- replace: true,
- scope: { content: '@', placement: '@', animation: '&', isOpen: '&' },
- templateUrl: 'template/tooltip/tooltip-html-unsafe-popup.html',
- };
- });
-}
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_html_unsafe_popup.html b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_html_unsafe_popup.html
deleted file mode 100644
index b48bf7049890..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_html_unsafe_popup.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
\ No newline at end of file
diff --git a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_popup.html b/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_popup.html
deleted file mode 100644
index eed4ca7d9301..000000000000
--- a/src/plugins/opensearch_dashboards_legacy/public/angular_bootstrap/tooltip/tooltip_popup.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
\ No newline at end of file
diff --git a/src/plugins/opensearch_dashboards_legacy/public/index.ts b/src/plugins/opensearch_dashboards_legacy/public/index.ts
index 67cd6def9f0f..ec74afc903f6 100644
--- a/src/plugins/opensearch_dashboards_legacy/public/index.ts
+++ b/src/plugins/opensearch_dashboards_legacy/public/index.ts
@@ -36,8 +36,6 @@ export const plugin = (initializerContext: PluginInitializerContext) =>
export * from './plugin';
-export { initAngularBootstrap } from './angular_bootstrap';
export { PaginateDirectiveProvider, PaginateControlsDirectiveProvider } from './paginate/paginate';
-export * from './angular';
export * from './notify';
export * from './utils';
diff --git a/src/plugins/tile_map/public/plugin.ts b/src/plugins/tile_map/public/plugin.ts
index 4b6b76ae193d..37d6d3e14c00 100644
--- a/src/plugins/tile_map/public/plugin.ts
+++ b/src/plugins/tile_map/public/plugin.ts
@@ -38,7 +38,7 @@ import {
import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { VisualizationsSetup } from '../../visualizations/public';
// TODO: Determine why visualizations don't populate without this
-import 'angular-sanitize';
+// import 'angular-sanitize';
// @ts-ignore
import { createTileMapFn } from './tile_map_fn';
diff --git a/yarn.lock b/yarn.lock
index 544864b2e711..6df97ecb5926 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2838,18 +2838,6 @@
resolved "https://registry.yarnpkg.com/@tsd/typescript/-/typescript-4.7.4.tgz#f1e4e6c3099a174a0cb7aa51cf53f34f6494e528"
integrity sha512-jbtC+RgKZ9Kk65zuRZbKLTACf+tvFW4Rfq0JEMXrlmV3P3yme+Hm+pnb5fJRyt61SjIitcrC810wj7+1tgsEmg==
-"@types/angular-mocks@^1.7.1":
- version "1.7.1"
- resolved "https://registry.yarnpkg.com/@types/angular-mocks/-/angular-mocks-1.7.1.tgz#0f18066f8e6f327493aad0c280a43801ffa09464"
- integrity sha512-44kaQL8sMGUIDV76zbJ3MX6aqPng7Wmfz91uds+WcNQFHTdSu6KDZNIypIZVAdrWnJfqrfL5VysaCejTW3JVIw==
- dependencies:
- "@types/angular" "*"
-
-"@types/angular@*", "@types/angular@^1.8.4":
- version "1.8.4"
- resolved "https://registry.yarnpkg.com/@types/angular/-/angular-1.8.4.tgz#a2cc163e508389c51d4c4119ebff6b9395cec472"
- integrity sha512-wPS/ncJWhyxJsndsW1B6Ta8D4mi97x1yItSu+rkLDytU3oRIh2CFAjMuJceYwFAh9+DIohndWM0QBA9OU2Hv0g==
-
"@types/archiver@^5.3.1":
version "5.3.1"
resolved "https://registry.yarnpkg.com/@types/archiver/-/archiver-5.3.1.tgz#02991e940a03dd1a32678fead4b4ca03d0e387ca"
@@ -4392,43 +4380,6 @@ ajv@^8.0.1, ajv@^8.11.0, ajv@^8.6.2:
require-from-string "^2.0.2"
uri-js "^4.2.2"
-angular-aria@^1.8.0:
- version "1.8.2"
- resolved "https://registry.yarnpkg.com/angular-aria/-/angular-aria-1.8.2.tgz#3e5d546e549d8bddcf0b8031c677d3129d82a76d"
- integrity sha512-xWT1Lm+Xug2GM6nGNMioBP4hXt3sj2eGaExa4cVCZUYSVWezgyuD1RiLgzJzwTkBGYplHQUzQaz3yDY8jVI6yQ==
-
-angular-elastic@^2.5.1:
- version "2.5.1"
- resolved "https://registry.yarnpkg.com/angular-elastic/-/angular-elastic-2.5.1.tgz#e938ab1bd8c76415b8ca6514b15fe3593a5df535"
- integrity sha1-6TirG9jHZBW4ymUUsV/jWTpd9TU=
- dependencies:
- angular ">=1.0.6"
-
-angular-mocks@^1.8.2:
- version "1.8.2"
- resolved "https://registry.yarnpkg.com/angular-mocks/-/angular-mocks-1.8.2.tgz#dc022420b86978cf317a8447c116c0be73a853bf"
- integrity sha512-I5L3P0l21HPdVsP4A4qWmENt4ePjjbkDFdAzOaM7QiibFySbt14DptPbt2IjeG4vFBr4vSLbhIz8Fk03DISl8Q==
-
-angular-recursion@^1.0.5:
- version "1.0.5"
- resolved "https://registry.yarnpkg.com/angular-recursion/-/angular-recursion-1.0.5.tgz#cd405428a0bf55faf52eaa7988c1fe69cd930543"
- integrity sha1-zUBUKKC/Vfr1Lqp5iMH+ac2TBUM=
-
-angular-route@^1.8.0:
- version "1.8.2"
- resolved "https://registry.yarnpkg.com/angular-route/-/angular-route-1.8.2.tgz#d482bf05a8c9e448300acd8f9989c635d31b5077"
- integrity sha512-49LJYxuaQ/ZDiu9dD2xo1LkazqObkGjw0a7dUF7UKCT8EELgBsMd6QrI6aEVGtI62ppkiFkxqmiV8fcwYdXpug==
-
-angular-sanitize@^1.8.0:
- version "1.8.2"
- resolved "https://registry.yarnpkg.com/angular-sanitize/-/angular-sanitize-1.8.2.tgz#ae78040f00c5e2ce1c63780bcc47fa14a1698296"
- integrity sha512-OB6Goa+QN3byf5asQ7XRl7DKZejm/F/ZOqa9z1skqYVOWA2hoBxoCmt9E7+i7T/TbxZP5zYzKxNZVVJNu860Hg==
-
-angular@>=1.0.6, angular@^1.8.2:
- version "1.8.2"
- resolved "https://registry.yarnpkg.com/angular/-/angular-1.8.2.tgz#5983bbb5a9fa63e213cb7749199e0d352de3a2f1"
- integrity sha512-IauMOej2xEe7/7Ennahkbb5qd/HFADiNuLSESz9Q27inmi32zB0lnAsFeLEWcox3Gd1F6YhNd1CP7/9IukJ0Gw==
-
ansi-colors@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"