From 2d938a8063aa50ae254ae7a78f25795b9f1f29a9 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Mon, 18 Nov 2024 22:29:03 +0100 Subject: [PATCH 1/3] add bulk edit button --- .../FlipRestrictionList/FlipRestrictionList.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx index a0017448..25246f2a 100644 --- a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx +++ b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx @@ -155,8 +155,7 @@ function FlipRestrictionList(props: Props) { newRestrictions[index].tags = updateState.tags newRestrictions[index].isEdited = false newRestrictions[index].type = restriction.type - if (updateState.selectedItem) - newRestrictions[index].item = updateState.selectedItem + if (updateState.selectedItem) newRestrictions[index].item = updateState.selectedItem }) setSetting(RESTRICTIONS_SETTINGS_KEY, JSON.stringify(getCleanRestrictionsForApi(newRestrictions))) @@ -294,7 +293,7 @@ function FlipRestrictionList(props: Props) { } function recalculateListHeight() { - ; (listRef.current as any).resetAfterRowIndex(0, false) + ;(listRef.current as any).resetAfterRowIndex(0, false) } function handleContextMenuForRestriction(event) { @@ -598,6 +597,18 @@ function FlipRestrictionList(props: Props) { )} ) : null} +
+ +
{clearListDialog} From a6b811a32ec5f36ed48fa2354ae77f531c4d6be4 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Wed, 20 Nov 2024 23:34:36 +0100 Subject: [PATCH 2/3] change icon --- .../FlipRestrictionList.tsx | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx index 25246f2a..9bc898a3 100644 --- a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx +++ b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx @@ -18,6 +18,7 @@ import FlipRestrictionListEntry from './RestrictionListEntry/FlipRestrictionList import { Item, Menu, useContextMenu } from 'react-contexify' import BlockIcon from '@mui/icons-material/Block' import CheckIcon from '@mui/icons-material/CheckCircle' +import MoreVertIcon from '@mui/icons-material/MoreVert' interface Props { onRestrictionsChange(restrictions: FlipRestriction[], type: 'whitelist' | 'blacklist'): void @@ -514,6 +515,16 @@ function FlipRestrictionList(props: Props) { }} /> +
+ { + setIsNewFlipperExtended(true) + }} + > + {addIcon} + Delete all curren showing + +
@@ -597,18 +608,6 @@ function FlipRestrictionList(props: Props) { )} ) : null} -
- -
{clearListDialog} From 0e74461f0d486780e93b0b2dfcadee15ec8eb614 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Tue, 26 Nov 2024 18:06:54 +0100 Subject: [PATCH 3/3] finish bulk edit options fix disable feature --- .../FlipRestrictionList.tsx | 93 ++++++++++++++----- utils/SettingsUtils.tsx | 9 +- 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx index 9bc898a3..5d42adc8 100644 --- a/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx +++ b/components/Flipper/FlipRestrictionList/FlipRestrictionList.tsx @@ -18,7 +18,8 @@ import FlipRestrictionListEntry from './RestrictionListEntry/FlipRestrictionList import { Item, Menu, useContextMenu } from 'react-contexify' import BlockIcon from '@mui/icons-material/Block' import CheckIcon from '@mui/icons-material/CheckCircle' -import MoreVertIcon from '@mui/icons-material/MoreVert' +import ListIcon from '@mui/icons-material/ListAlt' +import { Check } from '@mui/icons-material' interface Props { onRestrictionsChange(restrictions: FlipRestriction[], type: 'whitelist' | 'blacklist'): void @@ -26,13 +27,13 @@ interface Props { } const RESTRICTION_CONTEXT_MENU_ID = 'restriction-entry-context-menu' +const RESTRICTION_CONTEXT_CURRENT_SHOING_MENU_ID = 'restriction-entry-context-menu-current-showing' function FlipRestrictionList(props: Props) { let [isAddNewFlipperExtended, setIsNewFlipperExtended] = useState(props.prefillRestriction !== undefined) - let [restrictions, setRestrictions] = useState(getInitialFlipRestrictions()) + let [restrictions, setRestrictions] = useState(() => getInitialFlipRestrictions()) let [restrictionInEditMode, setRestrictionsInEditMode] = useState([]) let [showDeleteRestrictionsDialog, setShowDeleteRestrictionsDialog] = useState(false) - let [isRefreshingItemNames, setIsRefreshingItemNames] = useState(false) let [searchText, setSearchText] = useState('') let [sortByName, setSortByName] = useState(false) let [isSSR, setIsSSR] = useState(true) @@ -42,6 +43,9 @@ function FlipRestrictionList(props: Props) { const { show } = useContextMenu({ id: RESTRICTION_CONTEXT_MENU_ID }) + const { show: showEditShowingRestrictionsMenu } = useContextMenu({ + id: RESTRICTION_CONTEXT_CURRENT_SHOING_MENU_ID + }) useEffect(() => { function onControlF(event: KeyboardEvent) { @@ -68,6 +72,7 @@ function FlipRestrictionList(props: Props) { } restriction.itemKey = generateUUID() }) + console.log(restrictions) return restrictions } @@ -265,7 +270,6 @@ function FlipRestrictionList(props: Props) { function refreshItemNames() { let newRestrictions = [...restrictions] - setIsRefreshingItemNames(true) let items: Item[] = [] newRestrictions.forEach(restriction => { if (restriction.item && restriction.item.tag) { @@ -280,7 +284,6 @@ function FlipRestrictionList(props: Props) { } }) toast.success('Reloaded all item names') - setIsRefreshingItemNames(false) setRestrictions(newRestrictions) setSetting(RESTRICTIONS_SETTINGS_KEY, JSON.stringify(getCleanRestrictionsForApi(newRestrictions))) if (props.onRestrictionsChange) { @@ -351,6 +354,23 @@ function FlipRestrictionList(props: Props) { } } + function changeRestrictionDisableStateForAllCurrentShowing(newValue: boolean) { + let newRestrictions = [...restrictions] + let shownRestrictions = getRestrictionsFilteredBySearch(restrictions) + newRestrictions.forEach(r => { + if (r.itemKey && shownRestrictions.find(sr => sr.itemKey === r.itemKey)) { + r.disabled = newValue + } + }) + setRestrictions(newRestrictions) + + setSetting(RESTRICTIONS_SETTINGS_KEY, JSON.stringify(getCleanRestrictionsForApi(newRestrictions))) + if (props.onRestrictionsChange) { + props.onRestrictionsChange(getCleanRestrictionsForApi(newRestrictions), 'blacklist') + props.onRestrictionsChange(getCleanRestrictionsForApi(newRestrictions), 'whitelist') + } + } + let clearListDialog = ( ) + let currentShowingItemOptionsContextMenuElement = ( +
+ + { + setShowDeleteRestrictionsDialog(true) + }} + > + + Delete all current showing + + { + changeRestrictionDisableStateForAllCurrentShowing(true) + }} + > + + Disable all current showing + + { + changeRestrictionDisableStateForAllCurrentShowing(false) + }} + > + + Enable all current showing + + + + Refresh item names + + +
+ ) + let windowWidth = isSSR ? 1920 : window.innerWidth let singleColumn = windowWidth < 1024 @@ -480,17 +535,16 @@ function FlipRestrictionList(props: Props) { {addIcon} Add new restriction - - + + + )}
@@ -515,16 +569,6 @@ function FlipRestrictionList(props: Props) { }} /> -
- { - setIsNewFlipperExtended(true) - }} - > - {addIcon} - Delete all curren showing - -
@@ -612,6 +656,7 @@ function FlipRestrictionList(props: Props) {
{clearListDialog} {currentItemContextMenuElement} + {currentShowingItemOptionsContextMenuElement} ) } diff --git a/utils/SettingsUtils.tsx b/utils/SettingsUtils.tsx index 9eae2703..2058ac32 100644 --- a/utils/SettingsUtils.tsx +++ b/utils/SettingsUtils.tsx @@ -123,7 +123,8 @@ export function setSettingsFromServerSide( newRestrictions.push({ type: type, itemFilter: item.filter, - tags: item.tags + tags: item.tags, + disabled: item.disabled }) } else if (itemName && item.tag) { newRestrictions.push({ @@ -134,7 +135,8 @@ export function setSettingsFromServerSide( iconUrl: api.getItemImageUrl(item) }, itemFilter: item.filter, - tags: item.tags + tags: item.tags, + disabled: item.disabled }) } else { tagsToFindNamesFor.add(item.tag) @@ -146,7 +148,8 @@ export function setSettingsFromServerSide( iconUrl: api.getItemImageUrl(item) }, itemFilter: item.filter, - tags: item.tags + tags: item.tags, + disabled: item.disabled }) } })