Skip to content

Commit 51fca9c

Browse files
authored
feat(ecommerce): Add Account Type Dropdown to Operator UI (#4218)
* ✨ Add Account Type Dropdown to Operator * ✨ Format dropdown and add to organizations list * 🏷️ Add type to `useState` in operator * 🏷️ Replace `string` with `AccountType` * 🏷️ Update operator types * 🔧 Use new SHA for `openapi` * 🏷️ Use `type` instead of `JSON.parse` * 🏷️ Update type for operator `setAccountType` function
1 parent 699bf9b commit 51fca9c

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"cy": "CYPRESS_dexUrl=https://$INGRESS_HOST:$PORT_HTTPS CYPRESS_baseUrl=http://localhost:9999 cypress open",
5353
"cy:dev": "source ../monitor-ci/.env && CYPRESS_dexUrl=CLOUD CYPRESS_baseUrl=https://$INGRESS_HOST:$PORT_HTTPS cypress open --config testFiles='{cloud,shared}/**/*.*'",
5454
"cy:dev-oss": "source ../monitor-ci/.env && CYPRESS_dexUrl=OSS CYPRESS_baseUrl=https://$INGRESS_HOST:$PORT_HTTPS cypress open --config testFiles='{oss,shared}/**/*.*'",
55-
"generate": "export SHA=8823ef7b35fe7096856fa903649f7986ff31ef2e && export REMOTE=https://raw.githubusercontent.com/influxdata/openapi/${SHA}/ && yarn generate-meta",
55+
"generate": "export SHA=1a800fb92ad8ed86e28365c4fd5ac43ff193c303 && export REMOTE=https://raw.githubusercontent.com/influxdata/openapi/${SHA}/ && yarn generate-meta",
5656
"generate-local": "export REMOTE=../openapi/ && yarn generate-meta",
5757
"generate-meta": "if [ -z \"${CLOUD_URL}\" ]; then yarn generate-meta-oss; else yarn generate-meta-cloud; fi",
5858
"generate-meta-oss": "yarn oss-api && yarn notebooks && yarn unity && yarn annotations-oss && yarn pinned && yarn mapsd-oss && yarn cloudPriv && yarn fluxdocs && yarn subscriptions-oss",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
ComponentColor,
3+
DropdownMenuTheme,
4+
MultiSelectDropdown,
5+
} from '@influxdata/clockface'
6+
import React, {FC, useContext} from 'react'
7+
import {OperatorContext} from './context/operator'
8+
import {AccountType} from 'src/types'
9+
10+
const allAccountTypes: AccountType[] = [
11+
'cancelled',
12+
'contract',
13+
'free',
14+
'pay_as_you_go',
15+
]
16+
17+
const ResourcesAccountType: FC = () => {
18+
const {accountTypes, setAccountTypes} = useContext(OperatorContext)
19+
20+
const handleSelect = (selectedOption: AccountType): void =>
21+
accountTypes.includes(selectedOption)
22+
? setAccountTypes(prev => prev.filter(x => x !== selectedOption))
23+
: setAccountTypes(prev => [selectedOption, ...prev])
24+
25+
return (
26+
<MultiSelectDropdown
27+
style={{width: '220px', marginRight: '20px'}}
28+
options={allAccountTypes}
29+
selectedOptions={accountTypes}
30+
onSelect={(value: AccountType) => handleSelect(value)}
31+
menuTheme={DropdownMenuTheme.Onyx}
32+
emptyText="Account Types"
33+
buttonColor={ComponentColor.Primary}
34+
/>
35+
)
36+
}
37+
38+
export default ResourcesAccountType

src/operator/ResourcesTable.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
ComponentSize,
77
Tabs,
88
Orientation,
9+
FlexBox,
10+
FlexDirection,
911
} from '@influxdata/clockface'
1012

1113
// Components
@@ -26,6 +28,7 @@ import {OperatorRoutes} from 'src/operator/constants'
2628

2729
// Types
2830
import {OperatorOrg, OperatorAccount} from 'src/types'
31+
import ResourcesAccountType from './ResourcesAccountType'
2932

