From 07553b99370eb412f5288f3dfea701325f5194cc Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Mon, 26 Jul 2021 13:58:18 +0200 Subject: [PATCH 01/19] clear form action - draft --- .../EventsEditor/actions/index.js | 3 ++ packages/client/src/constants.js | 1 + packages/client/src/utils/buttonActions.js | 9 ++++++ .../src/forms/InnerForm.svelte | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js index b8114461f9..2c9023714f 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js @@ -42,4 +42,7 @@ export default [ name: "Log Out", component: LogOut, }, + { + name: "Clear Form", + }, ] diff --git a/packages/client/src/constants.js b/packages/client/src/constants.js index e0595c0ce9..049b16801b 100644 --- a/packages/client/src/constants.js +++ b/packages/client/src/constants.js @@ -6,6 +6,7 @@ export const ActionTypes = { ValidateForm: "ValidateForm", RefreshDatasource: "RefreshDatasource", SetDataProviderQuery: "SetDataProviderQuery", + ClearForm: "ClearForm" } export const ApiVersion = "1" diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index af4826a1c4..d7707bfb11 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -77,6 +77,14 @@ const refreshDatasourceHandler = async (action, context) => { ) } +const clearFormHandler = async (action, context) => { + return await executeActionHandler( + context, + action.parameters.componentId, + ActionTypes.ClearForm + ) +} + const handlerMap = { ["Save Row"]: saveRowHandler, ["Delete Row"]: deleteRowHandler, @@ -85,6 +93,7 @@ const handlerMap = { ["Trigger Automation"]: triggerAutomationHandler, ["Validate Form"]: validateFormHandler, ["Refresh Datasource"]: refreshDatasourceHandler, + ["Clear Form"]: clearFormHandler } const confirmTextMap = { diff --git a/packages/standard-components/src/forms/InnerForm.svelte b/packages/standard-components/src/forms/InnerForm.svelte index 3a63b63bdc..55e14217e1 100644 --- a/packages/standard-components/src/forms/InnerForm.svelte +++ b/packages/standard-components/src/forms/InnerForm.svelte @@ -64,6 +64,13 @@ }) return get(formState).valid }, + clear: () => { + const fields = Object.keys(fieldMap) + fields.forEach(field => { + const { fieldApi } = fieldMap[field] + fieldApi.clearValue(); + }) + } } // Provide both form API and state to children @@ -72,6 +79,7 @@ // Action context to pass to children const actions = [ { type: ActionTypes.ValidateForm, callback: formApi.validate }, + { type: ActionTypes.ClearForm, callback: formApi.clear }, ] // Creates an API for a specific field @@ -108,8 +116,28 @@ return !newError } + + const clearValue = () => { + const { fieldState } = fieldMap[field] + fieldState.update(state => { + state.value = defaultValue + state.error = null + return state + }) + + formState.update(state => { + state.values = { ...state.values, [field]: defaultValue } + delete state.errors[field] + state.valid = Object.keys(state.errors).length === 0 + return state + }) + + return true + } + return { setValue, + clearValue, validate: () => { const { fieldState } = fieldMap[field] setValue(get(fieldState).value, true) From 3dbafac80647298fb375b574353f867b42d347ae Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Mon, 26 Jul 2021 15:05:22 +0200 Subject: [PATCH 02/19] clear form action - adjust manifest and add settings form --- .../EventsEditor/actions/ClearForm.svelte | 35 +++++++++++++++++++ .../EventsEditor/actions/index.js | 2 ++ packages/standard-components/manifest.json | 3 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/ClearForm.svelte diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/ClearForm.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/ClearForm.svelte new file mode 100644 index 0000000000..74eae6283c --- /dev/null +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/ClearForm.svelte @@ -0,0 +1,35 @@ + + +
+ + ($touched.name = true)} + on:change={() => dirty = true} + label="Name" + /> + + diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 6c229c1980..02260e19ec 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -14,6 +14,7 @@ Body, } from "@budibase/bbui" import CreateAppModal from "components/start/CreateAppModal.svelte" + import UpdateAppModal from "components/start/UpdateAppModal.svelte" import api, { del } from "builderStore/api" import analytics from "analytics" import { onMount } from "svelte" @@ -30,6 +31,7 @@ let template let selectedApp let creationModal + let updatingModal let deletionModal let unpublishModal let creatingApp = false @@ -164,6 +166,11 @@ selectedApp = null } + const updateApp = async app => { + selectedApp = app + updatingModal.show() + } + const releaseLock = async app => { try { const response = await del(`/api/dev/${app.devId}/lock`) @@ -236,6 +243,7 @@ {editApp} {exportApp} {deleteApp} + {updateApp} /> {/each}
@@ -289,6 +297,12 @@ Are you sure you want to unpublish the app {selectedApp?.name}? + + +