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

Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal #5229

Merged
merged 1 commit into from May 7, 2020

Conversation

vikram-raj
Copy link
Member

@vikram-raj vikram-raj commented Apr 29, 2020

Fixes:
https://issues.redhat.com/browse/ODC-3421

Analysis / Root cause:
MultiColumnField in Traffic Splitting modal is not aligned properly.

Solution Description:
Align the MultiColumnField in Traffic Splitting modal by fixing the width of the field.

Screen shots / Gifs for design review:
traffic

Unit test coverage report:
Screenshot 2020-05-06 at 11 22 40 AM

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

@vikram-raj vikram-raj changed the title Action menu should be 'fix alignment issues with MultiColumnField in Traffic Splitting modal fix alignment issues with MultiColumnField in Traffic Splitting modal Apr 29, 2020
@vikram-raj
Copy link
Member Author

/retitle Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal

@openshift-ci-robot openshift-ci-robot changed the title fix alignment issues with MultiColumnField in Traffic Splitting modal Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal Apr 29, 2020
@vikram-raj
Copy link
Member Author

cc: @openshift/team-devconsole-ux

@openshift-ci-robot openshift-ci-robot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Apr 29, 2020
@openshift-ci-robot
Copy link
Contributor

@vikram-raj: This pull request references Bugzilla bug 1829385, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

@openshift/team-devconsole-ux Are we okay with 3 equal columns? I'm thinking the first column could be smaller given it can't really ever be longer than the length of '100'.

Comment on lines 3 to 4
flex: auto;
width: 30%;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
flex: auto;
width: 30%;
flex-grow: 1;

Grow to the same size? I haven't tested this out, not sure if the grow-basis will impact the solution, may need grow: 1 1 0;

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried flex-grow and it does work in this case as the width of the dropdown varies as per the option length. That is why it is not aligned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Flex-box in the horizontal direction handles width. You don't need the width property. If it's not working you're conflicting with other styles / indeterminate items. I'll look more into it in a few, haven't checked out the code yet.

EDIT: If you are unsure about what flex can do, this is a good guide.

Copy link
Contributor

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

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

Agreed, can we make the first column smaller since it's a 3 char max? and add that space to the dropdown in the last column?

@openshift-ci-robot
Copy link
Contributor

@vikram-raj: This pull request references Bugzilla bug 1829385, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@serenamarie125 serenamarie125 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 great, thanks for the updates @vikram-raj

