Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"d3": "^5.9.2",
"file-saver": "1.3.x",
"focus-trap-react": "^6.0.0",
"formik": "2.0.1-rc.5",
"formik": "2.0.3",
"fuzzysearch": "1.0.x",
"history": "4.x",
"immutable": "3.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const ToggleableFieldBase: React.FC<ToggleableFieldBaseProps> = ({
helpText,
required,
children,
value,
name,
...props
}) => {
const [field, { touched, error }] = useField(props.name);
const fieldId = getFieldId(props.name, 'checkbox');
const [field, { touched, error }] = useField({ value, name, type: 'checkbox' });
const fieldId = getFieldId(name, 'checkbox');
const isValid = !(touched && error);
const errorMessage = !isValid ? error : '';
return (
Expand All @@ -32,12 +34,13 @@ const ToggleableFieldBase: React.FC<ToggleableFieldBaseProps> = ({
{children({
...field,
...props,
value: field.value,
id: fieldId,
label,
isChecked: field.value,
isChecked: field.checked,
isValid,
'aria-describedby': `${fieldId}-helper`,
onChange: (value, event) => field.onChange(event),
onChange: (val, event) => field.onChange(event),
})}
</FormGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface TextAreaProps extends FieldProps {

export interface CheckboxFieldProps extends FieldProps {
formLabel?: string;
value?: string;
}

export interface SearchInputFieldProps extends InputFieldProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as React from 'react';
import { ResourceLimitField } from '@console/shared';
import { useField } from 'formik';
import { useFormikContext, FormikValues } from 'formik';
import FormSection from '../section/FormSection';
import { MemoryUnits, CPUUnits } from '../import-types';

const ResourceLimitSection: React.FC = () => {
const [cpuLimits] = useField('limits.cpu');
const [memoryLimits] = useField('limits.memory');
const {
values: {
limits: { cpu, memory },
},
} = useFormikContext<FormikValues>();
Comment on lines +8 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@divyanshiGupta divyanshiGupta Jan 31, 2020

Choose a reason for hiding this comment

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

@christianvogt after upgrade it was throwing error on line 18,27,37 and 46 that the defaultRequestUnit does not exist on type string, I tried to do a bunch of things but the error wont go, then I tried to use the same values from useFormikContext and the error was gone.

Then I went through the implementation and they have changed the implementation of getFieldProps (used inside useField to get the field values) a bit from 2.0.1rc5 to 2.0.3. Now in 2.0.3 its enforced that we need to pass an object to useField for field types such as checkbox to get the desired data, but for other field types such TextInput passing a string of field name is sufficient. For full context you will have to go through the above 2 links I posted.

I missed to update the ToggleableFieldBase though, will do it. But I think for our use case here its okay to use useFormikContext in ResourceLimitSection since its not a FormikField and useField, if you see the implementation makes more sense when used in a FormikField.

return (
<FormSection title="Resource Limit">
<div className="co-section-heading-tertiary">CPU</div>
Expand All @@ -15,7 +18,7 @@ const ResourceLimitSection: React.FC = () => {
label="Request"
unitName="limits.cpu.requestUnit"
unitOptions={CPUUnits}
defaultUnitSize={`${cpuLimits.value.defaultRequestUnit}`}
defaultUnitSize={`${cpu.defaultRequestUnit}`}
helpText="The minimum amount of CPU the container is guaranteed."
/>

Expand All @@ -24,7 +27,7 @@ const ResourceLimitSection: React.FC = () => {
label="Limit"
unitName="limits.cpu.limitUnit"
unitOptions={CPUUnits}
defaultUnitSize={`${cpuLimits.value.defaultLimitUnit}`}
defaultUnitSize={`${cpu.defaultLimitUnit}`}
helpText="The maximum amount of CPU the container is allowed to use when running."
/>

Expand All @@ -34,7 +37,7 @@ const ResourceLimitSection: React.FC = () => {
label="Request"
unitName="limits.memory.requestUnit"
unitOptions={MemoryUnits}
defaultUnitSize={`${memoryLimits.value.defaultRequestUnit}`}
defaultUnitSize={`${memory.defaultRequestUnit}`}
helpText="The minimum amount of Memory the container is guaranteed."
/>

Expand All @@ -43,7 +46,7 @@ const ResourceLimitSection: React.FC = () => {
label="Limit"
unitName="limits.memory.limitUnit"
unitOptions={MemoryUnits}
defaultUnitSize={`${memoryLimits.value.defaultLimitUnit}`}
defaultUnitSize={`${memory.defaultLimitUnit}`}
helpText="The maximum amount of Memory the container is allowed to use when running."
/>
</FormSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Renderer from 'react-test-renderer';
import PipelineResourceSection, {
ResourceSectionProps,
} from '../pipeline-form/PipelineResourceSection';
import { Formik } from 'formik';

jest.mock('react-dom', () => ({
findDOMNode: () => ({}),
Expand Down Expand Up @@ -34,7 +35,11 @@ describe('PipelineResourceSection component', () => {
});

it('It should match the previous pipeline snapshot', () => {
const tree = Renderer.create(<PipelineResourceSection resources={resources} />).toJSON();
const tree = Renderer.create(
<Formik onSubmit={() => {}} initialValues={{}}>
{() => <PipelineResourceSection resources={resources} />}
</Formik>,
).toJSON();
expect(tree).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('Project Access Form', () => {
unregisterField: jest.fn(),
validateField: jest.fn(),
validateForm: jest.fn(),
getFieldMeta: jest.fn(),
validateOnBlur: true,
validateOnChange: true,
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/components/factory/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export type ModalSubmitFooterProps = {
message?: string;
errorMessage?: string;
inProgress: boolean;
cancel: (e: Event) => void;
cancel: (e: React.SyntheticEvent<any, Event>) => void;
cancelText?: React.ReactNode;
submitText: React.ReactNode;
submitDisabled?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const configureMachineAutoscalerModal = createModalLauncher(ConfigureMach

export type ConfigureMachineAutoscalerModalProps = {
machineSet: K8sResourceKind;
cancel: (e: Event) => void;
cancel: (e: React.SyntheticEvent<any, Event>) => void;
close: () => void;
};

Expand Down
14 changes: 7 additions & 7 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7857,15 +7857,15 @@ format@^0.2.2:
resolved "https://registry.yarnpkg.com/format/-/format-0.2.2.tgz#d6170107e9efdc4ed30c9dc39016df942b5cb58b"
integrity sha1-1hcBB+nv3E7TDJ3DkBbflCtctYs=

formik@2.0.1-rc.5:
version "2.0.1-rc.5"
resolved "https://registry.yarnpkg.com/formik/-/formik-2.0.1-rc.5.tgz#856a36036fa27d707aa6879476623b4a7753e158"
integrity sha512-EEz+CLL5RYh95di4gdnlfrfCJrsC48Eis+kZhcqhanxlkA2ZMBmMLo7XxUZjMx+8aTZjEBOR3GQZstQ2/44chg==
formik@2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/formik/-/formik-2.0.3.tgz#7cf088b1a6e0ba21782b73a90453a78426959168"
integrity sha512-kYBvcxlsYSncY8OiJHD49C0UmoWXbgmIc9V1g3N1WwBJ7SMLk34QpcJDgroYd42K1cH+mSJlXhB7PlgTXTzlWg==
dependencies:
deepmerge "^2.1.1"
hoist-non-react-statics "^3.3.0"
lodash "^4.17.11"
lodash-es "^4.17.11"
lodash "^4.17.14"
lodash-es "^4.17.14"
react-fast-compare "^2.0.1"
scheduler "^0.14.0"
tiny-warning "^1.0.2"
Expand Down Expand Up @@ -10509,7 +10509,7 @@ lodash-es@4.x, lodash-es@^4.2.1:
version "4.17.7"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.7.tgz#db240a3252c3dd8360201ac9feef91ac977ea856"

lodash-es@^4.17.11:
lodash-es@^4.17.14:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
Expand Down