-
Notifications
You must be signed in to change notification settings - Fork 66
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
Feature/81 depend on several fields #82
Conversation
beforeDestroy() { | ||
Nova.$off("nova-belongsto-depend-" + this.field.dependsOn); | ||
if (this.field.dependsOn) { |
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.
This should support both string and array inputs for dependsOn.
if (this.fields.dependsOn instanceof Array) {
// incoming changes
} else {
Nova.$off(`nova-belongsto-depend-${this.field.dependsOn}`);
}
created() { | ||
if (this.field.dependsOn) { | ||
Nova.$on("nova-belongsto-depend-" + this.field.dependsOn, async (dependsOnValue) => { | ||
|
||
let $busEvents = []; |
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.
Same here
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.
Added some recommendations to support backwards-compatibility
} | ||
}); | ||
} | ||
}, | ||
|
||
methods: { | ||
updateDependsMap(dependsOnValue) { | ||
let exists = false; |
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.
Can be refactored to
updateDependsMap({ value, field: { modelClass, modelPrimaryKey } }) {
const entry = this.field.dependsMap.find(e => e.key === modelClass);
if (entry) {
entry.value = value[modelPrimaryKey];
} else {
this.field.dependsMap.push({
key: modelClass,
value: value[modelPrimaryKey]
});
}
},
{ | ||
$this->dependsOn = Str::lower($relationship); | ||
foreach ($classNames as &$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.
Continuing the effort to make this a non breaking change, if $classNames
has one entry, assign it to dependsOn
, otherwise create and assign $classNames
@cwilby thank you very much for your feedback and suggestions. I will apply them until the end of this week. |
@cwilby I have checked you suggestions in detailed. I have applyed them and taked a look at the end result. Sorry, but I am agains that change. The "string" path is unnecessary as we can handle this case very good with the "array" as well. As you already highlighted in src/NovaBelongsToDepend.php There is one rare case, that I see where this can be not the case. |
@Sergej-Tihonov thanks for jumping in again 👍 I see your point, I don't think $this->dependsOn = is_array($this->dependsOn) ? $this->dependsOn : [$this->dependsOn]; Also curious - why was this block removed? - if ($this->dependsOn) {
- $this->dependKey = $resource->{$this->dependsOn}()->getForeignKeyName();
- } Thanks for pushing this forward! |
is backwards compatible with the old syntax