Skip to content

Commit bbe2fcb

Browse files
restauranttdyongxu
andauthored
refactor: 💡 [HCPSDKFIORIUIKIT-2232]SortFilterView NoteFormView (SAP#1024)
* refactor: 💡 [HCPSDKFIORIUIKIT-2232]SortFilterView NoteFormView * refactor: 💡 [HCPSDKFIORIUIKIT-2232]SortFilterView NoteFormView --------- Co-authored-by: dyongxu <[email protected]>
1 parent 78df295 commit bbe2fcb

File tree

8 files changed

+382
-31
lines changed

8 files changed

+382
-31
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ struct SortFilterExample: View {
3939
.datetime(item: .init(name: "Completion Date", value: nil), showsOnFilterFeedbackBar: true)
4040
],
4141
[
42-
.title(item: .init(name: "Title", text: "This is default text.", placeholder: "Please input", maxTextLength: 20, isCharCountEnabled: true, charCountBeyondLimitMsg: "CharCountBeyondLimit"), showsOnFilterFeedbackBar: true)
42+
.title(item: .init(name: "Title", text: "This is default text.", placeholder: "Please input", maxTextLength: 20, isCharCountEnabled: true, charCountBeyondLimitMsg: "Char count beyond limit"), showsOnFilterFeedbackBar: true),
43+
.note(item: .init(name: "Note", text: "This is default text.", placeholder: "Please input", maxTextLength: 200, isCharCountEnabled: true, charCountBeyondLimitMsg: "Char count beyond limit"), showsOnFilterFeedbackBar: false)
4344
]
4445
]
4546

Apps/Examples/Examples/FioriSwiftUICore/SortFilter/SortFilterView+Extensions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension View {
1818
return self.json(item: v)
1919
case .title(let v, _):
2020
return self.json(item: v)
21+
case .note(let v, _):
22+
return self.json(item: v)
2123
}
2224
}
2325

@@ -44,4 +46,8 @@ extension View {
4446
func json(item: SortFilterItem.TitleItem) -> String {
4547
"{name: \(item.name), value: \(item.text)}"
4648
}
49+
50+
func json(item: SortFilterItem.NoteItem) -> String {
51+
"{name: \(item.name), value: \(item.text)}"
52+
}
4753
}

Sources/FioriSwiftUICore/DataTypes/SortFilter+DataType.swift

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public enum SortFilterItem: Identifiable, Hashable {
2020
return item.id
2121
case .title(let item, _):
2222
return item.id
23+
case .note(let item, _):
24+
return item.id
2325
}
2426
}
2527

@@ -75,6 +77,14 @@ public enum SortFilterItem: Identifiable, Hashable {
7577
///
7678
/// 2. A section of view containing a SwiftUI TitleFormView with Fiori style
7779
case title(item: TitleItem, showsOnFilterFeedbackBar: Bool)
80+
81+
/// The type of UI control is used to build:
82+
/// Typically not used in FilterFeedbackBar.
83+
///
84+
/// 1. Sort & Filter's menu item associated with a popover containing a SwiftUI NoteFormView with Fiori style
85+
///
86+
/// 2. A section of view containing a SwiftUI NoteFormView with Fiori style
87+
case note(item: NoteItem, showsOnFilterFeedbackBar: Bool)
7888

7989
public var showsOnFilterFeedbackBar: Bool {
8090
switch self {
@@ -92,6 +102,8 @@ public enum SortFilterItem: Identifiable, Hashable {
92102
return showsOnFilterFeedbackBar
93103
case .title(_, let showsOnFilterFeedbackBar):
94104
return showsOnFilterFeedbackBar
105+
case .note(_, let showsOnFilterFeedbackBar):
106+
return showsOnFilterFeedbackBar
95107
}
96108
}
97109

@@ -133,6 +145,11 @@ public enum SortFilterItem: Identifiable, Hashable {
133145
hasher.combine(item.originalText)
134146
hasher.combine(item.workingText)
135147
hasher.combine(item.text)
148+
case .note(let item, _):
149+
hasher.combine(item.id)
150+
hasher.combine(item.originalText)
151+
hasher.combine(item.workingText)
152+
hasher.combine(item.text)
136153
}
137154
}
138155
}
@@ -278,6 +295,26 @@ extension SortFilterItem {
278295
}
279296
}
280297

298+
var note: NoteItem {
299+
get {
300+
switch self {
301+
case .note(let item, _):
302+
return item
303+
default:
304+
fatalError("Unexpected value \(self)")
305+
}
306+
}
307+
308+
set {
309+
switch self {
310+
case .note(_, let showsOnFilterFeedbackBar):
311+
self = .note(item: newValue, showsOnFilterFeedbackBar: showsOnFilterFeedbackBar)
312+
default:
313+
fatalError("Unexpected value \(self)")
314+
}
315+
}
316+
}
317+
281318
var isChanged: Bool {
282319
switch self {
283320
case .picker(let item, _):
@@ -294,6 +331,8 @@ extension SortFilterItem {
294331
return item.isChanged
295332
case .title(let item, _):
296333
return item.isChanged
334+
case .note(let item, _):
335+
return item.isChanged
297336
}
298337
}
299338

@@ -313,6 +352,8 @@ extension SortFilterItem {
313352
return item.isOriginal
314353
case .title(let item, _):
315354
return item.isOriginal
355+
case .note(let item, _):
356+
return item.isOriginal
316357
}
317358
}
318359

@@ -339,6 +380,9 @@ extension SortFilterItem {
339380
case .title(var item, _):
340381
item.cancel()
341382
self.title = item
383+
case .note(var item, _):
384+
item.cancel()
385+
self.note = item
342386
}
343387
}
344388

