Dispatch Input based in property datatype#123
Conversation
cd84139 to
c143726
Compare
55d5506 to
5a85c5b
Compare
c6d8d31 to
367c79a
Compare
41863fc to
8cdfb10
Compare
d2abab6 to
2331149
Compare
jakobw
left a comment
There was a problem hiding this comment.
Looks good! I tried it out locally and it works nicely! 🏆
I left a suggestion in there for the value input dispatching code. I don't think this necessarily has to happen in this PR but I'm curious to hear thoughts.
| <ItemValueLookup | ||
| v-if="datatype === 'wikibase-item'" | ||
| :value="value" | ||
| @input="$emit('input', $event)" | ||
| :error="error" | ||
| :disabled="disabled" | ||
| /> | ||
| <TextInput | ||
| v-else | ||
| :value="value" | ||
| :label="$i18n('query-builder-input-value-label')" | ||
| @input="$emit('input', $event)" | ||
| :error="error && { message: $i18n(error.message), type: error.type }" | ||
| :placeholder="$i18n('query-builder-input-value-placeholder')" | ||
| :disabled="disabled" | ||
| /> |
There was a problem hiding this comment.
If value input components share the same interface (which they probably should) this whole template (or the whole component?) could turn into something like this:
| <ItemValueLookup | |
| v-if="datatype === 'wikibase-item'" | |
| :value="value" | |
| @input="$emit('input', $event)" | |
| :error="error" | |
| :disabled="disabled" | |
| /> | |
| <TextInput | |
| v-else | |
| :value="value" | |
| :label="$i18n('query-builder-input-value-label')" | |
| @input="$emit('input', $event)" | |
| :error="error && { message: $i18n(error.message), type: error.type }" | |
| :placeholder="$i18n('query-builder-input-value-placeholder')" | |
| :disabled="disabled" | |
| /> | |
| <component | |
| :is="{ | |
| string: 'TextInput', | |
| 'external-id': 'TextInput', | |
| 'wikibase-item': 'ItemValueLookup' | |
| }[datatype]" | |
| :value="value" | |
| :label="$i18n('query-builder-input-value-label')" | |
| @input="$emit('input', $event)" | |
| :error="error && { message: $i18n(error.message), type: error.type }" | |
| :placeholder="$i18n('query-builder-input-value-placeholder')" | |
| :disabled="disabled" | |
| /> |
... but ideally without doing the dispatching in the template.
If that works out, all this component does is forwarding props. At that point it seems cleaner to put the dispatching code into a regular function, and move the differences we see in the templates (error handling, messages, ...) down into the value input components. Then this can become a functional component or be removed entirely if nothing is left.
There was a problem hiding this comment.
I really like the looks of this, thanks! I had looked at <component is="" previously and it didn't seem exactly right, but your approach is very convincing.
Then the first step for this would be to wrap the TextInput into its own component to align the interfaces, right?. That was on my Todo-list anyway, I will look into it.
There was a problem hiding this comment.
Then the first step for this would be to wrap the TextInput into its own component to align the interfaces, right?
Yes, that sounds good!
8cdfb10 to
5bb9de5
Compare
2331149 to
04195e2
Compare
04195e2 to
f1a3c0c
Compare
jakobw
left a comment
There was a problem hiding this comment.
I think this looks super good! ValueInput.vue could use a test though, and it should be very nicely testable now.
f1a3c0c to
1090647
Compare
eedb41d to
ecab75f
Compare
1090647 to
e58f9a4
Compare
Bug: T270257
e58f9a4 to
cd5b138
Compare
(To be merged into master after #142)
Todo:
Bug: T270257