chore(MembersDropdown): Search behavior adjusted
This commit is contained in:
parent
c290562ce1
commit
6fcb533b68
|
@ -152,12 +152,8 @@ SplitView {
|
|||
}
|
||||
|
||||
expression: {
|
||||
membersDropdown.selectedKeys
|
||||
membersDropdown.searchText
|
||||
|
||||
if (membersDropdown.selectedKeys.indexOf(model.pubKey) > -1)
|
||||
return true
|
||||
|
||||
const filter = membersDropdown.searchText.toLowerCase()
|
||||
return matchesAlias(model.alias.toLowerCase(), filter)
|
||||
|| model.displayName.toLowerCase().includes(filter)
|
||||
|
@ -175,7 +171,7 @@ SplitView {
|
|||
|
||||
onAddButtonClicked: {
|
||||
logs.logEvent("MembersDropdown::addButtonClicked, keys: "
|
||||
+ membersDropdown.selectedKeys)
|
||||
+ [...membersDropdown.selectedKeys])
|
||||
}
|
||||
|
||||
Component.onCompleted: open()
|
||||
|
@ -185,7 +181,7 @@ SplitView {
|
|||
|
||||
LogsAndControlsPanel {
|
||||
SplitView.minimumHeight: 100
|
||||
SplitView.preferredHeight: 250
|
||||
SplitView.preferredHeight: 320
|
||||
|
||||
logsView.logText: logs.logText
|
||||
|
||||
|
@ -343,7 +339,7 @@ SplitView {
|
|||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: `selected members: ${membersDropdown.selectedKeys}`
|
||||
text: `selected members: ${[...membersDropdown.selectedKeys]}`
|
||||
wrapMode: Label.Wrap
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import shared.controls.delegates 1.0
|
|||
StatusDropdown {
|
||||
id: root
|
||||
|
||||
property var selectedKeys: []
|
||||
property var selectedKeys: new Set()
|
||||
property bool forceButtonDisabled: false
|
||||
property int maximumListHeight: 288
|
||||
|
||||
|
@ -28,6 +28,33 @@ StatusDropdown {
|
|||
Add, Update
|
||||
}
|
||||
|
||||
Instantiator {
|
||||
id: selectionChecker
|
||||
|
||||
model: root.model
|
||||
|
||||
property var keys: []
|
||||
|
||||
delegate: QtObject {
|
||||
readonly property string key: model.pubKey
|
||||
}
|
||||
|
||||
readonly property bool allSelected:
|
||||
keys.every(key => root.selectedKeys.has(key))
|
||||
|
||||
onObjectAdded: {
|
||||
const keysCopy = [...keys]
|
||||
keysCopy.splice(index, 0, object.key)
|
||||
keys = keysCopy
|
||||
}
|
||||
|
||||
onObjectRemoved: {
|
||||
const keysCopy = [...keys]
|
||||
keysCopy.splice(index, 1)
|
||||
keys = keysCopy
|
||||
}
|
||||
}
|
||||
|
||||
property int mode: MembersDropdown.Mode.Add
|
||||
|
||||
signal backButtonClicked
|
||||
|
@ -145,7 +172,7 @@ StatusDropdown {
|
|||
text: qsTr("Select all")
|
||||
font.weight: Font.Medium
|
||||
|
||||
checked: root.selectedKeys.length === listView.count
|
||||
checked: selectionChecker.allSelected
|
||||
|
||||
leftSide: false
|
||||
size: StatusCheckBox.Size.Small
|
||||
|
@ -156,20 +183,15 @@ StatusDropdown {
|
|||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onClicked: {
|
||||
if (listView.headerItem.checked) {
|
||||
root.selectedKeys = []
|
||||
return
|
||||
}
|
||||
const currentKeys = selectionChecker.keys
|
||||
const keysSet = new Set([...root.selectedKeys])
|
||||
|
||||
const count = root.model.rowCount()
|
||||
const keys = []
|
||||
if (listView.headerItem.checked)
|
||||
currentKeys.forEach(key => keysSet.delete(key))
|
||||
else
|
||||
currentKeys.forEach(key => keysSet.add(key))
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const key = ModelUtils.get(root.model, i, "pubKey")
|
||||
keys.push(key)
|
||||
}
|
||||
|
||||
root.selectedKeys = keys
|
||||
root.selectedKeys = keysSet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,14 +210,12 @@ StatusDropdown {
|
|||
color: "transparent"
|
||||
|
||||
onClicked: {
|
||||
const index = root.selectedKeys.indexOf(model.pubKey)
|
||||
const selectedKeysCopy = Object.assign(
|
||||
[], root.selectedKeys)
|
||||
const selectedKeysCopy = new Set([...root.selectedKeys])
|
||||
|
||||
if (index === -1)
|
||||
selectedKeysCopy.push(model.pubKey)
|
||||
if (root.selectedKeys.has(model.pubKey))
|
||||
selectedKeysCopy.delete(model.pubKey)
|
||||
else
|
||||
selectedKeysCopy.splice(index, 1)
|
||||
selectedKeysCopy.add(model.pubKey)
|
||||
|
||||
root.selectedKeys = selectedKeysCopy
|
||||
}
|
||||
|
@ -205,7 +225,7 @@ StatusDropdown {
|
|||
id: contactCheckbox
|
||||
|
||||
size: StatusCheckBox.Size.Small
|
||||
checked: root.selectedKeys.indexOf(model.pubKey) > -1
|
||||
checked: root.selectedKeys.has(model.pubKey)
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
|
@ -246,7 +266,7 @@ StatusDropdown {
|
|||
return false
|
||||
|
||||
if (root.mode === MembersDropdown.Mode.Add)
|
||||
return root.selectedKeys.length > 0
|
||||
return root.selectedKeys.size > 0
|
||||
|
||||
return true
|
||||
}
|
||||
|
@ -255,8 +275,8 @@ StatusDropdown {
|
|||
if (root.mode === MembersDropdown.Mode.Update)
|
||||
return qsTr("Update members")
|
||||
|
||||
return root.selectedKeys.length > 0
|
||||
? qsTr("Add %n member(s)", "", root.selectedKeys.length)
|
||||
return root.selectedKeys.size > 0
|
||||
? qsTr("Add %n member(s)", "", root.selectedKeys.size)
|
||||
: qsTr("Add")
|
||||
}
|
||||
|
||||
|
|
|
@ -244,18 +244,17 @@ StatusScrollView {
|
|||
filters: ExpressionFilter {
|
||||
id: selectedKeysFilter
|
||||
|
||||
property var keys: []
|
||||
property var keys: new Set()
|
||||
|
||||
expression: keys.indexOf(model.pubKey) !== -1
|
||||
expression: keys.has(model.pubKey)
|
||||
}
|
||||
}
|
||||
|
||||
onRemoveMemberRequested: {
|
||||
const pubKey = ModelUtils.get(membersModel, index, "pubKey")
|
||||
const keyIndex = selectedKeysFilter.keys.indexOf(pubKey)
|
||||
|
||||
selectedKeysFilter.keys.splice(keyIndex, 1)
|
||||
selectedKeysFilter.keys = selectedKeysFilter.keys
|
||||
selectedKeysFilter.keys.delete(pubKey)
|
||||
selectedKeysFilter.keys = new Set([...selectedKeysFilter.keys])
|
||||
}
|
||||
|
||||
onAddAddressesRequested: (addresses_) => {
|
||||
|
@ -309,7 +308,7 @@ StatusScrollView {
|
|||
recipientTypeSelectionDropdown.close()
|
||||
membersDropdown.selectedKeys = selectedKeysFilter.keys
|
||||
|
||||
const hasSelection = selectedKeysFilter.keys.length !== 0
|
||||
const hasSelection = selectedKeysFilter.keys.size !== 0
|
||||
|
||||
membersDropdown.mode = hasSelection
|
||||
? MembersDropdown.Mode.Update
|
||||
|
@ -324,7 +323,7 @@ StatusScrollView {
|
|||
|
||||
forceButtonDisabled:
|
||||
mode === MembersDropdown.Mode.Update &&
|
||||
JSON.stringify(selectedKeys) === JSON.stringify(selectedKeysFilter.keys)
|
||||
[...selectedKeys].sort().join() === [...selectedKeysFilter.keys].sort().join()
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: membersModel
|
||||
|
@ -338,12 +337,8 @@ StatusScrollView {
|
|||
}
|
||||
|
||||
expression: {
|
||||
membersDropdown.selectedKeys
|
||||
membersDropdown.searchText
|
||||
|
||||
if (membersDropdown.selectedKeys.indexOf(model.pubKey) > -1)
|
||||
return true
|
||||
|
||||
const filter = membersDropdown.searchText.toLowerCase()
|
||||
return matchesAlias(model.alias.toLowerCase(), filter)
|
||||
|| model.displayName.toLowerCase().includes(filter)
|
||||
|
@ -394,7 +389,7 @@ StatusScrollView {
|
|||
const addresses_ = ModelUtils.modelToArray(
|
||||
addresses, ["address"]).map(e => e.address)
|
||||
|
||||
const pubKeys = selectedKeysFilter.keys
|
||||
const pubKeys = [...selectedKeysFilter.keys]
|
||||
|
||||
root.airdropClicked(airdropTokens, addresses_, pubKeys)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue