Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow comparing list sizes against a number #1530

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bitnimble
Copy link
Contributor

@bitnimble bitnimble commented Jan 24, 2025

This PR:

  • Creates new rule types, NUMBER_LIST and TEXT_LIST (I chose "list" to align with the term already used in the UI/copy)
  • Adds new rule actions for those rule types - COUNT_EQUALS, COUNT_NOT_EQUALS, COUNT_BIGGER, COUNT_SMALLER
  • Moves the existing rule possibilities/actions that were only applicable to lists from NUMBER and TEXT to the new rule types
  • Updates all existing rules that are lists to use the new RuleType
  • Adds tests, updates the frontend, etc to accommodate for the new rule type
  • Also does a small amount of cleanup of types, which was so I could make sure that I wasn't accidentally missing any cases when updating doRuleAction to support the new potential value types. I want to do a lot more cleanup here, but I'll do that in its own refactoring PR instead.

I think this requires no migration, since all rule actions that could have been applicable to list values previously are still valid on the new rule types (it is a superset). But I'm not 100% sure if I'm looking at the right place for how the rule actions are serialised and persisted.

image

image

Comment on lines -417 to +465
type: RuleType.NUMBER,
type: RuleType.NUMBER_LIST,
},
{
id: 9,
name: 'fileQuality',
humanName: '[list] File - quality (2160, 1080,..)',
mediaType: MediaType.MOVIE,
type: RuleType.NUMBER,
type: RuleType.NUMBER_LIST,
Copy link
Collaborator

@benscobie benscobie Jan 25, 2025

Choose a reason for hiding this comment

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

It turns out that the getters for these just return a number so the comparison currently returns false as they aren't arrays. The API response types are set to number, but I'm sure you could have multiple audio channels. I'll have a dig into the Radarr API and see what's going on with that one. fileQuality will only ever be a single number as you can't have multiple files so that one needs to be set to RuleType.NUMBER.

I actually think we'll need to re-include contains for RuleType.NUMBER as it's no longer possible to compare to a list. E.g. you may want to target qualities of 720, 1080. We'll have to fix the scenarios I mentioned in my other comment for that too. Hmm scratch that, as it was a number you could only provide a number, not a list. That's a bit of a limitation we could fix at some point though. I suspect people are working around this by including multiple rules.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can confirm that Radarr will only ever serve up a single number for audio channels, so that one can go back to RuleType.NUMBER now. I'm going to check all of the other [list]'s to see if we've got any more imposters...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Forgot to come back to this, all of the other [list]'s are fine.

],
'number list',
);
static readonly TEXT_LIST = new RuleType(
Copy link
Collaborator

@benscobie benscobie Jan 25, 2025

Choose a reason for hiding this comment

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

I just found that it's currently not possible to save a custom value for these types, the API returns Validation failed.

There's a few conditionals in ui\src\components\Rules\Rule\RuleCreator\RuleInput\index.tsx that likely need updating to handle the new types.

There's also a couple of functions that switch on the types that probably need updating as well:
See server\src\modules\rules\constants\constants.service.ts
getCustomValueIdentifier
getCustomValueFromIdentifier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aha good catch, thanks, just realised I didn't fully test end-to-end yet - only to the point of selecting it in the UI. I'll also actually run it on some rules and make sure it works...

@@ -372,7 +413,7 @@ export class RuleConstants {
name: 'tags',
humanName: '[list] Tags (Text if 1, otherwise list)',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
humanName: '[list] Tags (Text if 1, otherwise list)',
humanName: '[list] Tags',

This seems to always return a list even if there's 1 result, may have been a functionality change in the past.

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