Skip to content

Commit

Permalink
Add back the defaults to avoid breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Feb 28, 2025
1 parent 49affb3 commit 1becd19
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
23 changes: 22 additions & 1 deletion packages/components/src/query-controls/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,35 @@ import CategorySelect from './category-select';
const DEFAULT_MIN_ITEMS = 1;
const DEFAULT_MAX_ITEMS = 100;

const defaultOrderByOptions = [
{
label: __( 'Newest to oldest' ),
value: 'date/desc',
},
{
label: __( 'Oldest to newest' ),
value: 'date/asc',
},
{
/* translators: Label for ordering posts by title in ascending order. */
label: __( 'A → Z' ),
value: 'title/asc',
},
{
/* translators: Label for ordering posts by title in descending order. */
label: __( 'Z → A' ),
value: 'title/desc',
},
];

const QueryControls = memo(
( {
categoriesList,
selectedCategoryId,
numberOfItems,
order,
orderBy,
orderByOptions,
orderByOptions = defaultOrderByOptions,
maxItems = DEFAULT_MAX_ITEMS,
minItems = DEFAULT_MIN_ITEMS,
onCategoryChange,
Expand Down
24 changes: 23 additions & 1 deletion packages/components/src/query-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
QueryControlsProps,
QueryControlsWithMultipleCategorySelectionProps,
QueryControlsWithSingleCategorySelectionProps,
OrderByOption,
} from './types';

const DEFAULT_MIN_ITEMS = 1;
Expand All @@ -34,6 +35,27 @@ function isMultipleCategorySelection(
return 'categorySuggestions' in props;
}

const defaultOrderByOptions: OrderByOption[] = [
{
label: __( 'Newest to oldest' ),
value: 'date/desc',
},
{
label: __( 'Oldest to newest' ),
value: 'date/asc',
},
{
/* translators: Label for ordering posts by title in ascending order. */
label: __( 'A → Z' ),
value: 'title/asc',
},
{
/* translators: Label for ordering posts by title in descending order. */
label: __( 'Z → A' ),
value: 'title/desc',
},
];

/**
* Controls to query for posts.
*
Expand Down Expand Up @@ -65,7 +87,7 @@ export function QueryControls( {
numberOfItems,
order,
orderBy,
orderByOptions,
orderByOptions = defaultOrderByOptions,
maxItems = DEFAULT_MAX_ITEMS,
minItems = DEFAULT_MIN_ITEMS,
onAuthorChange,
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/query-controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export type AuthorSelectProps = Pick<

type Order = 'asc' | 'desc';
type OrderBy = 'date' | 'title' | 'menu_order';
type OrderByOption = {

export type OrderByOption = {
/**
* The label to be shown to the user.
*/
Expand Down

0 comments on commit 1becd19

Please sign in to comment.