Comment on lines 1 to 12
.odc-traffic-splitting-modal {
.odc-multi-column-field__col {
flex: none;
width: 10%;
}
.odc-multi-column-field__col:nth-of-type(2) {
width: 20%;
}
.odc-multi-column-field__col:nth-of-type(3) {
width: 60%;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not an appropriate solution @vikram-raj - this is a hack at best. For one, your percentages don't equal 100.

I think we need to update the MultiColumnField component to support this logic over "splitting the space equally with everyone". Otherwise we'll end up with this problem on every use of this component moving forward as well.

@christianvogt
Copy link
Contributor

@vikram-raj seems to me that this can occur with any usage of the MultiColumnField and therefore would be better off having a solution that can be reused everywhere.
I think what we want is the ability to use the standard 12 column distribution.
Would be good to even support a responsive layout in future.

Why don't we allow the for the children of the component to specify the grid spans?
eg.

<MultiColumnFieldCell span={2}><InputField /></MultiColumnFieldCell>

By default we evenly distribute the spans based on the number of columns.

cc @rohitkrai03 thoughts?

@rohitkrai03
Copy link
Contributor

@vikram-raj seems to me that this can occur with any usage of the MultiColumnField and therefore would be better off having a solution that can be reused everywhere.
I think what we want is the ability to use the standard 12 column distribution.
Would be good to even support a responsive layout in future.

Why don't we allow the for the children of the component to specify the grid spans?
eg.

<MultiColumnFieldCell span={2}><InputField /></MultiColumnFieldCell>

By default we evenly distribute the spans based on the number of columns.

cc @rohitkrai03 thoughts?

I agree with @christianvogt here, we should look at finding the solution which fixes this issue with all the usages of this component. I like the idea of children defining the space they need based on the 12 column grid layout. By default all columns can be divided into equal space.

@vikram-raj
Copy link
Member Author

Added pf Grid layout to MultiColumnField component.

Comment on lines 71 to 72
<GridItem span={span[key]}>
<div key={fieldName} className="odc-multi-column-field__col">
Copy link
Contributor

Choose a reason for hiding this comment

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

key needs to be on the GridItem

@@ -79,6 +79,7 @@ export interface MultiColumnFieldProps extends FieldProps {
emptyMessage?: string;
headers: string[];
children: React.ReactNode;
span: gridItemSpanValueShape[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Evenly space columns if omitted.

Suggested change
span: gridItemSpanValueShape[];
span?: gridItemSpanValueShape[];

I think we should name this spans instead since the api for headers is also plural.

@@ -1,15 +1,12 @@
.odc-multi-column-field {
&__row {
display: flex;
flex-direction: row;
position: relative;
margin-right: var(--pf-global--spacer--lg);
margin-bottom: var(--pf-global--spacer--lg);
max-height: var(--pf-global--spacer--xl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw that we have a max height per row. unsure why that is. @rohitkrai03 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping @rohitkrai03 ^

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't exactly remember as to why I added this but I think it was something to do with the UX designs at the moment and rows being bigger than the designs.

@@ -18,6 +15,7 @@
line-height: var(--pf-global--spacer--xl);
position: absolute;
right: -30px;
top: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want want to center the button vertically. For a typical row, the result is the same, but gives more flexibility if we start creating rows where the height differs from the button height.

top: 50%;
transform: translateY(-50%);

This would enable us to support the same layout as is done here:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Would not just a flex wrapper fix this? There are align center options natively available without going to negative translations.

))}
<div className="odc-multi-column-field__col--button" />
<Grid className="odc-multi-column-field__row">
{headers.map((header, key) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

key => i or index

);
})}
<Grid>
{React.Children.map(children, (child: React.ReactElement, key) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

key => i or index

@@ -20,6 +20,7 @@ const PipelineParameters: React.FC<PipelineParametersProps> = (props) => {
emptyValues={{ name: '', description: '', default: '' }}
emptyMessage={emptyMessage}
isReadOnly={isReadOnly}
span={[4, 4, 4]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be required and therefore columns should be evenly spaced.
Same comment for all instances where columns should be evenly spaced.

Copy link
Member Author

Choose a reason for hiding this comment

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

@christianvogt How will we evenly spaced the field in the case of 5, 7 or 9.. fields present in a row?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that we will be creating such layout but simply make them all even then add 1 to each column starting from the beginning until you've used up all the spaces.
eg.
5 = [3,3,2,2,2]
7 = [2,2,2,2,2,1,1]
9 = [2,2,2,1,1,1,1,1,1]

@@ -23,7 +23,7 @@ const TrafficSplittingModal: React.FC<Props> = ({
values,
}) => {
return (
<form className="modal-content" onSubmit={handleSubmit}>
<form className="modal-content odc-traffic-splitting-modal" onSubmit={handleSubmit}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see odc-traffic-splitting-modal defined.

@vikram-raj vikram-raj force-pushed the odc-3421 branch 2 times, most recently from 358eeb1 to e789885 Compare May 5, 2020 08:02
import { SecondaryStatus, useFormikValidationFix } from '@console/shared';
import { MultiColumnFieldProps } from '../field-types';
import MultiColumnFieldHeader from './MultiColumnFieldHeader';
import MultiColumnFieldRow from './MultiColumnFieldRow';
import MultiColumnFieldFooter from './MultiColumnFieldFooter';
import './MultiColumnField.scss';

const getSpans = (totalFieldCount: number): gridItemSpanValueShape[] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can get tests... can you move it to a utility file and then write a few tests to verify it?

Comment on lines 18 to 20
<div className="odc-multi-column-field__col--button" />
</Grid>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

The button column is outside of the grid on the MultiColumnFieldRow I think we can do the same here.

Suggested change
<div className="odc-multi-column-field__col--button" />
</Grid>
</div>
</Grid>
<div className="odc-multi-column-field__col--button" />
</div>

Comment on lines +18 to 19
top: 50%;
transform: translateY(-50%);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, wonder if we could make a slight change here.

cursor: pointer; impacts disabled buttons... Moving it to here would make it only cursor when you can click the button:

    button:not(:disabled) {
      cursor: pointer;
    }

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

/lgtm

/assign @christianvogt

Will need Christian's approval as I do not have power to approve shared package changes.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 5, 2020
Comment on lines 19 to 21
button:not(:disabled) {
cursor: pointer;
}
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 needed when we are using PF Button which already has a pointer cursor?

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 good point... I just moved the cursor without testing if it was needed.

Comment on lines 4 to 17
export const getSpans = (totalFieldCount: number): gridItemSpanValueShape[] => {
const spans: gridItemSpanValueShape[] = _.fill(Array(totalFieldCount), 1);
if (totalFieldCount === 1) {
return [12];
}
if (totalFieldCount === 12) {
return _.fill(Array(12), 1);
}
while (_.sum(spans) !== 12) {
for (let i = 0; i < totalFieldCount; i++) {
spans[i]++;
if (_.sum(spans) === 12) {
break;
}
}
}
return spans;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified to something like this:

const spans = _.fill(Array(totalFieldCount), Math.trunc(12 / totalFieldCount));
let remainder = 12 % totalFieldCount;
while (remainder--) {
  spans[remainder]++;
}
return spans;

import * as _ from 'lodash';
import { gridItemSpanValueShape } from '@patternfly/react-core';

export const getSpans = (totalFieldCount: number): gridItemSpanValueShape[] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const getSpans = (totalFieldCount: number): gridItemSpanValueShape[] => {
export const getSpans = (totalFieldCount: gridItemSpanValueShape): gridItemSpanValueShape[] => {

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 6, 2020
@openshift-ci-robot
Copy link
Contributor

@vikram-raj: This pull request references Bugzilla bug 1829385, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Comment on lines +31 to +33
const totalFieldCount: gridItemSpanValueShape = React.Children.count(
children,
) as gridItemSpanValueShape;
Copy link
Contributor

Choose a reason for hiding this comment

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

Typing and casting should not be needed... did TypeScript yell at you?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, after changing the type of totalFieldCount to gridItemSpanValueShape from number in the utils.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, i caused this because I didn't follow the code while making the suggestion for the input param type.
Don't care that much which approach you take so long as the getSpans function supports a number > 12.

const spans: gridItemSpanValueShape[] = _.fill(
Array(totalFieldCount),
Math.trunc(12 / totalFieldCount),
) as gridItemSpanValueShape[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, is the type & cast needed by TypeScript?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I was getting the type error because after adding return type gridItemSpanValueShape[] to this utils.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right... because _.fill has probably a very generic type (if any). Well, it's a nit at this point, but you don't have to type the variable if you're casting. It's always that type.

@andrewballantyne
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 6, 2020
@christianvogt
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, christianvogt, serenamarie125, vikram-raj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 6, 2020
@openshift-merge-robot openshift-merge-robot merged commit 2b598b0 into openshift:master May 7, 2020
@openshift-ci-robot
Copy link
Contributor

@vikram-raj: All pull requests linked via external trackers have merged: openshift/console#5229. Bugzilla bug 1829385 has been moved to the MODIFIED state.

In response to this:

Bug 1829385: fix alignment issues with MultiColumnField in Traffic Splitting modal

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@vikram-raj vikram-raj deleted the odc-3421 branch May 7, 2020 11:25
@spadgett spadgett added this to the v4.5 milestone May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/dev-console Related to dev-console component/knative Related to knative-plugin component/shared Related to console-shared lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants