Skip to content

Commit

Permalink
fix: 🐛 [IOSSDKBUG-447]SortFilterItem Reset button func (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
restaurantt authored Nov 20, 2024
1 parent 4d21c78 commit cff8360
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ struct SortFilterExample: View {
[
.switch(item: .init(name: "Favorite", value: true, icon: "heart.fill"), showsOnFilterFeedbackBar: true),
.switch(item: .init(name: "Tagged", value: nil, icon: "tag"), showsOnFilterFeedbackBar: false),
.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),
.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),
.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),
.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),
.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),
.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),
.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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ struct CancellableResettableDialogForm<Title: View, CancelAction: View, ResetAct

var body: some View {
VStack(spacing: UIDevice.current.userInterfaceIdiom != .phone ? 8 : 16) {
HStack {
self.cancelAction.accessibilityIdentifier("Cancel")
Spacer()
ZStack(alignment: .center, content: {
self.title
Spacer()
self.resetAction.accessibilityIdentifier("Reset")
}
HStack {
self.cancelAction.accessibilityIdentifier("Cancel")
Spacer()
self.resetAction.accessibilityIdentifier("Reset")
}
})
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16)

#if !os(visionOS)
Expand Down
45 changes: 43 additions & 2 deletions Sources/FioriSwiftUICore/DataTypes/SortFilter+DataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,38 @@ extension SortFilterItem {
}
}

/// FilterFeedbackBar ResetButton Configuration
public struct FilterFeedbackBarResetButtonConfiguration: Equatable {
var type: FilterFeedbackBarResetButtonType
var title: String
var isHidden: Bool

init(type: FilterFeedbackBarResetButtonType = .reset, title: String, isHidden: Bool = false) {
self.type = type
self.title = title
self.isHidden = isHidden
}

/// Default FilterFeedbackBarResetButtonConfiguration
public init() {
self.init(type: .reset, title: NSLocalizedString("Reset", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""), isHidden: false)
}

/// Customize FilterFeedbackBarResetButtonConfiguration
/// - Parameters:
/// - type: Reset button type
/// - title: Reset button title
/// - isHidden: A Boolean value that determines whether reset button is hidden.
public init(with type: FilterFeedbackBarResetButtonType = .reset, title: String = "", isHidden: Bool = false) {
self.init(type: type, title: title == "" ? NSLocalizedString("Reset", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") : title, isHidden: isHidden)
}

/// :nodoc:
public static func == (lhs: FilterFeedbackBarResetButtonConfiguration, rhs: FilterFeedbackBarResetButtonConfiguration) -> Bool {
lhs.type == rhs.type && lhs.title == rhs.title && lhs.isHidden == rhs.isHidden
}
}

public extension SortFilterItem {
/// Data structure for filter feedback, option list picker,
struct PickerItem: Identifiable, Equatable {
Expand All @@ -366,7 +398,9 @@ public extension SortFilterItem {
/// If seachBar in list display mode is shown. Default is `false`.
public var isSearchBarHidden: Bool = false
var disableListEntriesSection: Bool = false

var allowsDisplaySelectionCount: Bool = true
var resetButtonConfiguration: FilterFeedbackBarResetButtonConfiguration = .init()

/// Available OptionListPicker modes. Use this enum to define picker mode to present.
public enum DisplayMode {
/// Decided by options count
Expand Down Expand Up @@ -402,7 +436,7 @@ public extension SortFilterItem {
case disable
}

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) {
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()) {
self.id = id
self.name = name
self.value = value
Expand All @@ -425,6 +459,9 @@ public extension SortFilterItem {
case .enable:
self.disableListEntriesSection = false
}

self.allowsDisplaySelectionCount = allowsDisplaySelectionCount
self.resetButtonConfiguration = resetButtonConfiguration
}

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

mutating func clearAll() {
self.workingValue.removeAll()
}

mutating func apply() {
self.value = self.workingValue.map { $0 }
}
Expand Down
1 change: 1 addition & 0 deletions Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ public protocol OptionListPickerItemModel: OptionListPickerComponent {
// sourcery: virtualPropPopoverWidth = "let popoverWidth = 393.0"
// sourcery: virtualPropKeyboardHeight = "@State var _keyboardHeight: CGFloat = 0.0"
// sourcery: virtualPropDisableListEntriesSection = "var disableListEntriesSection: Bool = false"
// sourcery: virtualPropAllowsDisplaySelectionCount = "var allowsDisplaySelectionCount: Bool = true"
public protocol SearchListPickerItemModel: OptionListPickerComponent {
// sourcery: default.value = nil
// sourcery: no_view
Expand Down
30 changes: 24 additions & 6 deletions Sources/FioriSwiftUICore/Views/SearchListPickerItem+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public extension SearchListPickerItem {
/// - selectAll: The closure when click 'Select All' button.
/// - updateSearchListPickerHeight: The closure to update the parent view.
/// - disableListEntriesSection: A boolean value to indicate to disable entries section or not.
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) {
/// - allowsDisplaySelectionCount: A boolean value to indicate to display selection count or not.
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) {
self.init(value: value, valueOptions: valueOptions, hint: hint, onTap: onTap)

self.allowsMultipleSelection = allowsMultipleSelection
Expand All @@ -22,6 +23,7 @@ public extension SearchListPickerItem {
self.selectAll = selectAll
self.updateSearchListPickerHeight = updateSearchListPickerHeight
self.disableListEntriesSection = disableListEntriesSection
self.allowsDisplaySelectionCount = allowsDisplaySelectionCount
}
}

Expand Down Expand Up @@ -132,10 +134,24 @@ extension SearchListPickerItem: View {

private func selectionHeader() -> some View {
HStack {
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
.foregroundStyle(Color.preferredColor(.secondaryLabel))
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
if allowsDisplaySelectionCount {
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") + "(\(_value.count))")
.foregroundStyle(Color.preferredColor(.secondaryLabel))
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
} else {
Text(NSLocalizedString("Selected", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
.foregroundStyle(Color.preferredColor(.secondaryLabel))
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
}

Spacer()
Button(action: {
selectAll?(false)
}) {
Text(NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
.foregroundStyle(Color.preferredColor(.tintColor))
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
}.buttonStyle(PlainButtonStyle())
}
.padding([.leading, .trailing], UIDevice.current.userInterfaceIdiom != .phone ? 13 : 16)
.padding([.top, .bottom], 8)
Expand All @@ -156,9 +172,11 @@ extension SearchListPickerItem: View {
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
Spacer()
Button(action: {
selectAll?(_value.count != _valueOptions.count)
selectAll?(disableListEntriesSection && _value.count == _valueOptions.count ? false : true)
}) {
Text(_value.count == _valueOptions.count ? NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") : NSLocalizedString("Select All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
Text(disableListEntriesSection && _value.count == _valueOptions.count ?
NSLocalizedString("Deselect All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "") :
NSLocalizedString("Select All", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: ""))
.foregroundStyle(Color.preferredColor(.tintColor))
.font(.fiori(forTextStyle: .subheadline, weight: .regular))
}.buttonStyle(PlainButtonStyle())
Expand Down
Loading

0 comments on commit cff8360

Please sign in to comment.