From 0f2054ba5b70a39da9b7308a5c43ea91f3804b1e Mon Sep 17 00:00:00 2001 From: samaea <32162601+samaea@users.noreply.github.com> Date: Wed, 15 Mar 2023 23:12:59 +0000 Subject: [PATCH] Enhance the non-PII telemetry capture to improve the user experience (#539) * Initial commit. * Bug fixes and enhancements to AI. * Incorporated PR feedback. --- helper/src/components/common.js | 5 +++++ helper/src/components/deployTab.js | 4 ++-- helper/src/components/portalnav.js | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/helper/src/components/common.js b/helper/src/components/common.js index 040e3f923..ce9690f3b 100644 --- a/helper/src/components/common.js +++ b/helper/src/components/common.js @@ -1,5 +1,6 @@ import React, {useState} from 'react'; import {CommandBarButton} from '@fluentui/react' +import { appInsights } from '../index.js' export function arrayAdd(array, key) { return array.includes(key) ? array : array.concat(key) @@ -25,12 +26,16 @@ export function CodeBlock({deploycmd, testId, lang, filename, error, hideSave}) const [ copied, setCopied ] = useState(false) function copyIt() { + //console.log("AI:- Button.Copy." + testId) + appInsights.trackEvent({name: "Button.Copy."+ testId}); navigator.clipboard.writeText(deploycmd) setCopied(true) setTimeout(() => setCopied(false), 1000) } function downloadIt(){ + //console.log("AI:- Button.Save." + testId) + appInsights.trackEvent({name: "Button.Save."+ testId}); function dataUrl(data) {return "data:x-application/text," + escape(deploycmd);} window.open(dataUrl()); } diff --git a/helper/src/components/deployTab.js b/helper/src/components/deployTab.js index 38b398cff..fabc96493 100644 --- a/helper/src/components/deployTab.js +++ b/helper/src/components/deployTab.js @@ -466,7 +466,7 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa - Add the following code to a new file in your repos .github/workflows folder, this will call the AKS-Construction reusable workflow. NOTE: This example creates a manually triggered Action - Object.keys(defaults).reduce((a, c) => { return { ...a, [c]: [] } }, {})) // The selected cards within the sections for the chosen preset, for example { "ops": "normal", "secure": "high" } const [selected, setSelected] = useState(initSelected(urlParams.get('preset') || 'defaultOps')) + useAITracking("PageNav", selected.preset) // The tabValues, for example { "deploy": { "clusterName": "az234"}} const [tabValues, setTabValues] = useState(initTabValues(selected, defaults, true)) + // Field Selections - Used to keep track of the last FieldSelections monitored by App Insights to prevent logging the same entry continuously + const [lastAIUpdated, setLastAIUpdated] = useState ({tab: null, field: null}) function initSelected (currentPreset) { return { @@ -169,9 +171,9 @@ export default function PortalNav({ config }) { function updateTabValues(currenttabValues, sections, sectionKey, cardKey) { - console.log(`updateTabValues`) + //console.log(`updateTabValues`) const card_values = sections.find(s => s.key === sectionKey).cards.find(c => c.key === cardKey).values - console.log(`updateTabValues: sectionKey=${sectionKey} cardKey=${cardKey}, setting tabs ${JSON.stringify(Object.keys(card_values))}`) + //console.log(`updateTabValues: sectionKey=${sectionKey} cardKey=${cardKey}, setting tabs ${JSON.stringify(Object.keys(card_values))}`) return Object.keys(card_values).reduce((acc, curr) => { return { ...acc, @@ -186,7 +188,7 @@ export default function PortalNav({ config }) { val.reduce((a, c) => a === undefined ? (c.page && c.field ? (currenttabValues[c.page][c.field] === c.value ? c.set : undefined) : c.set) : a, undefined) : val - console.log(`updateTabValues: setting tab=${curr}, field=${c} val=${JSON.stringify(val)} targetVal=${JSON.stringify(targetVal)}`) + //console.log(`updateTabValues: setting tab=${curr}, field=${c} val=${JSON.stringify(val)} targetVal=${JSON.stringify(targetVal)}`) return { ...a, [c]: targetVal } }, {}) } @@ -195,8 +197,8 @@ export default function PortalNav({ config }) { } function updateSelected(sectionKey, cardKey) { - console.log("Update Selected Fired " + sectionKey + " - " + cardKey) - + //console.log("AI:- Card update fired " + sectionKey + " - " + cardKey) + appInsights.trackEvent({name: "Card." + sectionKey + "." + cardKey}); setUrlParams((currentUrlParams) => { currentUrlParams.set(sectionKey, cardKey) window.history.replaceState(null, null, "?"+currentUrlParams.toString()) @@ -282,9 +284,14 @@ export default function PortalNav({ config }) { } function mergeState(tab, field, value, previewLink) { - let updatevals let newFields = new Map() + if(lastAIUpdated.tab !== tab || lastAIUpdated.field !== field){ + //console.log("AI:- Field Selected " + tab + "-" + field) + appInsights.trackEvent({name: "FieldSelected." + tab + "." + field}); + setLastAIUpdated({tab: tab, field: field}) + } + if (typeof field === "string") { updatevals = { [field]: value } newFields.set(`${tab}.${field}`, value)