Skip to content

Commit

Permalink
Add cancel check connection button (#11360)
Browse files Browse the repository at this point in the history
* Implement check connection

* Add requeset cancelling

* Remove unused props

* Temporary comment analytics

* Add analytics calls

* Minor lint fixes

* fix renaming
  • Loading branch information
jamakase authored Mar 30, 2022
1 parent df6c8c7 commit 8b388c6
Show file tree
Hide file tree
Showing 38 changed files with 691 additions and 648 deletions.
22 changes: 1 addition & 21 deletions airbyte-webapp/src/core/domain/catalog/fieldUtil.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
import { JSONSchema7Definition } from "json-schema";
import Status from "core/statuses";
import { CommonRequestError } from "core/request/CommonRequestError";

import { SourceDiscoverSchemaRead } from "./api";
import { SyncSchemaField } from "./models";
import { ConnectionNamespaceDefinition } from "../connection";
import { SOURCE_NAMESPACE_TAG } from "../connector/source";

function toInnerModel(
result: SourceDiscoverSchemaRead
): SourceDiscoverSchemaRead {
if (result.jobInfo?.status === Status.FAILED || !result.catalog) {
// @ts-ignore address this case
const e = new CommonRequestError(result);
// Generate error with failed status and received logs
e._status = 400;
// @ts-ignore address this case
e.response = result.jobInfo;
throw e;
}

return result;
}

const traverseSchemaToField = (
jsonSchema: JSONSchema7Definition,
key: string
Expand Down Expand Up @@ -95,4 +75,4 @@ function getDestinationNamespace(opt: NamespaceOptions): string {
}
}

export { getDestinationNamespace, traverseSchemaToField, toInnerModel };
export { getDestinationNamespace, traverseSchemaToField };
44 changes: 44 additions & 0 deletions airbyte-webapp/src/core/domain/connector/DestinationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AirbyteRequestService } from "core/request/AirbyteRequestService";

import Status from "core/statuses";
import { LogsRequestError } from "core/request/LogsRequestError";
import { Scheduler } from "./types";
import { ConnectionConfiguration } from "core/domain/connection";

class DestinationService extends AirbyteRequestService {
get url(): string {
return "destinations";
}

public async check_connection(
params: {
destinationId?: string;
connectionConfiguration?: ConnectionConfiguration;
},
requestParams?: RequestInit
): Promise<Scheduler> {
const url = !params.destinationId
? `scheduler/${this.url}/check_connection`
: params.connectionConfiguration
? `${this.url}/check_connection_for_update`
: `${this.url}/check_connection`;

// migrated from rest-hooks. Needs proper fix to `Scheduler` type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = await this.fetch<any>(url, params, requestParams);

// If check connection for destination has status 'failed'
if (result.status === Status.FAILED) {
const jobInfo = {
...result.jobInfo,
status: result.status,
};

throw new LogsRequestError(jobInfo, jobInfo, result.message);
}

return result;
}
}

export { DestinationService };
34 changes: 34 additions & 0 deletions airbyte-webapp/src/core/domain/connector/SourceService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
import { AirbyteRequestService } from "core/request/AirbyteRequestService";
import { ConnectionConfiguration } from "../connection";
import { Scheduler } from "./types";
import Status from "core/statuses";
import { LogsRequestError } from "core/request/LogsRequestError";

class SourceService extends AirbyteRequestService {
get url(): string {
return "sources";
}

public async check_connection(
params: {
sourceId?: string;
connectionConfiguration?: ConnectionConfiguration;
},
requestParams?: RequestInit
): Promise<Scheduler> {
const url = !params.sourceId
? `scheduler/${this.url}/check_connection`
: params.connectionConfiguration
? `${this.url}/check_connection_for_update`
: `${this.url}/check_connection`;

// migrated from rest-hooks. Needs proper fix to `Scheduler` type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = await this.fetch<any>(url, params, requestParams);

// If check connection for source has status 'failed'
if (result.status === Status.FAILED) {
const jobInfo = {
...result.jobInfo,
status: result.status,
};

throw new LogsRequestError(jobInfo, jobInfo, result.message);
}

return result;
}
}