@@ -365,6 +409,9 @@ extension SortFilterItem {
365409
case .title(var item, _):
366410
item.reset()
367411
self.title = item
412+
case .note(var item, _):
413+
item.reset()
414+
self.note = item
368415
}
369416
}
370417

@@ -391,6 +438,9 @@ extension SortFilterItem {
391438
case .title(var item, _):
392439
item.apply()
393440
self.title = item
441+
case .note(var item, _):
442+
item.apply()
443+
self.note = item
394444
}
395445
}
396446
}
@@ -1175,4 +1225,94 @@ public extension SortFilterItem {
11751225
"\(self.name): \(self.text)"
11761226
}
11771227
}
1228+
1229+
/// Data structure for note type
1230+
struct NoteItem: Identifiable, Equatable {
1231+
public var id: String
1232+
public var name: String
1233+
public let icon: String?
1234+
1235+
public var text: String
1236+
var workingText: String
1237+
let originalText: String
1238+
public var placeholder: String?
1239+
public var controlState: ControlState = .normal
1240+
public var errorMessage: String?
1241+
public var maxTextLength: Int?
1242+
public let hintText: String?
1243+
public let hidesReadOnlyHint: Bool
1244+
public let isCharCountEnabled: Bool
1245+
public let allowsBeyondLimit: Bool
1246+
public let charCountReachLimitMessage: String?
1247+
public let charCountBeyondLimitMsg: String?
1248+
public let minTextEditorHeight: CGFloat?
1249+
public let maxTextEditorHeight: CGFloat?
1250+
1251+
/// Create a textfiled.
1252+
/// - Parameters:
1253+
/// - id: The unique identifier for TitleItem.
1254+
/// - name: Item name.
1255+
/// - text: The text in textfield.
1256+
/// - placeholder: A text for placeholder of textfield.
1257+
/// - controlState: A state for textfield.
1258+
/// - errorMessage: A text when the text of textfield not satisfy conditions.
1259+
/// - minTextEditorHeight: The minimum height of the TextEditor. It needs to be greater than 44. Otherwise, it is ignored.
1260+
/// - maxTextEditorHeight The maximum height of the TextEditor.
1261+
/// - maxTextLength: A maximum value for text length.
1262+
/// - hidesReadOnlyHint: A boolean value to indicate to hide read only hint or not.
1263+
/// - isCharCountEnabled: A boolean value to indicate to display char count or not.
1264+
/// - allowsBeyondLimit: A boolean value to indicate to allows inputting text beyond maximum char count limit or not.
1265+
/// - charCountReachLimitMessage: A text for char count reach maximum limit.
1266+
/// - charCountBeyondLimitMsg: A text for char beyond maximum limit.
1267+
/// - icon: The icon image in the item bar.
1268+
/// - hintText: The hint text of the textfiled.
1269+
public init(id: String = UUID().uuidString, name: String, text: String, isSecureEnabled: Bool? = false, placeholder: String? = nil, controlState: ControlState = .normal, errorMessage: String? = nil, minTextEditorHeight: CGFloat? = nil, maxTextEditorHeight: CGFloat? = nil, maxTextLength: Int? = nil, hidesReadOnlyHint: Bool = false, isCharCountEnabled: Bool = false, allowsBeyondLimit: Bool = false, charCountReachLimitMessage: String? = nil, charCountBeyondLimitMsg: String? = nil, icon: String? = nil, hintText: String? = nil) {
1270+
self.id = id
1271+
self.name = name
1272+
self.text = text
1273+
self.workingText = text
1274+
self.originalText = text
1275+
self.icon = icon
1276+
self.placeholder = placeholder
1277+
self.controlState = controlState
1278+
self.minTextEditorHeight = minTextEditorHeight
1279+
self.maxTextEditorHeight = maxTextEditorHeight
1280+
self.errorMessage = errorMessage
1281+
self.maxTextLength = maxTextLength
1282+
self.hidesReadOnlyHint = hidesReadOnlyHint
1283+
self.isCharCountEnabled = isCharCountEnabled
1284+
self.allowsBeyondLimit = allowsBeyondLimit
1285+
self.charCountReachLimitMessage = charCountReachLimitMessage
1286+
self.charCountBeyondLimitMsg = charCountBeyondLimitMsg
1287+
self.hintText = hintText
1288+
}
1289+
1290+
mutating func reset() {
1291+
self.workingText = self.originalText
1292+
}
1293+
1294+
mutating func cancel() {
1295+
self.workingText = self.text
1296+
}
1297+
1298+
mutating func apply() {
1299+
self.text = self.workingText
1300+
}
1301+
1302+
var isChecked: Bool {
1303+
!self.text.isEmpty
1304+
}
1305+
1306+
var isChanged: Bool {
1307+
self.text != self.workingText
1308+
}
1309+
1310+
var isOriginal: Bool {
1311+
self.workingText == self.originalText
1312+
}
1313+
1314+
var label: String {
1315+
"\(self.name): \(self.text)"
1316+
}
1317+
}
11781318
}

Sources/FioriSwiftUICore/Views/SortFilter/FilterFeedbackBarItemContainer.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ extension FilterFeedbackBarItemContainer: View {
6868
.accessibilityElement()
6969
.accessibilityLabel(self._items[r][c].title.label)
7070
.accessibilityIdentifier(self._items[r][c].title.name)
71+
case .note:
72+
NoteMenuItem(item: Binding<SortFilterItem.NoteItem>(get: { self._items[r][c].note }, set: { self._items[r][c].note = $0 }), onUpdate: self.onUpdate)
73+
.accessibilityElement()
74+
.accessibilityLabel(self._items[r][c].note.label)
75+
.accessibilityIdentifier(self._items[r][c].note.name)
7176
}
7277
}
7378
}

0 commit comments

Comments
 (0)