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

[WC-2758] combobox: load initial data on database source #1393

Closed
wants to merge 1 commit into from

Conversation

gjulivan
Copy link
Collaborator

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

Issue: combobox database source, with lazy load, don't have object data on initial load.
this cause combobox to not be able to render caption on initial load.

fix: load single object based on stored value attribute data on initial render.
method: use database filter. set limit to 1.

risk: because this is using literal filter (not object guid retrieval), data could be duplicate,
but because the data used is the stored value attribute, this should already be unique (otherwise, model failed)

this method is not needed on multi select, because database multi select cannot store attribute value.

@gjulivan gjulivan requested a review from a team as a code owner January 14, 2025 14:22
@gjulivan gjulivan changed the title fix: load initial data on database source [WC-2758] combobox: load initial data on database source Jan 14, 2025
@gjulivan gjulivan force-pushed the combobox-wc-2758 branch 2 times, most recently from ffb845b to 7caddff Compare January 15, 2025 10:16
if (this.lazyLoading && this.ds && this.attributeId) {
const filterCondition = datasourceFilter("containsExact", attributeValue, this.attributeId);
this.ds?.setFilter(filterCondition);
this.ds.setLimit(this.attributeId.length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this.attributeId.length return and why do we set it is limit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

basically it returns 1. because only works for single selection. database multi selection don't have attributes set.

set limit to 1 will fetch the datasource, because on lazy load, initial limit is 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@r0b1n you are correct. this is string length,
updated to hardcode: 1

const obj = this.options.getAll().find(option => {
return _valuesIsEqual(targetAttribute.value, this.values.get(option));
});
if (obj) {
this.currentId = obj;
} else {
if (targetAttribute.value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks redundant as we already checked that it is true at line 72.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -69,13 +69,17 @@ export class DatabaseSingleSelectionSelector<
if (this.lastSetValue === null || !_valuesIsEqual(this.lastSetValue, targetAttribute.value)) {
if (ds.status === "available") {
this.lastSetValue = this._attr.value;
if (!_valuesIsEqual(this.values.getEmptyValue(), targetAttribute.value)) {
if (targetAttribute.value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this check gone? I guess this will run the code even if the value is equals to "empty value", which seems incorrect.

Copy link
Collaborator Author

@gjulivan gjulivan Jan 15, 2025

Choose a reason for hiding this comment

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

empty value is default value. initially we did a hack by setting default value to $currentObject/attribute.
this is no longer applicable.
attribute value checks is sufficient.

@gjulivan gjulivan force-pushed the combobox-wc-2758 branch 3 times, most recently from d7a4a4f to 710ef88 Compare January 15, 2025 12:48
@gjulivan
Copy link
Collaborator Author

continue on #1408

@gjulivan gjulivan closed this Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants