Skip to content

Add support for "new items" facet.#4996

Draft
EreMaijala wants to merge 4 commits into
vufind-org:devfrom
EreMaijala:dev-new-items-facet
Draft

Add support for "new items" facet.#4996
EreMaijala wants to merge 4 commits into
vufind-org:devfrom
EreMaijala:dev-new-items-facet

Conversation

@EreMaijala
Copy link
Copy Markdown
Contributor

TODO:

  • Decide what, if anything, to do with current new item form and results actions.
  • Add tests.

@EreMaijala EreMaijala requested a review from demiankatz January 12, 2026 09:12
Copy link
Copy Markdown
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this started, @EreMaijala. I haven't had a chance to do any hands-on testing or to review everything carefully, but see below for a few minor things.

I'll comment further when I have a bit more time!

Comment on lines +1993 to +1998
* @param string|object|array $target String to translate or an array of text
* domain and string to translate
* @param array $tokens Tokens to inject into the translated
* string
* @param string $default Default value to use if no translation is
* found (null for no default).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting suggestions:

Suggested change
* @param string|object|array $target String to translate or an array of text
* domain and string to translate
* @param array $tokens Tokens to inject into the translated
* string
* @param string $default Default value to use if no translation is
* found (null for no default).
* @param string|object|array $target String to translate or an array of text
* domain and string to translate
* @param array $tokens Tokens to inject into the translated string
* @param string $default Default value to use if no translation is
* found (null for no default).

*
* @return string
*/
public function replaceFacet($field, $value, $operator = 'AND')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well add types to new methods...

Suggested change
public function replaceFacet($field, $value, $operator = 'AND')
public function replaceFacet(string $field, string $value, string $operator = 'AND'): static

* @param string $value Facet value
* @param string $operator Facet type to add (AND, OR, NOT)
*
* @return string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this isn't returning a string...

Suggested change
* @return string
* @return static

"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
"peer": true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This random change again!

Suggested change
"peer": true,

Copy link
Copy Markdown
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EreMaijala, I spent a little more time reviewing this today (at long last). See below for further comments.

Also, some other notes:

1.) I pushed up commit f47fa71 which is a quick-and-dirty proof of concept of redirecting from the Solr-based specialty "new items results" to a standard filtered search. If we want to do things this way, more cleanup is needed, and some other things need consideration:

a.) The [NewItem] filter setting generates hidden filters, which might make sense when "New Items" is a separate result screen, but is only going to confuse people if we integrate it with regular search. Should we just translate these hidden filters into non-hidden ones for clarity?

b.) The new item facets are currently implemented as OR facets, but this means weird things happen in the search results, because you can't de-select them normally. This appears to be an existing problem, but we may want to deal with it one way or another.

2.) I wonder if the new item control should be more tolerant of non-standard values -- that is, if a filter comes in from some other place, should we display it in the facet list as a de-selectable value, or should we keep it invisible as present. (E.g. if I apply a new item filter but then change the URL to use a non-standard number of days, the filter shows up correctly in the filter list but is ignored in the facet list sidebar).

* @param string $date Date
* @param string $domain Translation domain
*
* @return string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return string
* @return array

*
* @return string
*/
protected function formatNewItemsDateForDisplay($date, $domain)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function formatNewItemsDateForDisplay($date, $domain)
protected function formatNewItemsDateForDisplay(string $date, string $domain): array

}

/**
* Format a Solr date for display
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand this comment to explain the return value... because at present, I don't entirely understand what the second Boolean value is doing.

*
* @return array
*/
protected function formatNewItemsFilterListEntry($field, $value, $operator, $translate): array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function formatNewItemsFilterListEntry($field, $value, $operator, $translate): array
protected function formatNewItemsFilterListEntry(
string $field,
string $value,
string $operator,
bool $translate
): array

<li class="facet__list__item">
<?php
$addURL = $results->getUrlQuery()->replaceFacet($facet, $newItemsFilter);
$removeURL = $results->getUrlQuery()->removeFacet($facet, $newItemsFilter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make these $addUrl and $removeUrl for consistency with $toggleUrl? Seems weird to have two different styles close together, and I think the Url pattern is more common in the code at this point.

@demiankatz
Copy link
Copy Markdown
Member

I'm not sure why the Dependency Review action is failing; I suspect it's an intermittent issue that will go away if we try later.

@demiankatz
Copy link
Copy Markdown
Member

@EreMaijala, I think this one may have slipped through the cracks. I also see there are now some conflicts that need to be resolved. Please let me know if I can be of any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants