Skip to content

Commit

Permalink
feat(sampledata): Allow users to query buckets in 'other' org (#17207)
Browse files Browse the repository at this point in the history
* feat(sampledata): Query appropriate org in queries

* feat(sampledata): Add bucket resource fetching to Dashboard and DE

* feat(sampledata): Get orgID from query in refreshing view

* feat(sampledata): Be the change you want to see

* feat(sampledata): Only use loading state if resource has not been loaded before

* feat(sampledata )Get buckets from api endpoint rather than through query

* feat(sampledata): Direct load tag selector and values queries to correct org

* feat(sampledata): Protect against buckets that have no orgID.
  • Loading branch information
ebb-tide authored Mar 12, 2020
1 parent 9090517 commit 1ce19b5
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 86 deletions.
13 changes: 11 additions & 2 deletions ui/src/authorizations/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import {
NotificationAction,
Authorization,
AuthEntities,
ResourceType,
} from 'src/types'

// Selectors
import {getOrg} from 'src/organizations/selectors'
import {getStatus} from 'src/resources/selectors'

type GetAuthorizations = (
dispatch: Dispatch<Action | NotificationAction>,
Expand All @@ -50,8 +52,15 @@ export const getAuthorizations = () => async (
getState: GetState
) => {
try {
dispatch(setAuthorizations(RemoteDataState.Loading))
const org = getOrg(getState())
const state = getState()
if (
getStatus(state, ResourceType.Authorizations) ===
RemoteDataState.NotStarted
) {
dispatch(setAuthorizations(RemoteDataState.Loading))
}

const org = getOrg(state)
const resp = await api.getAuthorizations({query: {orgID: org.id}})

if (resp.status !== 200) {
Expand Down
10 changes: 7 additions & 3 deletions ui/src/buckets/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
Bucket,
BucketEntities,
Label,
ResourceType,
} from 'src/types'

// Utils
import {getErrorMessage} from 'src/utils/api'
import {getOrg} from 'src/organizations/selectors'
import {getLabels, getStatus} from 'src/resources/selectors'

// Actions
import {
Expand All @@ -46,7 +48,6 @@ import {
addBucketLabelFailed,
removeBucketLabelFailed,
} from 'src/shared/copy/notifications'
import {getLabels} from 'src/resources/selectors'

type Action = BucketAction | NotifyAction

Expand All @@ -55,8 +56,11 @@ export const getBuckets = () => async (
getState: GetState
) => {
try {
dispatch(setBuckets(RemoteDataState.Loading))
const org = getOrg(getState())
const state = getState()
if (getStatus(state, ResourceType.Buckets) === RemoteDataState.NotStarted) {
dispatch(setBuckets(RemoteDataState.Loading))
}
const org = getOrg(state)

const resp = await api.getBuckets({query: {orgID: org.id}})

Expand Down
2 changes: 1 addition & 1 deletion ui/src/buckets/components/BucketsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import {prettyBuckets} from 'src/shared/utils/prettyBucket'
import {extractBucketLimits} from 'src/cloud/utils/limits'
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'

// Types
import {
Expand All @@ -51,7 +52,6 @@ import {
ResourceType,
} from 'src/types'
import {SortTypes} from 'src/shared/utils/sort'
import {getAll} from 'src/resources/selectors'

interface StateProps {
org: Organization
Expand Down
9 changes: 6 additions & 3 deletions ui/src/checks/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {reportError} from 'src/shared/utils/errors'
import {createView} from 'src/views/helpers'
import {getOrg} from 'src/organizations/selectors'
import {toPostCheck, builderToPostCheck} from 'src/checks/utils'
import {getAll} from 'src/resources/selectors'
import {getAll, getStatus} from 'src/resources/selectors'

// Actions
import {
Expand Down Expand Up @@ -66,8 +66,11 @@ export const getChecks = () => async (
getState: GetState
) => {
try {
dispatch(setChecks(RemoteDataState.Loading))
const {id: orgID} = getOrg(getState())
const state = getState()
if (getStatus(state, ResourceType.Checks) === RemoteDataState.NotStarted) {
dispatch(setChecks(RemoteDataState.Loading))
}
const {id: orgID} = getOrg(state)

const resp = await api.getChecks({query: {orgID}})

Expand Down
13 changes: 10 additions & 3 deletions ui/src/dashboards/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {getSaveableView} from 'src/timeMachine/selectors'
import {incrementCloneName} from 'src/utils/naming'
import {isLimitError} from 'src/cloud/utils/limits'
import {getOrg} from 'src/organizations/selectors'
import {getAll, getByID} from 'src/resources/selectors'
import {getAll, getByID, getStatus} from 'src/resources/selectors'

// Constants
import * as copy from 'src/shared/copy/notifications'
Expand Down Expand Up @@ -193,10 +193,17 @@ export const getDashboards = () => async (
getState: GetState
): Promise<void> => {
try {
const org = getOrg(getState())
const {setDashboards} = creators

dispatch(setDashboards(RemoteDataState.Loading))
const state = getState()
if (
getStatus(state, ResourceType.Dashboards) === RemoteDataState.NotStarted
) {
dispatch(setDashboards(RemoteDataState.Loading))
}

const org = getOrg(state)

const resp = await api.getDashboards({query: {orgID: org.id}})

if (resp.status !== 200) {
Expand Down
9 changes: 6 additions & 3 deletions ui/src/dashboards/components/DashboardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {connect} from 'react-redux'

// Components
import GetResource from 'src/resources/components/GetResource'
import GetResources from 'src/resources/components/GetResources'
import DashboardPage from 'src/dashboards/components/DashboardPage'
import GetTimeRange from 'src/dashboards/components/GetTimeRange'
import DashboardRoute from 'src/shared/components/DashboardRoute'
Expand Down Expand Up @@ -43,9 +44,11 @@ const DashboardContainer: FC<Props> = ({autoRefresh, dashboard, children}) => {
return (
<DashboardRoute>
<GetResource resources={[{type: ResourceType.Dashboards, id: dashboard}]}>
<GetTimeRange />
<DashboardPage autoRefresh={autoRefresh} />
{children}
<GetResources resources={[ResourceType.Buckets]}>
<GetTimeRange />
<DashboardPage autoRefresh={autoRefresh} />
{children}
</GetResources>
</GetResource>
</DashboardRoute>
)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dataExplorer/components/DataExplorerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DataExplorerPage: SFC = ({children}) => {
return (
<Page titleTag={pageTitleSuffixer(['Data Explorer'])}>
{children}
<GetResources resources={[ResourceType.Variables]}>
<GetResources resources={[ResourceType.Variables, ResourceType.Buckets]}>
<Page.Header fullWidth={true}>
<Page.Title title="Data Explorer" />
</Page.Header>
Expand Down
20 changes: 16 additions & 4 deletions ui/src/dataLoaders/actions/telegrafEditor.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import {Bucket} from 'src/types'
import {getTelegrafPlugins} from 'src/client'
import {RemoteDataState} from 'src/types'
import {Dispatch} from 'react'

import {getTelegrafPlugins} from 'src/client'

import {
TelegrafEditorPluginState,
TelegrafEditorActivePluginState,
TelegrafEditorBasicPlugin,
} from 'src/dataLoaders/reducers/telegrafEditor'

// Utils

// Types
import {Bucket, RemoteDataState, ResourceType, GetState} from 'src/types'
import {getStatus} from 'src/resources/selectors'

export type PluginResourceAction =
| ReturnType<typeof setPlugins>
| ReturnType<typeof setPluginLoadingState>

export const getPlugins = () => async (
dispatch: Dispatch<PluginResourceAction>
dispatch: Dispatch<PluginResourceAction>,
getState: GetState
) => {
const state = getState()
if (getStatus(state, ResourceType.Plugins) === RemoteDataState.NotStarted) {
dispatch(setPluginLoadingState(RemoteDataState.Loading))
}

dispatch(setPluginLoadingState(RemoteDataState.Loading))

const result = await getTelegrafPlugins({}, {})
Expand Down
10 changes: 8 additions & 2 deletions ui/src/labels/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GetState,
Label,
LabelEntities,
ResourceType,
} from 'src/types'

// Actions
Expand All @@ -40,14 +41,19 @@ import {
// Utils
import {getOrg} from 'src/organizations/selectors'
import {viewableLabels} from 'src/labels/selectors'
import {getStatus} from 'src/resources/selectors'

export const getLabels = () => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
try {
const org = getOrg(getState())
dispatch(setLabels(RemoteDataState.Loading))
const state = getState()
if (getStatus(state, ResourceType.Labels) === RemoteDataState.NotStarted) {
dispatch(setLabels(RemoteDataState.Loading))
}

const org = getOrg(state)

const resp = await apiGetLabels({query: {orgID: org.id}})

Expand Down
20 changes: 15 additions & 5 deletions ui/src/members/actions/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Libraries
import {Dispatch} from 'react'
import {get} from 'lodash'
import {normalize} from 'normalizr'

Expand All @@ -7,10 +8,14 @@ import * as api from 'src/client'
import {memberSchema, arrayOfMembers} from 'src/schemas'

// Types
import {RemoteDataState, GetState} from 'src/types'
import {
RemoteDataState,
GetState,
Member,
MemberEntities,
ResourceType,
} from 'src/types'
import {AddResourceMemberRequestBody} from '@influxdata/influx'
import {Dispatch} from 'react'
import {Member, MemberEntities} from 'src/types'

// Actions
import {
Expand All @@ -29,14 +34,19 @@ import {

// Selectors
import {getOrg} from 'src/organizations/selectors'
import {getStatus} from 'src/resources/selectors'

export const getMembers = () => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
try {
const {id} = getOrg(getState())
dispatch(setMembers(RemoteDataState.Loading))
const state = getState()
if (getStatus(state, ResourceType.Members) === RemoteDataState.NotStarted) {
dispatch(setMembers(RemoteDataState.Loading))
}

const {id} = getOrg(state)

const [ownersResp, membersResp] = await Promise.all([
api.getOrgsOwners({orgID: id}),
Expand Down
12 changes: 9 additions & 3 deletions ui/src/notifications/endpoints/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as api from 'src/client'
// Utils
import {incrementCloneName} from 'src/utils/naming'
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'
import {getAll, getStatus} from 'src/resources/selectors'
import {toPostNotificationEndpoint} from 'src/notifications/endpoints/utils'
import * as copy from 'src/shared/copy/notifications'

Expand All @@ -50,9 +50,15 @@ export const getEndpoints = () => async (
getState: GetState
) => {
try {
dispatch(setEndpoints(RemoteDataState.Loading))
const state = getState()
if (
getStatus(state, ResourceType.NotificationEndpoints) ===
RemoteDataState.NotStarted
) {
dispatch(setEndpoints(RemoteDataState.Loading))
}

const {id: orgID} = getOrg(getState())
const {id: orgID} = getOrg(state)

const resp = await api.getNotificationEndpoints({
query: {orgID},
Expand Down
14 changes: 11 additions & 3 deletions ui/src/notifications/rules/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {setLabelOnResource} from 'src/labels/actions/creators'
// Utils
import {draftRuleToPostRule} from 'src/notifications/rules/utils'
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'
import {getAll, getStatus} from 'src/resources/selectors'

// Types
import {
Expand All @@ -54,8 +54,16 @@ export const getNotificationRules = () => async (
getState: GetState
) => {
try {
dispatch(setRules(RemoteDataState.Loading))
const {id: orgID} = getOrg(getState())
const state = getState()
if (
getStatus(state, ResourceType.NotificationRules) ===
RemoteDataState.NotStarted
) {
dispatch(setRules(RemoteDataState.Loading))
}

const {id: orgID} = getOrg(state)

const resp = await api.getNotificationRules({query: {orgID}})

if (resp.status !== 200) {
Expand Down
17 changes: 15 additions & 2 deletions ui/src/scrapers/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {client} from 'src/utils/api'
import {arrayOfScrapers, scraperSchema} from 'src/schemas'

// Types
import {RemoteDataState, GetState, Scraper, ScraperEntities} from 'src/types'
import {
RemoteDataState,
GetState,
Scraper,
ScraperEntities,
ResourceType,
} from 'src/types'
import {Dispatch} from 'react'

// Actions
Expand All @@ -32,6 +38,7 @@ import {

// Selectors
import {getOrg} from 'src/organizations/selectors'
import {getStatus} from 'src/resources/selectors'

type Action = ScraperAction | NotifyAction

Expand All @@ -40,7 +47,13 @@ export const getScrapers = () => async (
getState: GetState
) => {
try {
const org = getOrg(getState())
const state = getState()
if (
getStatus(state, ResourceType.Scrapers) === RemoteDataState.NotStarted
) {
dispatch(setScrapers(RemoteDataState.Loading))
}
const org = getOrg(state)

dispatch(setScrapers(RemoteDataState.Loading))

Expand Down
Loading

0 comments on commit 1ce19b5

Please sign in to comment.