Skip to content

Commit

Permalink
Move modifiers into selectable options (#5203)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored Oct 29, 2024
1 parent edb66bd commit f949fab
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 73 deletions.
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

0 comments on commit f949fab

Please sign in to comment.