Skip to content

Commit a4d004f

Browse files
authored
Card with entity UA must not reload data again (#2005)
1 parent df50119 commit a4d004f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

demos/data-action/factory-view.php

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ protected function getCardButton(Model\UserAction $action)
5656
DemoActionsUtil::setupDemoActions($country);
5757
$country = $country->loadBy($country->fieldName()->iso, 'fr');
5858
$country->name .= ' NO RELOAD';
59+
// suppress dirty field exception
60+
// https://github.com/atk4/data/blob/35dd7b7d95909cfe574b15e32b7cc57c39a16a58/src/Model/UserAction.php#L164
61+
unset($country->getDirtyRef()[$country->fieldName()->name]);
5962

6063
$cardActions = Card::addTo($app, ['useLabel' => true, 'executorFactory' => new $myFactory()]);
6164
$cardActions->setModel($country);

src/Card.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,16 @@ public function addClickAction(Model\UserAction $action, Button $button = null,
216216
{
217217
$btn = $this->addButton($button ?? $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::CARD_BUTTON));
218218

219+
$cardDeck = $this->getClosestOwner(CardDeck::class);
220+
219221
$defaults = [];
220222

221223
// Setting arg for model id. $args[0] is consider to hold a model id, i.e. as a js expression.
222224
if ($this->model && $this->model->isLoaded() && !isset($args[0])) {
223225
$defaults[] = $this->model->getId();
226+
if ($cardDeck === null && !$action->isOwnerEntity()) {
227+
$action = $action->getActionForEntity($this->model);
228+
}
224229
}
225230

226231
if ($args !== []) {
@@ -231,7 +236,6 @@ public function addClickAction(Model\UserAction $action, Button $button = null,
231236
$defaults['confirm'] = $confirm;
232237
}
233238

234-
$cardDeck = $this->getClosestOwner(CardDeck::class);
235239
if ($cardDeck !== null) {
236240
// mimic https://github.com/atk4/ui/blob/3c592b8f10fe67c61f179c5c8723b07f8ab754b9/src/Crud.php#L140
237241
// based on https://github.com/atk4/ui/blob/3c592b8f10fe67c61f179c5c8723b07f8ab754b9/src/UserAction/SharedExecutorsContainer.php#L24

tests-behat/card.feature

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Feature: Card
44
Given I am on "data-action/factory-view.php"
55
Then I click using selector "i.eye.icon"
66
Then Modal is open with text "Display Preview prior to run the action"
7-
# TODO fix
8-
# Then Modal is open with text "Previewing country France NO RELOAD"
7+
Then Modal is open with text "Previewing country France NO RELOAD"
98
Then I press Modal button "Preview"
109
Then Toast display should contain text "Success: Done previewing France"
1110

0 commit comments

Comments
 (0)