Skip to content

Commit

Permalink
Allow for manual override to the automatic component toggling in an I…
Browse files Browse the repository at this point in the history
…DE. (project-chip#1227)

* Fix some security issues.
* Add the UI element that will toggle the functionality of IDE component toggling.
* Deal with the back-end changes for the manual component toggling override.
  • Loading branch information
tecimovic authored Dec 5, 2023
1 parent ae7f7cf commit 3a3648d
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 36 deletions.
33 changes: 20 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 47 additions & 21 deletions src-electron/ide-integration/studio-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ async function integrationEnabled(db, sessionId) {
return typeof path !== 'undefined'
}

/**
* Resolves into true if user has actively disabled the component toggling.
* By default this row doesn't even exist in the DB, but if user toggles
* the toggle to turn this off, then the "disableComponentToggling" will
* be set so '1' in the database.
*
* @param {*} db
* @param {*} sessionId
* @returns promise that resolves into a true or false, depending on whether the component toggling has been disabled manually.
*/
async function isComponentTogglingDisabled(db, sessionId) {
let disableComponentToggling = await querySession.getSessionKeyValue(
db,
sessionId,
dbEnum.sessionKey.disableComponentToggling
)
// We may have an empty row or a 0 or a 1. Only 1 means that this is disabled.
return disableComponentToggling === 1
}

/**
* Studio REST API path helper/generator
* @param api
Expand Down Expand Up @@ -106,30 +126,32 @@ function wsApiUrl(api, path) {
async function getProjectInfo(db, sessionId) {
let project = await projectPath(db, sessionId)
let studioIntegration = await integrationEnabled(db, sessionId)

let isUserDisabled = await isComponentTogglingDisabled(db, sessionId)
if (project) {
let name = projectName(project)
if (studioIntegration) {
if (studioIntegration && !isUserDisabled) {
let path = restApiUrl(StudioRestAPI.GetProjectInfo, project)
env.logInfo(`StudioUC(${name}): GET: ${path}`)
env.logDebug(`StudioUC(${name}): GET: ${path}`)
return axios
.get(path)
.then((resp) => {
env.logInfo(`StudioUC(${name}): RESP: ${resp.status}`)
env.logDebug(`StudioUC(${name}): RESP: ${resp.status}`)
return resp
})
.catch((err) => {
env.logInfo(`StudioUC(${name}): ERR: ${err.message}`)
env.logWarning(`StudioUC(${name}): ERR: ${err.message}`)
return { data: [] }
})
} else {
env.logInfo(`StudioUC(${name}): Studio integration is not enabled!`)
if (!isUserDisabled)
env.logWarning(`StudioUC(${name}): Studio integration is now enabled!`)
return { data: [] }
}
} else {
env.logInfo(
`StudioUC(): Invalid Studio project path specified via project info API!`
)
if (!isUserDisabled)
env.logWarning(
`StudioUC(): Invalid Studio project path specified via project info API!`
)
return { data: [] }
}
}
Expand All @@ -156,17 +178,20 @@ async function updateComponentByClusterIdAndComponentId(
side
) {
if (!integrationEnabled(db, sessionId)) {
env.logWarning(
`StudioUC(): Failed to update component due to invalid Studio project path.`
)
queryNotification.setNotification(
db,
'WARNING',
`StudioUC(): Failed to update component due to invalid Studio project path.`,
sessionId,
2,
0
)
let isUserDisabled = await isComponentTogglingDisabled(db, sessionId)
if (!isUserDisabled) {
env.logWarning(
`StudioUC(): Failed to update component due to invalid Studio project path.`
)
queryNotification.setNotification(
db,
'WARNING',
`StudioUC(): Failed to update component due to invalid Studio project path.`,
sessionId,
2,
0
)
}
return Promise.resolve({ componentIds: [], added: add })
}

Expand Down Expand Up @@ -427,7 +452,8 @@ function deinitIdeIntegration() {
async function sendSelectedUcComponents(db, session, ucComponentStates) {
let socket = wsServer.clientSocket(session.sessionKey)
let studioIntegration = await integrationEnabled(db, session.sessionId)
if (socket && studioIntegration) {
let isUserDisabled = await isComponentTogglingDisabled(db, session.sessionId)
if (socket && studioIntegration && !isUserDisabled) {
wsServer.sendWebSocketMessage(socket, {
category: dbEnum.wsCategory.updateSelectedUcComponents,
payload: ucComponentStates,
Expand Down
1 change: 1 addition & 0 deletions src-shared/db-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exports.sessionKey = {
filePath: 'filePath',
ideProjectPath: 'ideProjectPath',
informationText: 'informationText',
disableComponentToggling: 'disableComponentToggling',
}

exports.pathRelativity = {
Expand Down
27 changes: 25 additions & 2 deletions src/components/ZclGeneralOptionsBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,23 @@ limitations under the License.
handleOptionChange('commandDiscovery', $event)
"
>
<q-tooltip> Enable Command Discovery for your project </q-tooltip>
<q-tooltip> Enable Command Discovery for your project</q-tooltip>
</q-toggle>
</div>
<div class="col-md q-mb-md col-sm-12">
<q-toggle
:model-value="disableComponentToggling == 1 ? false : true"
label="Enable Component Toggling in IDE"
dense
left-label
@update:model-value="
handleOptionChange('disableComponentToggling', !$event)
"
>
<q-tooltip
>Enable automatic toggling of components in an IDE for your
project</q-tooltip
>
</q-toggle>
</div>
</div>
Expand Down Expand Up @@ -148,13 +164,21 @@ export default {
return this.$store.state.zap.selectedGenericOptions['commandDiscovery']
},
},
disableComponentToggling: {
get() {
return this.$store.state.zap.selectedGenericOptions[
'disableComponentToggling'
]
},
},
},
data() {
return {
mfgOptions: null,
}
},
beforeMount() {
this.$store.dispatch('zap/loadSessionKeyValues')
this.mfgOptions = this.defaultManufacturerCodes
},
methods: {
Expand All @@ -165,7 +189,6 @@ export default {
})
},
handleOptionChange(option, value) {
console.log(value)
this.$store.dispatch('zap/setSelectedGenericKey', {
key: option,
value: value,
Expand Down

0 comments on commit 3a3648d

Please sign in to comment.