export { SourceService };
18 changes: 16 additions & 2 deletions airbyte-webapp/src/core/domain/connector/connector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { isSourceDefinition, isSourceDefinitionSpecification } from "./source";
import { ConnectorDefinition, ConnectorDefinitionSpecification } from "./types";
import {
isSource,
isSourceDefinition,
isSourceDefinitionSpecification,
} from "./source";
import {
ConnectorDefinition,
ConnectorDefinitionSpecification,
ConnectorT,
} from "./types";
import { DEV_IMAGE_TAG } from "./constants";

export class Connector {
Expand All @@ -22,6 +30,12 @@ export class Connector {
}
}

export class ConnectorHelper {
static id(connector: ConnectorT): string {
return isSource(connector) ? connector.sourceId : connector.destinationId;
}
}

export class ConnectorSpecification {
static id(connector: ConnectorDefinitionSpecification): string {
return isSourceDefinitionSpecification(connector)
Expand Down
6 changes: 6 additions & 0 deletions airbyte-webapp/src/core/domain/connector/source.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {
ConnectorDefinition,
ConnectorDefinitionSpecification,
ConnectorT,
Source,
SourceDefinition,
SourceDefinitionSpecification,
} from "./types";

export function isSource(connector: ConnectorT): connector is Source {
return "sourceId" in connector;
}

export function isSourceDefinition(
connector: ConnectorDefinition
): connector is SourceDefinition {
Expand Down
9 changes: 9 additions & 0 deletions airbyte-webapp/src/core/domain/connector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ConnectionSpecification,
} from "core/domain/connection";
import { DestinationSyncMode } from "core/domain/catalog";
import { JobInfo } from "../job";

export enum ReleaseStage {
"ALPHA" = "alpha",
Expand Down Expand Up @@ -119,3 +120,11 @@ export interface Destination {
destinationDefinitionId: string;
connectionConfiguration: ConnectionConfiguration;
}

export type ConnectorT = Destination | Source;

export interface Scheduler {
status: string;
message: string;
jobInfo?: JobInfo;
}
2 changes: 1 addition & 1 deletion airbyte-webapp/src/core/jsonSchema/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ test("apply func at", () => {

const applied = applyFuncAt(schema, ["ssl", 0], (sch) => {
if (typeof sch === "boolean") {
return sch as any;
return {};
}

sch.properties = sch.properties ?? {};
Expand Down
99 changes: 0 additions & 99 deletions airbyte-webapp/src/core/resources/Scheduler.ts

This file was deleted.

15 changes: 12 additions & 3 deletions airbyte-webapp/src/core/resources/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ReadShape, Resource, SchemaDetail } from "rest-hooks";

import BaseResource from "./BaseResource";
import { SourceDiscoverSchemaRead, SyncSchema } from "core/domain/catalog";
import { toInnerModel } from "core/domain/catalog/fieldUtil";
import { JobInfo } from "core/domain/job";
import Status from "../statuses";
import { CommonRequestError } from "../request/CommonRequestError";

export interface Schema extends SourceDiscoverSchemaRead {
id: string;
Expand All @@ -26,13 +27,21 @@ export default class SchemaResource extends BaseResource implements Schema {
return {
...super.detailShape(),
fetch: async (params: { sourceId: string }): Promise<Schema> => {
const response = await this.fetch(
const result = await this.fetch(
"post",
`${this.url(params)}/discover_schema`,
params
);

const result = toInnerModel(response);
if (result.jobInfo?.status === Status.FAILED || !result.catalog) {
// @ts-ignore address this case
const e = new CommonRequestError(result);
// Generate error with failed status and received logs
e._status = 400;
// @ts-ignore address this case
e.response = result.jobInfo;
throw e;
}

return {
catalog: result.catalog,
Expand Down
Loading

0 comments on commit 8b388c6

Please sign in to comment.