Skip to content

Commit 996d4be

Browse files
authored
Merge pull request #162 from PRO-Robotech/feature/dev
search: other inputs
2 parents f7c8b8a + 3a1ff83 commit 996d4be

File tree

2 files changed

+73
-8
lines changed

2 files changed

+73
-8
lines changed

src/components/molecules/Search/Search.tsx

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines-per-function */
22
import React, { FC, useState, useEffect } from 'react'
3-
import { Typography, Form, Select, SelectProps } from 'antd'
3+
import { Typography, Form, Select, SelectProps, Input } from 'antd'
44
import type { CustomTagProps } from 'rc-select/lib/BaseSelect'
55
import { useLocation, useSearchParams } from 'react-router-dom'
66
import { getKinds } from 'api/bff/search/getKinds'
@@ -20,10 +20,16 @@ export const Search: FC<TSearchProps> = ({ cluster }) => {
2020
const [searchParams, setSearchParams] = useSearchParams()
2121
const location = useLocation()
2222

23-
const FIELD_NAME = 'kinds' // the Form.Item name
23+
const FIELD_NAME = 'kinds'
24+
const FIELD_NAME_STRING = 'name'
25+
const FIELD_NAME_MULTIPLE = 'labels'
26+
const TYPE_SELECTOR = 'TYPE_SELECTOR'
2427
const QUERY_KEY = 'kinds' // the query param name
2528

2629
const watchedKinds = Form.useWatch<string[] | undefined>(FIELD_NAME, form)
30+
const watchedName = Form.useWatch<string | undefined>(FIELD_NAME_STRING, form)
31+
const watchedMultiple = Form.useWatch<string[] | undefined>(FIELD_NAME_MULTIPLE, form)
32+
const watchedTypedSelector = Form.useWatch<string | undefined>(TYPE_SELECTOR, form)
2733

2834
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2935
const [kindIndex, setKindIndex] = useState<TKindIndex>()
@@ -97,7 +103,7 @@ export const Search: FC<TSearchProps> = ({ cluster }) => {
97103
return (
98104
<Styled.CatContainer>
99105
<Form form={form} layout="vertical">
100-
<Styled.SelectContainer>
106+
<Styled.FormContainer>
101107
<Form.Item name={FIELD_NAME} label="Kinds">
102108
<Select
103109
mode="multiple"
@@ -109,9 +115,59 @@ export const Search: FC<TSearchProps> = ({ cluster }) => {
109115
tagRender={tagRender}
110116
/>
111117
</Form.Item>
112-
</Styled.SelectContainer>
113-
{/* Example of "watching" the value for display or side-effects */}
114-
<div>Current: {(watchedKinds || []).join(', ')}</div>
118+
<Form.Item name={TYPE_SELECTOR} label="Type">
119+
<Select
120+
placeholder="Select"
121+
options={[
122+
{ label: 'Name', value: 'name' },
123+
{ label: 'Labels', value: 'labels' },
124+
]}
125+
defaultValue="name"
126+
filterOption={filterSelectOptions}
127+
showSearch
128+
/>
129+
</Form.Item>
130+
<Styled.HideableContainer $isHidden={watchedTypedSelector === 'labels'}>
131+
<Form.Item name={FIELD_NAME_STRING} label="Name">
132+
<Input allowClear />
133+
</Form.Item>
134+
</Styled.HideableContainer>
135+
<Styled.HideableContainer $isHidden={watchedTypedSelector === 'name' || watchedTypedSelector === undefined}>
136+
<Form.Item
137+
name={FIELD_NAME_MULTIPLE}
138+
label="Labels"
139+
validateTrigger="onBlur"
140+
rules={[
141+
() => ({
142+
validator(_, value) {
143+
if (
144+
Array.isArray(value) &&
145+
value.every(str => typeof str === 'string' && str.includes('=') && !str.startsWith('='))
146+
) {
147+
return Promise.resolve()
148+
}
149+
return Promise.reject(new Error('Please enter key=value style'))
150+
},
151+
}),
152+
]}
153+
>
154+
<Select
155+
mode="tags"
156+
allowClear
157+
placeholder="Select"
158+
// dropdownStyle={{ display: 'none' }}
159+
tokenSeparators={[',', ' ', ' ']}
160+
suffixIcon={null}
161+
filterOption={filterSelectOptions}
162+
tagRender={tagRender}
163+
/>
164+
</Form.Item>
165+
</Styled.HideableContainer>
166+
{/* Example of "watching" the value for display or side-effects */}
167+
<div>Current: {(watchedKinds || []).join(', ')}</div>
168+
<div>Current name: {watchedName}</div>
169+
<div>Current labels: {(watchedMultiple || []).join(', ')}</div>
170+
</Styled.FormContainer>
115171
</Form>
116172
<Typography.Title>To Be Done</Typography.Title>
117173
</Styled.CatContainer>

src/components/molecules/Search/styled.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ const SelectTagSpan = styled.span`
2424
flex-direction: column;
2525
`
2626

27-
const SelectContainer = styled.div`
27+
const FormContainer = styled.div`
2828
width: 450px;
2929
`
3030

31+
type THideableContainerProps = {
32+
$isHidden?: boolean
33+
}
34+
35+
const HideableContainer = styled.div<THideableContainerProps>`
36+
display: ${({ $isHidden }) => ($isHidden ? 'none' : 'initial')};
37+
`
38+
3139
export const Styled = {
3240
CatContainer,
3341
SelectTag,
3442
SelectTagSpan,
35-
SelectContainer,
43+
FormContainer,
44+
HideableContainer,
3645
}

0 commit comments

Comments
 (0)