Skip to content

Commit 472b6d8

Browse files
restauranttdyongxu
andauthored
fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func (SAP#892)
* fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func SortFilterItem.PickerItem Reset button functionality * fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func SortFilterItem.PickerItem Reset button functionality * fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func * fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func --------- Co-authored-by: dyongxu <[email protected]>
1 parent dce2ec4 commit 472b6d8

File tree

9 files changed

+169
-43
lines changed

9 files changed

+169
-43
lines changed

Apps/Examples/Examples/FioriSwiftUICore/SortFilter/SortFilterExample.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ struct SortFilterExample: View {
66
[
77
.switch(item: .init(name: "Favorite", value: true, icon: "heart.fill"), showsOnFilterFeedbackBar: true),
88
.switch(item: .init(name: "Tagged", value: nil, icon: "tag"), showsOnFilterFeedbackBar: false),
9-
.picker(item: .init(name: "List No Search", value: [0], valueOptions: ["Received", "Started", "Hold"], allowsMultipleSelection: true, allowsEmptySelection: true, barItemDisplayMode: .name, isSearchBarHidden: true, icon: "clock", itemLayout: .fixed, displayMode: .list), showsOnFilterFeedbackBar: true),
9+
.picker(item: .init(name: "List Multiple", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed"], allowsMultipleSelection: true, allowsEmptySelection: true, barItemDisplayMode: .name, isSearchBarHidden: true, icon: "clock", itemLayout: .fixed, displayMode: .list, resetButtonConfiguration: FilterFeedbackBarResetButtonConfiguration(with: .clearAll, title: "Clear")), showsOnFilterFeedbackBar: true),
10+
.picker(item: .init(name: "List Single", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed"], allowsMultipleSelection: false, allowsEmptySelection: true, barItemDisplayMode: .name, isSearchBarHidden: true, icon: "clock", itemLayout: .fixed, displayMode: .list, resetButtonConfiguration: FilterFeedbackBarResetButtonConfiguration(with: .clearAll)), showsOnFilterFeedbackBar: true),
11+
.picker(item: .init(name: "List No Search", value: [0], valueOptions: ["Received", "Started", "Hold"], allowsMultipleSelection: false, allowsEmptySelection: true, barItemDisplayMode: .name, isSearchBarHidden: true, icon: "clock", itemLayout: .fixed, displayMode: .list), showsOnFilterFeedbackBar: true),
1012
.picker(item: .init(name: "List Status", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review Pending Pending Pending Pending Pending", "Accepted Medium", "Pending Medium", "Completed Medium"], allowsMultipleSelection: true, allowsEmptySelection: true, barItemDisplayMode: .name, icon: "clock", itemLayout: .fixed, displayMode: .list), showsOnFilterFeedbackBar: true),
1113
.picker(item: .init(name: "List Many Status", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review Pending Pending Pending Pending Pending", "Accepted Medium", "Pending Medium", "Completed Medium", "Checked", "Unchecked", "Partially Checked", "Checked and Unchecked", "Checked and Partially Checked", "Unchecked and Partially Checked", "Partially Checked and Unchecked", "Checked and Unchecked and Partially Checked", "Unchecked and Partially Checked and Partially Checked", "Partially Checked and Unchecked and Partially Checked", "Checked Finally", "Unchecked Finally", "Partially Checked Finally", "Checked and Unchecked Finally", "Checked and Partially Checked Finally", "Unchecked and Partially Checked Finally", "Partially Checked and Unchecked Finally", "Checked Finally and Partially Checked Finally", "Unchecked Finally and Partially Checked Finally", "Partially Checked Finally and Partially Checked Finally", "Review", "Reviewed", "To be Reviewed", "Pending for Review", "Booked", "To be Booked", "Will Book", "Booking Canceled"], allowsMultipleSelection: true, allowsEmptySelection: true, barItemDisplayMode: .value, icon: "clock", itemLayout: .fixed, displayMode: .list), showsOnFilterFeedbackBar: true),
1214
.picker(item: .init(name: "Flexible Filter", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review Pending Pending Pending Pending Pending", "Accepted Medium", "Pending", "Completed Medium"], allowsMultipleSelection: true, allowsEmptySelection: true, barItemDisplayMode: .nameAndValue, icon: "clock", itemLayout: .flexible, displayMode: .filterFormCell), showsOnFilterFeedbackBar: true),

Sources/FioriSwiftUICore/Components/CancellableResettableForm.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ struct CancellableResettableDialogForm<Title: View, CancelAction: View, ResetAct
2727

2828
var body: some View {
2929
VStack(spacing: UIDevice.current.userInterfaceIdiom != .phone ? 8 : 16) {
30-
HStack {
31-
self.cancelAction.accessibilityIdentifier("Cancel")
32-
Spacer()
30+
ZStack(alignment: .center, content: {
3331
self.title
34-
Spacer()
35-
self.resetAction.accessibilityIdentifier("Reset")
36-
}
32+
HStack {
33+
self.cancelAction.accessibilityIdentifier("Cancel")
34+
Spacer()
35+
self.resetAction.accessibilityIdentifier("Reset")
36+
}
37+
})
3738
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16)
3839

3940
#if !os(visionOS)

Sources/FioriSwiftUICore/DataTypes/SortFilter+DataType.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,38 @@ extension SortFilterItem {
346346
}
347347
}
348348

349+
/// FilterFeedbackBar ResetButton Configuration
350+
public struct FilterFeedbackBarResetButtonConfiguration: Equatable {
351+
var type: FilterFeedbackBarResetButtonType
352+
var title: String
353+
var isHidden: Bool
354+
355+
init(type: FilterFeedbackBarResetButtonType = .reset, title: String, isHidden: Bool = false) {
356+
self.type = type
357+
self.title = title
358+
self.isHidden = isHidden
359+
}
360+
361+
/// Default FilterFeedbackBarResetButtonConfiguration
362+
public init() {
363+
self.init(type: .reset, title: NSLocalizedString("Reset", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""), isHidden: false)
364+
}
365+
366+
/// Customize FilterFeedbackBarResetButtonConfiguration
367+
/// - Parameters:
368+
/// - type: Reset button type
369+
/// - title: Reset button title
370+
/// - isHidden: A Boolean value that determines whether reset button is hidden.
371+
public init(with type: FilterFeedbackBarResetButtonType = .reset, title: String = "", isHidden: Bool = false) {
372+
self.init(type: type, title: title == "" ? NSLocalizedString("Reset", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") : title, isHidden: isHidden)
373+
}
374+
375+
/// :nodoc:
376+
public static func == (lhs: FilterFeedbackBarResetButtonConfiguration, rhs: FilterFeedbackBarResetButtonConfiguration) -> Bool {
377+
lhs.type == rhs.type && lhs.title == rhs.title && lhs.isHidden == rhs.isHidden
378+
}
379+
}
380+
349381
public extension SortFilterItem {
350382
/// Data structure for filter feedback, option list picker,
351383
struct PickerItem: Identifiable, Equatable {
@@ -366,7 +398,9 @@ public extension SortFilterItem {
366398
/// If searchBar in list picker is shown. Default is `false`.
367399
public var isSearchBarHidden: Bool = false
368400
var disableListEntriesSection: Bool = false
369-
401+
var allowsDisplaySelectionCount: Bool = true
402+
var resetButtonConfiguration: FilterFeedbackBarResetButtonConfiguration = .init()
403+
370404
/// Available OptionListPicker modes. Use this enum to define picker mode to present.
371405
public enum DisplayMode {
372406
/// Decided by options count
@@ -402,7 +436,7 @@ public extension SortFilterItem {
402436
case disable
403437
}
404438

405-
public init(id: String = UUID().uuidString, name: String, value: [Int], valueOptions: [String], allowsMultipleSelection: Bool, allowsEmptySelection: Bool, barItemDisplayMode: BarItemDisplayMode = .name, isSearchBarHidden: Bool = false, icon: String? = nil, itemLayout: OptionListPickerItemLayoutType = .fixed, displayMode: DisplayMode = .automatic, listEntriesSectionMode: ListEntriesSectionMode = .default) {
439+
public init(id: String = UUID().uuidString, name: String, value: [Int], valueOptions: [String], allowsMultipleSelection: Bool, allowsEmptySelection: Bool, barItemDisplayMode: BarItemDisplayMode = .name, isSearchBarHidden: Bool = false, icon: String? = nil, itemLayout: OptionListPickerItemLayoutType = .fixed, displayMode: DisplayMode = .automatic, listEntriesSectionMode: ListEntriesSectionMode = .default, allowsDisplaySelectionCount: Bool = true, resetButtonConfiguration: FilterFeedbackBarResetButtonConfiguration = FilterFeedbackBarResetButtonConfiguration()) {
406440
self.id = id
407441
self.name = name
408442
self.value = value
@@ -425,6 +459,9 @@ public extension SortFilterItem {
425459
case .enable:
426460
self.disableListEntriesSection = false
427461
}
462+
463+
self.allowsDisplaySelectionCount = allowsDisplaySelectionCount
464+
self.resetButtonConfiguration = resetButtonConfiguration
428465
}
429466

430467
mutating func onTap(option: String) {
@@ -476,6 +513,10 @@ public extension SortFilterItem {
476513
self.workingValue = self.originalValue.map { $0 }
477514
}
478515

516+
mutating func clearAll() {
517+
self.workingValue.removeAll()
518+
}
519+
479520
mutating func apply() {
480521
self.value = self.workingValue.map { $0 }
481522
}

Sources/FioriSwiftUICore/Models/ModelDefinitions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ public protocol OptionListPickerItemModel: OptionListPickerComponent {
547547
// sourcery: virtualPropIsSearchBarHidden = "var isSearchBarHidden: Bool = false"
548548
// sourcery: virtualPropKeyboardHeight = "@State var _keyboardHeight: CGFloat = 0.0"
549549
// sourcery: virtualPropDisableListEntriesSection = "var disableListEntriesSection: Bool = false"
550+
// sourcery: virtualPropAllowsDisplaySelectionCount = "var allowsDisplaySelectionCount: Bool = true"
550551
public protocol SearchListPickerItemModel: OptionListPickerComponent {
551552
// sourcery: default.value = nil
552553
// sourcery: no_view

Sources/FioriSwiftUICore/Views/SearchListPickerItem+View.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public extension SearchListPickerItem {
1313
/// - selectAll: The closure when click 'Select All' button.
1414
/// - updateSearchListPickerHeight: The closure to update the parent view.
1515
/// - disableListEntriesSection: A boolean value to indicate to disable entries section or not.
16-
init(value: Binding<[Int]>, valueOptions: [String] = [], hint: String? = nil, allowsMultipleSelection: Bool, allowsEmptySelection: Bool, isSearchBarHidden: Bool = false, disableListEntriesSection: Bool, onTap: ((_ index: Int) -> Void)? = nil, selectAll: ((_ isAll: Bool) -> Void)? = nil, updateSearchListPickerHeight: ((CGFloat) -> Void)? = nil) {
16+
/// - allowsDisplaySelectionCount: A boolean value to indicate to display selection count or not.
17+
init(value: Binding<[Int]>, valueOptions: [String] = [], hint: String? = nil, allowsMultipleSelection: Bool, allowsEmptySelection: Bool, isSearchBarHidden: Bool = false, disableListEntriesSection: Bool, allowsDisplaySelectionCount: Bool, onTap: ((_ index: Int) -> Void)? = nil, selectAll: ((_ isAll: Bool) -> Void)? = nil, updateSearchListPickerHeight: ((CGFloat) -> Void)? = nil) {
1718
self.init(value: value, valueOptions: valueOptions, hint: hint, onTap: onTap)
1819

1920
self.allowsMultipleSelection = allowsMultipleSelection
@@ -22,6 +23,7 @@ public extension SearchListPickerItem {
2223
self.selectAll = selectAll
2324
self.updateSearchListPickerHeight = updateSearchListPickerHeight
2425
self.disableListEntriesSection = disableListEntriesSection
26+
self.allowsDisplaySelectionCount = allowsDisplaySelectionCount
2527
}
2628
}
2729

@@ -132,10 +134,24 @@ extension SearchListPickerItem: View {
132134

133135
private func selectionHeader() -> some View {
134136
HStack {
135-
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
136-
.foregroundStyle(Color.preferredColor(.secondaryLabel))
137-
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
137+
if allowsDisplaySelectionCount {
138+
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + "(\(_value.count))")
139+
.foregroundStyle(Color.preferredColor(.secondaryLabel))
140+
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
141+
} else {
142+
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
143+
.foregroundStyle(Color.preferredColor(.secondaryLabel))
144+
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
145+
}
146+
138147
Spacer()
148+
Button(action: {
149+
selectAll?(false)
150+
}) {
151+
Text(NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
152+
.foregroundStyle(Color.preferredColor(.tintColor))
153+
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
154+
}.buttonStyle(PlainButtonStyle())
139155
}
140156
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16)
141157
.padding([.top, .bottom], 8)
@@ -156,9 +172,11 @@ extension SearchListPickerItem: View {
156172
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
157173
Spacer()
158174
Button(action: {
159-
selectAll?(_value.count != _valueOptions.count)
175+
selectAll?(disableListEntriesSection && _value.count == _valueOptions.count ? false : true)
160176
}) {
161-
Text(_value.count == _valueOptions.count ? NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") : NSLocalizedString("Select All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
177+
Text(disableListEntriesSection && _value.count == _valueOptions.count ?
178+
NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") :
179+
NSLocalizedString("Select All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
162180
.foregroundStyle(Color.preferredColor(.tintColor))
163181
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
164182
}.buttonStyle(PlainButtonStyle())

0 commit comments

Comments
 (0)