-
Notifications
You must be signed in to change notification settings - Fork 593
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
.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); | ||
} | ||
|
||
&__col { | ||
flex: 1 0 0; | ||
margin-right: var(--pf-global--spacer--md); | ||
} | ||
|
||
&__col--button { | ||
cursor: pointer; | ||
line-height: var(--pf-global--spacer--xl); | ||
position: absolute; | ||
right: -30px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
} | ||
Comment on lines
+17
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, wonder if we could make a slight change here.
|
||
&__empty-message { | ||
margin-bottom: var(--pf-global--spacer--sm); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { FieldArray, useFormikContext, FormikValues } from 'formik'; | ||
import { FormGroup } from '@patternfly/react-core'; | ||
import { FormGroup, gridItemSpanValueShape } from '@patternfly/react-core'; | ||
import { SecondaryStatus, useFormikValidationFix } from '@console/shared'; | ||
import { MultiColumnFieldProps } from '../field-types'; | ||
import MultiColumnFieldHeader from './MultiColumnFieldHeader'; | ||
import MultiColumnFieldRow from './MultiColumnFieldRow'; | ||
import MultiColumnFieldFooter from './MultiColumnFieldFooter'; | ||
import { getSpans } from './multicolumn-field-utils'; | ||
import './MultiColumnField.scss'; | ||
|
||
const MultiColumnField: React.FC<MultiColumnFieldProps> = ({ | ||
|
@@ -23,9 +24,14 @@ const MultiColumnField: React.FC<MultiColumnFieldProps> = ({ | |
disableDeleteRow, | ||
disableAddRow, | ||
toolTip, | ||
spans, | ||
}) => { | ||
const { values } = useFormikContext<FormikValues>(); | ||
const fieldValue = _.get(values, name, []); | ||
const totalFieldCount: gridItemSpanValueShape = React.Children.count( | ||
children, | ||
) as gridItemSpanValueShape; | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typing and casting should not be needed... did TypeScript yell at you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, after changing the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const fieldSpans = spans || getSpans(totalFieldCount); | ||
useFormikValidationFix(fieldValue); | ||
return ( | ||
<FieldArray | ||
|
@@ -45,7 +51,7 @@ const MultiColumnField: React.FC<MultiColumnFieldProps> = ({ | |
</div> | ||
) | ||
) : ( | ||
<MultiColumnFieldHeader headers={headers} /> | ||
<MultiColumnFieldHeader headers={headers} spans={fieldSpans} /> | ||
)} | ||
{fieldValue.length > 0 && | ||
fieldValue.map((value, index) => ( | ||
|
@@ -57,6 +63,7 @@ const MultiColumnField: React.FC<MultiColumnFieldProps> = ({ | |
onDelete={() => remove(index)} | ||
isReadOnly={isReadOnly} | ||
disableDeleteRow={disableDeleteRow} | ||
spans={fieldSpans} | ||
> | ||
{children} | ||
</MultiColumnFieldRow> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getSpans } from '../multicolumn-field-utils'; | ||
|
||
describe('Multicolumn field utils', () => { | ||
it('should return single spans value', () => { | ||
const spans = getSpans(1); | ||
expect(spans).toEqual([12]); | ||
}); | ||
it('should return 12 spans equally sized', () => { | ||
const spans = getSpans(12); | ||
expect(spans).toEqual([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); | ||
}); | ||
it('should return spans [3, 3, 2, 2, 2]', () => { | ||
const spans = getSpans(5); | ||
expect(spans).toEqual([3, 3, 2, 2, 2]); | ||
}); | ||
it('should return spans [2, 2, 2, 2, 2, 1, 1]', () => { | ||
const spans = getSpans(7); | ||
expect(spans).toEqual([2, 2, 2, 2, 2, 1, 1]); | ||
}); | ||
it('should return spans [2, 2, 2, 1, 1, 1, 1, 1, 1]', () => { | ||
const spans = getSpans(9); | ||
expect(spans).toEqual([2, 2, 2, 1, 1, 1, 1, 1, 1]); | ||
}); | ||
it('should return spans [4, 4, 4]', () => { | ||
const spans = getSpans(3); | ||
expect(spans).toEqual([4, 4, 4]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as _ from 'lodash'; | ||
import { gridItemSpanValueShape } from '@patternfly/react-core'; | ||
|
||
export const getSpans = (totalFieldCount: gridItemSpanValueShape): gridItemSpanValueShape[] => { | ||
const spans: gridItemSpanValueShape[] = _.fill( | ||
Array(totalFieldCount), | ||
Math.trunc(12 / totalFieldCount), | ||
) as gridItemSpanValueShape[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, is the type & cast needed by TypeScript? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was getting the type error because after adding return type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right... because |
||
|
||
let remainder = 12 % totalFieldCount; | ||
|
||
while (remainder--) { | ||
spans[remainder]++; | ||
} | ||
|
||
return spans; | ||
}; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @rohitkrai03 ^
There was a problem hiding this comment.
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.