Skip to content

Commit

Permalink
Merge pull request #229 from alleyinteractive/revert-205-feature/TECH…
Browse files Browse the repository at this point in the history
…-93/filterable-max-posts

Take 2 of "Adds filter to control max number of posts in query block"
  • Loading branch information
ellm authored Dec 2, 2024
2 parents fe49de5 + 7727fbe commit ab5409f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `WP Curate` will be documented in this file.

## 2.4.4 - 2024-12-02

- Restore maxNumberOfPosts attribute with a default filterable value of maxPosts.

## 2.4.3 - 2024-11-18

- Enhancement: Post Title block (which allows title overrides for pinned posts) works in Subquery block.
Expand Down
4 changes: 4 additions & 0 deletions blocks/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
],
"type": "string"
},
"maxNumberOfPosts": {
"type": "number",
"default": 10
},
"minNumberOfPosts": {
"default": 1,
"type": "number"
Expand Down
8 changes: 5 additions & 3 deletions blocks/query/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface Window {
allowedPostTypes: PostTypeOrTerm[];
allowedTaxonomies: PostTypeOrTerm[];
parselyAvailable: string,
maxPosts: number,
maxPosts: string,
};
}

Expand All @@ -51,6 +51,7 @@ export default function Edit({
attributes: {
backfillPosts = [],
deduplication = 'inherit',
maxNumberOfPosts = 10,
minNumberOfPosts = 1,
numberOfPosts = 5,
offset = 0,
Expand All @@ -72,7 +73,7 @@ export default function Edit({
allowedPostTypes = [],
allowedTaxonomies = [],
parselyAvailable = 'false',
maxPosts = 10,
maxPosts = '10',
} = {},
} = (window as any as Window);

Expand Down Expand Up @@ -257,7 +258,8 @@ export default function Edit({
displayTypes={displayTypes}
isPostDeduplicating={isPostDeduplicating}
manualPosts={manualPosts}
maxPosts={maxPosts}
maxPosts={parseInt(maxPosts, 10)}
maxNumberOfPosts={maxNumberOfPosts}
minNumberOfPosts={minNumberOfPosts}
numberOfPosts={numberOfPosts}
offset={offset}
Expand Down
1 change: 1 addition & 0 deletions blocks/query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interface EditProps {
attributes: {
backfillPosts?: number[];
deduplication?: string;
maxNumberOfPosts?: number;
minNumberOfPosts?: number;
numberOfPosts?: number;
offset?: number;
Expand Down
6 changes: 5 additions & 1 deletion blocks/subquery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
],
"type": "string"
},
"maxNumberOfPosts": {
"type": "number",
"default": 10
},
"minNumberOfPosts": {
"default": 1,
"type": "number"
Expand Down Expand Up @@ -113,4 +117,4 @@
"type": "array"
}
}
}
}
2 changes: 2 additions & 0 deletions blocks/subquery/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function Edit({
attributes: {
backfillPosts = [],
deduplication = 'inherit',
maxNumberOfPosts = 10,
minNumberOfPosts = 1,
numberOfPosts = 5,
offset = 0,
Expand Down Expand Up @@ -258,6 +259,7 @@ export default function Edit({
isPostDeduplicating={isPostDeduplicating}
manualPosts={manualPosts}
maxPosts={maxPosts}
maxNumberOfPosts={maxNumberOfPosts}
minNumberOfPosts={minNumberOfPosts}
numberOfPosts={numberOfPosts}
offset={offset}
Expand Down
10 changes: 7 additions & 3 deletions components/QueryControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type QueryControlsProps = {
isPostDeduplicating: boolean;
manualPosts: Array<number | null>;
maxPosts: number;
maxNumberOfPosts: number;
minNumberOfPosts: number;
numberOfPosts: number;
offset: number;
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function QueryControls({
isPostDeduplicating,
manualPosts,
maxPosts,
maxNumberOfPosts: maxNumberOfPostsAttr,
minNumberOfPosts,
numberOfPosts,
offset,
Expand All @@ -84,6 +86,8 @@ export default function QueryControls({
},
];

const maxNumberOfPosts = !maxNumberOfPostsAttr || maxNumberOfPostsAttr > maxPosts ? maxPosts : maxNumberOfPostsAttr; // eslint-disable-line max-len

const setTerms = ((type: string, newTerms: Term[]) => {
const cleanedTerms = newTerms.map((term) => (
{
Expand All @@ -110,7 +114,7 @@ export default function QueryControls({

const setNumberOfPosts = (newValue?: number) => {
setAttributes({
numberOfPosts: newValue,
numberOfPosts: (newValue && newValue > maxNumberOfPosts) ? maxNumberOfPosts : newValue,
posts: manualPosts.slice(0, newValue),
});
};
Expand All @@ -132,14 +136,14 @@ export default function QueryControls({
title={__('Setup', 'wp-curate')}
initialOpen
>
{minNumberOfPosts !== undefined && minNumberOfPosts !== maxPosts ? (
{minNumberOfPosts !== undefined && minNumberOfPosts !== maxNumberOfPosts ? (
<RangeControl
label={__('Number of Posts', 'wp-curate')}
help={__('The maximum number of posts to show.', 'wp-curate')}
value={numberOfPosts}
onChange={setNumberOfPosts}
min={minNumberOfPosts}
max={maxPosts}
max={maxNumberOfPosts}
/>
) : null}
<RangeControl
Expand Down

0 comments on commit ab5409f

Please sign in to comment.