Skip to content

Commit

Permalink
[PLAY-1465] Fix Linting Errors - Typeahead Kit (#4091)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
This story fixes the typeahead kit linting errors. 

Ran yarn eslint --fix for each file other than the index file and none
of the warnings were corrected. I believe them to be unsafe changes and
will require manual intervention.

**Screenshots:** Screenshots to visualize your addition/change

**How to test?** Steps to confirm the desired behavior:
1. Go to 'Typeahead kit page
2. Should still work as expected


#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
- [ ] **TESTS** I have added test coverage to my code.
  • Loading branch information
Tomm1128 authored Jan 10, 2025
1 parent 477ba28 commit e2b0411
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 33 deletions.
5 changes: 3 additions & 2 deletions playbook/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type TypeaheadProps = {
id?: string,
label?: string,
loadOptions?: string | Noop,
getOptionLabel?: string | (() => any),
getOptionValue?: string | (() => any),
getOptionLabel?: string | (() => string),
getOptionValue?: string | (() => string),
name?: string,
marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
pillColor?: "primary" | "neutral" | "success" | "warning" | "error" | "info" | "data_1" | "data_2" | "data_3" | "data_4" | "data_5" | "data_6" | "data_7" | "data_8" | "windows" | "siding" | "roofing" | "doors" | "gutters" | "solar" | "insulation" | "accessories",
Expand Down Expand Up @@ -109,6 +109,7 @@ const Typeahead = ({
multiKit: '',
onCreateOption: null as null,
plusIcon: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onMultiValueClick: (_option: SelectValueType): any => undefined,
pillColor: pillColor,
...props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import React, { useEffect } from 'react'
import { components } from 'react-select'

const ClearContainer = (props: any) => {
type ClearContainerProps = {
children: React.ReactNode,
selectProps?: {
id: string,
},
clearValue: () => void,
}

const ClearContainer = (props: ClearContainerProps): React.ReactElement => {
const { selectProps, clearValue } = props
useEffect(() => {
document.addEventListener(`pb-typeahead-kit-${selectProps.id}:clear`, clearValue)
}, [true])
}, [clearValue, selectProps.id])

return (
<components.ClearIndicator
className="clear_indicator"
{...props}
className="clear_indicator"
{...props}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import Flex from '../../pb_flex/_flex'
import TextInput from '../../pb_text_input/_text_input'

type Props = {
selectProps: any,
selectProps: {
dark?: boolean,
label: string,
error?: string,
},
}

const TypeaheadControl = (props: Props) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from 'react'
import { components } from 'react-select'

const IndicatorsContainer = (props: any) => (
type IndicatorsContainerProps = {
children: React.ReactNode,
}


const IndicatorsContainer = (props: IndicatorsContainerProps): React.ReactElement => (
<components.IndicatorsContainer
className="text_input_indicators"
{...props}
className="text_input_indicators"
{...props}
/>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react'
import { components } from 'react-select'

const MenuList = (props: any) => {
type MenuListProps = {
children: React.ReactNode,
footer: React.ReactNode,
}

const MenuList = (props: MenuListProps): React.ReactElement => {
return (
<components.MenuList {...props}>
{props.children}
Expand Down
27 changes: 21 additions & 6 deletions playbook/app/pb_kits/playbook/pb_typeahead/components/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ import { components } from 'react-select'

import User from '../../pb_user/_user'

const Option = (props: any) => {
type OptionProps = {
children: React.ReactNode,
label?: string,
data: {
imageUrl?: string,
},
selectProps: {
dark?: boolean,
valueComponent?: (data: {
imageUrl?: string,
}) => React.ReactNode,
},
}


const Option = (props: OptionProps): React.ReactElement => {
const {
imageUrl,
} = props.data
Expand All @@ -14,11 +29,11 @@ const Option = (props: any) => {
<>
{!valueComponent && imageUrl &&
<User
align="left"
avatarUrl={imageUrl}
dark={props.selectProps.dark}
name={props.label}
orientation="horizontal"
align="left"
avatarUrl={imageUrl}
dark={props.selectProps.dark}
name={props.label}
orientation="horizontal"
/>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import { components } from 'react-select'
import Flex from '../../pb_flex/_flex'
import Icon from '../../pb_icon/_icon'

const Placeholder = (props: any) => (
type PlaceholderProps = {
children: React.ReactNode,
selectProps: {
plusIcon?: boolean,
},
}

const Placeholder = (props: PlaceholderProps): React.ReactElement => (
<>
<Flex
align="center"
className="placeholder"
align="center"
className="placeholder"
>
<components.IndicatorsContainer
{...props}
{...props}
/>
{props.selectProps.plusIcon &&
<Icon
className="typeahead-plus-icon"
icon="plus"
className="typeahead-plus-icon"
icon="plus"
/>
}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react'
import { components } from 'react-select'

const ValueContainer = (props: any) => (
type ValueContainerProps = {
children: React.ReactNode,
}

const ValueContainer = (props: ValueContainerProps): React.ReactElement => (
<components.ValueContainer
className="text_input_value_container"
{...props}
className="text_input_value_container"
{...props}
/>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react/no-multi-comp */

import React, { useState } from 'react'

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const promiseOptions = (inputValue) =>

const TypeaheadWithPillsAsync = (props) => {
const [users, setUsers] = useState([])
const handleOnChange = (value) => setUsers(formatUsers(value))
const formatValue = (users) => formatUsers(users)

const formatUsers = (users) => {
const results = () => (users.map((user) => {
if (Object.keys(user)[0] === 'name' || Object.keys(user)[1] === 'id'){
Expand All @@ -58,6 +57,9 @@ const TypeaheadWithPillsAsync = (props) => {
return results()
}

const handleOnChange = (value) => setUsers(formatUsers(value))
const formatValue = (users) => formatUsers(users)

return (
<>
{users && users.length > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ const TypeaheadWithPillsAsyncCustomOptions = (props) => {
onChange={handleOnChange}
onMultiValueClick={handleOnMultiValueClick}
placeholder="type the name of a Github user"
valueComponent={(props) => (
valueComponent={({imageUrl, label, territory, type}) => (
<User
avatar
avatarUrl={props.imageUrl}
name={props.label}
territory={props.territory}
title={props.type}
avatarUrl={imageUrl}
name={label}
territory={territory}
title={type}
/>
)}
{...props}
Expand Down

0 comments on commit e2b0411

Please sign in to comment.