Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into split-types-from-co…
Browse files Browse the repository at this point in the history
…de-on-kbn-ui-shared-deps-src-2
  • Loading branch information
mistic committed Jan 20, 2022
2 parents e3d254a + ee34a7a commit 7ae7c82
Show file tree
Hide file tree
Showing 229 changed files with 6,352 additions and 973 deletions.
18 changes: 9 additions & 9 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,19 @@ export class DocLinksService {
anomalyDetection: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-overview.html`,
anomalyDetectionJobs: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionConfiguringCategories: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-configuring-categories.html`,
anomalyDetectionBucketSpan: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionCardinality: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionCreateJobs: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionDetectors: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionInfluencers: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionBucketSpan: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-bucket-span`,
anomalyDetectionCardinality: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-cardinality`,
anomalyDetectionCreateJobs: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-create-job`,
anomalyDetectionDetectors: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-detectors`,
anomalyDetectionInfluencers: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-influencers`,
anomalyDetectionJobResource: `${ELASTICSEARCH_DOCS}ml-put-job.html#ml-put-job-path-parms`,
anomalyDetectionJobResourceAnalysisConfig: `${ELASTICSEARCH_DOCS}ml-put-job.html#put-analysisconfig`,
anomalyDetectionJobTips: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionJobTips: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-job-tips`,
alertingRules: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-configuring-alerts.html`,
anomalyDetectionModelMemoryLimits: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
calendars: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
anomalyDetectionModelMemoryLimits: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-model-memory-limits`,
calendars: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-calendars`,
classificationEvaluation: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-dfa-classification.html#ml-dfanalytics-classification-evaluation`,
customRules: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-finding-anomalies.html`,
customRules: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-ad-run-jobs.html#ml-ad-rules`,
customUrls: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-configuring-url.html`,
dataFrameAnalytics: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-dfanalytics.html`,
featureImportance: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-feature-importance.html`,
Expand Down
1 change: 1 addition & 0 deletions src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const storybookAliases = {
dashboard_enhanced: 'x-pack/plugins/dashboard_enhanced/.storybook',
dashboard: 'src/plugins/dashboard/.storybook',
data_enhanced: 'x-pack/plugins/data_enhanced/.storybook',
discover: 'src/plugins/discover/.storybook',
embeddable: 'src/plugins/embeddable/.storybook',
expression_error: 'src/plugins/expression_error/.storybook',
expression_image: 'src/plugins/expression_image/.storybook',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const tick = () => new Promise((resolve) => setTimeout(resolve, 1));
const setup = () => {
const { xhr, XMLHttpRequest } = mockXMLHttpRequest();
window.XMLHttpRequest = XMLHttpRequest;
(xhr as any).status = 200;
return { xhr };
};

Expand Down
32 changes: 31 additions & 1 deletion src/plugins/bfetch/public/streaming/from_streaming_xhr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const createXhr = (): XMLHttpRequest =>
onreadystatechange: () => {},
readyState: 0,
responseText: '',
status: 0,
status: 200,
} as unknown as XMLHttpRequest);

test('returns observable', () => {
Expand Down Expand Up @@ -156,6 +156,36 @@ test('errors observable if request returns with error', () => {
);
});

test('does not emit when gets error response', () => {
const xhr = createXhr();
const observable = fromStreamingXhr(xhr);

const next = jest.fn();
const complete = jest.fn();
const error = jest.fn();
observable.subscribe({
next,
complete,
error,
});

(xhr as any).responseText = 'error';
(xhr as any).status = 400;
xhr.onprogress!({} as any);

expect(next).toHaveBeenCalledTimes(0);

(xhr as any).readyState = 4;
xhr.onreadystatechange!({} as any);

expect(next).toHaveBeenCalledTimes(0);
expect(error).toHaveBeenCalledTimes(1);
expect(error.mock.calls[0][0]).toBeInstanceOf(Error);
expect(error.mock.calls[0][0].message).toMatchInlineSnapshot(
`"Batch request failed with status 400"`
);
});

test('when .onprogress called multiple times with same text, does not create new observable events', () => {
const xhr = createXhr();
const observable = fromStreamingXhr(xhr);
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/bfetch/public/streaming/from_streaming_xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export const fromStreamingXhr = (
let index = 0;
let aborted = false;

// 0 indicates a network failure. 400+ messages are considered server errors
const isErrorStatus = () => xhr.status === 0 || xhr.status >= 400;

const processBatch = () => {
if (aborted) return;
if (isErrorStatus()) return;

const { responseText } = xhr;
if (index >= responseText.length) return;
Expand Down Expand Up @@ -56,8 +60,7 @@ export const fromStreamingXhr = (
if (xhr.readyState === 4) {
if (signal) signal.removeEventListener('abort', onBatchAbort);

// 0 indicates a network failure. 400+ messages are considered server errors
if (xhr.status === 0 || xhr.status >= 400) {
if (isErrorStatus()) {
subject.error(new Error(`Batch request failed with status ${xhr.status}`));
} else {
subject.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ describe('Integration', () => {
cursor: { lineNumber: 7, column: 1 },
initialValue: '',
addTemplate: true,
prefixToAdd: ', ',
prefixToAdd: '',
suffixToAdd: '',
rangeToReplace: {
start: { lineNumber: 7, column: 1 },
Expand All @@ -374,7 +374,7 @@ describe('Integration', () => {
cursor: { lineNumber: 6, column: 15 },
initialValue: '',
addTemplate: true,
prefixToAdd: ', ',
prefixToAdd: '',
suffixToAdd: '',
rangeToReplace: {
start: { lineNumber: 6, column: 15 },
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/console/public/lib/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,18 @@ export default function ({
break;
default:
if (nonEmptyToken && nonEmptyToken.type.indexOf('url') < 0) {
context.prefixToAdd = ', ';
const { position, value } = nonEmptyToken;

// We can not rely on prefixToAdd here, because it adds a comma at the beginning of the new token
// Since we have access to the position of the previous token here, this could be a good place to insert a comma manually
context.prefixToAdd = '';
editor.insert(
{
column: position.column + value.length,
lineNumber: position.lineNumber,
},
', '
);
}
}

Expand Down
Loading

0 comments on commit 7ae7c82

Please sign in to comment.