From 39be0aac69869a7d56782ac5fd1600f139712314 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 10 May 2022 11:47:21 +0100 Subject: [PATCH] Prevent multiple home screen assignment for the same role by changing role on existing screens --- .../_components/ScreenSettingsPanel.svelte | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte index 7764ea04bf..850b56eac4 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte @@ -69,14 +69,21 @@ } // Update screen object in store - store.update(state => { - setWith(get(selectedScreen), key.split("."), value, Object) - return state + // If there are 2 home screens after this change, remove this screen as a + // home screen + const screen = get(selectedScreen) + setWith(screen, key.split("."), value, Object) + const roleId = screen.routing.roleId + const homeScreens = get(store).screens.filter(screen => { + return screen.routing.roleId === roleId && screen.routing.homeScreen }) + if (homeScreens.length > 1) { + screen.routing.homeScreen = false + } // Save new definition try { - store.actions.preview.saveSelected() + store.actions.screens.save(screen) } catch (error) { notifications.error("Error saving screen settings") }