Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui): use locally generated client for buckets and orgs #14531

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ui/src/authorizations/containers/TokensIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ui/src/buckets/containers/BucketsIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ui/src/dashboards/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboards/components/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
AppState,
AutoRefresh,
AutoRefreshStatus,
Organization,
} from 'src/types'
import {RemoteDataState} from 'src/types'
import {WithRouterProps} from 'react-router'
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions ui/src/labels/containers/LabelsIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 29 additions & 5 deletions ui/src/members/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))
Expand All @@ -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)))
Expand All @@ -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)))
Expand Down
3 changes: 1 addition & 2 deletions ui/src/members/containers/MembersIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/src/onboarding/components/CompletionAdvancedButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
14 changes: 11 additions & 3 deletions ui/src/onboarding/components/CompletionStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'

Expand All @@ -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<Props> {
Expand Down
77 changes: 63 additions & 14 deletions ui/src/organizations/actions/orgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand All @@ -168,10 +186,13 @@ export const createOrgWithBucket = (
dispatch(addOrg(createdOrg))
dispatch(push(`/orgs/${createdOrg.id}`))

await client.buckets.create({
...bucket,
orgID: createdOrg.id,
})
bucket.orgID = createdOrg.id
desa marked this conversation as resolved.
Show resolved Hide resolved

const bucketResp = await api.postBucket({data: bucket})

if (bucketResp.status !== 201) {
throw new Error(bucketResp.data.message)
}

dispatch(notify(bucketCreateSuccess()))
} catch (e) {
Expand All @@ -189,7 +210,14 @@ export const createOrg = (org: Organization) => async (
dispatch: Dispatch<Actions | RouterAction | NotificationAction>
): Promise<void> => {
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,
Expand All @@ -209,7 +237,12 @@ export const deleteOrg = (org: Organization) => async (
dispatch: Dispatch<RemoveOrg>
): Promise<void> => {
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)
Expand All @@ -220,8 +253,16 @@ export const updateOrg = (org: Organization) => async (
dispatch: Dispatch<EditOrg | NotificationAction>
) => {
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()))
Expand All @@ -233,8 +274,16 @@ export const renameOrg = (originalName: string, org: Organization) => async (
dispatch: Dispatch<EditOrg | NotificationAction>
) => {
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)))
Expand Down
3 changes: 1 addition & 2 deletions ui/src/organizations/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ui/src/organizations/components/CreateOrgOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ui/src/organizations/components/RenameOrgForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ui/src/organizations/containers/OrgProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion ui/src/pageLayout/components/AccountNavSubItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ui/src/pageLayout/containers/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions ui/src/scrapers/containers/ScrapersIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading