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

Move modifiers into selectable options in object filter selectors #5203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions ui/v2.5/src/components/List/CriterionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ const GenericCriterionEditor: React.FC<IGenericCriterionEditor> = ({

const { options, modifierOptions } = criterion.criterionOption;

const showModifierSelector = useMemo(() => {
if (
criterion instanceof PerformersCriterion ||
criterion instanceof StudiosCriterion ||
criterion instanceof TagsCriterion
) {
return false;
}

return modifierOptions && modifierOptions.length > 1;
}, [criterion, modifierOptions]);

const alwaysShowFilter = useMemo(() => {
return (
criterion instanceof StashIDCriterion ||
criterion instanceof PerformersCriterion ||
criterion instanceof StudiosCriterion ||
criterion instanceof TagsCriterion
);
}, [criterion]);

const onChangedModifierSelect = useCallback(
(m: CriterionModifier) => {
const newCriterion = cloneDeep(criterion);
Expand All @@ -71,7 +92,7 @@ const GenericCriterionEditor: React.FC<IGenericCriterionEditor> = ({
);

const modifierSelector = useMemo(() => {
if (!modifierOptions || modifierOptions.length === 0) {
if (!showModifierSelector) {
return;
}

Expand All @@ -90,7 +111,13 @@ const GenericCriterionEditor: React.FC<IGenericCriterionEditor> = ({
))}
</Form.Group>
);
}, [modifierOptions, onChangedModifierSelect, criterion.modifier, intl]);
}, [
showModifierSelector,
modifierOptions,
onChangedModifierSelect,
criterion.modifier,
intl,
]);

const valueControl = useMemo(() => {
function onValueChanged(value: CriterionValue) {
Expand All @@ -108,8 +135,9 @@ const GenericCriterionEditor: React.FC<IGenericCriterionEditor> = ({

// Hide the value select if the modifier is "IsNull" or "NotNull"
if (
criterion.modifier === CriterionModifier.IsNull ||
criterion.modifier === CriterionModifier.NotNull
!alwaysShowFilter &&
(criterion.modifier === CriterionModifier.IsNull ||
criterion.modifier === CriterionModifier.NotNull)
) {
return;
}
Expand Down Expand Up @@ -229,7 +257,7 @@ const GenericCriterionEditor: React.FC<IGenericCriterionEditor> = ({
return (
<InputFilter criterion={criterion} onValueChanged={onValueChanged} />
);
}, [criterion, setCriterion, options]);
}, [criterion, setCriterion, options, alwaysShowFilter]);

return (
<div>
Expand Down
Loading
Loading