-
Notifications
You must be signed in to change notification settings - Fork 416
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
base: devel
Are you sure you want to change the base?
CB-4067 Migrate Connection form to form template #3288
Conversation
webapp/packages/plugin-connection-search/src/Search/ConnectionSearchService.ts
Outdated
Show resolved
Hide resolved
webapp/packages/plugin-connection-search/src/Search/ConnectionSearchService.ts
Outdated
Show resolved
Hide resolved
webapp/packages/plugin-connection-search/src/Search/ConnectionSearchService.ts
Outdated
Show resolved
Hide resolved
.../plugin-connections-administration/src/Administration/Connections/CreateConnectionService.ts
Outdated
Show resolved
Hide resolved
.../plugin-connections-administration/src/Administration/Connections/CreateConnectionService.ts
Outdated
Show resolved
Hide resolved
|
||
const { selected } = useTab(tabId); | ||
const accessPart = getConnectionFormAccessPart(formState); | ||
const [initialFormMode] = useState<FormMode>(formState.mode); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
webapp/packages/plugin-connections/src/ConnectionForm/ConnectionForm.tsx
Outdated
Show resolved
Hide resolved
webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts
Outdated
Show resolved
Hide resolved
const isProjectOutdated = this.projectInfoResource.isOutdated(this.formState.state.projectId); | ||
|
||
if (!this.connectionKey) { | ||
return isProjectOutdated; | ||
} | ||
|
||
return this.connectionInfoResource.isOutdated(this.connectionKey) || isProjectOutdated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
this.setInitialState({ | ||
...defaults, | ||
...this.state, | ||
}); |
There was a problem hiding this comment.
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
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; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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:
- compare
model.id
withthis.initialState.authModelId
- when different reset
state.credentials
to{}
(empty object) - when equal, spread the initial state to the current state:
this.state.credentials = { ...this.initialState.credentials }
There was a problem hiding this comment.
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
config.host = this.state.host || driver?.defaultServer || 'localhost'; | ||
config.port = this.state.port || driver?.defaultPort; |
There was a problem hiding this comment.
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
if (this.formState.mode === 'edit') { | ||
this.state.connectionId = this.state.connectionId; | ||
} | ||
|
There was a problem hiding this comment.
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
webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts
Outdated
Show resolved
Hide resolved
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!)); | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
No description provided.