8000 Add Confirmation Dialog on Device Type Feature Toggle and Disable Toggling when Related Cluster is Disabled by ethanzhouyc · Pull Request #1554 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Confirmation Dialog on Device Type Feature Toggle and Disable Toggling when Related Cluster is Disabled #1554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15038,7 +15038,8 @@ HTTP GET: device type features
<a name="module_REST API_ user data..httpPostCheckConformOnFeatureUpdate"></a>

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

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

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

**Kind**: inner method of [<code>REST API: user data</code>](#module_REST API_ user data)
**Returns**: callback for the express uri registration
Expand Down
2 changes: 1 addition & 1 deletion src-electron/db/query-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async function insertOrUpdateAttributeState(
)
// only set featureMap bit to 1 for mandatory features
let featureMapBitsToBeEnabled = featuresOnEndpointTypeAndCluster
.filter((f) => f.conformance == 'M')
.filter((f) => f.conformance == dbEnum.conformance.mandatory)
.map((f) => f.featureBit)
featureMapBitsToBeEnabled.forEach(
(featureBit) =>
Expand Down
38 changes: 20 additions & 18 deletions src-electron/rest/user-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ function httpGetDeviceTypeFeatures(db) {
}

/**
* HTTP POST: elements to be updated after toggle a device type feature
* HTTP POST: elements to be updated after toggle a device type feature.
* Set related warnings if user confirmed the change or change is disabled.
*
* @param {*} db
* @returns callback for the express uri registration
*/
function httpPostCheckConformOnFeatureUpdate(db) {
return async (request, response) => {
let sessionId = request.zapSessionId
let { featureData, featureMap, endpointId } = request.body
let { featureData, featureMap, endpointId, changeConfirmed } = request.body
let { endpointTypeClusterId, deviceTypeClusterId } = featureData

let elements = await queryEndpointType.getEndpointTypeElements(
Expand All @@ -123,25 +124,26 @@ function httpPostCheckConformOnFeatureUpdate(db) {
featureData,
endpointId
)

// set device type feature warning
await querySessionNotification.setNotificationOnFeatureChange(
db,
sessionId,
result
)
// do not set element warning if feature change disabled
if (!result.disableChange) {
let outdatedWarnings = conformChecker.getOutdatedElementWarning(
featureData,
elements,
result.elementMap
)
await querySessionNotification.deleteNotificationWithPatterns(
if (changeConfirmed || result.disableChange) {
// set device type feature warning
await querySessionNotification.setNotificationOnFeatureChange(
db,
sessionId,
outdatedWarnings
result
)
// do not set element warning if feature change disabled
if (!result.disableChange) {
let outdatedWarnings = conformChecker.getOutdatedElementWarning(
featureData,
elements,
result.elementMap
)
await querySessionNotification.deleteNotificationWithPatterns(
db,
sessionId,
outdatedWarnings
)
}
}

response.status(StatusCodes.OK).json(result)
Expand Down
7 changes: 6 additions & 1 deletion src-electron/validation/conformance-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const conformEvaluator = require('./conformance-expression-evaluator')
const queryFeature = require('../db/query-feature')
const querySessionNotice = require('../db/query-session-notification')
const queryEndpointType = require('../db/query-endpoint-type')
const dbEnum = require('../../src-shared/db-enum')

/**
*
Expand All @@ -37,7 +38,11 @@ const queryEndpointType = require(' 8000 ;../db/query-endpoint-type')
function filterRelatedDescElements(elements, featureCode) {
return elements.filter((element) => {
let terms = element.conformance.match(/[A-Za-z][A-Za-z0-9_]*/g)
return terms && terms.includes('desc') && terms.includes(featureCode)
return (
terms &&
terms.includes(dbEnum.conformance.desc) &&
terms.includes(featureCode)
)
})
}

Expand Down
19 changes: 12 additions & 7 deletions src-electron/validation/conformance-expression-evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @module Validation API: Evaluate conformance expressions
*/

const dbEnum = require('../../src-shared/db-enum')

/**
* Evaluate the value of a boolean conformance expression that includes terms and operators.
* A term can be an attribute, command, event, feature, or conformance abbreviation.
Expand Down Expand Up @@ -75,8 +77,8 @@ function evaluateConformanceExpression(expression, elementMap) {
// if any term is desc, the conformance is too complex to parse
for (let part of parts) {
let terms = part.match(/[A-Za-z][A-Za-z0-9_]*/g)
if (terms && terms.includes('desc')) {
return 'desc'
if (terms && terms.includes(dbEnum.conformance.desc)) {
return dbEnum.conformance.desc
}
}
for (let part of parts) {
Expand All @@ -91,13 +93,16 @@ function evaluateConformanceExpression(expression, elementMap) {
}
} else {
part = part.trim()
if (part == 'M') {
if (part == dbEnum.conformance.mandatory) {
return 'mandatory'
} else if (part == 'O') {
} else if (part == dbEnum.conformance.optional) {
return 'optional'
} else if (part == 'D' || part == 'X') {
} else if (
part == dbEnum.conformance.deprecated ||
part == dbEnum.conformance.disallowed
) {
return 'notSupported'
} else if (part == 'P') {
} else if (part == dbEnum.conformance.provisional) {
return 'provisional'
} else {
// Evaluate the part with parentheses if needed
Expand All @@ -123,7 +128,7 @@ function evaluateConformanceExpression(expression, elementMap) {
function checkMissingTerms(expression, elementMap) {
let terms = expression.match(/[A-Za-z][A-Za-z0-9_]*/g)
let missingTerms = []
let abbreviations = ['M', 'O', 'P', 'D', 'X']
let abbreviations = Object.values(dbEnum.conformance)
for (let term of terms) {
if (!(term in elementMap) && !abbreviations.includes(term)) {
missingTerms.push(term)
Expand Down
12 changes: 6 additions & 6 deletions src-electron/validation/conformance-xml-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
if (insideTerm && Object.keys(insideTerm).toString() != '$') {
return parseConformanceRecursively(operand.mandatoryConform[0], depth + 1)
} else {
return 'M'
return dbEnum.conformance.mandatory
}
} else if (operand.optionalConform) {
let insideTerm = operand.optionalConform[0]
Expand All @@ -101,7 +101,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
if (insideTerm && Object.keys(insideTerm).toString() != '$') {
return `[${parseConformanceRecursively(operand.optionalConform[0], depth + 1)}]`
} else {
return 'O'
return dbEnum.conformance.optional
}
} else if (operand.otherwiseConform) {
return Object.entries(operand.otherwiseConform[0])
Expand Down Expand Up @@ -142,11 +142,11 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
})
.join(` ${joinChar} `)
} else if (operand.provisionalConform) {
return 'P'
return dbEnum.conformance.pro 10112 visional
} else if (operand.disallowConform) {
return 'X'
return dbEnum.conformance.disallowed
} else if (operand.deprecateConform) {
return 'D'
return dbEnum.conformance.deprecated
} else {
// reach base level terms, return the name directly
for (const term of baseLevelTerms) {
Expand All @@ -155,7 +155,7 @@ function parseConformanceRecursively(operand, depth = 0, parentJoinChar = '') {
}
}
// reaching here means the term is too complex to parse
return 'desc'
return dbEnum.conformance.desc
}
}

Expand Down
7 changes: 7 additions & 0 deletions src-shared/db-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ exports.packageMatch = {

exports.feature = {
name: {
status: 'status',
enabled: 'enabled',
deviceType: 'deviceType',
cluster: 'cluster',
Expand All @@ -231,6 +232,7 @@ exports.feature = {
description: 'description'
},
label: {
status: '',
enabled: 'Enabled',
deviceType: 'Device Type',
cluster: 'Cluster',
Expand All @@ -256,3 +258,8 @@ exports.conformance = {
provisional: 'P',
desc: 'desc'
}

exports.clusterSide = {
client: 'client',
server: 'server'
}
Loading
0