|
| 1 | +// Libraries |
| 2 | +import React, {useContext} from 'react' |
| 3 | +import {useSelector} from 'react-redux' |
| 4 | +import {useHistory} from 'react-router-dom' |
| 5 | +import {ORGS} from 'src/shared/constants/routes' |
| 6 | +import {searchClients} from 'src/writeData' |
| 7 | + |
| 8 | +// Utils |
| 9 | +import {getOrg} from 'src/organizations/selectors' |
| 10 | +import {event} from 'src/cloud/utils/reporting' |
| 11 | + |
| 12 | +// Contexts |
| 13 | +import {WriteDataSearchContext} from 'src/writeData/containers/WriteDataPage' |
| 14 | + |
| 15 | +// Components |
| 16 | +import { |
| 17 | + SquareGrid, |
| 18 | + ComponentSize, |
| 19 | + Heading, |
| 20 | + HeadingElement, |
| 21 | + FontWeight, |
| 22 | +} from '@influxdata/clockface' |
| 23 | +import WriteDataItem from 'src/writeData/components/WriteDataItem' |
| 24 | + |
| 25 | +const ClientLibrarySectionSql = () => { |
| 26 | + const {searchTerm} = useContext(WriteDataSearchContext) |
| 27 | + const items = searchClients(searchTerm) |
| 28 | + |
| 29 | + const history = useHistory() |
| 30 | + const org = useSelector(getOrg) |
| 31 | + |
| 32 | + const onBoardingItems = { |
| 33 | + python: 'python', |
| 34 | + } |
| 35 | + |
| 36 | + if (!items.length) { |
| 37 | + return null |
| 38 | + } |
| 39 | + |
| 40 | + return ( |
| 41 | + <div |
| 42 | + className="write-data--section" |
| 43 | + data-testid="write-data--section client-libraries" |
| 44 | + > |
| 45 | + <Heading |
| 46 | + element={HeadingElement.H2} |
| 47 | + weight={FontWeight.Regular} |
| 48 | + style={{marginTop: '24px', marginBottom: '4px'}} |
| 49 | + > |
| 50 | + Client Libraries |
| 51 | + </Heading> |
| 52 | + <Heading |
| 53 | + element={HeadingElement.H5} |
| 54 | + weight={FontWeight.Regular} |
| 55 | + style={{marginBottom: '24px'}} |
| 56 | + > |
| 57 | + Back-end, front-end, and mobile applications |
| 58 | + </Heading> |
| 59 | + <SquareGrid cardSize="170px" gutter={ComponentSize.Small}> |
| 60 | + {items.map(item => { |
| 61 | + const goto = () => { |
| 62 | + event('Load data client library clicked', {type: item.name}) |
| 63 | + if (onBoardingItems.hasOwnProperty(`${item.id}`)) { |
| 64 | + return history.push( |
| 65 | + `/${ORGS}/${org.id}/new-user-setup/${onBoardingItems[item.id]}` |
| 66 | + ) |
| 67 | + } |
| 68 | + } |
| 69 | + if (onBoardingItems.hasOwnProperty(`${item.id}`)) { |
| 70 | + return ( |
| 71 | + <WriteDataItem |
| 72 | + key={item.id} |
| 73 | + id={item.id} |
| 74 | + name={item.name} |
| 75 | + image={item.logo} |
| 76 | + onClick={goto} |
| 77 | + /> |
| 78 | + ) |
| 79 | + } |
| 80 | + })} |
| 81 | + </SquareGrid> |
| 82 | + </div> |
| 83 | + ) |
| 84 | +} |
| 85 | + |
| 86 | +export default ClientLibrarySectionSql |
0 commit comments