diff --git a/ui/src/authorizations/containers/TokensIndex.tsx b/ui/src/authorizations/containers/TokensIndex.tsx index fbcf8ed57c3..6430f31134f 100644 --- a/ui/src/authorizations/containers/TokensIndex.tsx +++ b/ui/src/authorizations/containers/TokensIndex.tsx @@ -13,8 +13,7 @@ import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' import TokensTab from 'src/authorizations/components/TokensTab' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/buckets/containers/BucketsIndex.tsx b/ui/src/buckets/containers/BucketsIndex.tsx index 7df1a87828c..48c35cb7017 100644 --- a/ui/src/buckets/containers/BucketsIndex.tsx +++ b/ui/src/buckets/containers/BucketsIndex.tsx @@ -14,8 +14,7 @@ import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' import GetAssetLimits from 'src/cloud/components/GetAssetLimits' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/dashboards/components/DashboardHeader.tsx b/ui/src/dashboards/components/DashboardHeader.tsx index 7a453a3dabd..15404196c48 100644 --- a/ui/src/dashboards/components/DashboardHeader.tsx +++ b/ui/src/dashboards/components/DashboardHeader.tsx @@ -27,8 +27,8 @@ import { // Types import * as AppActions from 'src/types/actions/app' import * as QueriesModels from 'src/types/queries' -import {Dashboard, Organization} from '@influxdata/influx' -import {AutoRefresh, AutoRefreshStatus} from 'src/types' +import {Dashboard} from '@influxdata/influx' +import {AutoRefresh, AutoRefreshStatus, Organization} from 'src/types' interface Props { org: Organization diff --git a/ui/src/dashboards/components/DashboardPage.tsx b/ui/src/dashboards/components/DashboardPage.tsx index 85d149d3ec9..24962566679 100644 --- a/ui/src/dashboards/components/DashboardPage.tsx +++ b/ui/src/dashboards/components/DashboardPage.tsx @@ -49,6 +49,7 @@ import { AppState, AutoRefresh, AutoRefreshStatus, + Organization, } from 'src/types' import {RemoteDataState} from 'src/types' import {WithRouterProps} from 'react-router' @@ -57,7 +58,6 @@ import {Location} from 'history' import * as AppActions from 'src/types/actions/app' import * as ColorsModels from 'src/types/colors' import {toggleShowVariablesControls} from 'src/userSettings/actions' -import {Organization} from '@influxdata/influx' import {LimitStatus} from 'src/cloud/actions/limits' interface StateProps { diff --git a/ui/src/labels/containers/LabelsIndex.tsx b/ui/src/labels/containers/LabelsIndex.tsx index e58255a9df0..17957123b47 100644 --- a/ui/src/labels/containers/LabelsIndex.tsx +++ b/ui/src/labels/containers/LabelsIndex.tsx @@ -13,8 +13,7 @@ import LabelsTab from 'src/labels/components/LabelsTab' import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/members/actions/index.ts b/ui/src/members/actions/index.ts index e2d68f9db7f..6a864d99fd0 100644 --- a/ui/src/members/actions/index.ts +++ b/ui/src/members/actions/index.ts @@ -3,6 +3,7 @@ import _ from 'lodash' // API import {client} from 'src/utils/api' +import * as api from 'src/client' // Types import {RemoteDataState, GetState} from 'src/types' @@ -88,11 +89,23 @@ export const getMembers = () => async ( } = getState() dispatch(setMembers(RemoteDataState.Loading)) - const [owners, members] = await Promise.all([ - client.organizations.owners(id), - client.organizations.members(id), + const [ownersResp, membersResp] = await Promise.all([ + api.getOrgsOwners({orgID: id}), + api.getOrgsMembers({orgID: id}), ]) + if (ownersResp.status !== 200) { + throw new Error(ownersResp.data.message) + } + + if (membersResp.status !== 200) { + throw new Error(membersResp.data.message) + } + + const owners = ownersResp.data.users + + const members = membersResp.data.users + const users = [...owners, ...members] dispatch(setMembers(RemoteDataState.Done, users)) @@ -113,7 +126,13 @@ export const addNewMember = (member: AddResourceMemberRequestBody) => async ( }, } = getState() - const newMember = await client.organizations.addMember(id, member) + const resp = await api.postOrgsMember({orgID: id, data: member}) + + if (resp.status !== 201) { + throw new Error(resp.data.message) + } + + const newMember = resp.data dispatch(addMember(newMember)) dispatch(notify(memberAddSuccess(member.name))) @@ -136,7 +155,12 @@ export const deleteMember = (member: Member) => async ( }, } = getState() - await client.organizations.removeMember(id, member.id) + const resp = await api.deleteOrgsMember({orgID: id, userID: member.id}) + + if (resp.status !== 204) { + throw new Error(resp.data.message) + } + dispatch(removeMember(member.id)) dispatch(notify(memberRemoveSuccess(member.name))) diff --git a/ui/src/members/containers/MembersIndex.tsx b/ui/src/members/containers/MembersIndex.tsx index 88f2f729968..cb081e986bc 100644 --- a/ui/src/members/containers/MembersIndex.tsx +++ b/ui/src/members/containers/MembersIndex.tsx @@ -13,8 +13,7 @@ import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' import Members from 'src/members/components/Members' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/onboarding/components/CompletionAdvancedButton.tsx b/ui/src/onboarding/components/CompletionAdvancedButton.tsx index 672ddb1315e..3b9795729e1 100644 --- a/ui/src/onboarding/components/CompletionAdvancedButton.tsx +++ b/ui/src/onboarding/components/CompletionAdvancedButton.tsx @@ -8,7 +8,7 @@ import {Button, ComponentColor, ComponentSize} from '@influxdata/clockface' import {ErrorHandling} from 'src/shared/decorators/errors' // Types -import {Organization} from '@influxdata/influx' +import {Organization} from 'src/types' interface OwnProps { orgs: Organization[] diff --git a/ui/src/onboarding/components/CompletionStep.tsx b/ui/src/onboarding/components/CompletionStep.tsx index d3efcf534e6..9fd5847ecc3 100644 --- a/ui/src/onboarding/components/CompletionStep.tsx +++ b/ui/src/onboarding/components/CompletionStep.tsx @@ -21,6 +21,7 @@ import {QUICKSTART_DASHBOARD_NAME} from 'src/onboarding/constants' import {getDashboards} from 'src/organizations/apis' import {client} from 'src/utils/api' import {createDashboardFromTemplate as createDashboardFromTemplateAJAX} from 'src/templates/api' +import * as api from 'src/client' // Types import { @@ -30,8 +31,8 @@ import { Columns, Grid, } from '@influxdata/clockface' -import {DashboardTemplate} from 'src/types' -import {Organization, Dashboard, ScraperTargetRequest} from '@influxdata/influx' +import {DashboardTemplate, Organization} from 'src/types' +import {Dashboard, ScraperTargetRequest} from '@influxdata/influx' import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard' import {QUICKSTART_SCRAPER_TARGET_URL} from 'src/dataLoaders/constants/pluginConfigs' @@ -40,7 +41,14 @@ interface Props extends OnboardingStepProps { bucketID: string } -const getOrganizations = () => client.organizations.getAll() +const getOrganizations = async () => { + const resp = await api.getOrgs({}) + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + return resp.data.orgs +} @ErrorHandling class CompletionStep extends PureComponent { diff --git a/ui/src/organizations/actions/orgs.ts b/ui/src/organizations/actions/orgs.ts index 00f35fea978..595477addee 100644 --- a/ui/src/organizations/actions/orgs.ts +++ b/ui/src/organizations/actions/orgs.ts @@ -4,6 +4,7 @@ import {push, RouterAction} from 'react-router-redux' // APIs import {client, getErrorMessage} from 'src/utils/api' +import * as api from 'src/client' // Actions import {notify} from 'src/shared/actions/notifications' @@ -22,8 +23,12 @@ import { } from 'src/shared/copy/notifications' // Types -import {Bucket} from '@influxdata/influx' -import {Organization, RemoteDataState, NotificationAction} from 'src/types' +import { + Organization, + RemoteDataState, + NotificationAction, + Bucket, +} from 'src/types' export enum ActionTypes { SetOrgs = 'SET_ORGS', @@ -132,9 +137,17 @@ export const getOrganizations = () => async ( try { dispatch(setOrgsStatus(RemoteDataState.Loading)) - const organizations = await client.organizations.getAll() - dispatch(setOrgs(organizations, RemoteDataState.Done)) - return organizations + const resp = await api.getOrgs({}) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + const {orgs} = resp.data + + dispatch(setOrgs(orgs, RemoteDataState.Done)) + + return orgs } catch (e) { console.error(e) dispatch(setOrgs(null, RemoteDataState.Error)) @@ -150,7 +163,12 @@ export const createOrgWithBucket = ( let createdOrg: Organization try { - createdOrg = await client.organizations.create(org) + const orgResp = await api.postOrg({data: org}) + if (orgResp.status !== 201) { + throw new Error(orgResp.data.message) + } + createdOrg = orgResp.data + await client.templates.create({ ...defaultTemplates.systemTemplate(), orgID: createdOrg.id, @@ -168,11 +186,14 @@ export const createOrgWithBucket = ( dispatch(addOrg(createdOrg)) dispatch(push(`/orgs/${createdOrg.id}`)) - await client.buckets.create({ - ...bucket, - orgID: createdOrg.id, + const bucketResp = await api.postBucket({ + data: {...bucket, orgID: createdOrg.id}, }) + if (bucketResp.status !== 201) { + throw new Error(bucketResp.data.message) + } + dispatch(notify(bucketCreateSuccess())) } catch (e) { console.error(e) @@ -189,7 +210,14 @@ export const createOrg = (org: Organization) => async ( dispatch: Dispatch ): Promise => { try { - const createdOrg = await client.organizations.create(org) + const resp = await api.postOrg({data: org}) + + if (resp.status !== 201) { + throw new Error(resp.data.message) + } + + const createdOrg = resp.data + await client.templates.create({ ...defaultTemplates.systemTemplate(), orgID: createdOrg.id, @@ -209,7 +237,12 @@ export const deleteOrg = (org: Organization) => async ( dispatch: Dispatch ): Promise => { try { - await client.organizations.delete(org.id) + const resp = await api.deleteOrg({orgID: org.id}) + + if (resp.status !== 204) { + throw new Error(resp.data.message) + } + dispatch(removeOrg(org)) } catch (e) { console.error(e) @@ -220,8 +253,16 @@ export const updateOrg = (org: Organization) => async ( dispatch: Dispatch ) => { try { - const updatedOrg = await client.organizations.update(org.id, org) + const resp = await api.patchOrg({orgID: org.id, data: org}) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + const updatedOrg = resp.data + dispatch(editOrg(updatedOrg)) + dispatch(notify(orgEditSuccess())) } catch (e) { dispatch(notify(orgEditFailed())) @@ -233,8 +274,16 @@ export const renameOrg = (originalName: string, org: Organization) => async ( dispatch: Dispatch ) => { try { - const updatedOrg = await client.organizations.update(org.id, org) + const resp = await api.patchOrg({orgID: org.id, data: org}) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + const updatedOrg = resp.data + dispatch(editOrg(updatedOrg)) + dispatch(notify(orgRenameSuccess(updatedOrg.name))) } catch (e) { dispatch(notify(orgRenameFailed(originalName))) diff --git a/ui/src/organizations/apis/index.ts b/ui/src/organizations/apis/index.ts index 0761093d5ee..e1ef368b693 100644 --- a/ui/src/organizations/apis/index.ts +++ b/ui/src/organizations/apis/index.ts @@ -4,8 +4,7 @@ import _ from 'lodash' import {client} from 'src/utils/api' // Types -import {Organization} from '@influxdata/influx' -import {Dashboard} from 'src/types' +import {Dashboard, Organization} from 'src/types' // CRUD APIs for Organizations and Organization resources // i.e. Organization Members, Buckets, Dashboards etc diff --git a/ui/src/organizations/components/CreateOrgOverlay.tsx b/ui/src/organizations/components/CreateOrgOverlay.tsx index 593f9f790f6..ed684f60dc1 100644 --- a/ui/src/organizations/components/CreateOrgOverlay.tsx +++ b/ui/src/organizations/components/CreateOrgOverlay.tsx @@ -9,8 +9,7 @@ import _ from 'lodash' import {Form, Input, Button, Overlay} from '@influxdata/clockface' // Types -import {Organization} from '@influxdata/influx' -import {Bucket} from 'src/types' +import {Bucket, Organization} from 'src/types' import { ButtonType, ComponentColor, diff --git a/ui/src/organizations/components/RenameOrgForm.tsx b/ui/src/organizations/components/RenameOrgForm.tsx index dbc3ebcd5da..b6fa4c3285c 100644 --- a/ui/src/organizations/components/RenameOrgForm.tsx +++ b/ui/src/organizations/components/RenameOrgForm.tsx @@ -24,9 +24,8 @@ import {ErrorHandling} from 'src/shared/decorators/errors' import {renameOrg} from 'src/organizations/actions/orgs' // Types -import {Organization} from '@influxdata/influx' import {ComponentStatus} from '@influxdata/clockface' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { startOrg: Organization diff --git a/ui/src/organizations/containers/OrgProfilePage.tsx b/ui/src/organizations/containers/OrgProfilePage.tsx index 2ce1b2b2552..0ee23be37a8 100644 --- a/ui/src/organizations/containers/OrgProfilePage.tsx +++ b/ui/src/organizations/containers/OrgProfilePage.tsx @@ -12,8 +12,7 @@ import TabbedPageSection from 'src/shared/components/tabbed_page/TabbedPageSecti import {Grid, Columns} from '@influxdata/clockface' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' import OrgProfileTab from '../components/OrgProfileTab' interface StateProps { diff --git a/ui/src/pageLayout/components/AccountNavSubItem.tsx b/ui/src/pageLayout/components/AccountNavSubItem.tsx index a2d432cd190..dd959f6737f 100644 --- a/ui/src/pageLayout/components/AccountNavSubItem.tsx +++ b/ui/src/pageLayout/components/AccountNavSubItem.tsx @@ -4,10 +4,12 @@ import {Link} from 'react-router' // Components import {NavMenu} from '@influxdata/clockface' -import {Organization} from '@influxdata/influx' import SortingHat from 'src/shared/components/sorting_hat/SortingHat' import CloudExclude from 'src/shared/components/cloud/CloudExclude' +// Types +import {Organization} from 'src/types' + interface Props { orgs: Organization[] isShowingOrganizations: boolean diff --git a/ui/src/pageLayout/containers/Nav.tsx b/ui/src/pageLayout/containers/Nav.tsx index a5857eb1196..4e26b600422 100644 --- a/ui/src/pageLayout/containers/Nav.tsx +++ b/ui/src/pageLayout/containers/Nav.tsx @@ -16,9 +16,8 @@ import {FeatureFlag} from 'src/shared/utils/featureFlag' import {getNavItemActivation} from 'src/pageLayout/utils' // Types -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' import {IconFont} from '@influxdata/clockface' -import {Organization} from '@influxdata/influx' // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' diff --git a/ui/src/scrapers/containers/ScrapersIndex.tsx b/ui/src/scrapers/containers/ScrapersIndex.tsx index aa36b366c52..04d7275e3e1 100644 --- a/ui/src/scrapers/containers/ScrapersIndex.tsx +++ b/ui/src/scrapers/containers/ScrapersIndex.tsx @@ -15,8 +15,7 @@ import Scrapers from 'src/scrapers/components/Scrapers' import {ErrorHandling} from 'src/shared/decorators/errors' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/shared/containers/RouteToOrg.tsx b/ui/src/shared/containers/RouteToOrg.tsx index d70a3ee8b2d..4416b923b3a 100644 --- a/ui/src/shared/containers/RouteToOrg.tsx +++ b/ui/src/shared/containers/RouteToOrg.tsx @@ -4,8 +4,7 @@ import {connect} from 'react-redux' import {WithRouterProps} from 'react-router' // Types -import {AppState} from 'src/types' -import {Organization} from '@influxdata/influx' +import {AppState, Organization} from 'src/types' // Decorators diff --git a/ui/src/shared/containers/SetOrg.tsx b/ui/src/shared/containers/SetOrg.tsx index d2ba60bade2..c4cadf89914 100644 --- a/ui/src/shared/containers/SetOrg.tsx +++ b/ui/src/shared/containers/SetOrg.tsx @@ -3,8 +3,7 @@ import React, {useEffect, useState, FunctionComponent} from 'react' import {connect} from 'react-redux' // Types -import {AppState} from 'src/types' -import {Organization} from '@influxdata/influx' +import {AppState, Organization} from 'src/types' // Actions import {setOrg as setOrgAction} from 'src/organizations/actions/orgs' diff --git a/ui/src/telegrafs/components/CollectorCard.tsx b/ui/src/telegrafs/components/CollectorCard.tsx index de7c7a58878..18554cb219f 100644 --- a/ui/src/telegrafs/components/CollectorCard.tsx +++ b/ui/src/telegrafs/components/CollectorCard.tsx @@ -7,7 +7,6 @@ import {withRouter, WithRouterProps, Link} from 'react-router' import {Context} from 'src/clockface' import {ResourceCard, IconFont} from '@influxdata/clockface' import {ComponentColor} from '@influxdata/clockface' -import {ITelegraf as Telegraf, Organization} from '@influxdata/influx' import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels' // Actions @@ -24,8 +23,8 @@ import {viewableLabels} from 'src/labels/selectors' import {DEFAULT_COLLECTOR_NAME} from 'src/dashboards/constants' // Types -import {AppState} from 'src/types' -import {ILabel} from '@influxdata/influx' +import {AppState, Organization} from 'src/types' +import {ILabel, ITelegraf as Telegraf} from '@influxdata/influx' interface OwnProps { collector: Telegraf diff --git a/ui/src/telegrafs/containers/TelegrafsPage.tsx b/ui/src/telegrafs/containers/TelegrafsPage.tsx index 7b286598526..096445b80c2 100644 --- a/ui/src/telegrafs/containers/TelegrafsPage.tsx +++ b/ui/src/telegrafs/containers/TelegrafsPage.tsx @@ -1,7 +1,6 @@ // Libraries import React, {PureComponent} from 'react' import {connect} from 'react-redux' -import {AppState} from 'src/types' // Components import {ErrorHandling} from 'src/shared/decorators/errors' @@ -14,7 +13,7 @@ import TabbedPageSection from 'src/shared/components/tabbed_page/TabbedPageSecti import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Types -import {Organization} from '@influxdata/influx' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization diff --git a/ui/src/templates/containers/TemplatesIndex.tsx b/ui/src/templates/containers/TemplatesIndex.tsx index 907e896ba94..34896df4283 100644 --- a/ui/src/templates/containers/TemplatesIndex.tsx +++ b/ui/src/templates/containers/TemplatesIndex.tsx @@ -12,8 +12,7 @@ import TabbedPageSection from 'src/shared/components/tabbed_page/TabbedPageSecti import TemplatesPage from 'src/templates/components/TemplatesPage' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' interface StateProps { diff --git a/ui/src/types/members.ts b/ui/src/types/members.ts index c46705ce9c0..4d1663455cd 100644 --- a/ui/src/types/members.ts +++ b/ui/src/types/members.ts @@ -1,3 +1,3 @@ -import {ResourceMember, ResourceOwner} from '@influxdata/influx' +import {ResourceMember, ResourceOwner} from 'src/client' export type Member = ResourceMember | ResourceOwner diff --git a/ui/src/types/orgs.ts b/ui/src/types/orgs.ts index 0969ab0bcbb..2fce469d9c2 100644 --- a/ui/src/types/orgs.ts +++ b/ui/src/types/orgs.ts @@ -1,3 +1 @@ -import {Organization as OrgsAPI} from '@influxdata/influx' - -export interface Organization extends OrgsAPI {} +export {Organization} from 'src/client' diff --git a/ui/src/variables/containers/VariablesIndex.tsx b/ui/src/variables/containers/VariablesIndex.tsx index 27ed9811a19..f4bf876949f 100644 --- a/ui/src/variables/containers/VariablesIndex.tsx +++ b/ui/src/variables/containers/VariablesIndex.tsx @@ -13,8 +13,7 @@ import VariablesTab from 'src/variables/components/VariablesTab' import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Types -import {Organization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Organization} from 'src/types' interface StateProps { org: Organization