Skip to content

Commit

Permalink
feat(CommunityPermissions): Switch to enable/disable 'Who holds' section
Browse files Browse the repository at this point in the history
Closes: #8498
  • Loading branch information
micieslak committed Apr 5, 2023
1 parent 43196d9 commit 8dafdfc
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
2 changes: 2 additions & 0 deletions storybook/pages/CommunityNewPermissionViewPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SplitView {
permissionDuplicated: isPermissionDuplicatedCheckBox.checked
permissionTypeLimitReached: isLimitReachedCheckBox.checked

showWhoHoldsSwitch: true

assetsModel: AssetsModel {}
collectiblesModel: CollectiblesModel {}
channelsModel: ChannelsModel {}
Expand Down
2 changes: 2 additions & 0 deletions storybook/pages/CommunityPermissionsSettingsPanelPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ SplitView {

isOwner: isOwnerCheckBox.checked

showWhoHoldsSwitch: true

onCreatePermissionRequested: {
permissionsStoreMock.createPermission(holdings, permissionType,
isPrivate, channels)
Expand Down
2 changes: 2 additions & 0 deletions ui/StatusQ/src/StatusQ/Components/StatusItemSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ StatusFlowSelector {
*/
property bool itemsClickable: true

readonly property alias count: repeater.count

/*!
\qmlsignal StatusItemSelector::itemClicked
This signal is emitted when the item is clicked.
Expand Down
5 changes: 4 additions & 1 deletion ui/app/AppLayouts/Chat/controls/community/PermissionItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ Control{
StatusBaseText {
font.pixelSize: d.itemTextPixelSize
height: d.flowRowHeight
text: qsTr("Anyone who holds")
text: holdingsRepeater.count > 0 ? qsTr("Anyone who holds")
: qsTr("Anyone")
verticalAlignment: Text.AlignVCenter
}

Repeater {
id: holdingsRepeater

model: root.holdingsListModel

StatusListItemTag {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ SettingsPageLayout {

property int viewWidth: 560 // by design

// TODO: temporary property, to be removed when no need to hide the switch
// in the app
property bool showWhoHoldsSwitch: false

signal createPermissionRequested(
int permissionType, var holdings, var channels, bool isPrivate)

Expand Down Expand Up @@ -182,6 +186,10 @@ SettingsPageLayout {

permissionType: d.permissionTypeToEdit
isPrivate: d.isPrivateToEditValue
holdingsRequired: selectedHoldingsModel ? selectedHoldingsModel.count > 0
: false

showWhoHoldsSwitch: root.showWhoHoldsSwitch

permissionDuplicated: {
// dependencies
Expand All @@ -205,6 +213,12 @@ SettingsPageLayout {

const same = (a, b) => ModelUtils.checkEqualitySet(a, b, ["key"])

if (holdings.rowCount() === 0 && dirtyValues.holdingsRequired)
continue

if (holdings.rowCount() !== 0 && !dirtyValues.holdingsRequired)
continue

if (same(dirtyValues.selectedHoldingsModel, holdings)
&& same(dirtyValues.selectedChannelsModel, channels)
&& dirtyValues.permissionType === permissionType)
Expand Down Expand Up @@ -233,9 +247,11 @@ SettingsPageLayout {
}

onCreatePermissionClicked: {
const holdings = ModelUtils.modelToArray(
dirtyValues.selectedHoldingsModel,
["key", "type", "amount"])
const holdings = dirtyValues.holdingsRequired ?
ModelUtils.modelToArray(
dirtyValues.selectedHoldingsModel,
["key", "type", "amount"])
: []

const channels = ModelUtils.modelToArray(
dirtyValues.selectedChannelsModel, ["key"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick 2.14
import QtQuick.Layouts 1.14
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQml 2.15

import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
Expand Down Expand Up @@ -30,21 +31,27 @@ StatusScrollView {
property int viewWidth: 560 // by design
property bool isEditState: false

// TODO: temporary property, to be removed when no need to hide the switch
// in the app
property bool showWhoHoldsSwitch: false

readonly property bool dirty:
!holdingsModelComparator.equal ||
root.holdingsRequired !== d.dirtyValues.holdingsRequired ||
(d.dirtyValues.holdingsRequired && !holdingsModelComparator.equal) ||
!channelsModelComparator.equal ||
root.isPrivate !== d.dirtyValues.isPrivate ||
root.permissionType !== d.dirtyValues.permissionType

readonly property alias dirtyValues: d.dirtyValues

readonly property bool isFullyFilled:
dirtyValues.selectedHoldingsModel.count > 0 &&
(dirtyValues.selectedHoldingsModel.count > 0 || !whoHoldsSwitch.checked) &&
dirtyValues.permissionType !== PermissionTypes.Type.None &&
(d.isCommunityPermission || dirtyValues.selectedChannelsModel.count > 0)

property int permissionType: PermissionTypes.Type.None
property bool isPrivate: false
property bool holdingsRequired: true

// roles: type, key, name, amount, imageSource
property var selectedHoldingsModel: ListModel {}
Expand Down Expand Up @@ -111,6 +118,7 @@ StatusScrollView {

property int permissionType: PermissionTypes.Type.None
property bool isPrivate: false
property bool holdingsRequired: true

Binding on isPrivate {
value: (d.dirtyValues.permissionType === PermissionTypes.Type.Admin) ||
Expand Down Expand Up @@ -161,6 +169,9 @@ StatusScrollView {

// Is private permission
d.dirtyValues.isPrivate = root.isPrivate

// Are holdings required
d.dirtyValues.holdingsRequired = root.holdingsRequired
}
}

Expand Down Expand Up @@ -192,7 +203,8 @@ StatusScrollView {
tagLeftPadding: 2
asset.height: 28
asset.width: asset.height
addButton.visible: model.count < d.maxHoldingsItems
addButton.visible: count < d.maxHoldingsItems &&
whoHoldsSwitch.checked

model: HoldingsSelectionModel {
sourceModel: d.dirtyValues.selectedHoldingsModel
Expand All @@ -201,6 +213,36 @@ StatusScrollView {
collectiblesModel: root.collectiblesModel
}

label.enabled: whoHoldsSwitch.checked
placeholderItem.visible: count === 0 && whoHoldsSwitch.checked

Binding on model {
when: !whoHoldsSwitch.checked
value: 0
restoreMode: Binding.RestoreBindingOrValue
}

Binding on bottomPadding {
when: !whoHoldsSwitch.checked
value: 0
restoreMode: Binding.RestoreBindingOrValue
}

children: StatusSwitch {
id: whoHoldsSwitch

visible: root.showWhoHoldsSwitch

padding: 0
anchors.right: parent.right
anchors.top: parent.top
anchors.rightMargin: 12
anchors.topMargin: 10

checked: d.dirtyValues.holdingsRequired
onToggled: d.dirtyValues.holdingsRequired = checked
}

HoldingsDropdown {
id: dropdown

Expand Down

0 comments on commit 8dafdfc

Please sign in to comment.