Skip to content

Commit 9d668ce

Browse files
authored
Merge pull request #211 from citizennet/API-1813/multi-select-toolbar-search-dropdown
API-1813 Allow Selecting Multiple in renderToolbarSearchDropdown
2 parents 1b24b28 + a2b9a47 commit 9d668ce

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purescript-ocelot",
3-
"version": "0.32.1",
3+
"version": "0.33.0",
44
"private": true,
55
"scripts": {
66
"build-all": "make build",

src/Interfaces/Typeahead/Interface.purs

+4-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ searchDropdownInputToToolbarSingleInput r =
300300
, disabled: false
301301
, render: renderToolbarSearchDropdown
302302
r.placeholder
303-
r.resetLabel
304-
renderLabel
303+
( case _ of
304+
Nothing -> HH.text r.resetLabel
305+
Just x -> renderLabel x
306+
)
305307
renderFuzzy
306308
}
307309
where

src/Typeahead.purs

+13-11
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import Data.Foldable as Data.Foldable
6868
import Data.Fuzzy as Data.Fuzzy
6969
import Data.Maybe (Maybe(..))
7070
import Data.Maybe as Data.Maybe
71-
import Data.Newtype as Data.Newtype
7271
import Data.Rational ((%))
7372
import Data.String as Data.String
7473
import Data.Time.Duration as Data.Time.Duration
@@ -914,12 +913,13 @@ renderMultiInput input renderContainer st =
914913
]
915914

916915
renderSearchDropdown
917-
:: action item m
916+
:: action f item m
918917
. Eq item
918+
=> Data.Foldable.Foldable f
919919
=> String
920920
-> Halogen.HTML.PlainHTML
921921
-> (Data.Fuzzy.Fuzzy item -> Halogen.HTML.PlainHTML)
922-
-> CompositeComponentRender action Maybe item m
922+
-> CompositeComponentRender action f item m
923923
renderSearchDropdown resetLabel label renderFuzzy st =
924924
Halogen.HTML.label
925925
[ Ocelot.HTML.Properties.css "relative" ]
@@ -934,12 +934,14 @@ renderSearchDropdown resetLabel label renderFuzzy st =
934934
[ Ocelot.Block.ItemContainer.dropdownContainer
935935
[ renderInput, renderReset ]
936936
renderFuzzy
937-
((==) st.selected <<< Just <<< _.original <<< Data.Newtype.unwrap)
937+
isSelected
938938
st.fuzzyItems
939939
st.highlightedIndex
940940
]
941941
]
942942
where
943+
isSelected :: Data.Fuzzy.Fuzzy item -> Boolean
944+
isSelected (Data.Fuzzy.Fuzzy { original }) = Data.Foldable.elem original st.selected
943945
renderInput =
944946
Halogen.HTML.div
945947
[ Ocelot.HTML.Properties.css "m-4 border-b-2 border-blue-88 pb-2 flex" ]
@@ -954,7 +956,7 @@ renderSearchDropdown resetLabel label renderFuzzy st =
954956
[ Halogen.HTML.Events.onClick \_ -> Select.Action $ RemoveAll
955957
]
956958
[ Halogen.HTML.text resetLabel ]
957-
( Data.Maybe.isNothing st.selected )
959+
( Data.Foldable.null st.selected )
958960
false
959961

960962
renderSingle
@@ -1013,14 +1015,14 @@ renderSingle iprops renderItem renderContainer st =
10131015
showSelected = Data.Maybe.isJust st.selected && st.visibility == Select.Off
10141016

10151017
renderToolbarSearchDropdown
1016-
:: action item m
1018+
:: action f item m
10171019
. Eq item
1020+
=> Data.Foldable.Foldable f
10181021
=> String
1019-
-> String
1020-
-> (item -> Halogen.HTML.PlainHTML)
1022+
-> (f item -> Halogen.HTML.PlainHTML)
10211023
-> (Data.Fuzzy.Fuzzy item -> Halogen.HTML.PlainHTML)
1022-
-> CompositeComponentRender action Maybe item m
1023-
renderToolbarSearchDropdown defaultLabel resetLabel renderItem renderFuzzy st =
1024+
-> CompositeComponentRender action f item m
1025+
renderToolbarSearchDropdown resetLabel renderText renderFuzzy st =
10241026
renderSearchDropdown resetLabel label renderFuzzy st
10251027
where
10261028
label = Ocelot.Block.ItemContainer.dropdownButton
@@ -1030,7 +1032,7 @@ renderToolbarSearchDropdown defaultLabel resetLabel renderItem renderFuzzy st =
10301032
: Ocelot.Block.Button.buttonMainClasses
10311033
<> Ocelot.Block.Button.buttonClearClasses
10321034
]
1033-
[ Data.Maybe.maybe (Halogen.HTML.text defaultLabel) (Halogen.HTML.fromPlainHTML <<< renderItem) st.selected ]
1035+
[ (Halogen.HTML.fromPlainHTML <<< renderText) st.selected ]
10341036

10351037
replaceSelected
10361038
:: forall action f item m

ui-guide/Components/Typeaheads.purs

+36-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Prelude
44

55
import Control.Parallel as Control.Parallel
66
import Data.Array (head, take)
7+
import Data.Array as Data.Array
78
import Data.Maybe (Maybe(..))
89
import Data.Newtype (unwrap)
910
import Effect.Aff.Class (class MonadAff)
@@ -647,8 +648,42 @@ cnDocumentationBlocks =
647648
, disabled: false
648649
, render: TA.renderToolbarSearchDropdown
649650
"All Locations"
651+
( case _ of
652+
Nothing -> HH.text "All Locations"
653+
Just (Async.Location x) -> HH.text x.name
654+
)
655+
(HH.span_ <<< IC.boldMatches "name")
656+
}
657+
]
658+
]
659+
, content
660+
[ Card.card
661+
[ HP.class_ $ HH.ClassName "flex-1" ]
662+
[ HH.h3
663+
[ HP.classes Format.captionClasses ]
664+
[ HH.text "Multi - Searchable Dropdown in a Toolbar (e.g. for filtering)" ]
665+
, HH.slot_ _multiLocation 11
666+
( TA.component
667+
{ runSelect: Data.Array.cons
668+
, runRemove: Data.Array.filter <<< (/=)
669+
, runFilterFuzzy: identity
670+
, runFilterItems: const
671+
}
672+
)
673+
{ items: NotAsked
674+
, insertable: TA.NotInsertable
675+
, keepOpen: true
676+
, debounceTime: Nothing
677+
, async: Nothing
678+
, itemToObject: Async.locationToObject
679+
, disabled: false
680+
, render: TA.renderToolbarSearchDropdown
650681
"All Locations"
651-
(HH.text <<< _.name <<< unwrap)
682+
( case _ of
683+
[] -> HH.text "All Locations"
684+
[ Async.Location x ] -> HH.text x.name
685+
xs -> HH.text (show (Data.Array.length xs) <> " Locations Selected")
686+
)
652687
(HH.span_ <<< IC.boldMatches "name")
653688
}
654689
]

0 commit comments

Comments
 (0)