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

CB-4067 Migrate Connection form to form template #3288

Open
wants to merge 92 commits into
base: devel
Choose a base branch
from

Conversation

sergeyteleshev
Copy link
Contributor

No description provided.


const { selected } = useTab(tabId);
const accessPart = getConnectionFormAccessPart(formState);
const [initialFormMode] = useState<FormMode>(formState.mode);
Copy link
Member

Choose a reason for hiding this comment

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

I think that you can use formState.mode directly, it will reflect actual state of form

Copy link
Contributor Author

@sergeyteleshev sergeyteleshev Mar 26, 2025

Choose a reason for hiding this comment

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

no. cause after saving OptionsPart we set mode to edit and this will show lead to incorrect behavior

Comment on lines 121 to 127
const isProjectOutdated = this.projectInfoResource.isOutdated(this.formState.state.projectId);

if (!this.connectionKey) {
return isProjectOutdated;
}

return this.connectionInfoResource.isOutdated(this.connectionKey) || isProjectOutdated;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isProjectOutdated = this.projectInfoResource.isOutdated(this.formState.state.projectId);
if (!this.connectionKey) {
return isProjectOutdated;
}
return this.connectionInfoResource.isOutdated(this.connectionKey) || isProjectOutdated;
if (this.projectInfoResource.isOutdated(this.formState.state.projectId)) {
return true;
}
return this.connectionKey && this.connectionInfoResource.isOutdated(this.connectionKey);

Comment on lines 134 to 137
this.setInitialState({
...defaults,
...this.state,
});
Copy link
Member

Choose a reason for hiding this comment

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

setInitialState should set the initial state of the form. In case we create new entity we should always return the initial state object, we should not mix it with state this will lead to the form being detected as not changed because after calling the loader initial state and state will be equal

Comment on lines 216 to 224
if (model.id === info?.authModel) {
if (info.authProperties) {
for (const property of info.authProperties) {
if (!property.features.includes('password')) {
this.state.credentials[property.id!] = property.value;
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

i think that we need to:

  1. compare model.id with this.initialState.authModelId
  2. when different reset state.credentials to {} (empty object)
  3. when equal, spread the initial state to the current state: this.state.credentials = { ...this.initialState.credentials }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems fine after few tests, thanks

Comment on lines 240 to 241
config.host = this.state.host || driver?.defaultServer || 'localhost';
config.port = this.state.port || driver?.defaultPort;
Copy link
Member

Choose a reason for hiding this comment

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

using state is unsafe here because it may affect initial state

Comment on lines 264 to 267
if (this.formState.mode === 'edit') {
this.state.connectionId = this.state.connectionId;
}

Copy link
Member

Choose a reason for hiding this comment

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

probably you can remove it

Comment on lines 309 to 322
const info =
this.state.connectionId && this.formState.state.projectId
? this.connectionInfoResource.get(createConnectionParam(this.formState.state.projectId, this.state.connectionId))
: undefined;

const properties = await this.getConnectionAuthModelProperties(this.state.authModelId, info);
const passwordProperty = properties.find(property => property.features.includes('password'));
const isPasswordEmpty =
passwordProperty &&
(this.state.credentials?.[passwordProperty.id!] === passwordProperty.defaultValue || !this.state.credentials?.[passwordProperty.id!]);

if (isCredentialsChanged(properties, this.state.credentials!)) {
this.state.credentials = prepareDynamicProperties(properties, toJS(this.state.credentials!));
}
Copy link
Member

Choose a reason for hiding this comment

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

probably you can use this.initialState.credentials instead (to compare for changes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lets not. it has the logic with file

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.

3 participants