Merge pull request #11682 from influxdata/feat/switch-sources-client-library
Switch sources api calls to clientpull/11688/head
commit
36d866d20a
|
@ -829,9 +829,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"@influxdata/influx": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.7.tgz",
|
||||
"integrity": "sha512-n7YuYSj/lr2KCpTs6HysJfCT9yFDrFsxz7JVKtAdGr1m1QEUtEBLP016MRXEc+VQSYbPb3zZ4C8zbtu7RpbicA==",
|
||||
"version": "0.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.9.tgz",
|
||||
"integrity": "sha512-AoOK71N/jUqAJxGVFZ2quPe79eeDvtZuzF0ITzg4HXeVDZJrdWL2c1HeF/gbS1OOQcMj4UGFMXUzzeSpRaXY4g==",
|
||||
"requires": {
|
||||
"axios": "^0.18.0"
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@influxdata/react-custom-scrollbars": "4.3.8",
|
||||
"@influxdata/influx": "^0.1.7",
|
||||
"@influxdata/influx": "^0.1.9",
|
||||
"axios": "^0.18.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"bignumber.js": "^4.0.2",
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from 'src/logs/utils/logQuery'
|
||||
|
||||
// APIs
|
||||
import {readSource} from 'src/sources/apis'
|
||||
import {client} from 'src/utils/api'
|
||||
import {executeQueryAsync} from 'src/logs/api/v2'
|
||||
|
||||
// Data
|
||||
|
@ -301,7 +301,7 @@ export const populateBucketsAsync = () => async (): Promise<void> => {}
|
|||
export const getSourceAndPopulateBucketsAsync = (id: string) => async (
|
||||
dispatch
|
||||
): Promise<void> => {
|
||||
const source = await readSource(id)
|
||||
const source = await client.sources.get(id)
|
||||
|
||||
dispatch(setSource(source))
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import {notify} from 'src/shared/actions/notifications'
|
|||
import {client} from 'src/utils/api'
|
||||
|
||||
// Types
|
||||
import {SetupParams} from 'src/onboarding/apis'
|
||||
import {ISetupParams} from '@influxdata/influx'
|
||||
|
||||
export type Action =
|
||||
| SetSetupParams
|
||||
|
@ -18,10 +18,10 @@ export type Action =
|
|||
|
||||
interface SetSetupParams {
|
||||
type: 'SET_SETUP_PARAMS'
|
||||
payload: {setupParams: SetupParams}
|
||||
payload: {setupParams: ISetupParams}
|
||||
}
|
||||
|
||||
export const setSetupParams = (setupParams: SetupParams): SetSetupParams => ({
|
||||
export const setSetupParams = (setupParams: ISetupParams): SetSetupParams => ({
|
||||
type: 'SET_SETUP_PARAMS',
|
||||
payload: {setupParams},
|
||||
})
|
||||
|
@ -62,7 +62,7 @@ export const setBucketID = (bucketID: string): SetBucketID => ({
|
|||
payload: {bucketID},
|
||||
})
|
||||
|
||||
export const setupAdmin = (params: SetupParams) => async dispatch => {
|
||||
export const setupAdmin = (params: ISetupParams) => async dispatch => {
|
||||
try {
|
||||
dispatch(setSetupParams(params))
|
||||
const response = await client.setup.create(params)
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// Libraries
|
||||
import _ from 'lodash'
|
||||
|
||||
// Utils
|
||||
import {sourcesAPI} from 'src/utils/api'
|
||||
|
||||
export interface SetupParams {
|
||||
username: string
|
||||
password: string
|
||||
org: string
|
||||
bucket: string
|
||||
}
|
||||
|
||||
export const trySources = async (): Promise<boolean> => {
|
||||
try {
|
||||
await sourcesAPI.sourcesGet('')
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Sign in has failed', error)
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -27,9 +27,9 @@ import * as copy from 'src/shared/copy/notifications'
|
|||
// Types
|
||||
import {StepStatus} from 'src/clockface/constants/wizard'
|
||||
import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard'
|
||||
import {SetupParams} from 'src/onboarding/apis'
|
||||
import {ISetupParams} from '@influxdata/influx'
|
||||
|
||||
interface State extends SetupParams {
|
||||
interface State extends ISetupParams {
|
||||
confirmPassword: string
|
||||
isAlreadySet: boolean
|
||||
isPassMismatched: boolean
|
||||
|
|
|
@ -9,13 +9,13 @@ import CompletionStep from 'src/onboarding/components/CompletionStep'
|
|||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||
|
||||
// Types
|
||||
import {SetupParams} from 'src/onboarding/apis'
|
||||
import {ISetupParams} from '@influxdata/influx'
|
||||
import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard'
|
||||
import {setupAdmin} from 'src/onboarding/actions'
|
||||
|
||||
interface Props {
|
||||
onboardingStepProps: OnboardingStepProps
|
||||
setupParams: SetupParams
|
||||
setupParams: ISetupParams
|
||||
currentStepIndex: number
|
||||
onSetupAdmin: typeof setupAdmin
|
||||
orgID: string
|
||||
|
|
|
@ -22,7 +22,7 @@ import {StepStatus} from 'src/clockface/constants/wizard'
|
|||
|
||||
// Types
|
||||
import {Links} from 'src/types/v2/links'
|
||||
import {SetupParams} from 'src/onboarding/apis'
|
||||
import {ISetupParams} from '@influxdata/influx'
|
||||
import {Notification, NotificationFunc} from 'src/types'
|
||||
import {AppState} from 'src/types/v2'
|
||||
|
||||
|
@ -36,8 +36,8 @@ export interface OnboardingStepProps {
|
|||
onSetSubstepIndex: (index: number, subStep: number | 'streaming') => void
|
||||
stepStatuses: StepStatus[]
|
||||
stepTitles: string[]
|
||||
setupParams: SetupParams
|
||||
handleSetSetupParams: (setupParams: SetupParams) => void
|
||||
setupParams: ISetupParams
|
||||
handleSetSetupParams: (setupParams: ISetupParams) => void
|
||||
notify: (message: Notification | NotificationFunc) => void
|
||||
onCompleteSetup: () => void
|
||||
onExit: () => void
|
||||
|
@ -64,7 +64,7 @@ interface DispatchProps {
|
|||
interface StateProps {
|
||||
links: Links
|
||||
stepStatuses: StepStatus[]
|
||||
setupParams: SetupParams
|
||||
setupParams: ISetupParams
|
||||
orgID: string
|
||||
bucketID: string
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ import {StepStatus} from 'src/clockface/constants/wizard'
|
|||
|
||||
// Types
|
||||
import {Action} from 'src/onboarding/actions'
|
||||
import {SetupParams} from 'src/onboarding/apis'
|
||||
import {ISetupParams} from '@influxdata/influx'
|
||||
|
||||
export interface OnboardingState {
|
||||
stepStatuses: StepStatus[]
|
||||
setupParams: SetupParams
|
||||
setupParams: ISetupParams
|
||||
orgID: string
|
||||
bucketID: string
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import MockChild from 'mocks/MockChild'
|
|||
|
||||
import {source} from 'mocks/dummyData'
|
||||
|
||||
jest.mock('src/sources/apis', () => require('mocks/sources/apis'))
|
||||
|
||||
const onReadSources = jest.fn(() => Promise.resolve())
|
||||
|
||||
const setup = (override?) => {
|
||||
|
|
|
@ -2,12 +2,7 @@
|
|||
import {Dispatch} from 'redux'
|
||||
|
||||
// APIs
|
||||
import {
|
||||
readSources as readSourcesAJAX,
|
||||
createSource as createSourceAJAX,
|
||||
updateSource as updateSourceAJAX,
|
||||
deleteSource as deleteSourceAJAX,
|
||||
} from 'src/sources/apis'
|
||||
import {client} from 'src/utils/api'
|
||||
|
||||
// Types
|
||||
import {GetState} from 'src/types/v2'
|
||||
|
@ -70,17 +65,15 @@ export const removeSource = (sourceID: string): RemoveSourceAction => ({
|
|||
})
|
||||
|
||||
export const readSources = () => async (dispatch: Dispatch<Action>) => {
|
||||
const sources = await readSourcesAJAX()
|
||||
const sources = await client.sources.getAll()
|
||||
|
||||
dispatch(setSources(sources))
|
||||
}
|
||||
|
||||
export const createSource = (attrs: Partial<Source>) => async (
|
||||
dispatch: Dispatch<Action>,
|
||||
getState: GetState
|
||||
dispatch: Dispatch<Action>
|
||||
) => {
|
||||
const sourcesLink = getState().links.sources
|
||||
const source = await createSourceAJAX(sourcesLink, attrs)
|
||||
const source = await client.sources.create('', attrs)
|
||||
|
||||
dispatch(setSource(source))
|
||||
}
|
||||
|
@ -88,7 +81,7 @@ export const createSource = (attrs: Partial<Source>) => async (
|
|||
export const updateSource = (source: Source) => async (
|
||||
dispatch: Dispatch<Action>
|
||||
) => {
|
||||
const updatedSource = await updateSourceAJAX(source.id, source)
|
||||
const updatedSource = await client.sources.update(source.id, source)
|
||||
|
||||
dispatch(setSource(updatedSource))
|
||||
}
|
||||
|
@ -103,7 +96,7 @@ export const deleteSource = (sourceID: string) => async (
|
|||
throw new Error(`no source with ID "${sourceID}" exists`)
|
||||
}
|
||||
|
||||
await deleteSourceAJAX(source)
|
||||
await client.sources.delete(source.id)
|
||||
|
||||
dispatch(removeSource(sourceID))
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
import {Source} from 'src/api'
|
||||
import {sourcesAPI} from 'src/utils/api'
|
||||
|
||||
export const readSources = async (): Promise<Source[]> => {
|
||||
const {data} = await sourcesAPI.sourcesGet('')
|
||||
|
||||
return data.sources
|
||||
}
|
||||
|
||||
export const readSource = async (id: string): Promise<Source> => {
|
||||
const {data} = await sourcesAPI.sourcesSourceIDGet(id)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export const createSource = async (
|
||||
org: string,
|
||||
attributes: Partial<Source>
|
||||
): Promise<Source> => {
|
||||
const {data} = await sourcesAPI.sourcesPost(org, attributes)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export const updateSource = async (
|
||||
id: string,
|
||||
source: Partial<Source>
|
||||
): Promise<Source> => {
|
||||
const {data} = await sourcesAPI.sourcesSourceIDPatch(id, source)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteSource(source: Source): Promise<void> {
|
||||
await sourcesAPI.sourcesSourceIDDelete(source.id)
|
||||
}
|
||||
|
||||
export const getSourceHealth = async (id: string): Promise<void> => {
|
||||
await sourcesAPI.sourcesSourceIDHealthGet(id)
|
||||
}
|
|
@ -1,11 +1,4 @@
|
|||
import {
|
||||
DashboardsApi,
|
||||
CellsApi,
|
||||
ViewsApi,
|
||||
SourcesApi,
|
||||
QueryApi,
|
||||
ProtosApi,
|
||||
} from 'src/api'
|
||||
import {DashboardsApi, CellsApi, ViewsApi, QueryApi, ProtosApi} from 'src/api'
|
||||
|
||||
import Client from '@influxdata/influx'
|
||||
|
||||
|
@ -16,6 +9,5 @@ export const client = new Client(basePath)
|
|||
export const viewsAPI = new ViewsApi({basePath})
|
||||
export const dashboardsAPI = new DashboardsApi({basePath})
|
||||
export const cellsAPI = new CellsApi({basePath})
|
||||
export const sourcesAPI = new SourcesApi({basePath})
|
||||
export const queryAPI = new QueryApi({basePath})
|
||||
export const protosAPI = new ProtosApi({basePath})
|
||||
|
|
Loading…
Reference in New Issue