From 6c46422d8c7d0febc74238105f7b62fba0c0ad5d Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 23 Nov 2021 09:01:12 +0000 Subject: [PATCH 1/3] remove nav selection modal --- .../NavigationSelectionModal.svelte | 88 +----------------- .../NavigationPanel/NewScreenModal.svelte | 11 +-- .../NavigationPanel/ScreenDetailsModal.svelte | 4 +- .../NavigationPanel/ScreenWizard.svelte | 89 +++++++++++++++++-- 4 files changed, 90 insertions(+), 102 deletions(-) diff --git a/packages/builder/src/components/design/NavigationPanel/NavigationSelectionModal.svelte b/packages/builder/src/components/design/NavigationPanel/NavigationSelectionModal.svelte index 8035281193..52a8e91451 100644 --- a/packages/builder/src/components/design/NavigationPanel/NavigationSelectionModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NavigationSelectionModal.svelte @@ -1,98 +1,12 @@ 0 && !blankSelected + let templates = getTemplates($store, $tables.list) - $: templates = getTemplates($store, $tables.list) const toggleScreenSelection = table => { if (selectedScreens.find(s => s.name.includes(table.name))) { selectedScreens = selectedScreens.filter( screen => !screen.name.includes(table.name) ) } else { - templates = templates.filter(template => - template.name.includes(table.name) + let partialTemplates = getTemplates($store, $tables.list).filter( + template => template.name.includes(table.name) ) - selectedScreens = [...templates, ...selectedScreens] + selectedScreens = [...partialTemplates, ...selectedScreens] } } @@ -31,7 +32,7 @@ title="Add screens" confirmText="Add Screens" cancelText="Cancel" - onConfirm={() => (autoSelected ? chooseModal(2) : chooseModal(1))} + onConfirm={() => (autoSelected ? save() : chooseModal(1))} disabled={!selectedScreens.length} size="L" > diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenDetailsModal.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenDetailsModal.svelte index f353da1a4b..f67f363ce8 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenDetailsModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenDetailsModal.svelte @@ -6,7 +6,7 @@ export let screenName export let url export let chooseModal - + export let save let routeError let roleId = $selectedAccessRole || "BASIC" @@ -37,7 +37,7 @@ title={"Enter details"} confirmText={"Continue"} onCancel={() => chooseModal(0)} - onConfirm={() => chooseModal(2)} + onConfirm={() => save()} cancelText={"Back"} disabled={!screenName || !url || routeError} > diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte index 33d3cbb4aa..f3a2d5ca50 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte @@ -2,7 +2,10 @@ import NavigationSelectionModal from "components/design/NavigationPanel/NavigationSelectionModal.svelte" import ScreenDetailsModal from "components/design/NavigationPanel/ScreenDetailsModal.svelte" import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte" + import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl" import { Modal } from "@budibase/bbui" + import { store, selectedAccessRole, allScreens } from "builderStore" + import { onDestroy } from "svelte" let newScreenModal let navigationSelectionModal @@ -11,6 +14,81 @@ let url = "" let selectedScreens = [] + let roleId = $selectedAccessRole || "BASIC" + + let routeError + let createdScreens = [] + $: { + selectedScreens?.forEach(screen => { + createdScreens = [...createdScreens, screen.create()] + }) + } + + const save = async () => { + for (let screen of createdScreens) { + await saveScreens(screen) + } + + await store.actions.routing.fetch() + selectedScreens = [] + screenName = "" + url = "" + } + const saveScreens = async draftScreen => { + let existingScreenCount = $store.screens.filter( + s => s.props._instanceName == draftScreen.props._instanceName + ).length + + if (existingScreenCount > 0) { + let oldUrlArr = draftScreen.routing.route.split("/") + oldUrlArr[1] = `${oldUrlArr[1]}-${existingScreenCount + 1}` + draftScreen.routing.route = oldUrlArr.join("/") + } + + let route = url ? sanitizeUrl(`${url}`) : draftScreen.routing.route + if (draftScreen) { + if (!route) { + routeError = "URL is required" + } else { + if (routeExists(route, roleId)) { + routeError = "This URL is already taken for this access role" + } else { + routeError = "" + } + } + + if (routeError) return false + + if (screenName) { + draftScreen.props._instanceName = screenName + } + + draftScreen.routing.route = route + + await store.actions.screens.create(draftScreen) + if (draftScreen.props._instanceName.endsWith("List")) { + await store.actions.components.links.save( + draftScreen.routing.route, + draftScreen.routing.route.split("/")[1] + ) + } + } + } + + const routeExists = (route, roleId) => { + return $allScreens.some( + screen => + screen.routing.route.toLowerCase() === route.toLowerCase() && + screen.routing.roleId === roleId + ) + } + + onDestroy(() => { + selectedScreens = [] + screenName = "" + url = "" + }) + export const showModal = () => { newScreenModal.show() } @@ -32,17 +110,12 @@ - + - + - + From 1b69fb8349412b58645b6381d422f787f4d18934 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 23 Nov 2021 09:39:40 +0000 Subject: [PATCH 2/3] fixng some auto screen bugs --- packages/builder/cypress/support/commands.js | 5 +---- .../components/design/NavigationPanel/NewScreenModal.svelte | 4 ++-- .../components/design/NavigationPanel/ScreenWizard.svelte | 4 ---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 2a5a7eb130..1b1cc0c2b0 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -195,10 +195,7 @@ Cypress.Commands.add("createScreen", (screenName, route) => { cy.get("input").first().clear().type(screenName) cy.get("input").eq(1).clear().type(route) cy.get(".spectrum-Button--cta").click() - }) - cy.get(".spectrum-Modal").within(() => { - cy.get(`[data-cy="left-nav"]`).click() - cy.get(".spectrum-Button--cta").click() + cy.wait(2000) }) }) diff --git a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte index e9cedd66fb..cc8365f234 100644 --- a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte @@ -13,7 +13,6 @@ $: blankSelected = selectedScreens?.length === 1 $: autoSelected = selectedScreens?.length > 0 && !blankSelected let templates = getTemplates($store, $tables.list) - const toggleScreenSelection = table => { if (selectedScreens.find(s => s.name.includes(table.name))) { selectedScreens = selectedScreens.filter( @@ -26,6 +25,7 @@ selectedScreens = [...partialTemplates, ...selectedScreens] } } + $: console.log($tables.list) Autogenerated Screens - {#each $tables.list.filter(table => table.type !== "external") as table} + {#each $tables.list.filter(table => table.type !== "external" && table._id !== "ta_users") as table}
x.name.includes(table.name))} diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte index f3a2d5ca50..7018bc2ed4 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte @@ -1,5 +1,4 @@