Skip to content

Commit

Permalink
[7.x] [Snapshot & Restore] NP migration (#59109) (#59520)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga authored Mar 6, 2020
1 parent 50a84e3 commit de404f5
Show file tree
Hide file tree
Showing 228 changed files with 3,956 additions and 3,286 deletions.
26 changes: 13 additions & 13 deletions src/plugins/es_ui_shared/public/request/np_ready_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export interface SendRequestConfig {
body?: any;
}

export interface SendRequestResponse<D = any> {
export interface SendRequestResponse<D = any, E = Error> {
data: D | null;
error: Error | null;
error: E | null;
}

export interface UseRequestConfig extends SendRequestConfig {
Expand All @@ -39,20 +39,21 @@ export interface UseRequestConfig extends SendRequestConfig {
deserializer?: (data: any) => any;
}

export interface UseRequestResponse<D = any> {
export interface UseRequestResponse<D = any, E = Error> {
isInitialRequest: boolean;
isLoading: boolean;
error: Error | null;
error: E | null;
data: D | null;
sendRequest: (...args: any[]) => Promise<SendRequestResponse<D>>;
sendRequest: (...args: any[]) => Promise<SendRequestResponse<D, E>>;
}

export const sendRequest = async <D = any>(
export const sendRequest = async <D = any, E = Error>(
httpClient: HttpSetup,
{ path, method, body, query }: SendRequestConfig
): Promise<SendRequestResponse<D>> => {
): Promise<SendRequestResponse<D, E>> => {
try {
const response = await httpClient[method](path, { body, query });
const stringifiedBody = typeof body === 'string' ? body : JSON.stringify(body);
const response = await httpClient[method](path, { body: stringifiedBody, query });

return {
data: response.data ? response.data : response,
Expand All @@ -66,7 +67,7 @@ export const sendRequest = async <D = any>(
}
};

export const useRequest = <D = any>(
export const useRequest = <D = any, E = Error>(
httpClient: HttpSetup,
{
path,
Expand All @@ -77,9 +78,8 @@ export const useRequest = <D = any>(
initialData,
deserializer = (data: any): any => data,
}: UseRequestConfig
): UseRequestResponse<D> => {
const sendRequestRef = useRef<() => Promise<SendRequestResponse<D>>>();

): UseRequestResponse<D, E> => {
const sendRequestRef = useRef<() => Promise<SendRequestResponse<D, E>>>();
// Main states for tracking request status and data
const [error, setError] = useState<null | any>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
Expand Down Expand Up @@ -123,7 +123,7 @@ export const useRequest = <D = any>(
body,
};

const response = await sendRequest(httpClient, requestBody);
const response = await sendRequest<D, E>(httpClient, requestBody);
const { data: serializedResponseData, error: responseError } = response;

// If an outdated request has resolved, DON'T update state, but DO allow the processData handler
Expand Down
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"xpack.security": ["legacy/plugins/security", "plugins/security"],
"xpack.server": "legacy/server",
"xpack.siem": "legacy/plugins/siem",
"xpack.snapshotRestore": "legacy/plugins/snapshot_restore",
"xpack.snapshotRestore": "plugins/snapshot_restore",
"xpack.spaces": ["legacy/plugins/spaces", "plugins/spaces"],
"xpack.taskManager": "legacy/plugins/task_manager",
"xpack.transform": ["legacy/plugins/transform", "plugins/transform"],
Expand Down
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { crossClusterReplication } from './legacy/plugins/cross_cluster_replicat
import { upgradeAssistant } from './legacy/plugins/upgrade_assistant';
import { uptime } from './legacy/plugins/uptime';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
import { snapshotRestore } from './legacy/plugins/snapshot_restore';
import { transform } from './legacy/plugins/transform';
import { actions } from './legacy/plugins/actions';
import { alerting } from './legacy/plugins/alerting';
Expand Down Expand Up @@ -70,7 +69,6 @@ module.exports = function(kibana) {
uptime(kibana),
encryptedSavedObjects(kibana),
lens(kibana),
snapshotRestore(kibana),
actions(kibana),
alerting(kibana),
ingestManager(kibana),
Expand Down

This file was deleted.

This file was deleted.

55 changes: 0 additions & 55 deletions x-pack/legacy/plugins/snapshot_restore/index.ts

This file was deleted.

67 changes: 0 additions & 67 deletions x-pack/legacy/plugins/snapshot_restore/public/app/index.tsx

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/snapshot_restore/public/index.html

This file was deleted.

11 changes: 0 additions & 11 deletions x-pack/legacy/plugins/snapshot_restore/public/index.ts

This file was deleted.

Loading

0 comments on commit de404f5

Please sign in to comment.