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

Fix saved filter UI bugs #4394

Merged
merged 5 commits into from
Dec 26, 2023
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
55 changes: 31 additions & 24 deletions ui/v2.5/src/components/FrontPage/FrontPageConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { FormattedMessage, IntlShape, useIntl } from "react-intl";
import { useFindSavedFilters } from "src/core/StashService";
import { LoadingIndicator } from "../Shared/LoadingIndicator";
import { Button, Form, Modal } from "react-bootstrap";
import {
FilterMode,
FindSavedFiltersQuery,
SavedFilter,
} from "src/core/generated-graphql";
import * as GQL from "src/core/generated-graphql";
import { ConfigurationContext } from "src/hooks/Config";
import {
IUIConfig,
Expand All @@ -21,24 +17,25 @@ import {
interface IAddSavedFilterModalProps {
onClose: (content?: FrontPageContent) => void;
existingSavedFilterIDs: string[];
candidates: FindSavedFiltersQuery;
candidates: GQL.FindSavedFiltersQuery;
}

const FilterModeToMessageID = {
[FilterMode.Galleries]: "galleries",
[FilterMode.Images]: "images",
[FilterMode.Movies]: "movies",
[FilterMode.Performers]: "performers",
[FilterMode.SceneMarkers]: "markers",
[FilterMode.Scenes]: "scenes",
[FilterMode.Studios]: "studios",
[FilterMode.Tags]: "tags",
[GQL.FilterMode.Galleries]: "galleries",
[GQL.FilterMode.Images]: "images",
[GQL.FilterMode.Movies]: "movies",
[GQL.FilterMode.Performers]: "performers",
[GQL.FilterMode.SceneMarkers]: "markers",
[GQL.FilterMode.Scenes]: "scenes",
[GQL.FilterMode.Studios]: "studios",
[GQL.FilterMode.Tags]: "tags",
};

function filterTitle(intl: IntlShape, f: Pick<SavedFilter, "mode" | "name">) {
return `${intl.formatMessage({ id: FilterModeToMessageID[f.mode] })}: ${
f.name
}`;
type SavedFilter = Pick<GQL.SavedFilter, "id" | "mode" | "name">;

function filterTitle(intl: IntlShape, f: SavedFilter) {
const typeMessage = intl.formatMessage({ id: FilterModeToMessageID[f.mode] });
return `${typeMessage}: ${f.name}`;
}

const AddContentModal: React.FC<IAddSavedFilterModalProps> = ({
Expand Down Expand Up @@ -98,7 +95,7 @@ const AddContentModal: React.FC<IAddSavedFilterModalProps> = ({
.filter((f) => {
// markers not currently supported
return (
f.mode !== FilterMode.SceneMarkers &&
f.mode !== GQL.FilterMode.SceneMarkers &&
!existingSavedFilterIDs.includes(f.id)
);
})
Expand Down Expand Up @@ -232,7 +229,7 @@ const AddContentModal: React.FC<IAddSavedFilterModalProps> = ({

interface IFilterRowProps {
content: FrontPageContent;
allSavedFilters: Pick<SavedFilter, "id" | "mode" | "name">[];
allSavedFilters: SavedFilter[];
onDelete: () => void;
}

Expand All @@ -242,10 +239,9 @@ const ContentRow: React.FC<IFilterRowProps> = (props: IFilterRowProps) => {
function title() {
switch (props.content.__typename) {
case "SavedFilter":
const savedFilterId = String(props.content.savedFilterId);
const savedFilter = props.allSavedFilters.find(
(f) =>
f.id ===
(props.content as ISavedFilterRow).savedFilterId?.toString()
(f) => f.id === savedFilterId
);
if (!savedFilter) return "";
return filterTitle(intl, savedFilter);
Expand Down Expand Up @@ -302,7 +298,18 @@ export const FrontPageConfig: React.FC<IFrontPageConfigProps> = ({

const frontPageContent = getFrontPageContent(ui);
if (frontPageContent) {
setCurrentContent(frontPageContent);
setCurrentContent(
// filter out rows where the saved filter no longer exists
frontPageContent.filter((r) => {
if (r.__typename === "SavedFilter") {
const savedFilterId = String(r.savedFilterId);
return allFilters.findSavedFilters.some(
(f) => f.id === savedFilterId
);
}
return true;
})
);
}
}, [allFilters, ui]);

Expand Down
2 changes: 1 addition & 1 deletion ui/v2.5/src/components/List/Filters/PhashFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const PhashFilter: React.FC<IPhashFilterProps> = ({
className="btn-secondary"
onChange={valueChanged}
value={value ? value.value : ""}
placeholder={intl.formatMessage({ id: "phash" })}
placeholder={intl.formatMessage({ id: "media_info.phash" })}
/>
</Form.Group>
{criterion.modifier !== CriterionModifier.IsNull &&
Expand Down
35 changes: 15 additions & 20 deletions ui/v2.5/src/components/List/SavedFilterList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react";
import React, { useState } from "react";
import {
Button,
ButtonGroup,
Expand Down Expand Up @@ -39,7 +39,6 @@ export const SavedFilterList: React.FC<ISavedFilterListProps> = ({
const intl = useIntl();

const { data, error, loading, refetch } = useFindSavedFilters(filter.mode);
const oldError = useRef(error);

const [filterName, setFilterName] = useState("");
const [saving, setSaving] = useState(false);
Expand All @@ -56,14 +55,6 @@ export const SavedFilterList: React.FC<ISavedFilterListProps> = ({

const savedFilters = data?.findSavedFilters ?? [];

useEffect(() => {
if (error && error !== oldError.current) {
Toast.error(error);
}

oldError.current = error;
}, [error, Toast, oldError]);

async function onSaveFilter(name: string, id?: string) {
const filterCopy = filter.clone();

Expand Down Expand Up @@ -285,6 +276,8 @@ export const SavedFilterList: React.FC<ISavedFilterListProps> = ({
}

function renderSavedFilters() {
if (error) return <h6 className="text-center">{error.message}</h6>;

if (loading || saving) {
return (
<div className="loading">
Expand All @@ -311,20 +304,22 @@ export const SavedFilterList: React.FC<ISavedFilterListProps> = ({
function maybeRenderSetDefaultButton() {
if (persistState === PersistanceLevel.ALL) {
return (
<Button
className="set-as-default-button"
variant="secondary"
size="sm"
onClick={() => onSetDefaultFilter()}
>
{intl.formatMessage({ id: "actions.set_as_default" })}
</Button>
<div className="mt-1">
<Button
className="set-as-default-button"
variant="secondary"
size="sm"
onClick={() => onSetDefaultFilter()}
>
{intl.formatMessage({ id: "actions.set_as_default" })}
</Button>
</div>
);
}
}

return (
<div>
<>
{maybeRenderDeleteAlert()}
{maybeRenderOverwriteAlert()}
<InputGroup>
Expand Down Expand Up @@ -359,6 +354,6 @@ export const SavedFilterList: React.FC<ISavedFilterListProps> = ({
</InputGroup>
{renderSavedFilters()}
{maybeRenderSetDefaultButton()}
</div>
</>
);
};
11 changes: 11 additions & 0 deletions ui/v2.5/src/components/List/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ input[type="range"].zoom-slider {
.saved-filter-list-menu {
width: 300px;

&.dropdown-menu.show {
display: flex;
flex-direction: column;
}

.set-as-default-button {
float: right;
margin-right: 0.5rem;
}

.LoadingIndicator {
Expand Down Expand Up @@ -94,12 +100,17 @@ input[type="range"].zoom-slider {
align-items: center;
display: inline;
overflow-x: hidden;
padding-left: 1.25rem;
padding-right: 0.25rem;
text-overflow: ellipsis;
}

.btn-group {
margin-left: auto;

.btn {
border-radius: 0;
}
}

.delete-button {
Expand Down
1 change: 0 additions & 1 deletion ui/v2.5/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ div.react-select__menu,
div.dropdown-menu {
background-color: $secondary;
color: $text-color;
z-index: 1600;

.react-select__option,
.dropdown-item {
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@
"unknown": "Unknown",
"wall": "Wall"
},
"distance": "Distance",
"donate": "Donate",
"dupe_check": {
"description": "Levels below 'Exact' can take longer to calculate. False positives might also be returned on lower accuracy levels.",
Expand Down