From ad1cf8e6350cb0278f7af0674321ace78f6677de Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Sat, 3 Aug 2024 00:43:12 +0900 Subject: [PATCH] fix: validate the proposal creation form (#524) * fix: add limits to proposal's title, choices, and discussion * fix: validate and show error on proposal body * fix: revert changes, moved to later PR * fix: style composer textarea like s-box * fix: improve CSS * fix: remove unused class * fix(ui): add some padding * fix(ui): add min height * fix(ui): make offset emulate border * fix: add maxLength/items validation to proposals fields * fix: always show form error * fix: always show composer error * fix: add validation to statement * revert: reverting unrelated changes * feat: use different proposal body limit for trubo space * refactor: use camel case variable name * fix: revert changes, will be extracted to another dedicated PR * refactor: rename regular to default --- apps/ui/src/views/Editor.vue | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/ui/src/views/Editor.vue b/apps/ui/src/views/Editor.vue index 01e4a07ce..d397d20a1 100644 --- a/apps/ui/src/views/Editor.vue +++ b/apps/ui/src/views/Editor.vue @@ -18,30 +18,31 @@ type StrategyWithTreasury = SelectedStrategy & { treasury: RequiredProperty; }; +const MAX_BODY_LENGTH = { + default: 10000, + turbo: 40000 +} as const; + const TITLE_DEFINITION = { type: 'string', title: 'Title', - minLength: 1 + minLength: 1, + maxLength: 256 }; const DISCUSSION_DEFINITION = { type: 'string', format: 'uri', title: 'Discussion', + maxLength: 256, examples: ['e.g. https://forum.balancer.fi/t/proposal…'] }; -const BODY_DEFINITION = { - type: 'string', - format: 'long', - title: 'Body', - maxLength: 9600 -}; - const CHOICES_DEFINITION = { type: 'array', title: 'Choices', minItems: 1, + maxItems: 500, items: [{ type: 'string', minLength: 1, maxLength: 32 }], additionalItems: { type: 'string', maxLength: 32 } }; @@ -192,6 +193,12 @@ const extraContacts = computed(() => { return space.value.treasuries as Contact[]; }); +const bodyDefinition = computed(() => ({ + type: 'string', + format: 'long', + title: 'Body', + maxLength: MAX_BODY_LENGTH[space.value?.turbo ? 'turbo' : 'default'] +})); const formErrors = computed(() => { if (!proposal.value) return {}; @@ -203,7 +210,7 @@ const formErrors = computed(() => { required: ['title', 'choices'], properties: { title: TITLE_DEFINITION, - body: BODY_DEFINITION, + body: bodyDefinition.value, discussion: DISCUSSION_DEFINITION, choices: CHOICES_DEFINITION } @@ -470,7 +477,7 @@ export default defineComponent({