diff --git a/http/cur_swagger.yml b/http/cur_swagger.yml index 6b3d8c5d10..d23b993680 100644 --- a/http/cur_swagger.yml +++ b/http/cur_swagger.yml @@ -1786,175 +1786,176 @@ paths: schema: $ref: "#/components/schemas/Error" /query: - get: - tags: - - Query - summary: query influx with specified return formatting. The spec and query fields are mutually exclusive. - parameters: - - in: query - name: org - description: specifies the organization of the resource - required: true - schema: - type: string - - in: query - name: query - description: query script to execute. - required: true - schema: - type: string - - in: header - name: Authorization - description: the authorization header should be in the format of `Token ` - schema: - type: string - responses: - '200': - description: query results + get: + tags: + - Query + summary: query influx with specified return formatting. The spec and query fields are mutually exclusive. + parameters: + - in: query + name: org + description: specifies the organization of the resource + required: true + schema: + type: string + - in: query + name: query + description: query script to execute. + required: true + schema: + type: string + - in: header + name: Authorization + description: the authorization header should be in the format of `Token ` + schema: + type: string + responses: + '200': + description: query results + content: + text/csv: + schema: + type: string + example: > + result,table,_start,_stop,_time,region,host,_value + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43 + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25 + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62 + '400': + description: error processing query + headers: + X-Influx-Error: + description: error string describing the problem + schema: + type: string + X-Influx-Reference: + description: reference code unique to the error type + schema: + type: integer + content: + text/csv: + schema: + type: string + example: > + error,reference + Failed to parse query,897 + default: + description: internal server error + headers: + X-Influx-Error: + description: error string describing the problem + schema: + type: string + X-Influx-Reference: + description: reference code unique to the error type + schema: + type: integer + content: + text/csv: + schema: + type: string + example: > + error,reference + Failed to parse query,897 + post: + tags: + - Query + summary: query an influx + parameters: + - in: header + name: Accept + description: specifies the return content format. Each response content type will have its own dialect options. + schema: + type: string + description: return format of either CSV or Arrow buffers + default: text/csv + enum: + - text/csv + - application/vnd.influx.arrow + - in: header + name: Content-Type + schema: + type: string + enum: + - application/json + - in: header + name: Authorization + description: the authorization header should be in the format of `Token ` + schema: + type: string + - in: query + name: org + description: specifies the name of the organization executing the query. + schema: + type: string + requestBody: + description: flux query or specification to execute content: - text/csv: - schema: - type: string - example: > - result,table,_start,_stop,_time,region,host,_value - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43 - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25 - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62 - '400': - description: error processing query - headers: - X-Influx-Error: - description: error string describing the problem - schema: - type: string - X-Influx-Reference: - description: reference code unique to the error type - schema: - type: integer - content: - text/csv: - schema: - type: string - example: > - error,reference - Failed to parse query,897 - default: - description: internal server error - headers: - X-Influx-Error: - description: error string describing the problem - schema: - type: string - X-Influx-Reference: - description: reference code unique to the error type - schema: - type: integer - content: - text/csv: - schema: - type: string - example: > - error,reference - Failed to parse query,897 - post: - tags: - - Query - summary: query an influx - parameters: - - in: header - name: Accept - description: specifies the return content format. Each response content type will have its own dialect options. - schema: - type: string - description: return format of either CSV or Arrow buffers - default: text/csv - enum: - - text/csv - - application/vnd.influx.arrow - - in: header - name: Content-Type - schema: - type: string - enum: - - application/json - - in: header - name: Authorization - description: the authorization header should be in the format of `Token ` - schema: - type: string - - in: query - name: org - description: specifies the name of the organization executing the query. - schema: - type: string - requestBody: - description: flux query or specification to execute - content: - application/json: - schema: - $ref: "#/components/schemas/Query" - responses: - '200': - description: query results - content: - text/csv: - schema: - type: string - example: > - result,table,_start,_stop,_time,region,host,_value - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43 - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25 - mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62 - application/vnd.influx.arrow: - schema: - type: string - format: binary - '400': - description: error processing query - headers: - X-Influx-Error: - description: error string describing the problem - schema: - type: string - X-Influx-Reference: - description: reference code unique to the error type - schema: - type: integer - content: - text/csv: - schema: - type: string - example: > - error,reference - Failed to parse query,897 - application/vnd.influx.arrow: + application/json: schema: + $ref: "#/components/schemas/Query" + responses: + '200': + description: query results + content: + text/csv: + schema: + type: string + example: > + result,table,_start,_stop,_time,region,host,_value + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43 + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25 + mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62 + application/vnd.influx.arrow: + schema: type: string format: binary - default: - description: internal server error - headers: - X-Influx-Error: - description: error string describing the problem - schema: - type: string - X-Influx-Reference: - description: reference code unique to the error type - schema: - type: integer - content: - text/csv: - schema: - type: string - example: > - error,reference - Failed to parse query,897 - application/vnd.influx.arrow: - schema: + '400': + description: error processing query + headers: + X-Influx-Error: + description: error string describing the problem + schema: type: string - format: binary + X-Influx-Reference: + description: reference code unique to the error type + schema: + type: integer + content: + text/csv: + schema: + type: string + example: > + error,reference + Failed to parse query,897 + application/vnd.influx.arrow: + schema: + type: string + format: binary + default: + description: internal server error + headers: + X-Influx-Error: + description: error string describing the problem + schema: + type: string + X-Influx-Reference: + description: reference code unique to the error type + schema: + type: integer + content: + text/csv: + schema: + type: string + example: > + error,reference + Failed to parse query,897 + application/vnd.influx.arrow: + schema: + type: string + format: binary /buckets: get: + x-generated: true tags: - Buckets summary: List all buckets @@ -1979,6 +1980,7 @@ paths: schema: $ref: "#/components/schemas/Error" post: + x-generated: true tags: - Buckets summary: Create a bucket @@ -2011,6 +2013,7 @@ paths: $ref: "#/components/schemas/Error" '/buckets/{bucketID}': get: + x-generated: true tags: - Buckets summary: Retrieve a bucket @@ -2035,6 +2038,7 @@ paths: schema: $ref: "#/components/schemas/Error" patch: + x-generated: true tags: - Buckets summary: Update a bucket @@ -2239,6 +2243,7 @@ paths: $ref: "#/components/schemas/Error" /orgs: get: + x-generated: true tags: - Organizations summary: List all organizations @@ -2256,6 +2261,7 @@ paths: schema: $ref: "#/components/schemas/Error" post: + x-generated: true tags: - Organizations summary: Create an organization @@ -2281,6 +2287,7 @@ paths: $ref: "#/components/schemas/Error" '/orgs/{orgID}': get: + x-generated: true tags: - Organizations summary: Retrieve an organization @@ -2305,6 +2312,7 @@ paths: schema: $ref: "#/components/schemas/Error" patch: + x-generated: true tags: - Organizations summary: Update an organization @@ -2335,6 +2343,27 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + delete: + x-generated: true + tags: + - Organizations + summary: delete an organization + parameters: + - in: path + name: orgID + schema: + type: string + required: true + description: ID of organization to get + responses: + '200': + description: organization deleted + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" '/orgs/{orgID}/members': get: tags: diff --git a/ui/src/Setup.tsx b/ui/src/Setup.tsx index 2eb06416ec..42c541aec9 100644 --- a/ui/src/Setup.tsx +++ b/ui/src/Setup.tsx @@ -17,7 +17,6 @@ import {isOnboardingURL} from 'src/onboarding/utils' // Types import {Notification, NotificationFunc, RemoteDataState} from 'src/types' -import {Links} from 'src/types/v2/links' interface State { loading: RemoteDataState @@ -25,7 +24,6 @@ interface State { } interface Props { - links: Links router: InjectedRouter children: ReactElement notify: (message: Notification | NotificationFunc) => void @@ -43,7 +41,7 @@ export class Setup extends PureComponent { } public async componentDidMount() { - const {links, router} = this.props + const {router} = this.props if (isOnboardingURL()) { this.setState({ @@ -52,7 +50,7 @@ export class Setup extends PureComponent { return } - const isSetupAllowed = await getSetupStatus(links.setup) + const isSetupAllowed = await getSetupStatus() this.setState({ loading: RemoteDataState.Done, }) @@ -81,13 +79,11 @@ export class Setup extends PureComponent { } } -const mstp = ({links}) => ({links}) - const mdtp = { notify: notifyAction, } export default connect( - mstp, + null, mdtp )(Setup) diff --git a/ui/src/Signin.tsx b/ui/src/Signin.tsx index 0a8a2b63d7..3247bbbb6c 100644 --- a/ui/src/Signin.tsx +++ b/ui/src/Signin.tsx @@ -1,6 +1,5 @@ // Libraries import React, {ReactElement, PureComponent} from 'react' -import {connect} from 'react-redux' // APIs import {trySources} from 'src/onboarding/apis' @@ -12,7 +11,6 @@ import Notifications from 'src/shared/components/notifications/Notifications' // Types import {RemoteDataState} from 'src/types' -import {Links} from 'src/types/v2/links' interface State { loading: RemoteDataState @@ -20,7 +18,6 @@ interface State { } interface Props { - links: Links children: ReactElement } @@ -36,8 +33,7 @@ export class Signin extends PureComponent { } public async componentDidMount() { - const {links} = this.props - const isSourcesAllowed = await trySources(links.sources) + const isSourcesAllowed = await trySources() const isUserSignedIn = isSourcesAllowed this.setState({loading: RemoteDataState.Done, isUserSignedIn}) } @@ -73,8 +69,4 @@ export class Signin extends PureComponent { } } -const mstp = ({links}) => ({ - links, -}) - -export default connect(mstp)(Signin) +export default Signin diff --git a/ui/src/api/api.ts b/ui/src/api/api.ts index b17daf22d5..f52b879108 100644 --- a/ui/src/api/api.ts +++ b/ui/src/api/api.ts @@ -8457,6 +8457,39 @@ export const OrganizationsApiAxiosParamCreator = function (configuration?: Confi options: localVarRequestOptions, }; }, + /** + * + * @summary delete an organization + * @param {string} orgID ID of organization to get + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + orgsOrgIDDelete(orgID: string, options: any = {}): RequestArgs { + // verify required parameter 'orgID' is not null or undefined + if (orgID === null || orgID === undefined) { + throw new RequiredError('orgID','Required parameter orgID was null or undefined when calling orgsOrgIDDelete.'); + } + const localVarPath = `/orgs/{orgID}` + .replace(`{${"orgID"}}`, encodeURIComponent(String(orgID))); + const localVarUrlObj = url.parse(localVarPath, true); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions = Object.assign({ method: 'DELETE' }, baseOptions, options); + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query); + // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 + delete localVarUrlObj.search; + localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); + + return { + url: url.format(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Retrieve an organization @@ -8818,6 +8851,20 @@ export const OrganizationsApiFp = function(configuration?: Configuration) { return axios.request(axiosRequestArgs); }; }, + /** + * + * @summary delete an organization + * @param {string} orgID ID of organization to get + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + orgsOrgIDDelete(orgID: string, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise { + const localVarAxiosArgs = OrganizationsApiAxiosParamCreator(configuration).orgsOrgIDDelete(orgID, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = Object.assign(localVarAxiosArgs.options, {url: basePath + localVarAxiosArgs.url}) + return axios.request(axiosRequestArgs); + }; + }, /** * * @summary Retrieve an organization @@ -8967,6 +9014,16 @@ export const OrganizationsApiFactory = function (configuration?: Configuration, orgsGet(options?: any) { return OrganizationsApiFp(configuration).orgsGet(options)(axios, basePath); }, + /** + * + * @summary delete an organization + * @param {string} orgID ID of organization to get + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + orgsOrgIDDelete(orgID: string, options?: any) { + return OrganizationsApiFp(configuration).orgsOrgIDDelete(orgID, options)(axios, basePath); + }, /** * * @summary Retrieve an organization @@ -9083,6 +9140,18 @@ export class OrganizationsApi extends BaseAPI { return OrganizationsApiFp(this.configuration).orgsGet(options)(this.axios, this.basePath); } + /** + * + * @summary delete an organization + * @param {string} orgID ID of organization to get + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof OrganizationsApi + */ + public orgsOrgIDDelete(orgID: string, options?: any) { + return OrganizationsApiFp(this.configuration).orgsOrgIDDelete(orgID, options)(this.axios, this.basePath); + } + /** * * @summary Retrieve an organization diff --git a/ui/src/logs/api/v2/index.ts b/ui/src/logs/api/v2/index.ts index dfc185a951..b519c6d67a 100644 --- a/ui/src/logs/api/v2/index.ts +++ b/ui/src/logs/api/v2/index.ts @@ -1,11 +1,11 @@ // Utils -import AJAX from 'src/utils/ajax' import {parseResponse} from 'src/shared/parsing/flux/response' // Types -import {InfluxLanguage} from 'src/types/v2/dashboards' import {FluxTable} from 'src/types' import {SearchStatus} from 'src/types/logs' +import {queryAPI} from 'src/utils/api' +import {Query, Dialect} from 'src/api' export interface QueryResponse { tables: FluxTable[] @@ -13,26 +13,27 @@ export interface QueryResponse { } export const executeQueryAsync = async ( - link: string, query: string, - type: InfluxLanguage = InfluxLanguage.Flux + type: Query.TypeEnum = Query.TypeEnum.Influxql ): Promise => { try { const dialect = { header: true, - annotations: ['datatype', 'group', 'default'], + annotations: [ + Dialect.AnnotationsEnum.Datatype, + Dialect.AnnotationsEnum.Group, + Dialect.AnnotationsEnum.Default, + ], delimiter: ',', } - const {data} = await AJAX({ - method: 'POST', - url: link, - data: { - type, - query, - dialect, - }, - }) + const {data} = await queryAPI.queryPost( + 'text/csv', + 'application/json', + null, + null, + {type, query, dialect} + ) const tables = parseResponse(data) const status = responseStatus(tables) diff --git a/ui/src/logs/utils/logQuery.test.ts b/ui/src/logs/utils/logQuery.test.ts index f066bef971..879ab62b18 100644 --- a/ui/src/logs/utils/logQuery.test.ts +++ b/ui/src/logs/utils/logQuery.test.ts @@ -9,8 +9,7 @@ import {oneline} from 'src/logs/utils/helpers/formatting' import {QueryConfig} from 'src/types' import {Filter, LogQuery} from 'src/types/logs' -import {InfluxLanguage} from 'src/types/v2' -import {Source} from 'src/api' +import {Source, Query} from 'src/api' describe('Logs.LogQuery', () => { let config: QueryConfig @@ -57,7 +56,7 @@ describe('Logs.LogQuery', () => { }) it('can build a flux query', () => { - const actual = buildLogQuery(InfluxLanguage.Flux, { + const actual = buildLogQuery(Query.TypeEnum.Flux, { lower, upper, config, @@ -86,7 +85,7 @@ describe('Logs.LogQuery', () => { it('can build an influxql query', () => { filters = [{key: 'severity', operator: '==', value: 'notice', id: '1'}] - const actual = buildLogQuery(InfluxLanguage.InfluxQL, { + const actual = buildLogQuery(Query.TypeEnum.Influxql, { lower, upper, config, diff --git a/ui/src/logs/utils/logQuery.ts b/ui/src/logs/utils/logQuery.ts index 88508bc317..eae1c0693f 100644 --- a/ui/src/logs/utils/logQuery.ts +++ b/ui/src/logs/utils/logQuery.ts @@ -11,8 +11,7 @@ import {buildFluxQuery} from 'src/logs/utils/v2/queryBuilder' import {buildInfluxQLQuery} from 'src/logs/utils/v1/queryBuilder' // Types -import {Bucket} from 'src/api' -import {InfluxLanguage} from 'src/types/v2/dashboards' +import {Bucket, Query} from 'src/api' import {QueryConfig} from 'src/types' import { LogSearchParams, @@ -91,13 +90,13 @@ export const buildTableQueryConfig = (bucket: Bucket): QueryConfig => { } export const buildLogQuery = ( - type: InfluxLanguage, + type: Query.TypeEnum, searchParams: LogSearchParams ): string => { switch (type) { - case InfluxLanguage.InfluxQL: + case Query.TypeEnum.Influxql: return `${buildInfluxQLQuery(searchParams)} ORDER BY time DESC` - case InfluxLanguage.Flux: + case Query.TypeEnum.Flux: return buildFluxQuery(searchParams) } } @@ -107,14 +106,11 @@ export const getTableData = async ( logQuery: LogQuery ): Promise => { const {source, ...searchParams} = logQuery - const { - links: {query: queryLink}, - } = source // TODO: get type from source - const type = InfluxLanguage.Flux + const type = Query.TypeEnum.Flux const query = buildLogQuery(type, searchParams) - const response = await executeQuery(queryLink, query, type) + const response = await executeQuery(query, type) const {config} = searchParams const columnNames: string[] = config.fields.map(f => f.alias) diff --git a/ui/src/onboarding/apis/index.ts b/ui/src/onboarding/apis/index.ts index 419488acab..59c5605d8e 100644 --- a/ui/src/onboarding/apis/index.ts +++ b/ui/src/onboarding/apis/index.ts @@ -1,21 +1,17 @@ // Libraries import _ from 'lodash' -import {baseAPI} from 'src/utils/api' +import {baseAPI, setupAPI, sourcesAPI} from 'src/utils/api' // Utils -import AJAX from 'src/utils/ajax' import {telegrafsAPI, authorizationsAPI, writeAPI} from 'src/utils/api' import {Telegraf, WritePrecision, TelegrafRequest} from 'src/api' import {getDeep} from 'src/utils/wrappers' -export const getSetupStatus = async (url: string): Promise => { +export const getSetupStatus = async (): Promise => { try { - const {data} = await AJAX({ - method: 'GET', - url, - }) + const {data} = await setupAPI.setupGet() const {allowed} = data return allowed } catch (error) { @@ -49,15 +45,10 @@ export interface SetupParams { } export const setSetupParams = async ( - url: string, setupParams: SetupParams ): Promise => { try { - await AJAX({ - method: 'POST', - url, - data: setupParams, - }) + await setupAPI.setupPost(setupParams) } catch (error) { console.error("Can't set setup parameters", error) throw error @@ -77,12 +68,9 @@ export const signin = async (params: { } } -export const trySources = async (url: string): Promise => { +export const trySources = async (): Promise => { try { - await AJAX({ - method: 'GET', - url, - }) + await sourcesAPI.sourcesGet(null) return true } catch (error) { console.error('Sign in has failed', error) diff --git a/ui/src/onboarding/apis/mocks.ts b/ui/src/onboarding/apis/mocks.ts index 42a9610b65..5ce4f481d2 100644 --- a/ui/src/onboarding/apis/mocks.ts +++ b/ui/src/onboarding/apis/mocks.ts @@ -9,12 +9,19 @@ const telegrafsPost = jest.fn(() => Promise.resolve(createTelegrafConfigResponse) ) const authorizationsGet = jest.fn(() => Promise.resolve(authResponse)) +const setupPost = jest.fn(() => Promise.resolve()) +const setupGet = jest.fn(() => Promise.resolve({data: {allowed: true}})) export const telegrafsAPI = { telegrafsGet, telegrafsPost, } +export const setupAPI = { + setupPost, + setupGet, +} + export const authorizationsAPI = { authorizationsGet, } diff --git a/ui/src/onboarding/apis/onboarding.test.ts b/ui/src/onboarding/apis/onboarding.test.ts index 7ab73c7be4..877ae5dad0 100644 --- a/ui/src/onboarding/apis/onboarding.test.ts +++ b/ui/src/onboarding/apis/onboarding.test.ts @@ -7,12 +7,13 @@ import { getAuthorizationToken, } from 'src/onboarding/apis' -import AJAX from 'src/utils/ajax' - import {telegrafConfig, token} from 'mocks/dummyData' -import {telegrafsAPI, authorizationsAPI} from 'src/onboarding/apis/mocks' +import { + telegrafsAPI, + authorizationsAPI, + setupAPI, +} from 'src/onboarding/apis/mocks' -jest.mock('src/utils/ajax', () => require('mocks/utils/ajax')) jest.mock('src/utils/api', () => require('src/onboarding/apis/mocks')) describe('Onboarding.Apis', () => { @@ -22,30 +23,21 @@ describe('Onboarding.Apis', () => { describe('getSetupStatus', () => { it('is called with the expected body', () => { - const url = '/api/v2/setup' - getSetupStatus(url) - expect(AJAX).toHaveBeenCalledWith({ - method: 'GET', - url, - }) + getSetupStatus() + expect(setupAPI.setupGet).toHaveBeenCalled() }) }) describe('setSetupParams', () => { it('is called with the expected body', () => { - const url = '/api/v2/setup' const setupParams: SetupParams = { username: 'moo', password: 'pwoo', bucket: 'boo', org: 'ooo', } - setSetupParams(url, setupParams) - expect(AJAX).toHaveBeenCalledWith({ - method: 'POST', - url, - data: setupParams, - }) + setSetupParams(setupParams) + expect(setupAPI.setupPost).toHaveBeenCalledWith(setupParams) }) }) diff --git a/ui/src/onboarding/components/AdminStep.tsx b/ui/src/onboarding/components/AdminStep.tsx index 5604497cb1..765db50262 100644 --- a/ui/src/onboarding/components/AdminStep.tsx +++ b/ui/src/onboarding/components/AdminStep.tsx @@ -262,7 +262,6 @@ class AdminStep extends PureComponent { private handleNext = async () => { const { - links, onSetStepStatus, currentStepIndex, handleSetSetupParams, @@ -286,7 +285,7 @@ class AdminStep extends PureComponent { } try { - await setSetupParams(links.setup, setupParams) + await setSetupParams(setupParams) await signin({username, password}) notify(copy.SetupSuccess) handleSetSetupParams(setupParams) diff --git a/ui/src/organizations/actions/index.ts b/ui/src/organizations/actions/index.ts index 8841ab5787..743ff33683 100644 --- a/ui/src/organizations/actions/index.ts +++ b/ui/src/organizations/actions/index.ts @@ -50,13 +50,13 @@ export const addOrg = (org: Organization): AddOrg => ({ export interface RemoveOrg { type: ActionTypes.RemoveOrg payload: { - link: string + org: Organization } } -export const removeOrg = (link: string): RemoveOrg => ({ +export const removeOrg = (org: Organization): RemoveOrg => ({ type: ActionTypes.RemoveOrg, - payload: {link}, + payload: {org}, }) export interface EditOrg { @@ -95,12 +95,12 @@ export const createOrg = (org: Organization) => async ( } } -export const deleteOrg = (link: string) => async ( +export const deleteOrg = (org: Organization) => async ( dispatch: Dispatch ): Promise => { try { - await deleteOrgAPI(link) - dispatch(removeOrg(link)) + await deleteOrgAPI(org) + dispatch(removeOrg(org)) } catch (e) { console.error(e) } diff --git a/ui/src/organizations/apis/index.ts b/ui/src/organizations/apis/index.ts index a1386cd145..24cbcde56a 100644 --- a/ui/src/organizations/apis/index.ts +++ b/ui/src/organizations/apis/index.ts @@ -1,5 +1,4 @@ // Libraries -import AJAX from 'src/utils/ajax' import _ from 'lodash' import {orgsAPI, bucketsAPI, dashboardsAPI, taskAPI} from 'src/utils/api' @@ -27,12 +26,9 @@ export const createOrg = async (org: Organization): Promise => { } } -export const deleteOrg = async (url: string): Promise => { +export const deleteOrg = async (org: Organization): Promise => { try { - await AJAX({ - url, - method: 'DELETE', - }) + await orgsAPI.orgsOrgIDDelete(org.id) } catch (error) { console.error('Could not delete org', error) throw error @@ -75,15 +71,11 @@ export const getBuckets = async (org: Organization): Promise => { } export const createBucket = async ( - url: string, - bucket: Partial + org: Organization, + bucket: Bucket ): Promise => { try { - const {data} = await AJAX({ - method: 'POST', - url, - data: bucket, - }) + const {data} = await bucketsAPI.bucketsPost(org.name, bucket) return data } catch (error) { @@ -94,11 +86,7 @@ export const createBucket = async ( export const updateBucket = async (bucket: Bucket): Promise => { try { - const {data} = await AJAX({ - url: bucket.links.self, - method: 'PATCH', - data: bucket, - }) + const {data} = await bucketsAPI.bucketsBucketIDPatch(bucket.id, bucket) return data } catch (error) { diff --git a/ui/src/organizations/components/Buckets.tsx b/ui/src/organizations/components/Buckets.tsx index 5332df6b3a..85148ec922 100644 --- a/ui/src/organizations/components/Buckets.tsx +++ b/ui/src/organizations/components/Buckets.tsx @@ -94,7 +94,6 @@ export default class Buckets extends PureComponent { @@ -117,10 +116,10 @@ export default class Buckets extends PureComponent { } private handleCreateBucket = async ( - link: string, - bucket: Partial + org: Organization, + bucket: Bucket ): Promise => { - const b = await createBucket(link, bucket) + const b = await createBucket(org, bucket) const buckets = this.prettyBuckets([b, ...this.props.buckets]) this.setState({buckets}) this.handleCloseModal() diff --git a/ui/src/organizations/components/CreateBucketOverlay.tsx b/ui/src/organizations/components/CreateBucketOverlay.tsx index 80c5c263f3..6b1c9c41e1 100644 --- a/ui/src/organizations/components/CreateBucketOverlay.tsx +++ b/ui/src/organizations/components/CreateBucketOverlay.tsx @@ -14,10 +14,9 @@ import BucketOverlayForm from 'src/organizations/components/BucketOverlayForm' import {Bucket, BucketRetentionRules, Organization} from 'src/api' interface Props { - link: string org: Organization onCloseModal: () => void - onCreateBucket: (link: string, bucket: Partial) => Promise + onCreateBucket: (org: Organization, bucket: Partial) => Promise } interface State { @@ -106,7 +105,7 @@ export default class BucketOverlay extends PureComponent { } private handleCreateBucket = (): void => { - const {link, onCreateBucket, org} = this.props + const {onCreateBucket, org} = this.props const organizationID = org.id const organization = org.name @@ -116,7 +115,7 @@ export default class BucketOverlay extends PureComponent { organization, } - onCreateBucket(link, bucket) + onCreateBucket(org, bucket) } private handleChangeInput = (e: ChangeEvent) => { diff --git a/ui/src/organizations/components/DeleteOrgButton.tsx b/ui/src/organizations/components/DeleteOrgButton.tsx index ed73c5505c..5ad9871545 100644 --- a/ui/src/organizations/components/DeleteOrgButton.tsx +++ b/ui/src/organizations/components/DeleteOrgButton.tsx @@ -5,11 +5,11 @@ import React, {Component} from 'react' import {Button, ComponentColor, ComponentSize} from 'src/clockface' // Types -import {Organization} from 'src/types/v2' +import {Organization} from 'src/api' interface Props { org: Organization - onDeleteOrg: (link: string) => void + onDeleteOrg: (org: Organization) => void } class DeleteOrgButton extends Component { @@ -26,7 +26,7 @@ class DeleteOrgButton extends Component { private handleDeleteOrg = () => { const {org, onDeleteOrg} = this.props - onDeleteOrg(org.links.self) + onDeleteOrg(org) } } diff --git a/ui/src/organizations/reducers/orgs.ts b/ui/src/organizations/reducers/orgs.ts index 25c68b63e8..e3b28daf16 100644 --- a/ui/src/organizations/reducers/orgs.ts +++ b/ui/src/organizations/reducers/orgs.ts @@ -10,7 +10,7 @@ export default (state = defaultState, action: Actions): Organization[] => { case ActionTypes.AddOrg: return [...state, {...action.payload.org}] case ActionTypes.RemoveOrg: - return state.filter(org => org.links.self !== action.payload.link) + return state.filter(org => org !== action.payload.org) case ActionTypes.EditOrg: const newState = state.map(o => { const {org} = action.payload diff --git a/ui/src/shared/apis/v2/organization.ts b/ui/src/shared/apis/v2/organization.ts index 1dbbac78d6..713f486b06 100644 --- a/ui/src/shared/apis/v2/organization.ts +++ b/ui/src/shared/apis/v2/organization.ts @@ -1,14 +1,9 @@ import _ from 'lodash' -import AJAX from 'src/utils/ajax' +import {orgsAPI} from 'src/utils/api' -import {Organization} from 'src/types/v2' +import {Organization} from 'src/api' -export const getOrganizations = async ( - url: string -): Promise => { - const {data} = await AJAX({ - url, - }) - - return _.get(data, 'orgs', []) +export const getOrganizations = async (): Promise => { + const {data} = await orgsAPI.orgsGet() + return data.orgs } diff --git a/ui/src/utils/api.ts b/ui/src/utils/api.ts index df801b7d0d..ce9feda5ba 100644 --- a/ui/src/utils/api.ts +++ b/ui/src/utils/api.ts @@ -11,6 +11,8 @@ import { DefaultApi, BucketsApi, OrganizationsApi, + QueryApi, + SetupApi, } from 'src/api' const basePath = '/api/v2' @@ -27,3 +29,5 @@ export const writeAPI = new WriteApi({basePath}) export const sourcesAPI = new SourcesApi({basePath}) export const bucketsAPI = new BucketsApi({basePath}) export const orgsAPI = new OrganizationsApi({basePath}) +export const queryAPI = new QueryApi({basePath}) +export const setupAPI = new SetupApi({basePath})