Skip to content

Commit

Permalink
Fix QA
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Nov 24, 2023
1 parent fe40b8c commit e8a0309
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 82 deletions.
12 changes: 7 additions & 5 deletions sources/js/src/components/composite-posts-post-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ export function CompositePostsPostTypes<P, T>(
};

const onChangePostType = (postType: T) => {
searchPostsByPostType('', postType);
setState({ ...state, postType, posts: Set([]) });
props.postType.onChange(postType);
props.posts.onChange(Set([]));
};

const searchPostsByPostType = async (phrase: string) => {
const searchPostsByPostType = async (phrase: string, postType: T) => {
if (!isFunction(props.searchPosts)) {
return Promise.resolve(Set([]));
return Promise.resolve(Set(props.posts.options));
}

return props
.searchPosts(phrase, state.postType)
.searchPosts(phrase, postType)
.then((newOptions) => {
const immutableOptions = Set(newOptions);
setPostsOptions(immutableOptions);
Expand All @@ -48,8 +49,9 @@ export function CompositePostsPostTypes<P, T>(
};

useEffect(() => {
searchPostsByPostType('');
}, [state.postType]);
searchPostsByPostType('', state.postType);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const posts: EntitiesSearch.PostsControl<P> = {
...props.posts,
Expand Down
3 changes: 2 additions & 1 deletion sources/js/src/components/post-type-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export function PostTypeRadio(
<div className={className}>
{props.options.map((option) => (
<div key={option.value} className="wz-posts-toggle-item">
<label>
<label htmlFor={`wz-post-type-radio-${option.value}`}>
<input
type="radio"
id={`wz-post-type-radio-${option.value}`}
checked={props.value === option.value}
value={option.value}
onChange={(event) =>
Expand Down
3 changes: 2 additions & 1 deletion sources/js/src/components/posts-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export function PostsToggle(
<div className={className}>
{props.options.map((option) => (
<div key={option.value} className="wz-posts-toggle-item">
<label>
<label htmlFor={`wz-post-type-toggle-${option.value}`}>
<input
type="checkbox"
id={`wz-post-type-toggle-${option.value}`}
checked={props.value?.has(option.value)}
value={option.value}
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ document.addEventListener('DOMContentLoaded', () => {

const {
searchPosts,
PostTypeSelect,
PostTypeRadio,
PostsSelect,
PostsToggle,
CompositePostsPostTypes,
useQueryViewablePostTypes,
Expand Down
73 changes: 0 additions & 73 deletions tests/js/unit/utils/is-control-option.test.ts

This file was deleted.

0 comments on commit e8a0309

Please sign in to comment.