Skip to content

Commit 22a7ca3

Browse files
authored
Add Confirmation Dialog on Device Type Feature Toggle and Disable Toggling when Related Cluster is Disabled (#1554)
* display confirm dialog after toggling feature * show warning and disable change for features with disabled cluster
1 parent edb12bb commit 22a7ca3

File tree

9 files changed

+351
-206
lines changed

9 files changed

+351
-206
lines changed

docs/api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15038,7 +15038,8 @@ HTTP GET: device type features
1503815038
<a name="module_REST API_ user data..httpPostCheckConformOnFeatureUpdate"></a>
1503915039

1504015040
### REST API: user data~httpPostCheckConformOnFeatureUpdate(db) ⇒
15041-
HTTP POST: elements to be updated after toggle a device type feature
15041+
HTTP POST: elements to be updated after toggle a device type feature.
15042+
Set related warnings if user confirmed the change or change is disabled.
1504215043

1504315044
**Kind**: inner method of [<code>REST API: user data</code>](#module_REST API_ user data)
1504415045
**Returns**: callback for the express uri registration
@@ -16373,7 +16374,8 @@ HTTP GET: device type features
1637316374
<a name="module_REST API_ user data..httpPostCheckConformOnFeatureUpdate"></a>
1637416375

1637516376
### REST API: user data~httpPostCheckConformOnFeatureUpdate(db) ⇒
16376-
HTTP POST: elements to be updated after toggle a device type feature
16377+
HTTP POST: elements to be updated after toggle a device type feature.
16378+
Set related warnings if user confirmed the change or change is disabled.
1637716379

1637816380
**Kind**: inner method of [<code>REST API: user data</code>](#module_REST API_ user data)
1637916381
**Returns**: callback for the express uri registration

src-electron/db/query-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async function insertOrUpdateAttributeState(
230230
)
231231
// only set featureMap bit to 1 for mandatory features
232232
let featureMapBitsToBeEnabled = featuresOnEndpointTypeAndCluster
233-
.filter((f) => f.conformance == 'M')
233+
.filter((f) => f.conformance == dbEnum.conformance.mandatory)
234234
.map((f) => f.featureBit)
235235
featureMapBitsToBeEnabled.forEach(
236236
(featureBit) =>

src-electron/rest/user-data.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ function httpGetDeviceTypeFeatures(db) {
100100
}
101101

102102
/**
103-
* HTTP POST: elements to be updated after toggle a device type feature
103+
* HTTP POST: elements to be updated after toggle a device type feature.
104+
* Set related warnings if user confirmed the change or change is disabled.
104105
*
105106
* @param {*} db
106107
* @returns callback for the express uri registration
107108
*/
108109
function httpPostCheckConformOnFeatureUpdate(db) {
109110
return async (request, response) => {
110111
let sessionId = request.zapSessionId
111-
let { featureData, featureMap, endpointId } = request.body
112+
let { featureData, featureMap, endpointId, changeConfirmed } = request.body
112113
let { endpointTypeClusterId, deviceTypeClusterId } = featureData
113114

114115
let elements = await queryEndpointType.getEndpointTypeElements(
@@ -123,25 +124,26 @@ function httpPostCheckConformOnFeatureUpdate(db) {
123124
featureData,
124125
endpointId
125126
)
126-
127-
// set device type feature warning
128-
await querySessionNotification.setNotificationOnFeatureChange(
129-
db,
130-
sessionId,
131-
result
132-
)
133-
// do not set element warning if feature change disabled
134-
if (!result.disableChange) {
135-
let outdatedWarnings = conformChecker.getOutdatedElementWarning(
136-
featureData,
137-
elements,
138-
result.elementMap
139-
)
140-
await querySessionNotification.deleteNotificationWithPatterns(
127+
if (changeConfirmed || result.disableChange) {
128+
// set device type feature warning
129+
await querySessionNotification.setNotificationOnFeatureChange(
141130
db,
142131
sessionId,
143-
outdatedWarnings
132+
result
144133
)
134+
// do not set element warning if feature change disabled
135+
if (!result.disableChange) {
136+
let outdatedWarnings = conformChecker.getOutdatedElementWarning(
137+
featureData,
138+
elements,
139+
result.elementMap
140+
)
141+
await querySessionNotification.deleteNotificationWithPatterns(
142+
db,
143+
sessionId,
144+
outdatedWarnings
145+
)
146+
}
145147
}
146148

147149
response.status(StatusCodes.OK).json(result)

src-electron/validation/conformance-checker.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const conformEvaluator = require('./conformance-expression-evaluator')
2626
const queryFeature = require('../db/query-feature')
2727
const querySessionNotice = require('../db/query-session-notification')
2828
const queryEndpointType = require('../db/query-endpoint-type')
29+
const dbEnum = require('../../src-shared/db-enum')
2930

3031
/**
3132
*
@@ -37,7 +38,11 @@ const queryEndpointType = require('../db/query-endpoint-type')
3738
function filterRelatedDescElements(elements, featureCode) {
3839
return elements.filter((element) => {
3940
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9_]*/g)
40-
return terms && terms.includes('desc') && terms.includes(featureCode)
41+
return (
42+
terms &&
43+
terms.includes(dbEnum.conformance.desc) &&
44+
terms.includes(featureCode)
45+
)
4146
})
4247
}
4348

src-electron/validation/conformance-expression-evaluator.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* @module Validation API: Evaluate conformance expressions
2222
*/
2323

24+
const dbEnum = require('../../src-shared/db-enum')
25+
2426
/**
2527
* Evaluate the value of a boolean conformance expression that includes terms and operators.
2628
* A term can be an attribute, command, event, feature, or conformance abbreviation.
@@ -75,8 +77,8 @@ function evaluateConformanceExpression(expression, elementMap) {
7577
// if any term is desc, the conformance is too complex to parse
7678
for (let part of parts) {
7779
let terms = part.match(/[A-Za-z][A-Za-z0-9_]*/g)
78-
if (terms && terms.includes('desc')) {
79-
return 'desc'
80+
if (terms && terms.includes(dbEnum.conformance.desc)) {
81+
return dbEnum.conformance.desc
8082
}
8183
}
8284
for (let part of parts) {
@@ -91,13 +93,16 @@ function evaluateConformanceExpression(expression, elementMap) {
9193
}
9294
} else {
9395
part = part.trim()
94-
if (part == 'M') {
96+
if (part == dbEnum.conformance.mandatory) {
9597
return 'mandatory'
96-
} else if (part == 'O') {
98+
} else if (part == dbEnum.conformance.optional) {
9799
return 'optional'
98-
} else if (part == 'D' || part == 'X') {
100+
} else if (
101+
part == dbEnum.conformance.deprecated ||
102+
part == dbEnum.conformance.disallowed
103+
) {
99104
return 'notSupported'
100-
} else if (part == 'P') {
105+
} else if (part == dbEnum.conformance.provisional) {
101106
return 'provisional'
102107
} else {
103108
// Evaluate the part with parentheses if needed
@@ -123,7 +128,7 @@ function evaluateConformanceExpression(expression, elementMap) {
123128
function checkMissingTerms(expression, elementMap) {
124129
let terms = expression.match(/[A-Za-z][A-Za-z0-9_]*/g)
125130
let missingTerms = []
126-
let abbreviations = ['M', 'O', 'P', 'D', 'X']
131+
let abbreviations = Object.values(dbEnum.conformance)
127132
for (let term of terms) {
128133
if (!(term in elementMap) && !abbreviations.includes(term)) {
129134
missingTerms.push(term)

src-electron/validation/conformance-xml-parser.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
9292
if (insideTerm && Object.keys(insideTerm).toString() != '$') {
9393
return parseConformanceRecursively(operand.mandatoryConform[0], depth + 1)
9494
} else {
95-
return 'M'
95+
return dbEnum.conformance.mandatory
9696
}
9797
} else if (operand.optionalConform) {
9898
let insideTerm = operand.optionalConform[0]
@@ -101,7 +101,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
101101
if (insideTerm && Object.keys(insideTerm).toString() != '$') {
102102
return `[${parseConformanceRecursively(operand.optionalConform[0], depth + 1)}]`
103103
} else {
104-
return 'O'
104+
return dbEnum.conformance.optional
105105
}
106106
} else if (operand.otherwiseConform) {
107107
return Object.entries(operand.otherwiseConform[0])
@@ -142,11 +142,11 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
142142
})
143143
.join(` ${joinChar} `)
144144
} else if (operand.provisionalConform) {
145-
return 'P'
145+
return dbEnum.conformance.provisional
146146
} else if (operand.disallowConform) {
147-
return 'X'
147+
return dbEnum.conformance.disallowed
148148
} else if (operand.deprecateConform) {
149-
return 'D'
149+
return dbEnum.conformance.deprecated
150150
} else {
151151
// reach base level terms, return the name directly
152152
for (const term of baseLevelTerms) {
@@ -155,7 +155,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
155155
}
156156
}
157157
// reaching here means the term is too complex to parse
158-
return 'desc'
158+
return dbEnum.conformance.desc
159159
}
160160
}
161161

src-shared/db-enum.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ exports.packageMatch = {
220220

221221
exports.feature = {
222222
name: {
223+
status: 'status',
223224
enabled: 'enabled',
224225
deviceType: 'deviceType',
225226
cluster: 'cluster',
@@ -231,6 +232,7 @@ exports.feature = {
231232
description: 'description'
232233
},
233234
label: {
235+
status: '',
234236
enabled: 'Enabled',
235237
deviceType: 'Device Type',
236238
cluster: 'Cluster',
@@ -256,3 +258,8 @@ exports.conformance = {
256258
provisional: 'P',
257259
desc: 'desc'
258260
}
261+
262+
exports.clusterSide = {
263+
client: 'client',
264+
server: 'server'
265+
}

0 commit comments

Comments
 (0)