From 2712549a61524b3ed0e6c5b524eff3981b914784 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Mon, 18 Mar 2024 16:45:46 +0100 Subject: [PATCH] add button to fill last used items into new restriction --- .../NewRestriction/NewRestriction.module.css | 13 ++++++++++++- .../NewRestriction/NewRestriction.tsx | 13 +++++++++++-- components/Search/MultiSearch.tsx | 9 +++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.module.css b/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.module.css index 600db009..a1b32c22 100644 --- a/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.module.css +++ b/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.module.css @@ -1,3 +1,14 @@ -.newRestrictionSearchbar { +.newRestrictionSearchbarContainer { margin-top: 20px; } + +.newRestrictionSearchbarContainer{ + display: flex; + justify-content: center; + align-items: center; + gap: 10px; +} + +.multiSearch { + flex: 1; +} \ No newline at end of file diff --git a/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.tsx b/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.tsx index 8444d01f..5898e20f 100644 --- a/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.tsx +++ b/components/Flipper/FlipRestrictionList/NewRestriction/NewRestriction.tsx @@ -29,6 +29,7 @@ function NewRestriction(props: Props) { }) let [isFilterValid, setIsFilterValid] = useState(true) let [filters, setFilters] = useState([]) + let [showFillLastUsedItems, setShowFillLastUsedItems] = useState(sessionStorage.getItem('lastUsedItemsForNewRestrictions') !== null) useEffect(() => { loadFilters() @@ -68,6 +69,11 @@ function NewRestriction(props: Props) { } } + function fillLastUsedItems() { + let lastUsedItems = JSON.parse(sessionStorage.getItem('lastUsedItemsForNewRestrictions') || '[]') + setCreateState({ ...createState, selectedItems: lastUsedItems }) + } + let getButtonVariant = (range: string): string => { return range === createState.type ? 'primary' : 'secondary' } @@ -100,8 +106,9 @@ function NewRestriction(props: Props) { Whitelist -
+
{ setCreateState({ ...createState, @@ -115,7 +122,7 @@ function NewRestriction(props: Props) { }) }} searchFunction={api.itemSearch} - defaultSelected={createState.selectedItems?.map(item => { + selected={createState.selectedItems?.map(item => { return { dataItem: { name: item.name, @@ -126,6 +133,7 @@ function NewRestriction(props: Props) { } as unknown as SearchResultItem })} /> + {showFillLastUsedItems && }
{ + sessionStorage.setItem('lastUsedItemsForNewRestrictions', JSON.stringify(createState.selectedItems)) props.onSaveRestrictions( (createState.selectedItems || [null]).map(item => { return { diff --git a/components/Search/MultiSearch.tsx b/components/Search/MultiSearch.tsx index c7a30623..218fb868 100644 --- a/components/Search/MultiSearch.tsx +++ b/components/Search/MultiSearch.tsx @@ -1,6 +1,6 @@ 'use client' import { forwardRef, Ref, useState } from 'react' -import { AsyncTypeahead, Highlighter } from 'react-bootstrap-typeahead' +import { AsyncTypeahead } from 'react-bootstrap-typeahead' import { v4 as generateUUID } from 'uuid' import Typeahead from 'react-bootstrap-typeahead/types/core/Typeahead' import api from '../../api/ApiHelper' @@ -15,7 +15,8 @@ interface Props { placeholder?: string defaultValue?: string searchFunction?(searchText: string): Promise - defaultSelected?: SearchResultItem[] + selected?: SearchResultItem[] + className?: string } export let MultiSearch = forwardRef((props: Props, ref: Ref) => { @@ -48,7 +49,7 @@ export let MultiSearch = forwardRef((props: Props, ref: Ref) => { return ( true} @@ -74,7 +75,7 @@ export let MultiSearch = forwardRef((props: Props, ref: Ref) => { minLength={1} onSearch={handleSearch} defaultInputValue={props.defaultValue} - defaultSelected={props.defaultSelected} + selected={props.selected} options={results} placeholder={props.placeholder || 'Search item...'} onChange={_onChange}