-
Notifications
You must be signed in to change notification settings - Fork 4
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
Link value component #27
Conversation
…ty in MatAutoComplete module
show all the possible options in the menu after selection
Thanks for this PR, I will try to review it tomorrow. |
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
please see my proposal #47 |
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
Shall I take another look? |
if you wish so |
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.spec.ts
Outdated
Show resolved
Hide resolved
valueChangesSubscription: Subscription; | ||
labelChangesSubscription: Subscription; | ||
// label cannot contain logical operations of lucene index | ||
customValidators = []; |
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 a custom validator function is needed because all modes but update
cannot check if the value is actually an instance of ReadResource
. I guess you could define something like the following and just include it in the customValidators
:
export function resourceValidator(control: AbstractControl) {
const invalid = !(control.value instanceof ReadResource);
return invalid ? {'invalidType': {value: control.value}} : null;
}
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.
the use case is here is more complex because the value of the FormControl
is a string / label as long as the user types and an instance of ReadResource
once the user selects from the list.
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.
the use case is here is more complex because the value of the
FormControl
is a string / label as long as the user types and an instance ofReadResource
once the user selects from the list.
If I understand what you suggest correctly, you mean there should be a validator to check that a chosen option is an instance of ReadResource
. However, in "update", "create", and "search" modes, the dropdown menu shows the options for the user to choose from. These options are always instances of ReadResource
. The user does not have any other choice than choosing one item from the menu. Hence, an option selected by the user is always an instance of ReadResource
. That would mean that such a double validation would not actually be necessary.
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.
However, in "update", "create", and "search" modes, the dropdown menu shows the options for the user to choose from. These options are always instances of ReadResource. The user does not have any other choice than choosing one item from the menu. Hence, an option selected by the user is always an instance of ReadResource. That would mean that such a double validation would not actually be necessary.
Yes, but as long as the user types, the FormControl
's value is just a string (the label). So this is to make sure that the user selected an option from the list.
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.
the "save" button is inactive unless an option is chosen from the dropdown menu.
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, not yet. But you test it by directly adding the link value component to app.component.html
. I think @mdelez will wok on a create component soon.
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.
or you can just try it out in your spec
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 am trying out in spec for a while now. It would have been nice to have the component.
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.
yes! Now we can make it a user story :-)
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.
@SepidehAlassi I can start to work on the create component tomorrow
@tobiasschweizer I have added the missing validator and tests for creation mode in case user enters a string instead of choosing an item from the dropdown menu. |
@tobiasschweizer I think this PR can really be merged, oder? |
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.ts
Outdated
Show resolved
Hide resolved
I think you are almost done, please see my comments. |
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.spec.ts
Show resolved
Hide resolved
projects/knora-ui/src/lib/viewer/values/link-value/link-value.component.spec.ts
Show resolved
Hide resolved
@tobiasschweizer Can I merge this now? |
// at least 3 characters are required | ||
if ( typeof searchTerm === 'string' && searchTerm.length >= 3) { | ||
|
||
this.knoraApiConnection.v2.search.doSearchByLabel(searchTerm, 0, {limitToResourceClass: this.restrictToResourceClass}).subscribe( | ||
(response: ReadResource[]) => { | ||
this.resources = response; | ||
}); | ||
} else { | ||
// clear selection | ||
this.resources = undefined; |
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 the idea of clearing the selection is good, what I meant is just this.resources = []
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.
looks good, thanks
I have just one last comment: #27 (review)
@Input() displayValue?: ReadLinkValue; | ||
@Input() parentResource: ReadResource; | ||
@Input() propIri: string; | ||
resources: ReadResource[] = []; |
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.
@tobiasschweizer I have already initialized it here to an empty array
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 understood that your idea of clearing selection empties the list when the user types and the string is still too short. I think this idea is good.
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 this is important when user selects a resource and then wants to change it again. Then the selection has to change to.
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.
because I think otherwise you still get the old selection when the label string is shorter than 3 chars
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.
but maybe I am wrong, I will leave this to you. Please proceed as you want.
see my reply above |
to do:
display:
edit:
search for all possible resources with given three letters of the label
list the resource labels of all possible target resources in a drop-down menu
read the user's choice and assign to the target of the link value
test
closes #14