Skip to content

Commit

Permalink
MNT Use React Testing Library
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 1, 2023
1 parent 09212e4 commit f2990cb
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 511 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions client/src/components/TagField.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class TagField extends Component {
if (!input) {
return Promise.resolve([]);
}

return this.fetchOptions(input);
}

Expand Down Expand Up @@ -152,20 +151,32 @@ class TagField extends Component {
}

render() {
const { lazyLoad, options, creatable, multi, disabled, labelKey, valueKey, ...passThroughAttributes } =
this.props;
const {
lazyLoad,
options,
creatable,
multi,
disabled,
labelKey,
valueKey,
SelectComponent,
AsyncCreatableSelectComponent,
AsyncSelectComponent,
CreatableSelectComponent,
...passThroughAttributes
} = this.props;

const optionAttributes = lazyLoad
? { loadOptions: this.getOptions }
: { options };

let SelectComponent = Select;
let DynamicSelect = SelectComponent;
if (lazyLoad && creatable) {
SelectComponent = AsyncCreatableSelect;
DynamicSelect = AsyncCreatableSelectComponent;
} else if (lazyLoad) {
SelectComponent = AsyncSelect;
DynamicSelect = AsyncSelectComponent;
} else if (creatable) {
SelectComponent = CreatableSelect;
DynamicSelect = CreatableSelectComponent;
}

// Update the value to passthrough with the kept state provided this component is not
Expand All @@ -190,7 +201,7 @@ class TagField extends Component {

return (
<EmotionCssCacheProvider>
<SelectComponent
<DynamicSelect
{...passThroughAttributes}
isMulti={multi}
isDisabled={disabled}
Expand Down Expand Up @@ -222,6 +233,10 @@ TagField.propTypes = {
value: PropTypes.any,
onChange: PropTypes.func,
onBlur: PropTypes.func,
SelectComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
AsyncCreatableSelectComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
AsyncSelectComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
CreatableSelectComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
};

TagField.defaultProps = {
Expand All @@ -231,6 +246,10 @@ TagField.defaultProps = {
lazyLoad: false,
creatable: false,
multi: false,
SelectComponent: Select,
AsyncCreatableSelectComponent: AsyncCreatableSelect,
AsyncSelectComponent: AsyncSelect,
CreatableSelectComponent: CreatableSelect,
};

export { TagField as Component };
Expand Down
Loading

0 comments on commit f2990cb

Please sign in to comment.