Fix tag menu when restricting results

When search results are restricted in a share view, tags may disappear
and thus the tags from the beginning need to be kept.
This commit is contained in:
eikek 2021-10-06 00:26:53 +02:00
parent 813797756c
commit 4ad90b76b4
4 changed files with 70 additions and 11 deletions

View File

@ -9,6 +9,7 @@ module Comp.SearchMenu exposing
( Model
, Msg(..)
, NextState
, SearchTab(..)
, TextSearchModel
, getItemQuery
, init
@ -563,7 +564,7 @@ updateDrop ddm flags settings msg model =
List.sortBy .count stats.tagCategoryCloud.items
selectModel =
Comp.TagSelect.modifyCount model.tagSelectModel tagCount catCount
Comp.TagSelect.modifyCountKeepExisting model.tagSelectModel tagCount catCount
orgOpts =
Comp.Dropdown.update (Comp.Dropdown.SetOptions (List.map .ref stats.corrOrgStats))
@ -1044,15 +1045,20 @@ updateDrop ddm flags settings msg model =
--- View2
viewDrop2 : Texts -> DD.DragDropData -> Flags -> UiSettings -> Model -> Html Msg
viewDrop2 texts ddd flags settings model =
type alias ViewConfig =
{ overrideTabLook : SearchTab -> Comp.Tabs.Look -> Comp.Tabs.Look
}
viewDrop2 : Texts -> DD.DragDropData -> Flags -> ViewConfig -> UiSettings -> Model -> Html Msg
viewDrop2 texts ddd flags cfg settings model =
let
akkordionStyle =
Comp.Tabs.searchMenuStyle
in
Comp.Tabs.akkordion
akkordionStyle
(searchTabState settings model)
(searchTabState settings cfg model)
(searchTabs texts ddd flags settings model)
@ -1254,12 +1260,9 @@ tabLook settings model tab =
Comp.Tabs.Normal
searchTabState : UiSettings -> Model -> Comp.Tabs.Tab Msg -> ( Comp.Tabs.State, Msg )
searchTabState settings model tab =
searchTabState : UiSettings -> ViewConfig -> Model -> Comp.Tabs.Tab Msg -> ( Comp.Tabs.State, Msg )
searchTabState settings cfg model tab =
let
isHidden f =
Data.UiSettings.fieldHidden settings f
searchTab =
findTab tab
@ -1273,7 +1276,7 @@ searchTabState settings model tab =
state =
{ folded = folded
, look =
Maybe.map (tabLook settings model) searchTab
Maybe.map (\t -> tabLook settings model t |> cfg.overrideTabLook t) searchTab
|> Maybe.withDefault Comp.Tabs.Normal
}
in

View File

@ -16,6 +16,7 @@ module Comp.TagSelect exposing
, makeWorkModel
, modifyAll
, modifyCount
, modifyCountKeepExisting
, reset
, toggleTag
, update
@ -99,6 +100,40 @@ modifyCount model tags cats =
}
modifyCountKeepExisting : Model -> List TagCount -> List NameCount -> Model
modifyCountKeepExisting model tags cats =
let
tagZeros : Dict String TagCount
tagZeros =
Dict.map (\_ -> \tc -> TagCount tc.tag 0) model.availableTags
tagAvail =
List.foldl (\tc -> \dict -> Dict.insert tc.tag.id tc dict) tagZeros tags
tcs =
Dict.values tagAvail
catcs =
List.filterMap (\e -> Maybe.map (\k -> CategoryCount k e.count) e.name) cats
catZeros : Dict String CategoryCount
catZeros =
Dict.map (\_ -> \cc -> CategoryCount cc.name 0) model.availableCats
catAvail =
List.foldl (\cc -> \dict -> Dict.insert cc.name cc dict) catZeros catcs
ccs =
Dict.values catAvail
in
{ model
| tagCounts = tcs
, availableTags = tagAvail
, categoryCounts = ccs
, availableCats = catAvail
}
reset : Model -> Model
reset model =
{ model

View File

@ -82,10 +82,16 @@ viewSearch texts flags settings model =
, end = []
, rootClasses = "my-1 text-xs hidden sm:flex"
}
, Html.map SearchMenuMsg
, let
searchMenuCfg =
{ overrideTabLook = \_ -> identity
}
in
Html.map SearchMenuMsg
(Comp.SearchMenu.viewDrop2 texts.searchMenu
model.dragDropData
flags
searchMenuCfg
settings
model.searchMenuModel
)

View File

@ -8,6 +8,7 @@
module Page.Share.Sidebar exposing (..)
import Comp.SearchMenu
import Comp.Tabs
import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
@ -19,6 +20,19 @@ import Util.ItemDragDrop
view : Texts -> Flags -> UiSettings -> Model -> Html Msg
view texts flags settings model =
let
hideTrashTab tab default =
case tab of
Comp.SearchMenu.TabTrashed ->
Comp.Tabs.Hidden
_ ->
default
searchMenuCfg =
{ overrideTabLook = hideTrashTab
}
in
div
[ class "flex flex-col"
]
@ -26,6 +40,7 @@ view texts flags settings model =
(Comp.SearchMenu.viewDrop2 texts.searchMenu
ddDummy
flags
searchMenuCfg
settings
model.searchMenuModel
)