Improving the value selector performance, only initializing it on activation
This commit is contained in:
parent
31cd68bade
commit
7368edc160
3 changed files with 35 additions and 1 deletions
|
@ -71,6 +71,7 @@ export default class PropertyValueElement extends React.Component<Props, State>
|
|||
}
|
||||
return (
|
||||
<ValueSelector
|
||||
emptyValue={emptyDisplayValue}
|
||||
options={propertyTemplate.options}
|
||||
value={propertyTemplate.options.find((p) => p.id === propertyValue)}
|
||||
onChange={(value) => {
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
background-color: rgba(var(--main-fg), 0.1),
|
||||
}
|
||||
|
||||
> .octo-label {
|
||||
margin: 0 10px;
|
||||
&.empty {
|
||||
color: rgba(var(--main-fg), 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
.value-menu-option {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
|
|
|
@ -19,6 +19,7 @@ import './valueSelector.scss'
|
|||
type Props = {
|
||||
options: IPropertyOption[]
|
||||
value: IPropertyOption;
|
||||
emptyValue: string;
|
||||
onCreate?: (value: string) => void
|
||||
onChange?: (value: string) => void
|
||||
onChangeColor?: (option: IPropertyOption, color: string) => void
|
||||
|
@ -26,7 +27,18 @@ type Props = {
|
|||
intl: IntlShape
|
||||
}
|
||||
|
||||
class ValueSelector extends React.Component<Props> {
|
||||
type State = {
|
||||
activated: boolean
|
||||
}
|
||||
|
||||
class ValueSelector extends React.Component<Props, State> {
|
||||
public constructor(props: Props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
activated: false,
|
||||
}
|
||||
}
|
||||
|
||||
public shouldComponentUpdate(): boolean {
|
||||
return true
|
||||
}
|
||||
|
@ -65,6 +77,18 @@ class ValueSelector extends React.Component<Props> {
|
|||
}
|
||||
|
||||
public render(): JSX.Element {
|
||||
if (!this.state.activated) {
|
||||
return (
|
||||
<div
|
||||
className='ValueSelector'
|
||||
onClick={() => this.setState({activated: true})}
|
||||
>
|
||||
<span className={`octo-label ${this.props.value ? this.props.value.color : 'empty'}`}>
|
||||
{this.props.value ? this.props.value.value : this.props.emptyValue}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<CreatableSelect
|
||||
styles={{
|
||||
|
@ -119,6 +143,8 @@ class ValueSelector extends React.Component<Props> {
|
|||
autoFocus={true}
|
||||
value={this.props.value}
|
||||
closeMenuOnSelect={true}
|
||||
placeholder={this.props.emptyValue}
|
||||
defaultMenuIsOpen={true}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue