Skip to content

Commit

Permalink
Merge branch 'main' into files-restructure-endpoint-types-ii
Browse files Browse the repository at this point in the history
* main:
  [Files] Use self destruct flag in upload component (elastic#141366)
  [Synthetics] Unskip certs flaky test (elastic#141423)
  updated openapi for bulk action responses (elastic#141566)
  Fix page responsiveness for smaller screen sizes (elastic#141471)
  • Loading branch information
jloleysens committed Sep 23, 2022
2 parents f213668 + c5debde commit a6c8292
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SearchIndexPipelines: React.FC = () => {
return (
<>
<EuiSpacer />
<EuiFlexGroup direction="row">
<EuiFlexGroup direction="row" wrap>
<EuiFlexItem grow={5}>
<DataPanel
hasBorder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ export const DataPanel: React.FC<Props> = ({
<EuiSplitPanel.Inner>
<EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
<EuiFlexItem grow>
<EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
<EuiFlexGroup
className="eui-textNoWrap"
gutterSize="s"
alignItems="center"
responsive={false}
>
{iconType && (
<EuiFlexItem grow={false}>
<EuiIcon type={iconType} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ describe('UploadState', () => {
testScheduler = getTestScheduler();
});

it('calls file client with expected arguments', async () => {
testScheduler.run(({ expectObservable, cold, flush }) => {
const file1 = { name: 'test.png', size: 1 } as File;

uploadState.setFiles([file1]);

// Simulate upload being triggered async
const upload$ = cold('--a|').pipe(tap(uploadState.upload));

expectObservable(upload$).toBe('--a|');

flush();

expect(filesClient.create).toHaveBeenCalledTimes(1);
expect(filesClient.create).toHaveBeenNthCalledWith(1, {
kind: 'test',
meta: 'a',
mimeType: 'image/png',
name: 'test',
});
expect(filesClient.upload).toHaveBeenCalledTimes(1);
expect(filesClient.upload).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
selfDestructOnAbort: true,
})
);
});
});

it('uploads all provided files and reports errors', async () => {
testScheduler.run(({ expectObservable, cold, flush }) => {
const file1 = { name: 'test', size: 1 } as File;
Expand Down Expand Up @@ -132,7 +162,6 @@ describe('UploadState', () => {
name: 'test 2',
});
expect(filesClient.upload).toHaveBeenCalledTimes(2);
expect(filesClient.delete).toHaveBeenCalledTimes(2);
});
});

Expand Down
14 changes: 3 additions & 11 deletions x-pack/plugins/files/public/components/upload_file/upload_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export class UploadState {
}

let uploadTarget: undefined | FileJSON;
let erroredOrAborted = false;

file$.setState({ status: 'uploading', error: undefined });

Expand Down Expand Up @@ -190,6 +189,7 @@ export class UploadState {
id: uploadTarget.id,
kind: this.fileKind.id,
abortSignal,
selfDestructOnAbort: true,
contentType: mime,
})
);
Expand All @@ -198,15 +198,9 @@ export class UploadState {
file$.setState({ status: 'uploaded', id: uploadTarget?.id });
}),
catchError((e) => {
erroredOrAborted = true;
const isAbortError = e.message === 'Abort!';
file$.setState({ status: 'upload_failed', error: isAbortError ? undefined : e });
return of(isAbortError ? undefined : e);
}),
finalize(() => {
if (erroredOrAborted && uploadTarget) {
this.client.delete({ id: uploadTarget.id, kind: this.fileKind.id });
}
})
);
};
Expand All @@ -219,9 +213,7 @@ export class UploadState {
const sub = this.abort$.subscribe(abort$);
const upload$ = this.files$$.pipe(
take(1),
switchMap((files$) => {
return forkJoin(files$.map((file$) => this.uploadFile(file$, abort$, meta)));
}),
switchMap((files$) => forkJoin(files$.map((file$) => this.uploadFile(file$, abort$, meta)))),
map(() => undefined),
finalize(() => {
if (this.opts.allowRepeatedUploads) this.clear();
Expand All @@ -230,7 +222,7 @@ export class UploadState {
shareReplay()
);

upload$.subscribe();
upload$.subscribe(); // Kick off the upload

return upload$;
};
Expand Down
16 changes: 5 additions & 11 deletions x-pack/plugins/files/public/files_client/files_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe('apiRoutes', () => {
`"/api/files/files/test/123"`
);

expect(apiRoutes.getListRoute('test', 1, 1)).toMatchInlineSnapshot(
`"/api/files/files/test/list?page=1&perPage=1"`
);
expect(apiRoutes.getListRoute('test')).toMatchInlineSnapshot(`"/api/files/files/test/list"`);

expect(apiRoutes.getByIdRoute('test', '123')).toMatchInlineSnapshot(
`"/api/files/files/test/123"`
Expand All @@ -39,17 +37,13 @@ describe('apiRoutes', () => {
`"/api/files/shares/test/123"`
);

expect(apiRoutes.getListSharesRoute('test', 1, 1)).toMatchInlineSnapshot(
`"/api/files/shares/test?page=1&perPage=1"`
);
expect(apiRoutes.getListSharesRoute('test')).toMatchInlineSnapshot(`"/api/files/shares/test"`);

expect(apiRoutes.getPublicDownloadRoute('test', 'my-file.pdf')).toMatchInlineSnapshot(
`"/api/files/public/blob/my-file.pdf?token=test"`
expect(apiRoutes.getPublicDownloadRoute('my-file.pdf')).toMatchInlineSnapshot(
`"/api/files/public/blob/my-file.pdf"`
);

expect(apiRoutes.getFindRoute(1, 1)).toMatchInlineSnapshot(
`"/api/files/find?page=1&perPage=1"`
);
expect(apiRoutes.getFindRoute()).toMatchInlineSnapshot(`"/api/files/find"`);

expect(apiRoutes.getMetricsRoute()).toMatchInlineSnapshot(`"/api/files/metrics"`);
});
Expand Down
49 changes: 20 additions & 29 deletions x-pack/plugins/files/public/files_client/files_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { pipe } from 'fp-ts/lib/function';
import * as qs from 'query-string';
import type { HttpStart } from '@kbn/core/public';
import type { ScopedFilesClient, FilesClient } from '../types';
import {
Expand All @@ -16,13 +14,6 @@ import {
FILES_SHARE_API_BASE_PATH,
} from '../../common/api_routes';

const addQueryParams =
(queryParams: object) =>
(path: string): string => {
const stringified = qs.stringify(queryParams);
return `${path}${stringified ? `?${stringified}` : ''}`;
};

/**
* @internal
*/
Expand All @@ -36,32 +27,25 @@ export const apiRoutes = {
`${FILES_API_BASE_PATH}/${fileKind}/${id}/blob${fileName ? '/' + fileName : ''}`,
getUpdateRoute: (fileKind: string, id: string) => `${FILES_API_BASE_PATH}/${fileKind}/${id}`,
getDeleteRoute: (fileKind: string, id: string) => `${FILES_API_BASE_PATH}/${fileKind}/${id}`,
getListRoute: (fileKind: string, page?: number, perPage?: number) => {
return pipe(`${FILES_API_BASE_PATH}/${fileKind}/list`, addQueryParams({ page, perPage }));
},
getListRoute: (fileKind: string) => `${FILES_API_BASE_PATH}/${fileKind}/list`,
getByIdRoute: (fileKind: string, id: string) => `${FILES_API_BASE_PATH}/${fileKind}/${id}`,

/**
* Scope to file shares and file kind
*/
getShareRoute: (fileKind: string, id: string) => `${FILES_SHARE_API_BASE_PATH}/${fileKind}/${id}`,
getListSharesRoute: (fileKind: string, page?: number, perPage?: number, forFileId?: string) =>
pipe(`${FILES_SHARE_API_BASE_PATH}/${fileKind}`, addQueryParams({ page, perPage, forFileId })),
getListSharesRoute: (fileKind: string) => `${FILES_SHARE_API_BASE_PATH}/${fileKind}`,

/**
* Public routes
*/
getPublicDownloadRoute: (token: string, fileName?: string) =>
pipe(
`${FILES_PUBLIC_API_BASE_PATH}/blob${fileName ? '/' + fileName : ''}`,
addQueryParams({ token })
),
getPublicDownloadRoute: (fileName?: string) =>
`${FILES_PUBLIC_API_BASE_PATH}/blob${fileName ? '/' + fileName : ''}`,

/**
* Top-level routes
*/
getFindRoute: (page?: number, perPage?: number) =>
pipe(`${API_BASE_PATH}/find`, addQueryParams({ page, perPage })),
getFindRoute: () => `${API_BASE_PATH}/find`,
getMetricsRoute: () => `${API_BASE_PATH}/metrics`,
};

Expand Down Expand Up @@ -118,17 +102,20 @@ export function createFilesClient({
getById: ({ kind, ...args }) => {
return http.get(apiRoutes.getByIdRoute(scopedFileKind ?? kind, args.id));
},
list({ kind, ...args } = { kind: '' }) {
return http.get(apiRoutes.getListRoute(scopedFileKind ?? kind, args.page, args.perPage));
list({ kind, page, perPage } = { kind: '' }) {
return http.get(apiRoutes.getListRoute(scopedFileKind ?? kind), {
query: { page, perPage },
});
},
update: ({ kind, id, ...body }) => {
return http.patch(apiRoutes.getUpdateRoute(scopedFileKind ?? kind, id), {
headers: commonBodyHeaders,
body: JSON.stringify(body),
});
},
upload: ({ kind, abortSignal, contentType, ...args }) => {
upload: ({ kind, abortSignal, contentType, selfDestructOnAbort, ...args }) => {
return http.put(apiRoutes.getUploadRoute(scopedFileKind ?? kind, args.id), {
query: { selfDestructOnAbort },
headers: {
'Content-Type': contentType ?? 'application/octet-stream',
},
Expand All @@ -152,12 +139,16 @@ export function createFilesClient({
return http.get(apiRoutes.getShareRoute(scopedFileKind ?? kind, id));
},
listShares: ({ kind, forFileId, page, perPage }) => {
return http.get(
apiRoutes.getListSharesRoute(scopedFileKind ?? kind, page, perPage, forFileId)
);
return http.get(apiRoutes.getListSharesRoute(scopedFileKind ?? kind), {
query: { page, perPage, forFileId },
});
},
find: ({ page, perPage, ...filterArgs }) => {
return http.post(apiRoutes.getFindRoute(page, perPage), {
return http.post(apiRoutes.getFindRoute(), {
query: {
page,
perPage,
},
headers: commonBodyHeaders,
body: JSON.stringify(filterArgs),
});
Expand All @@ -166,7 +157,7 @@ export function createFilesClient({
return http.get(apiRoutes.getMetricsRoute());
},
publicDownload: ({ token, fileName }) => {
return http.get(apiRoutes.getPublicDownloadRoute(token, fileName));
return http.get(apiRoutes.getPublicDownloadRoute(fileName), { query: { token } });
},
};
return api;
Expand Down
25 changes: 24 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@
"in": "query"
}
],
"required": true,
"post": {
"summary": "Packages - Install",
"tags": [],
Expand Down Expand Up @@ -1253,6 +1252,12 @@
"application/json": {
"schema": {
"type": "object",
"properties": {
"actionId": {
"type": "string",
"description": "action id when running in async mode (>10k agents)"
}
},
"additionalProperties": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1842,6 +1847,12 @@
"application/json": {
"schema": {
"type": "object",
"properties": {
"actionId": {
"type": "string",
"description": "action id when running in async mode (>10k agents)"
}
},
"additionalProperties": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1918,6 +1929,12 @@
"application/json": {
"schema": {
"type": "object",
"properties": {
"actionId": {
"type": "string",
"description": "action id when running in async mode (>10k agents)"
}
},
"additionalProperties": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2001,6 +2018,12 @@
"application/json": {
"schema": {
"type": "object",
"properties": {
"actionId": {
"type": "string",
"description": "action id when running in async mode (>10k agents)"
}
},
"additionalProperties": {
"type": "object",
"properties": {
Expand Down
19 changes: 17 additions & 2 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ paths:
name: ignoreUnverified
description: Ignore if the package is fails signature verification
in: query
required: true
post:
summary: Packages - Install
tags: []
Expand Down Expand Up @@ -772,6 +771,10 @@ paths:
application/json:
schema:
type: object
properties:
actionId:
type: string
description: action id when running in async mode (>10k agents)
additionalProperties:
type: object
properties:
Expand Down Expand Up @@ -1139,6 +1142,10 @@ paths:
application/json:
schema:
type: object
properties:
actionId:
type: string
description: action id when running in async mode (>10k agents)
additionalProperties:
type: object
properties:
Expand Down Expand Up @@ -1185,6 +1192,10 @@ paths:
application/json:
schema:
type: object
properties:
actionId:
type: string
description: action id when running in async mode (>10k agents)
additionalProperties:
type: object
properties:
Expand Down Expand Up @@ -1236,6 +1247,10 @@ paths:
application/json:
schema:
type: object
properties:
actionId:
type: string
description: action id when running in async mode (>10k agents)
additionalProperties:
type: object
properties:
Expand Down Expand Up @@ -1332,7 +1347,7 @@ paths:
name: full
description: >-
When set to true, retrieve the related package policies for each
agent policy/
agent policy.
description: ''
post:
summary: Agent policy - Create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ post:
application/json:
schema:
type: object
properties:
actionId:
type: string
description: action id when running in async mode (>10k agents)
additionalProperties:
type: object
properties:
Expand Down
Loading

0 comments on commit a6c8292

Please sign in to comment.