Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blizzz
Copy link
Member

@blizzz blizzz commented Jun 19, 2025

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.

@blizzz blizzz requested review from enjeck and a team June 19, 2025 17:11
@blizzz blizzz added enhancement New feature or request 2. developing Work in progress labels Jun 19, 2025
@blizzz
Copy link
Member Author

blizzz commented Jun 19, 2025

@AIlkiv if you don't mind, I'll fancy your opinion as well.

@blizzz blizzz force-pushed the feat/1154/view-column-info-value-obj branch 2 times, most recently from 2031718 to 870def3 Compare June 19, 2025 17:43
@blizzz blizzz added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 19, 2025
@blizzz blizzz moved this to 👀 In review in 📝 Office team Jun 19, 2025
@blizzz blizzz self-assigned this Jun 19, 2025
Copy link
Contributor

@enjeck enjeck left a comment

Choose a reason for hiding this comment

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

I like it!

@AIlkiv
Copy link
Contributor

AIlkiv commented Jun 27, 2025

@blizzz
What do you think about this idea, instead of ViewColumnInformation, create ViewColumnsInformation (or just ViewColumns). Encapsulate all related logic (sorting, decoding, etc.) in this class.

For example instead of:

$decodedValue = \json_decode($value, true);
$value = [];
foreach ($decodedValue as $order => $id) {
	$value[] = [
		'columnId' => $id,
		'order' => $order
	];

Do this:

$value = ViewColumnsInformation::decode($value): ViewColumnsInformation

@blizzz
Copy link
Member Author

blizzz commented Jul 11, 2025

Hi @AIlkiv, thank you for the suggestion. I think then I would still leave the ViewColumnInformation as is, really as value for each column. It makes sense to have a collection – leaning on your suggestion – on top that provides this utility methods and can hold the values. I am not sure about the balance between real benefit and another layer though.

@blizzz blizzz force-pushed the feat/1154/view-column-info-value-obj branch from 870def3 to 7ad43a4 Compare July 11, 2025 23:12
@blizzz
Copy link
Member Author

blizzz commented Jul 11, 2025

Hi @AIlkiv, thank you for the suggestion. I think then I would still leave the ViewColumnInformation as is, really as value for each column. It makes sense to have a collection – leaning on your suggestion – on top that provides this utility methods and can hold the values. I am not sure about the balance between real benefit and another layer though.

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);
Copy link
Contributor

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);
Copy link
Contributor

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)))),
Copy link
Contributor

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];
Copy link
Contributor

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

3 participants