Cb 4364 remove spaces at the beginning of the input fields#2252
Cb 4364 remove spaces at the beginning of the input fields#2252
Conversation
| return; | ||
| } | ||
|
|
||
| data.state.serverConfig.serverName = data.state.serverConfig.serverName?.trim(); |
There was a problem hiding this comment.
Please do not modify state directly, use contexts config
const config = contexts.getContext(configContext);
config.serverConfig.serverName = data.state.serverConfig.serverName?.trim()
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
please do not modify state object, create a temp object instead
| } | ||
|
|
||
| private async updateCredentials() { | ||
| this.state.password = this.state.password.trim(); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Why do we need to delete the property first and trim the key here?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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) { |
| } | ||
| } | ||
|
|
||
| private trimSSHInputConfig(input: NetworkHandlerConfigInput) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
and better is do it in prepareConfig stage
| state.credentials.credentials.user = state.credentials.credentials.user?.trim(); | ||
| state.credentials.credentials.password = state.credentials.credentials.password?.trim(); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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)[]; |
There was a problem hiding this comment.
double type declaration remove one
There was a problem hiding this comment.
and this also looks like global const for not global const please use camelCase
…he-input-fields
| } | ||
|
|
||
| private async updateMetaParameters() { | ||
| const tempMetaParameters = toJS(this.state.metaParameters); |
| provider = (provider || state.activeProvider) ?? undefined; | ||
| configuration = (configuration || state.activeConfiguration) ?? undefined; | ||
|
|
||
| const tempCredentials = toJS(state.credentials); |
There was a problem hiding this comment.
credentials have Record<string, any> type, so wee need more general aproach
…he-input-fields
|
|
||
| private async updateCredentials() { | ||
| if (this.state.password) { | ||
| const password = this.state.password.trim(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
…he-input-fields
…he-input-fields
…he-input-fields
No description provided.