-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 🎸 sort & filter enhancement part 2 #820
Merged
billzhou0223
merged 9 commits into
SAP:main
from
restaurantt:main-IOSSDKBUG-347-enhancement
Oct 17, 2024
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b84cc94
feat: 🎸 sort & filter enhancement part 2
restaurantt 58440d5
feat: 🎸 sort & filter enhancement part 2
restaurantt f953c7c
feat: 🎸 sort & filter enhancement part 2
restaurantt 3a109ae
Merge branch 'main' into main-IOSSDKBUG-347-enhancement
dyongxu 4db8bef
feat: 🎸 sort & filter enhancement part 2
restaurantt 3e4f923
Merge branch 'main-IOSSDKBUG-347-enhancement' of https://github.com/r…
restaurantt ce195e4
Merge branch 'main' into main-IOSSDKBUG-347-enhancement
restaurantt 8191698
feat: 🎸 sort & filter enhancement part 2
restaurantt 71f2362
Merge branch 'main' into main-IOSSDKBUG-347-enhancement
restaurantt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ public enum SortFilterItem: Identifiable, Hashable { | |
return item.id | ||
case .datetime(let item, _): | ||
return item.id | ||
case .listPicker(let item, _): | ||
return item.id | ||
} | ||
} | ||
|
||
|
@@ -58,6 +60,8 @@ public enum SortFilterItem: Identifiable, Hashable { | |
/// 2. A section of view containing a SwiftUI Canlendar | ||
case datetime(item: DateTimeItem, showsOnFilterFeedbackBar: Bool) | ||
|
||
case listPicker(item: ListPickerItem, showsOnFilterFeedbackBar: Bool) | ||
|
||
public var showsOnFilterFeedbackBar: Bool { | ||
switch self { | ||
case .picker(_, let showsOnFilterFeedbackBar): | ||
|
@@ -70,6 +74,8 @@ public enum SortFilterItem: Identifiable, Hashable { | |
return showsOnFilterFeedbackBar | ||
case .datetime(_, let showsOnFilterFeedbackBar): | ||
return showsOnFilterFeedbackBar | ||
case .listPicker(_, let showsOnFilterFeedbackBar): | ||
return showsOnFilterFeedbackBar | ||
} | ||
} | ||
|
||
|
@@ -101,6 +107,11 @@ public enum SortFilterItem: Identifiable, Hashable { | |
hasher.combine(item.originalValue) | ||
hasher.combine(item.workingValue) | ||
hasher.combine(item.value) | ||
case .listPicker(let item, _): | ||
hasher.combine(item.id) | ||
hasher.combine(item.originalValue) | ||
hasher.combine(item.workingValue) | ||
hasher.combine(item.value) | ||
} | ||
} | ||
} | ||
|
@@ -206,6 +217,26 @@ extension SortFilterItem { | |
} | ||
} | ||
|
||
var listPicker: ListPickerItem { | ||
get { | ||
switch self { | ||
case .listPicker(let item, _): | ||
return item | ||
default: | ||
fatalError("Unexpected value \(self)") | ||
} | ||
} | ||
|
||
set { | ||
switch self { | ||
case .listPicker(_, let showsOnFilterFeedbackBar): | ||
self = .listPicker(item: newValue, showsOnFilterFeedbackBar: showsOnFilterFeedbackBar) | ||
default: | ||
fatalError("Unexpected value \(self)") | ||
} | ||
} | ||
} | ||
|
||
var isChanged: Bool { | ||
switch self { | ||
case .picker(let item, _): | ||
|
@@ -218,6 +249,8 @@ extension SortFilterItem { | |
return item.isChanged | ||
case .slider(let item, _): | ||
return item.isChanged | ||
case .listPicker(let item, _): | ||
return item.isChanged | ||
} | ||
} | ||
|
||
|
@@ -233,6 +266,8 @@ extension SortFilterItem { | |
return item.isOriginal | ||
case .slider(let item, _): | ||
return item.isOriginal | ||
case .listPicker(let item, _): | ||
return item.isOriginal | ||
} | ||
} | ||
|
||
|
@@ -253,6 +288,9 @@ extension SortFilterItem { | |
case .slider(var item, _): | ||
item.cancel() | ||
self.slider = item | ||
case .listPicker(var item, _): | ||
item.cancel() | ||
self.listPicker = item | ||
} | ||
} | ||
|
||
|
@@ -273,6 +311,9 @@ extension SortFilterItem { | |
case .slider(var item, _): | ||
item.reset() | ||
self.slider = item | ||
case .listPicker(var item, _): | ||
item.reset() | ||
self.listPicker = item | ||
} | ||
} | ||
|
||
|
@@ -293,6 +334,9 @@ extension SortFilterItem { | |
case .slider(var item, _): | ||
item.apply() | ||
self.slider = item | ||
case .listPicker(var item, _): | ||
item.apply() | ||
self.listPicker = item | ||
} | ||
} | ||
} | ||
|
@@ -311,9 +355,23 @@ public extension SortFilterItem { | |
public let allowsEmptySelection: Bool | ||
public var showsValueForSingleSelected: Bool = true | ||
public let icon: String? | ||
/// itemLayout is used when listPickerMode is filterFormCell, otherwise is ignored. | ||
public var itemLayout: OptionListPickerItemLayoutType = .fixed | ||
|
||
public init(id: String = UUID().uuidString, name: String, value: [Int], valueOptions: [String], allowsMultipleSelection: Bool, allowsEmptySelection: Bool, showsValueForSingleSelected: Bool = true, icon: String? = nil, itemLayout: OptionListPickerItemLayoutType = .fixed) { | ||
public var displayMode: DisplayMode = .automatic | ||
|
||
/// Available OptionListPicker modes. Use this enum to define picker mode to present. | ||
public enum DisplayMode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nesting Violation: Types should be nested at most 1 level deep (nesting) |
||
/// Decided by options count | ||
case automatic | ||
/// FilterFormCell | ||
case filterFormCell | ||
/// Menu | ||
case menu | ||
/// List | ||
case list | ||
} | ||
|
||
public init(id: String = UUID().uuidString, name: String, value: [Int], valueOptions: [String], allowsMultipleSelection: Bool, allowsEmptySelection: Bool, showsValueForSingleSelected: Bool = true, icon: String? = nil, itemLayout: OptionListPickerItemLayoutType = .fixed, displayMode: DisplayMode = .automatic) { | ||
self.id = id | ||
self.name = name | ||
self.value = value | ||
|
@@ -325,6 +383,7 @@ public extension SortFilterItem { | |
self.showsValueForSingleSelected = showsValueForSingleSelected | ||
self.icon = icon | ||
self.itemLayout = itemLayout | ||
self.displayMode = displayMode | ||
} | ||
|
||
mutating func onTap(option: String) { | ||
|
@@ -389,6 +448,15 @@ public extension SortFilterItem { | |
self.workingValue.contains(index) | ||
} | ||
|
||
mutating func selectAll(_ isAll: Bool) { | ||
self.workingValue.removeAll() | ||
if isAll { | ||
for i in 0 ..< self.valueOptions.count { | ||
self.workingValue.append(i) | ||
} | ||
} | ||
} | ||
|
||
var isChecked: Bool { | ||
!self.value.isEmpty | ||
} | ||
|
@@ -582,4 +650,127 @@ public extension SortFilterItem { | |
self.workingValue == self.originalValue | ||
} | ||
} | ||
|
||
/// Data structure for filter feedback, option list picker, | ||
struct ListPickerItem: Identifiable, Equatable { | ||
public let id: String | ||
public var name: String | ||
public var value: [Int] | ||
public var workingValue: [Int] | ||
let originalValue: [Int] | ||
|
||
var valueOptions: [String] | ||
public let allowsMultipleSelection: Bool | ||
public let allowsEmptySelection: Bool | ||
public var showsValueForSingleSelected: Bool = true | ||
public let icon: String? | ||
|
||
public init(id: String = UUID().uuidString, name: String, value: [Int], valueOptions: [String], allowsMultipleSelection: Bool, allowsEmptySelection: Bool, showsValueForSingleSelected: Bool = true, icon: String? = nil) { | ||
self.id = id | ||
self.name = name | ||
self.value = value | ||
self.workingValue = value | ||
self.originalValue = value | ||
self.valueOptions = valueOptions | ||
self.allowsMultipleSelection = allowsMultipleSelection | ||
self.allowsEmptySelection = allowsEmptySelection | ||
self.showsValueForSingleSelected = showsValueForSingleSelected | ||
self.icon = icon | ||
} | ||
|
||
mutating func onTap(option: String) { | ||
guard let index = valueOptions.firstIndex(of: option) else { return } | ||
if self.workingValue.contains(index) { | ||
if self.workingValue.count > 1 { | ||
self.workingValue = self.workingValue.filter { $0 != index } | ||
} else { | ||
if self.allowsEmptySelection { | ||
self.workingValue = [] | ||
} else { | ||
self.workingValue = index == 1 ? [0] : [1] | ||
} | ||
} | ||
} else { | ||
if self.allowsMultipleSelection { | ||
self.workingValue.append(index) | ||
} else { | ||
self.workingValue = [index] | ||
} | ||
} | ||
} | ||
|
||
mutating func optionOnTap(_ index: Int) { | ||
if self.workingValue.contains(index) { | ||
if self.workingValue.count > 1 { | ||
self.workingValue = self.workingValue.filter { $0 != index } | ||
} else { | ||
if self.allowsEmptySelection { | ||
self.workingValue = [] | ||
} else { | ||
self.workingValue = index == 1 ? [0] : [1] | ||
} | ||
} | ||
} else { | ||
if self.allowsMultipleSelection { | ||
self.workingValue.append(index) | ||
} else { | ||
self.workingValue = [index] | ||
} | ||
} | ||
} | ||
|
||
mutating func cancel() { | ||
self.workingValue = self.value.map { $0 } | ||
} | ||
|
||
mutating func reset() { | ||
self.workingValue = self.originalValue.map { $0 } | ||
} | ||
|
||
mutating func apply() { | ||
self.value = self.workingValue.map { $0 } | ||
} | ||
|
||
func isOptionSelected(_ option: String) -> Bool { | ||
guard let idx = valueOptions.firstIndex(of: option) else { return false } | ||
return self.workingValue.contains(idx) | ||
} | ||
|
||
func isOptionSelected(index: Int) -> Bool { | ||
self.workingValue.contains(index) | ||
} | ||
|
||
mutating func selectAll(_ isAll: Bool) { | ||
self.workingValue.removeAll() | ||
if isAll { | ||
for i in 0 ..< self.valueOptions.count { | ||
self.workingValue.append(i) | ||
} | ||
} | ||
} | ||
|
||
var isChecked: Bool { | ||
!self.value.isEmpty | ||
} | ||
|
||
var label: String { | ||
if self.allowsMultipleSelection, self.value.count >= 1 { | ||
if self.value.count == 1, self.showsValueForSingleSelected { | ||
return self.valueOptions[self.value[0]] | ||
} else { | ||
return "\(self.name) (\(self.value.count))" | ||
} | ||
} else { | ||
return self.name | ||
} | ||
} | ||
|
||
var isChanged: Bool { | ||
self.value != self.workingValue | ||
} | ||
|
||
var isOriginal: Bool { | ||
self.workingValue == self.originalValue | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nesting Violation: Types should be nested at most 1 level deep (nesting)