From 2a4ca231b3c8e90d4a80d951f7b1af1806757c1d Mon Sep 17 00:00:00 2001 From: Dankonite <117317087+Dankonite@users.noreply.github.com> Date: Sat, 9 Sep 2023 22:30:28 -0600 Subject: [PATCH] Update SavedFilterList.tsx add all the savedfilterschanges ive made so far, --- .../src/components/List/SavedFilterList.tsx | 164 ++++++++++++++---- 1 file changed, 126 insertions(+), 38 deletions(-) diff --git a/ui/v2.5/src/components/List/SavedFilterList.tsx b/ui/v2.5/src/components/List/SavedFilterList.tsx index caa1277d6b2..1eca6ccb632 100644 --- a/ui/v2.5/src/components/List/SavedFilterList.tsx +++ b/ui/v2.5/src/components/List/SavedFilterList.tsx @@ -1,12 +1,15 @@ -import React, { useEffect, useRef, useState } from "react"; +import React, { FormEvent, useEffect, useRef, useState } from "react"; import { Button, ButtonGroup, Dropdown, + Form, FormControl, InputGroup, Modal, + NavItem, OverlayTrigger, + Row, Tooltip, } from "react-bootstrap"; import { @@ -17,12 +20,12 @@ import { } from "src/core/StashService"; import { useToast } from "src/hooks/Toast"; import { ListFilterModel } from "src/models/list-filter/filter"; -import { SavedFilterDataFragment } from "src/core/generated-graphql"; +import { FilterMode, SavedFilterDataFragment } from "src/core/generated-graphql"; import { PersistanceLevel } from "./ItemList"; import { FormattedMessage, useIntl } from "react-intl"; import { Icon } from "../Shared/Icon"; import { LoadingIndicator } from "../Shared/LoadingIndicator"; -import { faSave, faTimes } from "@fortawesome/free-solid-svg-icons"; +import { faEllipsisV, faPenToSquare, faSave, faTimes } from "@fortawesome/free-solid-svg-icons"; interface ISavedFilterListProps { filter: ListFilterModel; @@ -46,6 +49,9 @@ export const SavedFilterList: React.FC = ({ const [deletingFilter, setDeletingFilter] = useState< SavedFilterDataFragment | undefined >(); + const [renamingFilter, setRenamingFilter] = useState< + SavedFilterDataFragment | undefined + >(); const [overwritingFilter, setOverwritingFilter] = useState< SavedFilterDataFragment | undefined >(); @@ -82,16 +88,7 @@ export const SavedFilterList: React.FC = ({ }, }); - Toast.success({ - content: intl.formatMessage( - { - id: "toast.saved_entity", - }, - { - entity: intl.formatMessage({ id: "filter" }).toLocaleLowerCase(), - } - ), - }); + setFilterName(""); setOverwritingFilter(undefined); refetch(); @@ -101,7 +98,41 @@ export const SavedFilterList: React.FC = ({ setSaving(false); } } + async function setDefaultFilterClicked(f: SavedFilterDataFragment) { + const newFilter = filter.clone(); + + newFilter.currentPage = 1; + // #1795 - reset search term if not present in saved filter + newFilter.searchTerm = ""; + newFilter.configureFromSavedFilter(f); + // #1507 - reset random seed when loaded + newFilter.randomSeed = -1; + onSetFilter(newFilter); + try { + setSaving(true); + await setDefaultFilter({ + variables: { + input: { + mode: filter.mode, + find_filter: newFilter.makeFindFilter(), + object_filter: newFilter.makeSavedFindFilter(), + ui_options: newFilter.makeUIOptions(), + }, + }, + }); + + Toast.success({ + content: intl.formatMessage({ + id: "toast.default_filter_set", + }), + }); + } catch (err) { + Toast.error(err); + } finally { + setSaving(false); + } + } async function onDeleteFilter(f: SavedFilterDataFragment) { try { setSaving(true); @@ -176,46 +207,102 @@ export const SavedFilterList: React.FC = ({ onSetFilter(newFilter); } - + interface ISavedFilterItem { item: SavedFilterDataFragment; } const SavedFilterItem: React.FC = ({ item }) => { + const renderOperations = () => ( + + + + + + setOverwritingFilter(item)} + > + Overwrite + + setRenamingFilter(item)} + > + Rename + + { + setDefaultFilterClicked(item); + }} + > + Set Default + + setDeletingFilter(item)} + > + Delete + + + + ); return (
filterClicked(item)} title={item.name}> {item.name} - - + {renderOperations()}
); }; + function maybeRenderRenameAlert() { + const NameRef = useRef(null) + if (!renamingFilter) { + return; + } + function handleSubmit(e: FormEvent) { + onSaveFilter( + NameRef.current!.value, + renamingFilter!.id + ); + } + return
+ + +

Rename

+ + + + + + + +
+
+
+ } function maybeRenderDeleteAlert() { if (!deletingFilter) { return; @@ -326,6 +413,7 @@ export const SavedFilterList: React.FC = ({ return (
{maybeRenderDeleteAlert()} + {maybeRenderRenameAlert()} {maybeRenderOverwriteAlert()}