1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +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, dataSourceStore,
notificationStore, notificationStore,
routeStore, routeStore,
stateStore,
} from "stores" } from "stores"
import { Modal, ModalContent, ActionButton } from "@budibase/bbui" import { Modal, ModalContent, ActionButton } from "@budibase/bbui"
import { onDestroy } from "svelte" import { onDestroy } from "svelte"
@ -12,12 +13,13 @@
NOTIFICATION: "notification", NOTIFICATION: "notification",
CLOSE_SCREEN_MODAL: "close-screen-modal", CLOSE_SCREEN_MODAL: "close-screen-modal",
INVALIDATE_DATASOURCE: "invalidate-datasource", INVALIDATE_DATASOURCE: "invalidate-datasource",
UPDATE_STATE: "update-state",
} }
let iframe let iframe
let listenersAttached = false let listenersAttached = false
const invalidateDataSource = event => { const proxyInvalidation = event => {
const { dataSourceId } = event.detail const { dataSourceId } = event.detail
dataSourceStore.actions.invalidateDataSource(dataSourceId) dataSourceStore.actions.invalidateDataSource(dataSourceId)
} }
@ -27,14 +29,28 @@
notificationStore.actions.send(message, type, icon) 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) { function receiveMessage(message) {
const handlers = { const handlers = {
[MessageTypes.NOTIFICATION]: () => { [MessageTypes.NOTIFICATION]: () => {
proxyNotification(message.data) proxyNotification(message.data)
}, },
[MessageTypes.CLOSE_SCREEN_MODAL]: peekStore.actions.hidePeek, [MessageTypes.CLOSE_SCREEN_MODAL]: () => {
peekStore.actions.hidePeek()
},
[MessageTypes.INVALIDATE_DATASOURCE]: () => { [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") { } else if (type === "delete") {
stateStore.actions.deleteValue(key) 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 = { const handlerMap = {