Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Horizontal stacking of fields #2376

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

lenriquez
Copy link
Contributor

@lenriquez lenriquez commented Apr 26, 2021

Signed-off-by: Luis Enriquez [email protected]

What this PR does / why we need it:

Which issue(s) this PR fixes

Special notes for your reviewer:

For #2020
Vertical did not work so it was necessary to ask clarity team
Question to clarity team
https://vmware.slack.com/archives/C0JF8D2LB/p1619628404441100

Basically, there is no easy way to do it, is necessary to add a div with a layout horizontal for every row like is shown here
https://stackblitz.com/edit/typescript-ku7jz4?file=index.html

In order to encode that information on a JSON a new struct was created where all the horizontal field are contained on the attribute field

#2178
The above solution did not work because label use a lot of space
So at the end it was implemented a solution using width

#2223
The solution proposed by @GuessWhoSamFoo basically changed
image

to this solution
image

This is how it looks right now

image

@GuessWhoSamFoo solution help to reduce the amount of code on form

Release note:

release-note

<clr-checkbox-wrapper
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn"
>
<cds-form-group control-width="shrink">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think layout is working as expected and only allowed for radio buttons/checkboxes. It doesn't solve the original issue though

@lenriquez lenriquez force-pushed the issue-2020 branch 3 times, most recently from 66e9795 to 1465387 Compare May 3, 2021 21:25
@lenriquez lenriquez marked this pull request as ready for review May 3, 2021 21:27
pkg/view/component/form.go Outdated Show resolved Hide resolved
@@ -117,6 +118,126 @@ func marshalFormField(ff FormField) ([]byte, error) {
return json.Marshal(&m)
}

type FormFieldLayout struct {
*BaseFormField
value string
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be something more descriptive like row size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am using the values of a form, I don't think I am adding anything extra to this field

@@ -117,6 +118,126 @@ func marshalFormField(ff FormField) ([]byte, error) {
return json.Marshal(&m)
}

type FormFieldLayout struct {
*BaseFormField
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a form field type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, I have three solutions for this

  1. Add a boolean field to Base Form Field to see if it should be horizontal or not but this idea has a flaw
  2. Add a int to know the amount of fields going into a row
  3. Create a struct to save that information there

I think none of them are great solutions, but that's why I wanted to talk before implementing this

}

func (ff *FormFieldLayout) SetLabel(value string) {
ff.label = value
Copy link
Contributor

Choose a reason for hiding this comment

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

We can intuitively see the problem of making a field layout into a form field - labels and values are forced to be set even though there are largely not relevant in this context.

This is more apparent under UnmarshalJSON with error, name, validators, etc.

return ff.value
}

func (ff *FormFieldLayout) UnmarshalJSON(data []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

imo, this is a lot of extra churn just to insert a class:

https://github.com/vmware-tanzu/octant/pull/2376/files#diff-7d8ccf86c27d790d6cb4eb0c8e6aa65294788afdaa9b3076373a07e6a3a867f6R4

I think the preferred way to fix this is to implement the to-do (convert FormField into a struct).

Copy link
Contributor Author

@lenriquez lenriquez May 10, 2021

Choose a reason for hiding this comment

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

The problem is not the class but rather the div that provides the horizontal layout

@lenriquez lenriquez force-pushed the issue-2020 branch 4 times, most recently from d1fe1d1 to 10b4d7b Compare May 20, 2021 19:06
@@ -192,7 +97,8 @@ func TestForm_UnmarshalJSON(t *testing.T) {
var got Form
require.NoError(t, json.Unmarshal(data, &got))

assert.Equal(t, form, got)
dataGot, err := json.Marshal(&got)
assert.JSONEq(t, string(data), string(dataGot))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about this, equal is comparing pointers and not values

Copy link
Contributor

@mklanjsek mklanjsek left a comment

Choose a reason for hiding this comment

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

Looks pretty good just a few small thing mostly naming

web/src/stories/stepper.stories.mdx Show resolved Hide resolved
web/package-lock.json Outdated Show resolved Hide resolved
web/angular.json Outdated Show resolved Hide resolved
pkg/view/component/form.go Outdated Show resolved Hide resolved
pkg/view/component/form.go Outdated Show resolved Hide resolved
pkg/view/component/form.go Outdated Show resolved Hide resolved
@lenriquez lenriquez force-pushed the issue-2020 branch 3 times, most recently from 8df7222 to b00829d Compare June 1, 2021 03:02
@@ -115,3 +140,160 @@ export const StepperStoryTemplate = args => ({

<h2>Props</h2>
<Props story = "Stepper component"/>

export const stepperHFDocs = {
source: {code: `title = "Example Stepper with Horizontal Form" component.NewStepper()`},
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a snippet of working code that reflects what is shown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@GuessWhoSamFoo GuessWhoSamFoo merged commit 68df9b7 into vmware-archive:master Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Horizontal stacking of fields
3 participants