fix: Update duplicate ids for dashboard app frame (#8077)

This commit is contained in:
Pranav Raj S
2023-10-10 04:16:32 -07:00
committed by GitHub
parent bb5c6a416a
commit 1e54d6deb3
2 changed files with 13 additions and 4 deletions

View File

@@ -12,7 +12,7 @@
/> />
<iframe <iframe
v-if="configItem.type === 'frame' && configItem.url" v-if="configItem.type === 'frame' && configItem.url"
:id="`dashboard-app--frame-${index}`" :id="getFrameId(index)"
:src="configItem.url" :src="configItem.url"
@load="() => onIframeLoad(index)" @load="() => onIframeLoad(index)"
/> />
@@ -39,6 +39,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
position: {
type: Number,
required: true,
},
}, },
data() { data() {
return { return {
@@ -82,10 +86,14 @@ export default {
}; };
}, },
methods: { methods: {
getFrameId(index) {
return `dashboard-app--frame-${this.position}-${index}`;
},
onIframeLoad(index) { onIframeLoad(index) {
const frameElement = document.getElementById( // A possible alternative is to use ref instead of document.getElementById
`dashboard-app--frame-${index}` // However, when ref is used together with v-for, the ref you get will be
); // an array containing the child components mirroring the data source.
const frameElement = document.getElementById(this.getFrameId(index));
const eventData = { event: 'appContext', data: this.dashboardAppContext }; const eventData = { event: 'appContext', data: this.dashboardAppContext };
frameElement.contentWindow.postMessage(JSON.stringify(eventData), '*'); frameElement.contentWindow.postMessage(JSON.stringify(eventData), '*');
this.iframeLoading = false; this.iframeLoading = false;

View File

@@ -52,6 +52,7 @@
:key="currentChat.id + '-' + dashboardApp.id" :key="currentChat.id + '-' + dashboardApp.id"
:is-visible="activeIndex - 1 === index" :is-visible="activeIndex - 1 === index"
:config="dashboardApps[index].content" :config="dashboardApps[index].content"
:position="index"
:current-chat="currentChat" :current-chat="currentChat"
/> />
</div> </div>