From 0f2bcf581dbc662e833118114416770dd6bb7367 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Sun, 16 May 2021 21:25:37 +0100 Subject: [PATCH] revert functionality working --- packages/auth/src/db/Replication.js | 9 +- packages/auth/src/db/utils.js | 4 + .../src/builderStore/store/frontend.js | 4 +- .../src/components/deploy/DeployModal.svelte | 110 ++++++++++++++++++ .../src/components/deploy/RevertModal.svelte | 35 ++++++ .../src/components/start/AppCard.svelte | 2 +- .../src/components/start/AppRow.svelte | 2 +- .../components/start/CreateAppModal.svelte | 4 +- .../builder/app/[application]/_layout.svelte | 25 ++-- .../deploy => deploy_old}/_layout.svelte | 2 +- .../deploy => deploy_old}/index.svelte | 0 .../pages/builder/portal/apps/index.svelte | 8 +- packages/builder/src/stores/portal/apps.js | 1 + packages/builder/src/stores/portal/index.js | 2 +- packages/server/scripts/replicateApp.js | 5 +- .../server/src/api/controllers/application.js | 14 +-- .../server/src/api/controllers/component.js | 3 +- .../src/api/controllers/deploy/index.js | 39 ++++--- packages/server/src/api/controllers/dev.js | 37 ++++++ .../src/api/controllers/static/index.js | 5 +- packages/server/src/api/routes/dev.js | 8 +- .../routes/tests/utilities/TestFunctions.js | 2 +- packages/server/src/db/utils.js | 1 + .../src/tests/utilities/TestConfiguration.js | 4 +- packages/server/src/utilities/index.js | 6 +- packages/worker/src/api/controllers/app.js | 7 +- 26 files changed, 266 insertions(+), 73 deletions(-) create mode 100644 packages/builder/src/components/deploy/DeployModal.svelte create mode 100644 packages/builder/src/components/deploy/RevertModal.svelte rename packages/builder/src/pages/builder/app/{[application]/deploy => deploy_old}/_layout.svelte (64%) rename packages/builder/src/pages/builder/app/{[application]/deploy => deploy_old}/index.svelte (100%) diff --git a/packages/auth/src/db/Replication.js b/packages/auth/src/db/Replication.js index 9720776413..931bc3d496 100644 --- a/packages/auth/src/db/Replication.js +++ b/packages/auth/src/db/Replication.js @@ -31,7 +31,7 @@ class Replication { * Two way replication operation, intended to be promise based. * @param {Object} opts - PouchDB replication options */ - sync(opts) { + sync(opts = {}) { this.replication = this.promisify(this.source.sync, opts) return this.replication } @@ -40,7 +40,7 @@ class Replication { * One way replication operation, intended to be promise based. * @param {Object} opts - PouchDB replication options */ - replicate(opts) { + replicate(opts = {}) { this.replication = this.promisify(this.source.replicate.to, opts) return this.replication } @@ -61,8 +61,13 @@ class Replication { }) } + /** + * Rollback the target DB back to the state of the source DB + */ async rollback() { await this.target.destroy() + // Recreate the DB again + this.target = getDB(this.target.name) await this.replicate() } diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 44fe1da2db..c4849a6897 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -12,6 +12,9 @@ exports.StaticDatabases = { GLOBAL: { name: "global-db", }, + DEPLOYMENTS: { + name: "deployments", + }, } const DocumentTypes = { @@ -21,6 +24,7 @@ const DocumentTypes = { TEMPLATE: "template", APP: "app", APP_DEV: "app_dev", + APP_METADATA: "app_metadata", } exports.DocumentTypes = DocumentTypes diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index be553066b9..0d80065f2f 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -51,14 +51,14 @@ export const getFrontendStore = () => { store.actions = { initialise: async pkg => { const { layouts, screens, application, clientLibPath } = pkg - const components = await fetchComponentLibDefinitions(application._id) + const components = await fetchComponentLibDefinitions(application.appId) store.update(state => ({ ...state, libraries: application.componentLibraries, components, name: application.name, description: application.description, - appId: application._id, + appId: application.appId, url: application.url, layouts, screens, diff --git a/packages/builder/src/components/deploy/DeployModal.svelte b/packages/builder/src/components/deploy/DeployModal.svelte new file mode 100644 index 0000000000..5fffa4cd55 --- /dev/null +++ b/packages/builder/src/components/deploy/DeployModal.svelte @@ -0,0 +1,110 @@ + + + + + + + The changes you have made will be published to the production version of the application. + + diff --git a/packages/builder/src/components/deploy/RevertModal.svelte b/packages/builder/src/components/deploy/RevertModal.svelte new file mode 100644 index 0000000000..7eaac42bbd --- /dev/null +++ b/packages/builder/src/components/deploy/RevertModal.svelte @@ -0,0 +1,35 @@ + + + + + + + The changes you have made will be deleted and the application reverted back to its production state. + + diff --git a/packages/builder/src/components/start/AppCard.svelte b/packages/builder/src/components/start/AppCard.svelte index 174ac585d4..7415e2568e 100644 --- a/packages/builder/src/components/start/AppCard.svelte +++ b/packages/builder/src/components/start/AppCard.svelte @@ -41,7 +41,7 @@ {/if} {#if app.lockedBy && app.lockedBy?.email === $auth.user?.email} - releaseLock(app._id)} icon="LockOpen"> + releaseLock(app.appId)} icon="LockOpen"> Release Lock {/if} diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index 693c717ab5..1a4ec1a152 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -50,7 +50,7 @@ deleteApp(app)} icon="Delete">Delete {/if} {#if app.lockedBy && app.lockedBy?.email === $auth.user?.email} - releaseLock(app._id)} icon="LockOpen"> + releaseLock(app.appId)} icon="LockOpen"> Release Lock {/if} diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 44859fbb17..8d2ec56655 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -96,7 +96,7 @@ // Select Correct Application/DB in prep for creating user const applicationPkg = await get( - `/api/applications/${appJson._id}/appPackage` + `/api/applications/${appJson.instance._id}/appPackage` ) const pkg = await applicationPkg.json() if (applicationPkg.ok) { @@ -112,7 +112,7 @@ } const userResp = await api.post(`/api/users/metadata/self`, user) await userResp.json() - $goto(`/builder/app/${appJson._id}`) + $goto(`/builder/app/${appJson.instance._id}`) } catch (error) { console.error(error) notifications.error(error) diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index 98846b3db7..ba4181c6cc 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -1,10 +1,12 @@