Skip to content

Commit

Permalink
Add more documentation and update the code
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Feb 12, 2024
1 parent c15bd48 commit cf5f336
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,13 @@ used by other hooks to return a specific set of entities based on their configur

## `useQueryViewablePostTypes`

This hook is a subset of the `useEntitiesRecords` hook. It is used to retrieve the list of the viewable post types.

## `useQueryViewableTaxonomies`

This hook is a subset of the `useEntitiesRecords` hook. It is used to retrieve the list of the viewable taxonomies.

## `useSearch`

This hook will return a throttled function to search for the entities.

3 changes: 3 additions & 0 deletions sources/client/src/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import apiFetch from '@wordpress/api-fetch';

/**
* @internal
*/
export const fetch = apiFetch;
6 changes: 6 additions & 0 deletions sources/client/src/components/composite-entities-by-kind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { orderSelectedOptionsAtTheTop } from '../utils/order-selected-options-at
import { uniqueControlOptions } from '../utils/unique-control-options';
import { Set } from '../vo/set';

/**
* A composite component that provides a way to search for entities by kind.
*
* @public
* @param props The component props.
*/
export function CompositeEntitiesByKind<E, K>(
props: EntitiesSearch.CompositeEntitiesKinds<E, K>
): JSX.Element {
Expand Down
5 changes: 5 additions & 0 deletions sources/client/src/hooks/use-entities-options-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type _Reducer<E, K> = Reducer<
EntitiesSearch.StoreAction<E, K>
>;

/**
* @public
* @param initialState The initial state configuration
* @param searchEntities The function that will search the entities
*/
export function useEntitiesOptionsStorage<E, K>(
initialState: Pick<EntitiesSearch.EntitiesState<E, K>, 'entities' | 'kind'>,
searchEntities: EntitiesSearch.SearchEntitiesFunction<E, K>
Expand Down
2 changes: 1 addition & 1 deletion sources/client/src/hooks/use-entity-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ResolveStatus {
* This is to guarantee a better flow in the data manipulation, therefore do not count on the data returned by the
* `records()` as an indicator of the hook status.
*
* @internal
* @public
* @param kind The kind of entity to fetch. E.g. 'root', 'postType', 'taxonomy', etc.
* @param name The name of the entity to fetch. E.g. 'post', 'page', 'category', etc.
* @param queryArgs The query args to pass to the entity fetch. E.g. { per_page: 100 }
Expand Down
10 changes: 10 additions & 0 deletions sources/client/src/hooks/use-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { Set } from '../vo/set';
type SearchPhrase = Parameters<EntitiesSearch.SearchControl['onChange']>[0];
type SearchFunc = (phrase: SearchPhrase) => void;

/**
* Build a function to search the entities by a phrase
*
* @public
* @param setSearchPhrase A function to set the search phrase
* @param searchEntities The function that will search the entities
* @param kind The kind of entities to search
* @param entities The entities to exclude from the search
* @param dispatch The dispatch function to update the state
*/
export function useSearch<E, K>(
setSearchPhrase: (search: string) => void,
searchEntities: EntitiesSearch.SearchEntitiesFunction<E, K>,
Expand Down
1 change: 0 additions & 1 deletion sources/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './api/fetch';
export * from './api/search-entities';

export * from './components/composite-entities-by-kind';
Expand Down

0 comments on commit cf5f336

Please sign in to comment.