1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00

Proxy state updates back from peek modals

This commit is contained in:
Andrew Kingston 2021-12-14 14:04:10 +00:00
parent 1ab1e7517d
commit 98cd12db5f
2 changed files with 28 additions and 3 deletions

View file

@ -4,6 +4,7 @@
dataSourceStore,
notificationStore,
routeStore,
stateStore,
} from "stores"
import { Modal, ModalContent, ActionButton } from "@budibase/bbui"
import { onDestroy } from "svelte"
@ -12,12 +13,13 @@
NOTIFICATION: "notification",
CLOSE_SCREEN_MODAL: "close-screen-modal",
INVALIDATE_DATASOURCE: "invalidate-datasource",
UPDATE_STATE: "update-state",
}
let iframe
let listenersAttached = false
const invalidateDataSource = event => {
const proxyInvalidation = event => {
const { dataSourceId } = event.detail
dataSourceStore.actions.invalidateDataSource(dataSourceId)
}
@ -27,14 +29,28 @@
notificationStore.actions.send(message, type, icon)
}
const proxyStateUpdate = event => {
const { type, key, value, persist } = event.detail
if (type === "set") {
stateStore.actions.setValue(key, value, persist)
} else if (type === "delete") {
stateStore.actions.deleteValue(key)
}
}
function receiveMessage(message) {
const handlers = {
[MessageTypes.NOTIFICATION]: () => {
proxyNotification(message.data)
},
[MessageTypes.CLOSE_SCREEN_MODAL]: peekStore.actions.hidePeek,
[MessageTypes.CLOSE_SCREEN_MODAL]: () => {
peekStore.actions.hidePeek()
},
[MessageTypes.INVALIDATE_DATASOURCE]: () => {
invalidateDataSource(message.data)
proxyInvalidation(message.data)
},
[MessageTypes.UPDATE_STATE]: () => {
proxyStateUpdate(message.data)
},
}

View file

@ -116,6 +116,15 @@ const updateStateHandler = action => {
} else if (type === "delete") {
stateStore.actions.deleteValue(key)
}
// Emit this as an event so that parent windows which are iframing us in
// can also update their state
if (get(routeStore).queryParams?.peek) {
window.parent.postMessage({
type: "update-state",
detail: { type, key, value, persist },
})
}
}
const handlerMap = {