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

[Improvement] Add exportable flag to column definition #308

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/03_Grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ in addition, it has a configuration which can be used to configure the column, l

## ColumnConfiguration
A column configuration represents how the column should behave, for example if it should be sort-able or editable.
For the column to be exportable please make sure that it can be represented as a string.

## ColumnData
A column data is the actual data for a column. It has a reference to the column and the actual data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public function __invoke(CsvCreationMessage $message): void
}
$settings = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_SETTINGS->value);
$columnCollection = $this->gridService->getConfigurationFromArray(
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value)
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value),
true
);

if (!isset($jobRun->getContext()[Csv::ASSET_EXPORT_DATA->value])) {
$this->abort($this->getAbortData(
Config::CSV_CREATION_FAILED_MESSAGE->value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public function __invoke(CsvCollectionMessage $message): void

return;
}

$columnCollection = $this->gridService->getConfigurationFromArray(
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value)
$this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value),
true
);

try {
Expand Down
2 changes: 2 additions & 0 deletions src/Grid/Column/ColumnDefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public function getConfig(mixed $config): array;
public function isSortable(): bool;

public function getFrontendType(): string;

public function isExportable(): bool;
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/AssetDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::ELEMENT_DROPZONE->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/CheckboxDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::CHECKBOX->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/DataObjectDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::ELEMENT_DROPZONE->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/DateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::DATETIME->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/DocumentDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::ELEMENT_DROPZONE->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/InputDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::INPUT->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/SelectDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function getFrontendType(): string
{
return FrontendType::SELECT->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/MetaData/TextareaDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::TEXTAREA->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/System/DatetimeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::DATETIME->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/System/FileSizeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public function getFrontendType(): string
{
return FrontendType::INPUT->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/System/ImageDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public function getFrontendType(): string
{
return FrontendType::IMAGE->value;
}

public function isExportable(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/System/IntegerDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::INPUT->value;
}

public function isExportable(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/Grid/Column/Definition/System/StringDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function getFrontendType(): string
{
return FrontendType::INPUT->value;
}

public function isExportable(): bool
{
return true;
}
}
25 changes: 17 additions & 8 deletions src/Grid/Service/GridService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@ public function getAssetGridConfiguration(): array
continue;
}

$columns = array_merge(
$columns,
$collector->getColumnConfigurations(
$this->getColumnDefinitions()
)
);
// rather use the spread operator instead of array_merge in a loop
$columns = [...$columns, ...$collector->getColumnConfigurations($this->getColumnDefinitions())];
}

foreach ($columns as $column) {
Expand All @@ -186,10 +182,14 @@ public function getDataObjectGridColumns(ClassDefinition $classDefinition): Colu
/**
* @throws InvalidArgumentException
*/
public function getConfigurationFromArray(array $config): ColumnCollection
public function getConfigurationFromArray(array $config, bool $isExport = false): ColumnCollection
{
$columns = [];
foreach ($config as $column) {
if ($isExport && !$this->isExportable($column['type'])) {
throw new InvalidArgumentException('Column type is not exportable');
}

try {
$columns[] = new Column(
key: $column['key'],
Expand All @@ -198,7 +198,7 @@ public function getConfigurationFromArray(array $config): ColumnCollection
group: $column['group'] ?? null,
config: $column['config']
);
} catch (Exception $e) {
} catch (Exception) {
throw new InvalidArgumentException('Invalid column configuration');
}
}
Expand Down Expand Up @@ -268,4 +268,13 @@ private function getColumnResolvers(): array

return $this->columnResolvers;
}

private function isExportable(string $type): bool
{
if (!array_key_exists($type, $this->getColumnDefinitions())) {
return false;
mattamon marked this conversation as resolved.
Show resolved Hide resolved
}

return $this->getColumnDefinitions()[$type]->isExportable();
}
}
2 changes: 1 addition & 1 deletion src/Grid/Service/GridServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getGridValuesForElement(
string $elementType
): array;

public function getConfigurationFromArray(array $config): ColumnCollection;
public function getConfigurationFromArray(array $config, bool $isExport = false): ColumnCollection;

public function getAssetGrid(GridParameter $gridParameter): Collection;

Expand Down
Loading