Code Monkey home page Code Monkey logo

filament-drafts's Issues

Some issues

  1. In the create view, clicking Save draft publish the current element model
  2. Unpublish button does not appear
  3. After creating a draft, clicking Publish makes all elements a draft and its impossible to publish again in the same element

Add support for Filament V3

Lets add support for filament v3.

I will send the PR, just need to know if there is anyone already working on v3 support? @LukasFreyCZ

List Draft/Revisions in a separate Filament Tab

Problem

For some reason the table actions for draft/revisions table would not work. I have tried to add them separately and also tried to allow user to pass those actions but nothing works.

Solution

The work around for me was to use Tabs on ListRecord pages to filter records. This allowed the usage of existing actions. Other benefit of using tabs is:

  • Less space on page
  • Better UI
  • Less code to maintain, we can remove the list-draftable-records view file and the livewire components it loads
  • We dont need to define/pass which fields, actions and filters to load. Those will be loaded from resource itself.

The code we need:

use Illuminate\Database\Eloquent\Builder;
use Filament\Resources\Pages\ListRecords\Tab;

public function getTabs(): array
{
    return [
        'all' => Tab::make()
            ->modifyQueryUsing(fn (Builder $query) => $query->withoutDrafts()),
        'drafts' => Tab::make()
            ->modifyQueryUsing(fn (Builder $query) => $query->onlyDrafts()->where('is_current', true)),
    ];
}

@LukasFreyCZ I am planning to send this Pull request. I need to hear your thoughts.

Thanks :)

Incompatible with filament-nested-resources

Hi,
i found a couple of issues if used in tandem with filament-nested-resources.

  1. the handleRecordCreation needs to be using the getRelation Method
protected function handleRecordCreation(array $data): Model
    {
        $record = new ($this->getRelation()->getRelated())([
            ...$data,
            'is_published' => !$this->shouldSaveAsDraft,
        ]);

        if ($owner = $this->getOwnerRecord()) {
            $record = $this->associateRecordWithParent($record, $owner);
        }

        if (
            ($tenant = Filament::getTenant())
        ) {
            return $this->associateRecordWithTenant($record, $tenant);
        }
        $record->withoutRevision()->save();

        return $record;
    }
  1. SaveDraftAction needs to allow for CreateRelatedRecord as well as CreateRecord, i think even if you don't want to change the behaviour here it should throw an exception if its neither an instance of EditRecord nor CreateRecord.
protected function draft(): void
    {
        $livewire = $this->getLivewire();
        $livewire->shouldSaveAsDraft = true;

        if ($livewire instanceof EditRecord) {
            $livewire->save();
            return;
        }
        
        $livewire->create(); // don't know the side effects of just using create if it's not an instance of EditRecord but will see
    }

I'll update this issue as i find more.

Trait Method Collision Error

Description:
After adding the traits to all the resource pages I am getting the following error.

Note: It's happening because of Filament Translatable plugin.

Trait method Guava\FilamentDrafts\Admin\Resources\Pages\Create\Draftable::handleRecordCreation has not been applied as App\Filament\Resources\DeveloperResource\Pages\CreateDeveloper::handleRecordCreation, because of collision with Filament\Resources\Pages\CreateRecord\Concerns\Translatable::handleRecordCreation

Environment:

  • PHP version: 8.2
  • Laravel version: 11.14
  • Filament version: 3.2

Possible Solution:
To resolve the collision, consider renaming one of the conflicting methods..

Screenshot 2024-07-10 at 09 57 51

HasDrafts functionality raised error from seeder

I added into laravel/framework 9 / filament/filamen 2 app guava/filament-drafts 1.2
but after I added
HasDrafts
to one of my models, I got error in app init seeder :

2023_03_21_145712_create_page_contents_table .................... 952ms FAIL

   TypeError 

  Oddvalue\LaravelDrafts\LaravelDrafts::getCurrentUser(): Return value must be of type Illuminate\Contracts\Auth\Authenticatable, null returned

  at vendor/oddvalue/laravel-drafts/src/LaravelDrafts.php:15
     11▕     protected bool $withDrafts = false;
     12▕ 
     13▕     public function getCurrentUser(): Authenticatable
     14▕     {
  ➜  15▕         return Auth::guard(config('drafts.auth.guard'))->user();
     16▕     }
     17▕ 
     18▕     public function previewMode(bool $previewMode = true): void
     19▕     {

      +10 vendor frames 
  11  database/seeders/pageContentsWithInitData.php:52
      App\Models\PageContent::save()

I supposed it was raised as seeders has no current logged user.
Any hint how this issue could be salved? Say, to turn off HasDrafts functionality temporary?
Telling the true I do not need HasDrafts functionality when data are inserted from seeder on app init...

Guava\FilamentDrafts\Admin\Resources\Pages\Edit\Draftable collision.

Hello. Great package, enjoying it so far, but on some of my multi lingual assets when using both Translatable and Draftable traits on the same EditRecord class - there is a collision error.

Code -

<?php

namespace App\Filament\Resources\PillarResource\Pages;

use App\Filament\Resources\PillarResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Guava\FilamentDrafts\Admin\Resources\Pages\Edit\Draftable;
class EditPillar extends EditRecord
{
    use EditRecord\Concerns\Translatable;
    use Draftable;
    protected static string $resource = PillarResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\DeleteAction::make(),
            Actions\LocaleSwitcher::make(),

        ];
    }
}

Results in Trait method Guava\FilamentDrafts\Admin\Resources\Pages\Edit\Draftable::handleRecordUpdate has not been applied as App\Filament\Resources\PillarResource\Pages\EditPillar::handleRecordUpdate, because of collision with Filament\Resources\Pages\EditRecord\Concerns\Translatable::handleRecordUpdate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.