3033
const ResourcesTable: FC = () => {
3134
const {pathname, accounts, organizations, status} = useContext(
@@ -46,7 +49,10 @@ const ResourcesTable: FC = () => {
4649
<Tabs.Container orientation={Orientation.Horizontal}>
4750
<OperatorTabs />
4851
<Tabs.TabContents>
49-
<ResourcesSearchbar />
52+
<FlexBox direction={FlexDirection.Row}>
53+
<ResourcesAccountType />
54+
<ResourcesSearchbar />
55+
</FlexBox>
5056
<PageSpinner loading={status}>
5157
{resources?.length ? (
5258
<Table>

src/operator/context/operator.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {getAccountsError, getOrgsError} from 'src/shared/copy/notifications'
1010
import {getQuartzMe} from 'src/me/selectors'
1111

1212
// Types
13-
import {OperatorAccount, OperatorOrg, RemoteDataState} from 'src/types'
13+
import {
14+
AccountType,
15+
OperatorAccount,
16+
OperatorOrg,
17+
RemoteDataState,
18+
} from 'src/types'
1419

1520
// Constants
1621
import {OperatorRoutes} from 'src/operator/constants'
@@ -21,6 +26,10 @@ export type Props = {
2126

2227
export interface OperatorContextType {
2328
accounts: OperatorAccount[]
29+
accountTypes: AccountType[]
30+
setAccountTypes: (
31+
accountTypes: AccountType[] | ((prevState: AccountType[]) => AccountType[])
32+
) => void
2433
handleGetAccounts: () => void
2534
handleGetOrgs: () => void
2635
organizations: OperatorOrg[]
@@ -33,6 +42,8 @@ export interface OperatorContextType {
3342

3443
export const DEFAULT_CONTEXT: OperatorContextType = {
3544
accounts: [],
45+
accountTypes: [],
46+
setAccountTypes: () => {},
3647
handleGetAccounts: () => {},
3748
handleGetOrgs: () => {},
3849
organizations: [],
@@ -52,6 +63,7 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
5263
const [accountStatus, setAccountStatus] = useState(RemoteDataState.NotStarted)
5364
const [orgsStatus, setOrgsStatus] = useState(RemoteDataState.NotStarted)
5465
const [searchTerm, setSearchTerm] = useState('')
66+
const [accountTypes, setAccountTypes] = useState<AccountType[]>([])
5567
const dispatch = useDispatch()
5668
const quartzMe = useSelector(getQuartzMe)
5769

@@ -63,6 +75,7 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
6375
const resp = await getOperatorAccounts({
6476
query: {
6577
query: searchTerm,
78+
accountTypes,
6679
},
6780
})
6881

@@ -77,12 +90,14 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
7790
dispatch(notify(getAccountsError()))
7891
console.error({error})
7992
}
80-
}, [searchTerm, dispatch])
93+
}, [accountTypes, searchTerm, dispatch])
8194

8295
const handleGetOrgs = useCallback(async () => {
8396
try {
8497
setOrgsStatus(RemoteDataState.Loading)
85-
const resp = await getOperatorOrgs({query: {query: searchTerm}})
98+
const resp = await getOperatorOrgs({
99+
query: {query: searchTerm, accountTypes},
100+
})
86101

87102
if (resp.status !== 200) {
88103
throw new Error(resp.data.message)
@@ -95,7 +110,7 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
95110
setOrgsStatus(RemoteDataState.Error)
96111
dispatch(notify(getOrgsError()))
97112
}
98-
}, [searchTerm, dispatch])
113+
}, [accountTypes, searchTerm, dispatch])
99114

100115
const {pathname} = useLocation()
101116

@@ -134,6 +149,8 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
134149
<OperatorContext.Provider
135150
value={{
136151
accounts,
152+
accountTypes,
153+
setAccountTypes,
137154
handleGetAccounts,
138155
handleGetOrgs,
139156
organizations,

0 commit comments

Comments
 (0)