Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva committed May 14, 2024
2 parents addacb6 + 382ee2d commit ff3a57b
Show file tree
Hide file tree
Showing 55 changed files with 1,758 additions and 801 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@
"pretty-ms": "6.0.0",
"prop-types": "^15.8.1",
"proxy-from-env": "1.0.0",
"puppeteer": "22.3.0",
"puppeteer": "22.8.1",
"query-string": "^6.13.2",
"rbush": "^3.0.1",
"re-resizable": "^6.9.9",
Expand Down
1 change: 1 addition & 0 deletions packages/presentation/presentation_publishing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export {
export {
apiPublishesPanelDescription,
apiPublishesWritablePanelDescription,
getPanelDescription,
type PublishesPanelDescription,
type PublishesWritablePanelDescription,
} from './interfaces/titles/publishes_panel_description';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { BehaviorSubject } from 'rxjs';
import { getPanelDescription } from './publishes_panel_description';

describe('getPanelDescription', () => {
test('should return default description when description is undefined', () => {
const api = {
panelDescription: new BehaviorSubject<string | undefined>(undefined),
defaultPanelDescription: new BehaviorSubject<string | undefined>('default description'),
};
expect(getPanelDescription(api)).toBe('default description');
});

test('should return empty description when description is empty string', () => {
const api = {
panelDescription: new BehaviorSubject<string | undefined>(''),
defaultPanelDescription: new BehaviorSubject<string | undefined>('default description'),
};
expect(getPanelDescription(api)).toBe('');
});

test('should return description when description is provided', () => {
const api = {
panelDescription: new BehaviorSubject<string | undefined>('custom description'),
defaultPanelDescription: new BehaviorSubject<string | undefined>('default description'),
};
expect(getPanelDescription(api)).toBe('custom description');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface PublishesPanelDescription {
defaultPanelDescription?: PublishingSubject<string | undefined>;
}

export function getPanelDescription(api: Partial<PublishesPanelDescription>): string | undefined {
return api.panelDescription?.value ?? api.defaultPanelDescription?.value;
}

export type PublishesWritablePanelDescription = PublishesPanelDescription & {
setPanelDescription: (newTitle: string | undefined) => void;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ describe('getPanelTitle', () => {
expect(getPanelTitle(api)).toBe('default title');
});

test('should return default title when title is empty string', () => {
test('should return empty title when title is empty string', () => {
const api = {
panelTitle: new BehaviorSubject<string | undefined>(''),
defaultPanelTitle: new BehaviorSubject<string | undefined>('default title'),
};
expect(getPanelTitle(api)).toBe('default title');
expect(getPanelTitle(api)).toBe('');
});

test('should return title when title is provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface PublishesPanelTitle {
}

export function getPanelTitle(api: Partial<PublishesPanelTitle>): string | undefined {
return api.panelTitle?.value || api.defaultPanelTitle?.value;
return api.panelTitle?.value ?? api.defaultPanelTitle?.value;
}

export type PublishesWritablePanelTitle = PublishesPanelTitle & {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { useResizeCheckerUtils } from './use_resize_checker_utils';
export { useSetInitialValue } from './use_set_initial_value';
export { useSetupAutocompletePolling } from './use_setup_autocomplete_polling';
export { useSetupAutosave } from './use_setup_autosave';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IToasts } from '@kbn/core-notifications-browser';
import { decompressFromEncodedURIComponent } from 'lz-string';
import { i18n } from '@kbn/i18n';
import { useEffect } from 'react';
import { DEFAULT_INPUT_VALUE } from '../../../../../common/constants';
import { DEFAULT_INPUT_VALUE } from '../../../../../../common/constants';

interface QueryParams {
load_from: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { useEffect } from 'react';
import { AutocompleteInfo, Settings } from '../../../../services';
import { AutocompleteInfo, Settings } from '../../../../../services';

interface SetupAutocompletePollingParams {
/** The Console autocomplete service. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { useEffect, useRef } from 'react';
import { useSaveCurrentTextObject } from '../../../hooks';
import { useSaveCurrentTextObject } from '../../../../hooks';
import { readLoadFromParam } from './use_set_initial_value';

interface SetupAutosaveParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import {
useEditorReadContext,
useRequestActionContext,
} from '../../../contexts';
import { useSetInitialValue } from './use_set_initial_value';
import {
useSetInitialValue,
useSetupAutocompletePolling,
useSetupAutosave,
useResizeCheckerUtils,
} from './hooks';
import { MonacoEditorActionsProvider } from './monaco_editor_actions_provider';
import { useSetupAutocompletePolling } from './use_setup_autocomplete_polling';
import { useSetupAutosave } from './use_setup_autosave';
import { getSuggestionProvider } from './monaco_editor_suggestion_provider';
import { useResizeCheckerUtils } from './use_resize_checker_utils';

export interface EditorProps {
initialTextValue: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,36 @@

import { CSSProperties, Dispatch } from 'react';
import { debounce } from 'lodash';
import {
ConsoleParsedRequestsProvider,
getParsedRequestsProvider,
monaco,
ParsedRequest,
} from '@kbn/monaco';
import { ConsoleParsedRequestsProvider, getParsedRequestsProvider, monaco } from '@kbn/monaco';
import { IToasts } from '@kbn/core-notifications-browser';
import { i18n } from '@kbn/i18n';
import type { HttpSetup } from '@kbn/core-http-browser';
import { DEFAULT_VARIABLES } from '../../../../../common/constants';
import { getStorage, StorageKeys } from '../../../../services';
import { sendRequest } from '../../../hooks/use_send_current_request/send_request';
import { sendRequest } from '../../../hooks';
import { MetricsTracker } from '../../../../types';
import { Actions } from '../../../stores/request';

import {
AutocompleteType,
containsUrlParams,
getBodyCompletionItems,
getCurlRequest,
getDocumentationLink,
getDocumentationLinkFromAutocomplete,
getLineTokens,
getMethodCompletionItems,
getRequestEndLineNumber,
getRequestStartLineNumber,
getUrlParamsCompletionItems,
getUrlPathCompletionItems,
replaceRequestVariables,
SELECTED_REQUESTS_CLASSNAME,
stringifyRequest,
trackSentRequests,
getAutoIndentedRequests,
} from './utils';

const selectedRequestsClass = 'console__monaco_editor__selectedRequests';

export interface EditorRequest {
method: string;
url: string;
data: string[];
}

export interface AdjustedParsedRequest extends ParsedRequest {
startLineNumber: number;
endLineNumber: number;
}
enum AutocompleteType {
PATH = 'path',
URL_PARAMS = 'url_params',
METHOD = 'method',
BODY = 'body',
}
import type { AdjustedParsedRequest } from './types';

export class MonacoEditorActionsProvider {
private parsedRequestsProvider: ConsoleParsedRequestsProvider;
Expand Down Expand Up @@ -126,7 +108,7 @@ export class MonacoEditorActionsProvider {
range: selectedRange,
options: {
isWholeLine: true,
className: selectedRequestsClass,
className: SELECTED_REQUESTS_CLASSNAME,
},
},
]);
Expand Down Expand Up @@ -256,7 +238,7 @@ export class MonacoEditorActionsProvider {
}
const request = requests[0];

return getDocumentationLink(request, docLinkVersion);
return getDocumentationLinkFromAutocomplete(request, docLinkVersion);
}

private async getAutocompleteType(
Expand Down Expand Up @@ -303,7 +285,11 @@ export class MonacoEditorActionsProvider {
return AutocompleteType.BODY;
}

private async getSuggestions(model: monaco.editor.ITextModel, position: monaco.Position) {
private async getSuggestions(
model: monaco.editor.ITextModel,
position: monaco.Position,
context: monaco.languages.CompletionContext
) {
// determine autocomplete type
const autocompleteType = await this.getAutocompleteType(model, position);
if (!autocompleteType) {
Expand All @@ -329,6 +315,23 @@ export class MonacoEditorActionsProvider {
};
}

if (autocompleteType === AutocompleteType.BODY) {
// suggestions only when triggered by " or keyboard
if (context.triggerCharacter && context.triggerCharacter !== '"') {
return { suggestions: [] };
}
const requests = await this.getRequestsBetweenLines(
model,
position.lineNumber,
position.lineNumber
);
const requestStartLineNumber = requests[0].startLineNumber;
const suggestions = getBodyCompletionItems(model, position, requestStartLineNumber);
return {
suggestions,
};
}

return {
suggestions: [],
};
Expand All @@ -339,7 +342,7 @@ export class MonacoEditorActionsProvider {
context: monaco.languages.CompletionContext,
token: monaco.CancellationToken
): monaco.languages.ProviderResult<monaco.languages.CompletionList> {
return this.getSuggestions(model, position);
return this.getSuggestions(model, position, context);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
safeExpandLiteralStrings,
languageForContentType,
} from '../utilities';
import { useResizeCheckerUtils } from './use_resize_checker_utils';
import { useResizeCheckerUtils } from './hooks';

export const MonacoEditorOutput: FunctionComponent = () => {
const { settings: readOnlySettings } = useEditorReadContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getSuggestionProvider = (
): monaco.languages.CompletionItemProvider => {
return {
// force suggestions when these characters are used
triggerCharacters: ['/', '.', '_', ',', '?', '=', '&'],
triggerCharacters: ['/', '.', '_', ',', '?', '=', '&', '"'],
provideCompletionItems: (...args) => {
if (actionsProvider.current) {
return actionsProvider.current?.provideCompletionItems(...args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { ParsedRequest } from '@kbn/monaco';

export interface EditorRequest {
method: string;
url: string;
data: string[];
}

export interface AdjustedParsedRequest extends ParsedRequest {
startLineNumber: number;
endLineNumber: number;
}
Loading

0 comments on commit ff3a57b

Please sign in to comment.