diff --git a/packages/builder/cypress/integration/screens.spec.js b/packages/builder/cypress/integration/screens.spec.js new file mode 100644 index 0000000000..43f7d44917 --- /dev/null +++ b/packages/builder/cypress/integration/screens.spec.js @@ -0,0 +1,22 @@ + +context('Screen Tests', () => { + before(() => { + cy.visit('localhost:4001/_builder') + cy.createApp('Conor Cy App', 'Model App Description') + cy.navigateToFrontend() + }) + + it('Should successful create a screen', () => { + cy.createScreen("test Screen") + }) + + it('Should rename a screen', () => { + cy.get(".components-pane").within(() => { + cy.contains("Settings").click() + cy.get("input[name=_instanceName]").clear().type("About Us").blur() + }) + cy.get('.nav-items-container').within(() => { + cy.contains("About Us").should('exist') + }) + }) +}) \ No newline at end of file diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index ed19ba8233..33ae53d6da 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -103,3 +103,23 @@ Cypress.Commands.add("addButtonComponent", () => { cy.get("[data-cy=Button]").click() }) + +Cypress.Commands.add("navigateToFrontend", () => { + cy.get(".close", { timeout: 10000 }).click() + cy.contains("frontend").click() + cy.get(".close", { timeout: 10000 }).click() +}) + +Cypress.Commands.add("createScreen", (screenName, route) => { + cy.get(".newscreen").click() + cy.get(".uk-input:first").type(screenName) + if (route) { + cy.get(".uk-input:last").type(route) + } + cy.get(".uk-modal-footer").within(() => { + cy.contains("Create Screen").click() + }) + cy.get(".nav-items-container").within(() => { + cy.contains(screenName).should("exist") + }) +}) diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index 0b17e8c61c..11f2ed365e 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -1,4 +1,6 @@ import { values } from "lodash/fp" +import { get_capitalised_name } from "../../helpers" +import { backendUiStore } from "builderStore" import * as backendStoreActions from "./backend" import { writable, get } from "svelte/store" import api from "../api" @@ -22,7 +24,6 @@ import { saveCurrentPreviewItem as _saveCurrentPreviewItem, saveScreenApi as _saveScreenApi, regenerateCssForCurrentScreen, - renameCurrentScreen, } from "../storeUtils" export const getStore = () => { @@ -68,6 +69,7 @@ export const getStore = () => { store.getPathToComponent = getPathToComponent(store) store.addTemplatedComponent = addTemplatedComponent(store) store.setMetadataProp = setMetadataProp(store) + store.editPageOrScreen = editPageOrScreen(store) return store } @@ -152,14 +154,13 @@ const createScreen = store => (screenName, route, layoutComponentName) => { const rootComponent = state.components[layoutComponentName] const newScreen = { - name: screenName || "", description: "", url: "", _css: "", props: createProps(rootComponent).props, } - newScreen.route = route + newScreen.props._instanceName = screenName || "" state.currentPreviewItem = newScreen state.currentComponentInfo = newScreen.props state.currentFrontEndType = "screen" @@ -172,7 +173,7 @@ const createScreen = store => (screenName, route, layoutComponentName) => { const setCurrentScreen = store => screenName => { store.update(s => { - const screen = getExactComponent(s.screens, screenName) + const screen = getExactComponent(s.screens, screenName, true) s.currentPreviewItem = screen s.currentFrontEndType = "screen" s.currentView = "detail" @@ -243,6 +244,7 @@ const setCurrentPage = store => pageName => { const currentPage = state.pages[pageName] state.currentFrontEndType = "page" + state.currentView = "detail" state.currentPageName = pageName state.screens = Array.isArray(current_screens) ? current_screens @@ -294,10 +296,15 @@ const addChildComponent = store => (componentToAdd, presetName) => { const presetProps = presetName ? component.presets[presetName] : {} + const instanceId = get(backendUiStore).selectedDatabase._id + const instanceName = get_capitalised_name(componentToAdd) + const newComponent = createProps( component, { ...presetProps, + _instanceId: instanceId, + _instanceName: instanceName, }, state ) @@ -346,24 +353,23 @@ const selectComponent = store => component => { const setComponentProp = store => (name, value) => { store.update(state => { - const current_component = state.currentComponentInfo - state.currentComponentInfo[name] = value - - _saveCurrentPreviewItem(state) + let current_component = state.currentComponentInfo + current_component[name] = value state.currentComponentInfo = current_component + _saveCurrentPreviewItem(state) return state }) } const setPageOrScreenProp = store => (name, value) => { store.update(state => { - if (name === "name" && state.currentFrontEndType === "screen") { - state = renameCurrentScreen(value, state) + if (name === "_instanceName" && state.currentFrontEndType === "screen") { + state.currentPreviewItem.props[name] = value } else { state.currentPreviewItem[name] = value - _saveCurrentPreviewItem(state) } + _saveCurrentPreviewItem(state) return state }) } @@ -413,6 +419,18 @@ const setScreenType = store => type => { state.currentComponentInfo = pageOrScreen ? pageOrScreen.props : null state.currentPreviewItem = pageOrScreen + state.currentView = "detail" + return state + }) +} + +const editPageOrScreen = store => (key, value, setOnComponent = false) => { + store.update(state => { + setOnComponent + ? (state.currentPreviewItem.props[key] = value) + : (state.currentPreviewItem[key] = value) + _saveCurrentPreviewItem(state) + return state }) } diff --git a/packages/builder/src/builderStore/storeUtils.js b/packages/builder/src/builderStore/storeUtils.js index ff951e6b6f..63fd7ecd00 100644 --- a/packages/builder/src/builderStore/storeUtils.js +++ b/packages/builder/src/builderStore/storeUtils.js @@ -46,8 +46,9 @@ export const saveScreenApi = (screen, s) => { } export const renameCurrentScreen = (newname, state) => { - const oldname = state.currentPreviewItem.name - state.currentPreviewItem.name = newname + const oldname = state.currentPreviewItem.props._instanceName + state.currentPreviewItem.props._instanceName = newname + api.patch( `/_builder/api/${state.appId}/pages/${state.currentPageName}/screen`, { diff --git a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte index 88ce4edca9..0850125de1 100644 --- a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte +++ b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte @@ -1,6 +1,7 @@