Merge pull request #6828 from Budibase/bug/sev3/remove-validate-current-step-checkbox

Remove validate current step checkbox and show validation error messages
This commit is contained in:
melohagan 2022-07-28 10:21:51 +01:00 committed by GitHub
commit 27a1b12af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 41 deletions

View File

@ -1,5 +1,5 @@
<script> <script>
import { Select, Label, Checkbox } from "@budibase/bbui" import { Select, Label } from "@budibase/bbui"
import { currentAsset, store } from "builderStore" import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding" import { getActionProviderComponents } from "builderStore/dataBinding"
@ -21,10 +21,6 @@
getOptionValue={x => x._id} getOptionValue={x => x._id}
/> />
<div /> <div />
<Checkbox
text="Validate only current step"
bind:value={parameters.onlyCurrentStep}
/>
</div> </div>
<style> <style>

View File

@ -58,9 +58,18 @@ export const API = createAPIClient({
} }
} }
if (!ignore) { if (!ignore) {
const validationErrors = error?.json?.validationErrors
if (validationErrors) {
for (let field in validationErrors) {
notificationStore.actions.error(
`${field} ${validationErrors[field]}`
)
}
} else {
notificationStore.actions.error(message) notificationStore.actions.error(message)
} }
} }
}
// Log all errors to console // Log all errors to console
console.warn(`[Client] HTTP ${status} on ${method}:${url}\n\t${message}`) console.warn(`[Client] HTTP ${status} on ${method}:${url}\n\t${message}`)

View File

@ -204,14 +204,11 @@
return fieldInfo return fieldInfo
}, },
validate: (onlyCurrentStep = false) => { validate: () => {
let valid = true let valid = true
let validationFields = fields let validationFields = fields
// Reduce fields to only the current step if required
if (onlyCurrentStep) {
validationFields = fields.filter(f => get(f).step === get(currentStep)) validationFields = fields.filter(f => get(f).step === get(currentStep))
}
// Validate fields and check if any are invalid // Validate fields and check if any are invalid
validationFields.forEach(field => { validationFields.forEach(field => {

View File

@ -6,7 +6,7 @@
<div class="notifications"> <div class="notifications">
{#if $notificationStore} {#if $notificationStore}
{#key $notificationStore.id} {#each $notificationStore as { type, icon, message, id, dismissable } (id)}
<div <div
in:fly={{ in:fly={{
duration: 300, duration: 300,
@ -16,14 +16,14 @@
out:fly={{ y: -20, duration: 150 }} out:fly={{ y: -20, duration: 150 }}
> >
<Notification <Notification
type={$notificationStore.type} {type}
message={$notificationStore.message} {message}
icon={$notificationStore.icon} {icon}
dismissable={$notificationStore.dismissable} {dismissable}
on:dismiss={notificationStore.actions.dismiss} on:dismiss={() => notificationStore.actions.dismiss(id)}
/> />
</div> </div>
{/key} {/each}
{/if} {/if}
</div> </div>
@ -31,6 +31,7 @@
.notifications { .notifications {
position: fixed; position: fixed;
top: 20px; top: 20px;
bottom: 40px;
left: 0; left: 0;
right: 0; right: 0;
margin: 0 auto; margin: 0 auto;
@ -41,5 +42,10 @@
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
pointer-events: none; pointer-events: none;
gap: 10px;
}
.notifications :global(.spectrum-Toast) {
width: 400px;
max-width: 100vw;
} }
</style> </style>

View File

@ -1,18 +1,12 @@
import { writable, get } from "svelte/store" import { writable, get } from "svelte/store"
import { generate } from "shortid"
import { routeStore } from "./routes" import { routeStore } from "./routes"
const NOTIFICATION_TIMEOUT = 3000 const NOTIFICATION_TIMEOUT = 3000
const createNotificationStore = () => { const createNotificationStore = () => {
let timeout
let block = false let block = false
const store = writable(null, () => { const store = writable([])
return () => {
clearTimeout(timeout)
}
})
const blockNotifications = (timeout = 1000) => { const blockNotifications = (timeout = 1000) => {
block = true block = true
@ -37,26 +31,31 @@ const createNotificationStore = () => {
}) })
return return
} }
const _id = id()
store.set({ store.update(state => {
id: generate(), return [
...state,
{
id: _id,
type, type,
message, message,
icon, icon,
dismissable: !autoDismiss, dismissable: !autoDismiss,
delay: get(store) != null, delay: get(store) != null,
},
]
}) })
clearTimeout(timeout)
if (autoDismiss) { if (autoDismiss) {
timeout = setTimeout(() => { setTimeout(() => {
store.set(null) dismiss(_id)
}, NOTIFICATION_TIMEOUT) }, NOTIFICATION_TIMEOUT)
} }
} }
const dismiss = () => { const dismiss = id => {
clearTimeout(timeout) store.update(state => {
store.set(null) return state.filter(n => n.id !== id)
})
} }
return { return {
@ -71,6 +70,10 @@ const createNotificationStore = () => {
dismiss, dismiss,
}, },
} }
function id() {
return "_" + Math.random().toString(36).slice(2, 9)
}
} }
export const notificationStore = createNotificationStore() export const notificationStore = createNotificationStore()

View File

@ -179,8 +179,7 @@ const validateFormHandler = async (action, context) => {
return await executeActionHandler( return await executeActionHandler(
context, context,
action.parameters.componentId, action.parameters.componentId,
ActionTypes.ValidateForm, ActionTypes.ValidateForm
action.parameters.onlyCurrentStep
) )
} }