-
Notifications
You must be signed in to change notification settings - Fork 163
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
add array support for DependsOn #91
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,20 @@ | |
return; | ||
} | ||
|
||
if (Array.isArray(dependency.value)) { | ||
if (typeof this.dependencyValues[dependency.field] === 'object' && dependencyValue !== null) { | ||
if (dependency.hasOwnProperty('value') && dependency.value.includes(dependencyValue.id)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on how similar L129 conditional and L134 conditional are, can we find a way to combine those so that we aren't duplicating the conditional in 2 places? The only difference seems to be what we are seeing is included, dependencyValue.id vs just dependencyValue. All that duplication just means more code to manage and debug when something goes wrong |
||
this.dependenciesSatisfied = true; | ||
return; | ||
} | ||
} else { | ||
if (dependency.hasOwnProperty('value') && dependency.value.includes(dependencyValue)) { | ||
this.dependenciesSatisfied = true; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
if(dependency.hasOwnProperty('value') && dependencyValue == dependency.value) { | ||
this.dependenciesSatisfied = true; | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,23 @@ public function resolveForDisplay($resource, $attribute = null) | |
continue; | ||
} | ||
|
||
if (is_object($resource->{$dependency['property']}) && is_array($dependency['value'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you give an example in which scenario There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for when a dependency is on a BelongsTo. I have dependency container that is activated by the selection of a BelongsTo field. In that scenario, an object is passed here. You need to compare the id of that object to the passed in array of ids to match. |
||
if (array_key_exists('value', $dependency) && in_array($resource->{$dependency['property']}->id, $dependency['value'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here, you are already assuming |
||
$this->meta['dependencies'][$index]['satisfied'] = true; | ||
continue; | ||
} | ||
} | ||
|
||
if (is_iterable($resource->{$dependency['property']})) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you give an example in which scenario There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should match the opposite condition for when you want to match a value to an array of values. i.e. multiselect. can handle multi to multi case if needed also. |
||
$filtered = $resource->{$dependency['property']}->filter(function ($value, $key) use (&$dependency) { | ||
return $value->id == $dependency['value']; | ||
}); | ||
if (array_key_exists('value', $dependency) && $filtered->isNotEmpty()) { | ||
$this->meta['dependencies'][$index]['satisfied'] = true; | ||
continue; | ||
} | ||
} | ||
|
||
if (array_key_exists('value', $dependency)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same sort of comment as above, let's just expand the current dependsOn logic to be able to support arrays instead of duplicating it almost completely. |
||
if($dependency['value'] == $resource->{$dependency['property']}) { | ||
$this->meta['dependencies'][$index]['satisfied'] = true; | ||
|
@@ -165,7 +182,6 @@ public function resolveForDisplay($resource, $attribute = null) | |
continue; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
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 instead of adding a whole other case to worry about, we should just have the normal dependsOn case singular value just be upgraded to support arrays as values. I think there's also some misses here, specifically on L127, you are using
dependency.value
but you don't check if it exists until L129 which would make me ask 1. Why check after you are assuming it's there? 2. If we can assume it's there, then why are we checking it at all?