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

Refactor current basic form #1212

Merged
merged 5 commits into from
Oct 10, 2019
Merged

Refactor current basic form #1212

merged 5 commits into from
Oct 10, 2019

Conversation

andresmgot
Copy link
Contributor

This PR contains several improvements:

  • The hardcoded keys that Kubeapps expects has been reduced to the minimum possible (for the moment) and moved to the file schema.ts so any component can read those.
  • Instead of hardcoding titles, we will be using the ones used in the schema for all the parameters.
  • The component DatabaseSection has been refactored to Subsection to make it generic. The idea is to reuse this component for the hostname section.
  • The component DiskSize has been refactored to SliderParam to make it generic. The idea is to reuse this component for the resource params.

@@ -0,0 +1,85 @@
import * as React from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't know why this is detected as a new file. The changes here from the DatabaseSection are:

Comment on lines +12 to +13
enablerChildrenParam: string;
enablerCondition: boolean;
Copy link
Contributor Author

@andresmgot andresmgot Oct 9, 2019

Choose a reason for hiding this comment

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

These two parameters are used to know which of the children params is used to enable/disable the section.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need enablerCondition? Ah, because some charts might use enablePersistence while others disablePersistence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. A real example is the externalDatabase that to be enabled require the property mariadb.enabled to be false.

const { label, param, name, enablerChildrenParam, enablerCondition } = this.props;
return (
<div className="subsection margin-v-normal">
{param.children && param.children[enablerChildrenParam] && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only show the enabler section if that param exists

};
};

private renderParam(name: string, param: IBasicFormParam, index: number) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generically render sub params as in the BasicDeploymentForm component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can one implementation be shared for both cases then? (Assuming a subsection will generally be able to support all the same fields - though we don't need to support further subsections etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I thought about that but I didn't know where to place the function. Probably just the one in the BasicDeploymentForm should be enough.

/>
);
default:
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 have removed this case to assume that if the type is not set, it refers to a string

Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

+1 - a bunch of comments, but fine to land.

So we're still enforcing a certain structure on the schema now right? Or did I miss that here? (The reason I worry about enforcing a certain structure is that it might make people less likely to use it. If I have a chart with values where the db values are just at the top level, I'd have to break my chart compatability to use this - I think?)

export interface IDiskSizeParamState {
Gi: number;
export interface ISliderParamState {
amount: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

value is a bit more generic, but amount fine too.

Gi: toNumber(this.props.param.value) || 10,
class SliderParam extends React.Component<ISliderParamProps, ISliderParamState> {
public state: ISliderParamState = {
amount: toNumber(this.props.param.value) || this.props.min,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this mean it can be set initially outside min/max?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the default value comes from the values.yaml or the schema. If there is a problem with the configuration, the default value may not be valid

expect(defaultProps.param.children!.useSelfHostedDatabase.value).toBe(true);
expect(wrapper.find(".margin-t-normal").prop("hidden")).toBe(true);
expect(wrapper.find("div").findWhere(d => d.prop("hidden"))).toExist();
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is because there are more than one div ? So it's "expect at least one div with a hidden prop". Not sure if that should be more specific to match the test label.

Also - why are you creating a div with a hidden prop, rather than a className or similar? Also, does this return true for <div hidden={false}> as the prop is still passed (which is what the code below does, I think?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is because there are more than one div ? So it's "expect at least one div with a hidden prop". Not sure if that should be more specific to match the test label.

Yes. Taking a look to the functional code, I couldn't find something better to identify the div I am interested in.

Also - why are you creating a div with a hidden prop, rather than a className or similar?

Well, I am interested in hiding the div, why are you suggesting using a className instead? Is there something I am missing?

Also, does this return true for

as the prop is still passed (which is what the code below does, I think?)

No, since the property of hidden is false, the find iteration return false so it's not returned. It only returns true for <div hidden={true}>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I am interested in hiding the div, why are you suggesting using a className instead? Is there something I am missing?

No - I was just unsure whether the hidden attribute should be used in this case. See the MDN doc, I was thinking that what we're doing here is equivalent to hiding panels in a tabbed dialog (where it should not be used), but the use-case here is different in that the elements are only relevant if the self-hosted option is enabled (across all presentations) so I think you're right to use it.

Comment on lines +12 to +13
enablerChildrenParam: string;
enablerCondition: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need enablerCondition? Ah, because some charts might use enablePersistence while others disablePersistence?

};
};

private renderParam(name: string, param: IBasicFormParam, index: number) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can one implementation be shared for both cases then? (Assuming a subsection will generally be able to support all the same fields - though we don't need to support further subsections etc.)

@@ -90,7 +92,8 @@ export function setValue(values: string, path: string, newValue: any) {
export function getValue(values: string, path: string, defaultValue?: any) {
const doc = YAML.parseDocument(values);
const splittedPath = path.split(".");
return (doc as any).getIn(splittedPath) || defaultValue;
const value = (doc as any).getIn(splittedPath);
return value === undefined || value === null ? defaultValue : value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really important, but should the default also be limited to min/max? Completely ignorable :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the default is set by the user (the same way they set the min/max) so that shouldn't be a case (and their tests should catch that)

@andresmgot
Copy link
Contributor Author

andresmgot commented Oct 10, 2019

So we're still enforcing a certain structure on the schema now right? Or did I miss that here? (The reason I worry about enforcing a certain structure is that it might make people less likely to use it. If I have a chart with values where the db values are just at the top level, I'd have to break my chart compatability to use this - I think?)

Yes (that't not changed in this PR), but the logic is a bit different. If you want to have a subsection, you need to follow a certain structure. You still can set the db values at the top level but you won't see them grouped in a section, just as plain arguments. I think it makes sense to have this kind of conversion from structured objects to subsections (that's what automatic parsers do for JSON schemas).

Apart from that, we have the hardcoded change in which we are moving mariadb.enabled to externalDatabase to show it in the subsection. I am not very happy with that but better that than changing the values.yaml for the moment.

@andresmgot
Copy link
Contributor Author

Merging this to send another PR. If there is something unresolved please let me know!

@andresmgot andresmgot merged commit 9a3e8b4 into master Oct 10, 2019
@absoludity absoludity deleted the basicFormRefactor branch October 10, 2019 23:14
@absoludity
Copy link
Contributor

Merging this to send another PR. If there is something unresolved please let me know!

Yep, I often +1 with some comments, meaning that you should feel free to land it once you've looked at the comments and made a decision either way. Thanks!

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.

2 participants