fix(Community Permissions): Update `Who holds` add new item with always AND action

- Logic related to operators removed.
- Dropdown `and/or` removed.
- Updated `PermissionItem` to display only the tag and not the operator.
- Updated `storybook` according to new changes.

Fixes #8500
This commit is contained in:
Noelia 2023-01-12 12:31:08 +01:00 committed by Noelia
parent bfd5fe1446
commit 5676fb96ef
9 changed files with 34 additions and 157 deletions

View File

@ -13,8 +13,6 @@ ColumnLayout {
property string icon property string icon
property string amountText property string amountText
property bool isAmountVisible: false property bool isAmountVisible: false
property bool isExpression: false
property bool isAnd: true
property bool isImageSelectorVisible: true property bool isImageSelectorVisible: true
property var iconsModel property var iconsModel
@ -95,11 +93,4 @@ ColumnLayout {
} }
} }
} }
Switch {
visible: root.isExpression
text: "OR -- AND"
checked: root.isAnd
onToggled: root.isAnd = checked
}
} }

View File

@ -61,16 +61,7 @@ Flickable {
icon: model.imageSource icon: model.imageSource
amountText: model.amount amountText: model.amount
isAmountVisible: true isAmountVisible: true
isExpression: model.operator !== OperatorsUtils.Operators.None
isAnd: model.operator === OperatorsUtils.Operators.And
iconsModel: TokensCollectiblesIconsModel {} iconsModel: TokensCollectiblesIconsModel {}
onIsAndChanged: {
if(model.operator !== OperatorsUtils.Operators.None)
{
if(isAnd) model.operator = OperatorsUtils.Operators.And
else model.operator = OperatorsUtils.Operators.Or
}
}
onNameChanged: model.name = name onNameChanged: model.name = name
onIconChanged: model.imageSource = icon onIconChanged: model.imageSource = icon
onAmountTextChanged: model.amount = parseFloat(amountText) onAmountTextChanged: model.amount = parseFloat(amountText)
@ -85,7 +76,6 @@ Flickable {
amountText: d.newAmount amountText: d.newAmount
isAmountVisible: true isAmountVisible: true
iconsModel: TokensCollectiblesIconsModel {} iconsModel: TokensCollectiblesIconsModel {}
isExpression: false
onNameChanged: d.newName = name onNameChanged: d.newName = name
onIconChanged: d.newImageSource = icon onIconChanged: d.newImageSource = icon
onAmountTextChanged: d.newAmount = parseFloat(amountText) onAmountTextChanged: d.newAmount = parseFloat(amountText)
@ -97,7 +87,6 @@ Flickable {
text: "Add new holding" text: "Add new holding"
onClicked: { onClicked: {
model.holdingsListModel.append([{ model.holdingsListModel.append([{
operator: OperatorsUtils.Operators.And,
type: 1, type: 1,
key: d.newName, key: d.newName,
name: d.newName, name: d.newName,

View File

@ -24,11 +24,6 @@ Pane {
onClicked: openFlow(HoldingsDropdown.FlowType.Add) onClicked: openFlow(HoldingsDropdown.FlowType.Add)
} }
Button {
text: "AddWithOperators"
onClicked: openFlow(HoldingsDropdown.FlowType.AddWithOperators)
}
Button { Button {
text: "Update" text: "Update"
onClicked: openFlow(HoldingsDropdown.FlowType.Update) onClicked: openFlow(HoldingsDropdown.FlowType.Update)

View File

@ -30,7 +30,9 @@ QtObject {
case OperatorsUtils.Operators.Or: case OperatorsUtils.Operators.Or:
return root.orOperatorText return root.orOperatorText
case OperatorsUtils.Operators.None: case OperatorsUtils.Operators.None:
default:
return "" return ""
} }
} }
} }

View File

@ -25,9 +25,9 @@ StatusDropdown {
property int ensType: EnsPanel.EnsType.Any property int ensType: EnsPanel.EnsType.Any
property string ensDomainName: "" property string ensDomainName: ""
signal addToken(string key, real amount, int operator) signal addToken(string key, real amount)
signal addCollectible(string key, real amount, int operator) signal addCollectible(string key, real amount)
signal addEns(bool any, string customDomain, int operator) signal addEns(bool any, string customDomain)
signal updateToken(string key, real amount) signal updateToken(string key, real amount)
signal updateCollectible(string key, real amount) signal updateCollectible(string key, real amount)
@ -37,7 +37,6 @@ StatusDropdown {
function reset() { function reset() {
d.currentHoldingType = HoldingTypes.Type.Token d.currentHoldingType = HoldingTypes.Type.Token
d.operator = OperatorsUtils.Operators.None
d.tokenAmountText = "" d.tokenAmountText = ""
d.collectibleAmountText = "" d.collectibleAmountText = ""
@ -61,14 +60,11 @@ StatusDropdown {
onClosed: root.reset() onClosed: root.reset()
enum FlowType { enum FlowType {
Add, AddWithOperators, Update Add, Update
} }
function openFlow(flowType) { function openFlow(flowType) {
switch (flowType) { switch (flowType) {
case HoldingsDropdown.FlowType.AddWithOperators:
statesStack.push(d.operatorsState)
break
case HoldingsDropdown.FlowType.Add: case HoldingsDropdown.FlowType.Add:
statesStack.push(d.addState) statesStack.push(d.addState)
break break
@ -95,7 +91,6 @@ StatusDropdown {
readonly property bool collectiblesReady: root.collectibleAmount > 0 && root.collectibleKey readonly property bool collectiblesReady: root.collectibleAmount > 0 && root.collectibleKey
readonly property bool ensReady: root.ensType === EnsPanel.EnsType.Any || d.ensDomainNameValid readonly property bool ensReady: root.ensType === EnsPanel.EnsType.Any || d.ensDomainNameValid
readonly property string operatorsState: "OPERATORS"
readonly property string addState: "ADD" readonly property string addState: "ADD"
readonly property string updateState: "UPDATE" readonly property string updateState: "UPDATE"
readonly property string extendedState: "EXTENDED" readonly property string extendedState: "EXTENDED"
@ -108,7 +103,6 @@ StatusDropdown {
property int currentHoldingType: HoldingTypes.Type.Token property int currentHoldingType: HoldingTypes.Type.Token
property int operator: OperatorsUtils.Operators.None
property bool ensDomainNameValid: false property bool ensDomainNameValid: false
signal addClicked signal addClicked
@ -117,9 +111,6 @@ StatusDropdown {
// By design values: // By design values:
readonly property int padding: 8 readonly property int padding: 8
readonly property int operatorsWidth: 159
readonly property int operatorsHeight: 96
readonly property int defaultWidth: 289 readonly property int defaultWidth: 289
readonly property int extendedContentHeight: 380 readonly property int extendedContentHeight: 380
@ -193,11 +184,6 @@ StatusDropdown {
} }
states: [ states: [
State {
name: d.operatorsState
PropertyChanges {target: loader; sourceComponent: operatorsSelectorView}
PropertyChanges {target: root; width: d.operatorsWidth; height: d.operatorsHeight }
},
State { State {
name: d.addState name: d.addState
PropertyChanges {target: loader; sourceComponent: tabsView} PropertyChanges {target: loader; sourceComponent: tabsView}
@ -216,17 +202,6 @@ StatusDropdown {
] ]
} }
Component {
id: operatorsSelectorView
OperatorsSelector {
onOperatorSelected: {
d.operator = operator
statesStack.push(d.addState)
}
}
}
Component { Component {
id: tabsView id: tabsView
@ -325,7 +300,7 @@ StatusDropdown {
target: d target: d
function onAddClicked() { function onAddClicked() {
root.addToken(root.tokenKey, root.tokenAmount, d.operator) root.addToken(root.tokenKey, root.tokenAmount)
} }
function onUpdateClicked() { function onUpdateClicked() {
@ -370,7 +345,7 @@ StatusDropdown {
target: d target: d
function onAddClicked() { function onAddClicked() {
root.addCollectible(root.collectibleKey, collectiblesPanel.getAmount(), d.operator) root.addCollectible(root.collectibleKey, collectiblesPanel.getAmount())
} }
function onUpdateClicked() { function onUpdateClicked() {
@ -410,7 +385,7 @@ StatusDropdown {
target: d target: d
function onAddClicked() { function onAddClicked() {
root.addEns(root.ensType === EnsPanel.EnsType.Any, root.ensDomainName, d.operator) root.addEns(root.ensType === EnsPanel.EnsType.Any, root.ensDomainName)
} }
function onUpdateClicked() { function onUpdateClicked() {

View File

@ -1,48 +0,0 @@
import QtQuick.Layouts 1.14
import QtQuick 2.14
import StatusQ.Controls 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1
import utils 1.0
ColumnLayout {
id: root
signal operatorSelected(int operator)
spacing: 8
Repeater {
model: [
{
icon: "add",
text: qsTr("And..."),
operator: OperatorsUtils.Operators.And
},
{
icon: "condition-Or",
text: qsTr("Or..."),
operator: OperatorsUtils.Operators.Or
}
]
delegate: StatusPickerButton {
Layout.fillWidth: true
Layout.preferredHeight: 36
horizontalPadding: 12
spacing: 10
bgColor: Theme.palette.primaryColor3
contentColor: Theme.palette.primaryColor1
asset.name: Style.svg(modelData.icon)
asset.isImage: true
asset.height: 12
asset.width: 12
text: modelData.text
font.pixelSize: 13
onClicked: root.operatorSelected(modelData.operator)
}
}
}

View File

@ -96,22 +96,9 @@ Control{
Repeater { Repeater {
model: root.holdingsListModel model: root.holdingsListModel
RowLayout {
spacing: content.spacing
StatusBaseText {
id: operatorText
Layout.preferredHeight: d.flowRowHeight
visible: model.operator !== OperatorsUtils.Operators.None
Layout.alignment: Qt.AlignVCenter
text: OperatorsUtils.setOperatorTextFormat(model.operator)
font.pixelSize: d.itemTextPixelSize
verticalAlignment: Text.AlignVCenter
}
StatusListItemTag { StatusListItemTag {
Layout.preferredHeight: d.flowRowHeight height: d.flowRowHeight
Layout.maximumWidth: content.width - operatorText.width - spacing width: (implicitWidth > content.width) ? content.width : implicitWidth
leftPadding: 2 leftPadding: 2
title: model.text title: model.text
asset.name: model.imageSource asset.name: model.imageSource
@ -124,7 +111,6 @@ Control{
titleText.font.pixelSize: d.tagTextPixelSize titleText.font.pixelSize: d.tagTextPixelSize
} }
} }
}
StatusBaseText { StatusBaseText {
height: d.flowRowHeight height: d.flowRowHeight

View File

@ -100,9 +100,8 @@ QtObject {
// Setting HOLDINGS: // Setting HOLDINGS:
for (var i = 0; i < holdings.count; i++ ) { for (var i = 0; i < holdings.count; i++ ) {
var entry = holdings.get(i); var entry = holdings.get(i);
// roles: type, key, name, amount, imageSource, operator // roles: type, key, name, amount, imageSource
permission.holdingsListModel.push({ permission.holdingsListModel.push({
operator: entry.operator,
type: entry.type, type: entry.type,
key: entry.key, key: entry.key,
name: entry.name, name: entry.name,

View File

@ -52,7 +52,7 @@ StatusScrollView {
property int permissionIndex property int permissionIndex
// roles: type, key, name, amount, imageSource, operator // roles: type, key, name, amount, imageSource
property var holdingsModel: ListModel {} property var holdingsModel: ListModel {}
// roles: key, text, imageSource // roles: key, text, imageSource
@ -109,8 +109,7 @@ StatusScrollView {
name: item.name, name: item.name,
shortName: item.shortName, shortName: item.shortName,
amount: item.amount, amount: item.amount,
imageSource: item.imageSource, imageSource: item.imageSource
operator: item.operator
} }
} }
else { else {
@ -119,8 +118,7 @@ StatusScrollView {
key: item.key, key: item.key,
name: item.name, name: item.name,
amount: item.amount, amount: item.amount,
imageSource: item.imageSource, imageSource: item.imageSource
operator: item.operator
} }
} }
d.dirtyValues.holdingsModel.append(initItem) d.dirtyValues.holdingsModel.append(initItem)
@ -151,12 +149,11 @@ StatusScrollView {
const item1 = root.holdingsModel.get(i) const item1 = root.holdingsModel.get(i)
for(let j = 0; j < d.dirtyValues.holdingsModel.count; j++) { for(let j = 0; j < d.dirtyValues.holdingsModel.count; j++) {
let item2 = d.dirtyValues.holdingsModel.get(j) let item2 = d.dirtyValues.holdingsModel.get(j)
// key, name, shortName, amount, operator // key, name, shortName, amount
if((item1.key === item2.key) && if((item1.key === item2.key) &&
(item1.name === item2.name) && (item1.name === item2.name) &&
(item1.shortName === item2.shortName) && (item1.shortName === item2.shortName) &&
(item1.amount === item2.amount) && (item1.amount === item2.amount)) {
(item1.operator === item2.operator)) {
equals = equals + 1 equals = equals + 1
} }
} }
@ -211,25 +208,25 @@ StatusScrollView {
id: dropdown id: dropdown
store: root.store store: root.store
function addItem(type, item, amount, operator) { function addItem(type, item, amount) {
const key = item.key const key = item.key
const name = item.shortName ? item.shortName : item.name const name = item.shortName ? item.shortName : item.name
const imageSource = item.iconSource.toString() const imageSource = item.iconSource.toString()
d.dirtyValues.holdingsModel.append({ type, key, name, amount, imageSource, operator }) d.dirtyValues.holdingsModel.append({ type, key, name, amount, imageSource })
} }
onAddToken: { onAddToken: {
const modelItem = CommunityPermissionsHelpers.getTokenByKey( const modelItem = CommunityPermissionsHelpers.getTokenByKey(
store.tokensModel, key) store.tokensModel, key)
addItem(HoldingTypes.Type.Token, modelItem, amount, operator) addItem(HoldingTypes.Type.Token, modelItem, amount)
dropdown.close() dropdown.close()
} }
onAddCollectible: { onAddCollectible: {
const modelItem = CommunityPermissionsHelpers.getCollectibleByKey( const modelItem = CommunityPermissionsHelpers.getCollectibleByKey(
store.collectiblesModel, key) store.collectiblesModel, key)
addItem(HoldingTypes.Type.Collectible, modelItem, amount, operator) addItem(HoldingTypes.Type.Collectible, modelItem, amount)
dropdown.close() dropdown.close()
} }
@ -238,7 +235,7 @@ StatusScrollView {
const name = any ? "" : customDomain const name = any ? "" : customDomain
const icon = Style.svg("ensUsernames") const icon = Style.svg("ensUsernames")
d.dirtyValues.holdingsModel.append({type: HoldingTypes.Type.Ens, key, name, amount: 1, imageSource: icon, operator }) d.dirtyValues.holdingsModel.append({type: HoldingTypes.Type.Ens, key, name, amount: 1, imageSource: icon })
dropdown.close() dropdown.close()
} }
@ -276,11 +273,6 @@ StatusScrollView {
onRemoveClicked: { onRemoveClicked: {
d.dirtyValues.holdingsModel.remove(tokensSelector.editedIndex) d.dirtyValues.holdingsModel.remove(tokensSelector.editedIndex)
if (d.dirtyValues.holdingsModel && d.dirtyValues.holdingsModel.count) {
d.dirtyValues.holdingsModel.set(0, { operator: OperatorsUtils.Operators.None})
}
dropdown.close() dropdown.close()
} }
} }
@ -289,11 +281,7 @@ StatusScrollView {
dropdown.parent = tokensSelector.addButton dropdown.parent = tokensSelector.addButton
dropdown.x = tokensSelector.addButton.width + d.dropdownHorizontalOffset dropdown.x = tokensSelector.addButton.width + d.dropdownHorizontalOffset
dropdown.y = 0 dropdown.y = 0
if (d.dirtyValues.holdingsModel && d.dirtyValues.holdingsModel.count === 0)
dropdown.openFlow(HoldingsDropdown.FlowType.Add) dropdown.openFlow(HoldingsDropdown.FlowType.Add)
else
dropdown.openFlow(HoldingsDropdown.FlowType.AddWithOperators)
} }
onItemClicked: { onItemClicked: {