Skip to content

Commit 5c04d41

Browse files
jwasiakJarosław Wasiak
andauthored
fix: fix no display in filter drawer previous boolean and reference values (#1258)(@jwasiak)
* fix: no display in filter drawer previous boolean and reference values * Update filter.tsx Co-authored-by: Jarosław Wasiak <jaroslaw.wasiak@rst.com.pl>
1 parent 680c6fb commit 5c04d41

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/frontend/components/property-type/base-property-props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RecordJSON, ResourceJSON, PropertyJSON, PropertyPlace } from '../../int
33
import { BasePropertyJSON } from '../../interfaces/property-json/property-json.interface'
44

55
export type SelectRecord = {
6-
value: string;
6+
value: string | number;
77
label: string;
88
}
99

src/frontend/components/property-type/boolean/filter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Filter extends React.PureComponent<FilterPropertyProps> {
1818

1919
render(): ReactNode {
2020
const { property, filter = {} } = this.props
21-
const value = typeof filter[property.path] === 'undefined' ? '' : filter[property.path]
21+
const value = typeof filter[property.path] === 'undefined' ? '' : Boolean(filter[property.path])
2222
const options = [
2323
{ value: true, label: mapValue(true) },
2424
{ value: false, label: mapValue(false) },

src/frontend/components/property-type/reference/filter.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,46 @@ import ApiClient from '../../../utils/api-client'
55
import { FilterPropertyProps, SelectRecord } from '../base-property-props'
66

77
type CombinedProps = FilterPropertyProps
8+
type FilterState = {
9+
options: Array<SelectRecord>
10+
}
811

9-
class Filter extends React.PureComponent<CombinedProps> {
12+
class Filter extends React.PureComponent<CombinedProps, FilterState> {
1013
private api: ApiClient
1114

12-
private options: Array<SelectRecord>
13-
1415
constructor(props: CombinedProps) {
1516
super(props)
1617
this.api = new ApiClient()
17-
this.options = []
1818
this.loadOptions = this.loadOptions.bind(this)
1919
this.handleChange = this.handleChange.bind(this)
20+
this.state = {
21+
options: [],
22+
}
2023
}
2124

2225
handleChange(selected: SelectRecord): void {
2326
const { onChange, property } = this.props
2427
onChange(property.path, selected ? selected.value : '')
2528
}
2629

27-
async loadOptions(inputValue: string): Promise<Array<{value: string; label: string }>> {
30+
async loadOptions(inputValue: string): Promise<Array<{value: string | number; label: string }>> {
2831
const { property } = this.props
2932
const records = await this.api.searchRecords({
3033
resourceId: property.reference as string,
3134
query: inputValue,
3235
})
33-
this.options = records.map((r) => ({ value: r.id, label: r.title }))
34-
return this.options
36+
const options = records.map((r) => ({ value: r.id, label: r.title }))
37+
this.setState({
38+
options,
39+
})
40+
return options
3541
}
3642

3743
render(): ReactNode {
3844
const { property, filter } = this.props
45+
const { options } = this.state
3946
const value = typeof filter[property.path] === 'undefined' ? '' : filter[property.path]
40-
const selected = (this.options || []).find((o) => o.value === value)
47+
const selected = (options || []).find((o) => String(o.value) === String(value))
4148
return (
4249
<FormGroup>
4350
<Label>{property.label}</Label>

0 commit comments

Comments
 (0)