Skip to content
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

UserAction StepExecutor improvement #1687

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from

Conversation

ibelar
Copy link
Contributor

@ibelar ibelar commented Nov 4, 2021

Fix #1680
Fix #1681

  • Refactor in order to improve Class extension;
  • Allow settings Data\UserAction argument from a Data\Model
    • arguments can be validate using Model validation.

@ibelar ibelar marked this pull request as draft November 4, 2021 19:10
@ibelar ibelar marked this pull request as ready for review November 4, 2021 20:17
@ibelar ibelar added the RTM label Nov 4, 2021
@ibelar ibelar requested a review from mvorisek November 4, 2021 20:17
*/
protected function getModelForArgs(): Model
{
$this->cloneAction = clone $this->getAction();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to clone, what is the purpose of using cloned&modified action internally?

this can lead also to many bugs when the action is semi-shallowly cloned, like when it has Closures bound still to the original action

Copy link
Contributor Author

@ibelar ibelar Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning was to duplicate Action arguments when set by model only, i.e. each editable model field need to be added as an argument to the UserAction. However, I realized I do not need to clone UserAction but only it's arguments.

A fix is on the way.

@ibelar ibelar marked this pull request as draft November 4, 2021 21:04
@ibelar ibelar removed the RTM label Nov 4, 2021
@ibelar ibelar marked this pull request as ready for review November 4, 2021 22:16
@ibelar ibelar added the RTM label Nov 4, 2021
$argsModel = Factory::factory($args['__atk_model']);
// if seed is supplied, we need to initialize.
if (!$argsModel->_initialized) {
$argsModel->invokeInit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model::init is invoked when persistence is set

when not initialized, I belive we should set new Array_([]) persistence instead

side question, when custom model for args does bring any advantage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • argument can be easily validate using a Validator;
  • argument can be easily define within a model;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when not initialized, I belive we should set new Array_([]) persistence instead

If using seed then developper should supply proper property within the seed array, including Persistence.

'caption' => 'Arg with Model',
'description' => 'Ask for Arguments set via a Data\Model. Allow usage of model validate() for your arguments',
'args' => [
'__atk_model' => new ArgModel(new Array_([])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ArgModel::class] should be probably here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It support both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, more like recommended usage ;-)

@ibelar
Copy link
Contributor Author

ibelar commented Nov 5, 2021

Question:
Will you be ok to add a property to Model\UserAction say $argModel instead of using a special key name '__atk_model' in args array?

Then executor can check for both UserAction property ($arg and $argModel) accordingly.

@mvorisek
Copy link
Member

mvorisek commented Nov 5, 2021

Question: Will you be ok to add a property to Model\UserAction say $argModel instead of using a special key name '__atk_model' in args array?

Then executor can check for both UserAction property ($arg and $argModel) accordingly.

If Model\UserAction::$args can be replaced with a Model, I would prefer that as otherwise args are passed like ...$args which has no typing check neither correct arg names/order/count.

I think lets use/stay with __atk_model for now as the args are not refactorable currently anyway. Maybe add it as a const to Model\UserAction class prefixed with the cl. name as other constants.

@ibelar
Copy link
Contributor Author

ibelar commented Nov 5, 2021

I am currently checking passing the entire $argModel to callback function as well instead of passing $args separately.
This will allow full usage of Model capability for action argument i.e usage of hook within the model.

@mvorisek mvorisek removed the RTM label Nov 12, 2021
@mvorisek mvorisek force-pushed the feature/step-executor-enhancement branch from fcdee8f to 8722647 Compare November 12, 2021 10:32
@mvorisek
Copy link
Member

@ibelar how does this PR fix #1680 and what do actaully mean by

Current implementation does not allow for easily overriding each step method

as described in the issue desc?

@@ -167,8 +190,9 @@ protected function doArgs(View $page): void
$this->jsSetPrevHandler($page, $this->step);

$form->onSubmit(function (Form $form) {
$form->model->save();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is now save needed?

@@ -72,6 +72,9 @@ trait StepExecutorTrait
/** @var string */
public $finalMsg = 'Complete!';

/** @var array An extended copy of UserAction arguments. It contains original action arguments and arguments set by '__atk_model'. */
private $cloneArgs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add native Model args support to atk4/data model. It is also not completely clear to me, why there are args & fields. In atk4/data, the UserAction::$fields property is described to be used for dirty detection only.

@mvorisek mvorisek force-pushed the feature/step-executor-enhancement branch from 8688dc7 to d0ab1c3 Compare April 29, 2023 17:07
* @property string $city @Atk4\Field()
* @property string $gender @Atk4\Field()
*/
class ArgModel extends Model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our testing/demos Model should be used here to test if field aliasing is used properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants