-
Notifications
You must be signed in to change notification settings - Fork 31
refactor: turn columnSettings data from loose array to value object #1845
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
base: main
Are you sure you want to change the base?
Conversation
@AIlkiv if you don't mind, I'll fancy your opinion as well. |
2031718
to
870def3
Compare
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 like it!
@blizzz For example instead of:
Do this:
|
Hi @AIlkiv, thank you for the suggestion. I think then I would still leave the |
Signed-off-by: Arthur Schiwon <[email protected]>
870def3
to
7ad43a4
Compare
OK, went through, but I did not see that many benefits really. Would keep it as option for the future though (or maybe it is late). |
'order' => $index | ||
]; | ||
'columnSettings' => json_encode(array_map(function (int $columnId, int $index): ViewColumnInformation { | ||
return new ViewColumnInformation($columnId, $index); |
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.
for better readability
order: $index
'order' => $index | ||
]; | ||
'columnSettings' => json_encode(array_map(function (Column $column, int $index): ViewColumnInformation { | ||
return new ViewColumnInformation($column->getId(), $index); |
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.
for better readability
order: $index
'order' => $index | ||
]; | ||
'columnSettings' => json_encode(array_map(function (Column $column, int $index): ViewColumnInformation { | ||
return new ViewColumnInformation($column->getId(), $index); | ||
}, array_values($columns), array_keys(array_values($columns)))), |
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.
json_encode(array_map(function (Column $column, int $index): ViewColumnInformation {
return new ViewColumnInformation($column->getId(), $index);
}, array_values($columns), array_keys(array_values($columns))))
It is possible to move these three lines to a new private method
usort($columnSettings, function ($a, $b) { | ||
return $a['order'] - $b['order']; | ||
usort($columnSettings, static function (ViewColumnInformation $a, ViewColumnInformation $b) { | ||
return $a[ViewColumnInformation::KEY_ORDER] - $b[ViewColumnInformation::KEY_ORDER]; |
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.
To make the code cleaner (type hints, etc.), it might be better to use a getter/setter. Remove the constants
$a[ViewColumnInformation::KEY_ORDER] - $b[ViewColumnInformation::KEY_ORDER]
VS
$a->getOrder() - $b->getOrder()
The aim is to make it easier to add properties like read-only or mandatory to user columns. Having the structure in a separate class makes it easier to organize it (no loose array structure flying around), to extend it and also to enforce the structure.
I thought creating a PR for the read-only feature first, but I think it is already a good size for a PR on its own.