Skip to content

Cb 4364 remove spaces at the beginning of the input fields#2252

Merged
devnaumov merged 35 commits intodevelfrom
CB-4364-remove-spaces-at-the-beginning-of-the-input-fields
Jan 3, 2024
Merged

Cb 4364 remove spaces at the beginning of the input fields#2252
devnaumov merged 35 commits intodevelfrom
CB-4364-remove-spaces-at-the-beginning-of-the-input-fields

Conversation

@sergeyteleshev
Copy link
Copy Markdown
Contributor

No description provided.

@sergeyteleshev sergeyteleshev self-assigned this Dec 21, 2023
return;
}

data.state.serverConfig.serverName = data.state.serverConfig.serverName?.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not modify state directly, use contexts config

const config = contexts.getContext(configContext);
config.serverConfig.serverName = data.state.serverConfig.serverName?.trim()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and better is do it in prepareConfig stage

config.parameters = state.config.parameters;

for (const key of Object.keys(config.parameters)) {
if (typeof config.parameters[key] === 'string') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const value = config.parameters[key];
config.parameters[key] = value.trim();


protected override async saveChanges(): Promise<void> {
private async createUser() {
this.state.userId = this.state.userId.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please trim it in place, we don't want to modify initial object
userId: this.state.userId.trim()

}

protected override async saveChanges(): Promise<void> {
await this.createUser();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you want to create a separate function, you can remove

this.initialState.userId = user.userId;
 this.formState.setMode(FormMode.Edit);

and move this.formState.mode === FormMode.Create check to saveChanges method, so you will always create user when you run createUser method

if(this.formState.mode === FormMode.Create) {
   const user = await this.createUser();
   this.initialState.userId = user.userId;
   this.formState.setMode(FormMode.Edit);
}

if (this.state.userId) {
const user = this.usersResource.get(this.state.userId);

for (const key in this.state.metaParameters) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please do not modify state object, create a temp object instead

}

private async updateCredentials() {
this.state.password = this.state.password.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please do not modify state object
const password = this.state.password.trim();


for (const key of Object.keys(config.properties)) {
const value = config.properties[key];
delete config.properties[key];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to delete the property first and trim the key here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we need to check if property is custom or not and do not trim properties that we get from the server (keep as is)


const properties = await this.getConnectionAuthModelProperties(tempConfig.authModelId, state.info);

properties.forEach(property => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like we should not trim properties here, as its from backend
we should trim credentials that we get from ui form

config.networkHandlersConfig.push(handlerConfig);
}

if (config.networkHandlersConfig?.length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

empty if block?

}
}

private trimSSHInputConfig(input: NetworkHandlerConfigInput) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably we should rename it to the getPreparedSSHConfig and return object from it, because its kind of hard to keep track of object mutations this way
const preparedSSHConfig = this.getPreparedSSHConfig(handlerConfig);

return;
}

data.state.serverConfig.serverName = data.state.serverConfig.serverName?.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and better is do it in prepareConfig stage

Comment on lines +176 to +177
state.credentials.credentials.user = state.credentials.credentials.user?.trim();
state.credentials.credentials.password = state.credentials.credentials.password?.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, please don't make modifications in functions like submit or save

form data -> prepare data -> submit data to the server -> load form data from the server

why?: let's imagine that we modified data before submitting to the server and now it's invalid or creates an exception on server side (user can't modify form to fix this error)


for (const key of Object.keys(config.properties)) {
const value = config.properties[key];
delete config.properties[key];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we need to check if property is custom or not and do not trim properties that we get from the server (keep as is)

}

private trimSSHInputConfig(input: NetworkHandlerConfigInput) {
const ATTRIBUTES_TO_TRIM: (keyof NetworkHandlerConfigInput)[] = Object.keys(input) as (keyof NetworkHandlerConfigInput)[];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

double type declaration remove one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and this also looks like global const for not global const please use camelCase

}

private async updateMetaParameters() {
const tempMetaParameters = toJS(this.state.metaParameters);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const metaParameters

provider = (provider || state.activeProvider) ?? undefined;
configuration = (configuration || state.activeConfiguration) ?? undefined;

const tempCredentials = toJS(state.credentials);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

credentials have Record<string, any> type, so wee need more general aproach


private async updateCredentials() {
if (this.state.password) {
const password = this.state.password.trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i've added format function to FormPart please format all needed data in this function (you will need to mutate form state, lets do it for that case and if needed we will change this behaviour later)

(you need to merge devel to get this changes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the main idea that we don't want to format data in different places because sometimes we need formatted data before we will submit it, for example to check if same name is taken. We need to format data first and then work with formatted data in all parts of our application (for validation, submitting and others)

@sergeyteleshev sergeyteleshev requested a review from Wroud January 3, 2024 11:14
@devnaumov devnaumov merged commit 9aace7c into devel Jan 3, 2024
@serge-rider serge-rider deleted the CB-4364-remove-spaces-at-the-beginning-of-the-input-fields branch February 21, 2024 11:08
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.

4 participants