Skip to content

Commit

Permalink
Merge pull request #15 from pxlrbt/fix/fix-tables
Browse files Browse the repository at this point in the history
Fix export and queued exports for table package
  • Loading branch information
pxlrbt authored Jun 20, 2022
2 parents 972d24b + 7d66f8f commit 6192907
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Exports/Concerns/CanQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ protected function prepareQueuedExport()

$this->filename = $this->getFilename();
$this->writerType = $this->getWriterType();
$this->columnFormats = $this->getColumnFormats();
$this->columnWidths = $this->getColumnWidths();
$this->livewireClass = $this->getLivewireClass();

// Reset
Expand Down
9 changes: 8 additions & 1 deletion src/Exports/Concerns/WithColumnFormats.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

trait WithColumnFormats
{
protected ?array $columnFormats = null;

public function columnFormats(): array
{
return $this->getMapping($this->getModelInstance())
return $this->getColumnFormats();
}

public function getColumnFormats(): array
{
return $this->columnFormat ??= $this->getMapping($this->getModelInstance())
->values()
->mapWithKeys(fn (Column $column, $key) => [
Coordinate::stringFromColumnIndex($key + 1) => $this->evaluate($column->getFormat()),
Expand Down
4 changes: 3 additions & 1 deletion src/Exports/Concerns/WithColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function fromForm(): static
public function fromModel(): static
{
$this->generatedColumns = function () {
$mapping = $this->createFieldMappingFromForm();
$mapping = $this->getResourceClass() !== null
? $this->createFieldMappingFromForm()
: collect();

return collect($this->getModelClass()::first()->getAttributes())
->map(
Expand Down
7 changes: 7 additions & 0 deletions src/Exports/Concerns/WithWidths.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

trait WithWidths
{
protected ?array $columnWidths = null;

public function columnWidths(): array
{
return $this->getColumnWidths();
}

public function getColumnWidths(): array
{
return $this->getMapping($this->getModelInstance())
->values()
Expand Down
2 changes: 1 addition & 1 deletion src/Exports/ExcelExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getModelClass(): ?string
public function hydrate($livewire = null, $records = null, $formData = null): static
{
$this->livewire = $livewire;
$this->modelKeyName = $this->getModelInstance()->getQualifiedKeyName();
$this->modelKeyName = $this->getModelInstance()->getKeyName();
$this->recordIds = $records?->pluck($this->modelKeyName)->toArray() ?? [];

$this->formData = $formData;
Expand Down

0 comments on commit 6192907

Please sign in to comment.