Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3 form components #639

Merged
merged 38 commits into from
May 4, 2023
Merged

Vue3 form components #639

merged 38 commits into from
May 4, 2023

Conversation

sgfost
Copy link
Contributor

@sgfost sgfost commented Apr 6, 2023

Adds:

  • Form management API and requests API
  • Form component library (inputs)
  • Select forms implemented as usage examples

sgfost and others added 22 commits April 4, 2023 14:09
use a more unique id than just name for fields
- add WIP codebase search component
- added composable API for tagger/codebase (partial)
essentially classes -> composition and getting rid of handlers

handlers are replaced with request state that are made available as
individual refs in components, which then can decide what to do instead
of a handler directly modifying component state behind the scenes
cleaned up where the rule found some style issues but otherwise its
not particularly useful for development of vue components nor the requests api
- should prefer using schema even when validation is not used but
  resolved the issue with trying to use an undefined schema in useForm
  anyways

Co-authored-by: Allen Lee <alee@users.noreply.github.com>
made date picker polymorphic (Date or string model value)

+ minor file renaming
sgfost and others added 7 commits April 14, 2023 12:04
- upgrade to bootstrap 5.2
- only use Date model value
- add minDate prop to set instead of the client-side validation that is
  confusing for everyone
Co-authored-by: Allen Lee <alee@users.noreply.github.com>
current thought is to be more explicit within the component about what
happens on success/error especially given the design of the
api composables giving access to request state
server errors are now packaged up in useAxios and given (along with
client-side validation errors from useForm) to a component to display
alerts

- added more constraints to the client-side date validation approach
which is just a textarea form component with a small indicator icon/link
to a markdown guide

eventually should be given some editing/previewing functionality once we
decide the best way to tackle that (comses/planning#106)

[no ci]
includes ux changes such as indicating you need to press enter to add an
item and automatically adding an item in the input field on blur (focus
lost) as a backup
* missing affiliations field (org search/items component needs to be
  implemented)

- minor refactoring of how props for the vue components are extracted
  from data attrs/path
- finalized profile edit form (minus a better markdown editor)
@sgfost sgfost marked this pull request as ready for review April 20, 2023 22:57
@sgfost
Copy link
Contributor Author

sgfost commented Apr 20, 2023

All form components (minus the placeholder markdown component) are finished, likely along with any major changes to the form api.

I'll put in place some component tests to finish off this PR and then work on some documentation for the different apis and then putting together the rest of the pages should be (relatively) straightforward

@sgfost sgfost linked an issue Apr 20, 2023 that may be closed by this pull request
@sgfost
Copy link
Contributor Author

sgfost commented Apr 20, 2023

resolves comses/planning#106, resolves #319, resolves #489, resolves #451, resolves #251, resolves #624

Copy link
Member

@alee alee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge pile of excellent work, thanks Scott! I'm good to merge it into the vue3 branch and continue moving forward there in a separate PR / commit stream but would leave it up to you. Left a few minor notes here and there. I think the main thing might be to rename the form components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These components are clean and well-designed, great work as usual!

Only nitpicks are in naming:

Should we add a Form prefix to all the components in form/ or just leave them as Alert.vue, Checkbox.vue, etc. The components/form package / dir name hierarchy indicates that they are all form components already. (for more context, see https://devcards.io/smurf-naming-convention and https://softwareengineering.stackexchange.com/questions/191929/the-problems-with-avoiding-smurf-naming-classes-with-namespaces)

Also the CheckboxProps seems like a more generalizable server/validation errors container interface, probably a copypasta that should be AlertProps instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of between a rock and a hard place w/ smurf naming and vue style guide/HTML collisions (https://vuejs.org/style-guide/rules-essential.html#use-multi-word-component-names)

How about getting more descriptive and prepending/appending more specific names?:

  • Form<...>.vue for non-field form-level stuff (really only alert for now) - FormAlert.vue
  • Field<...>.vue for field-level 'helpers' like label/error - FieldError.vue
  • <...>Field.vue for field components - CheckboxField.vue

Otherwise we're looking at more general prefixes, the vue 2 codebases uses C presumably for comses or custom. Here, we'd have to prefix the file name or add another script tag to set the name since <script setup> exports and imports the component as the file name automatically

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, gotcha - thanks for the style guide link! We could try something like ValidationErrorAlert. So TextArea and TextInput and things would conflict with native <textarea> tags or would it be translated to text-area which might also be confusing 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah since you can use either <text-area> or <TextArea> or any case variation I think it would still cause a conflict there. I tried out my first idea for now: https://github.com/comses/comses.net/tree/db8c099f6a35f0d2b2b9e99a4404b0b5d817949c/frontend-vue3/src/components/form, lmk if you have any thoughts

frontend-vue3/src/components/form/FormOrgItems.vue Outdated Show resolved Hide resolved
frontend-vue3/src/components/form/FormOrgItems.vue Outdated Show resolved Hide resolved
frontend-vue3/src/composables/api/axios.ts Outdated Show resolved Hide resolved
frontend-vue3/src/composables/api/axios.ts Outdated Show resolved Hide resolved
}
for (const key of Object.keys(body)) {
const value = body[key];
if (isISODateString(value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also use Date.parse, try/catch or are we only allowing iso date strings here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the intent was to strictly parse ISO 8601 date strings and assume everything else is meant to be a string, the spec for Date.parse seemed far too loose since most implementations would parse a string like "10 10 10"

frontend-vue3/src/composables/api/profile.ts Outdated Show resolved Hide resolved
frontend-vue3/src/composables/api/revieweditor.ts Outdated Show resolved Hide resolved
sgfost added 4 commits May 3, 2023 19:07
- use more descripting prefixes for form components
- some type/variable renaming
- create src/types.ts for shared types and a `BaseFieldProps` for field
  components to extend
using imported types with defineProps is currently unsupported but has
been fixed awaiting a release in vuejs/core#8083
- minor renaming and refactoring for clarity
- make `detailUrl` more robust so it can be used as a general url
  builder
@sgfost
Copy link
Contributor Author

sgfost commented May 4, 2023

Super helpful review @alee, thanks. Everything here should be addressed. I'll merge this into vue3 and then keep going straight on there for the most part

@sgfost sgfost merged commit 1012b8a into comses:vue3 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

frontend: refactor createFormValidator
2 participants