filament icon indicating copy to clipboard operation
filament copied to clipboard

Issue with translatable FileUpload field

Open msrivela opened this issue 1 year ago • 23 comments

Package

filament/spatie-laravel-translatable-plugin

Package Version

v3.2.2

Laravel Version

v10.41.0

Livewire Version

No response

PHP Version

PHP 8.3.1

Problem description

Case 1: Creating new record issue

FileUpload field do not clear to upload translated image when switching locale

After filling both languages and saving, edit page will throw Filament\Forms\Components\BaseFileUpload::Filament\Forms\Components\{closure}(): Argument #1 ($file) must be of type string, array given (https://flareapp.io/share/OmV0Wvp7)

Case 2: Updating record issue

Editing a record with only one locale filled, then uploading image for second locale will throw No synthesizer found for key: "" (https://flareapp.io/share/NPLRBLo5)

Expected behavior

Case 1: Creating new record issue

While creating new record it's expected to clear FileUpload field when locale is changed After saving, it's expected to be able to edit the record

Case 2: Updating record issue

Image is expected to be uploaded when filling second locale

Steps to reproduce

Case 1: Creating new record issue

  1. Click issues o menu
  2. Click "New issue"
  3. Fill "title" and "image"
  4. Change language to spanish (image will not clear, will have to manually delete to upload new image)
  5. Click "Create" button (error will throw after redirect to edit page)

Case 2: Updating record issue

  1. Click issues o menu
  2. Click "New issue"
  3. Fill "title" and "image"
  4. Click "Create" button
  5. Change locale to spanish
  6. Fill data (error will throw after image is uploaded)

Reproduction repository

https://github.com/msrivela/filament-issue-translatable

Relevant log output

No response

msrivela avatar Jan 17 '24 20:01 msrivela

Hey @msrivela! We're sorry to hear that you've hit this issue. 💛

However, it doesn't look like you've provided much information on how to replicate the issue. Please edit your original post with clear steps we need to take.

github-actions[bot] avatar Jan 17 '24 20:01 github-actions[bot]

Thank you for providing reproduction steps! Reopening the issue now.

github-actions[bot] avatar Jan 18 '24 18:01 github-actions[bot]

I have the same problem, any solution to this problem?

From my debugging, it appeared that in the database, the "main" language is stored correctly as an array [id => file_name], but it is this "extra" language that is stored as a string.

When debugging the package, I noticed that the "main" language from the "additional" language differs in that, before writing translations in the "additional" languages, the file writes in the form [id => Livewire\Features\SupportFileUploads\TemporaryUploadedFile], and the "main" language (which writes correctly) in the form [id => file_name].

kamil-bartczak avatar Feb 29 '24 21:02 kamil-bartczak

Unfortunately I don't have any workaround for the problem other than locking filament to version v3.0.75 when it worked. Please let me know if you figure something out.

msrivela avatar Mar 01 '24 11:03 msrivela

@kamil-bartczak @msrivela I think the problem is that the 'hydratestate' is not triggered in the handleRecordUpdate. go to Filament\Resources\Pages\ EditRecord \Concerns\Translatable method handleRecordUpdate and call $this->form->fill($this->data); before $this->form->validate(); Let me know if it solves your problem ! As a side note, If you guys are using this with Builders/Repeaters there is another problem with the ordering.

mybouhssina avatar Mar 08 '24 01:03 mybouhssina

@mybouhssina Sadly that solution did not work for me. I am in fact using inside a repeater in my project, but not in the reproduction repository.

msrivela avatar Mar 08 '24 13:03 msrivela

@msrivela I'm sorry to hear that, I think this issue might be related: https://github.com/filamentphp/filament/issues/11825

mybouhssina avatar Mar 12 '24 20:03 mybouhssina

I can confirm I have the same problem.

bojmaliev avatar Mar 13 '24 21:03 bojmaliev

See #11450

Voltra avatar Mar 14 '24 10:03 Voltra

@Voltra I've seen your solution but I think it doesn't take into consideration the dehydrate hook. Check my suggestion: https://github.com/filamentphp/filament/issues/11825

mybouhssina avatar Mar 14 '24 13:03 mybouhssina

That is quite possible since my test use case seemingly only use hydrated hooks. I'll check it out and adjust

Voltra avatar Mar 14 '24 14:03 Voltra

+1

mrtawil avatar Mar 29 '24 13:03 mrtawil

The latest changes to the PR should get it to work

Voltra avatar Mar 29 '24 15:03 Voltra

Sticking to Filament 3.0.75 works, as mentioned by @msrivela

But for this to works in the latest version, i had to use both @mybouhssina and @Voltra workarounds. @Voltra solution fixing the lang switching on edit and @mybouhssina solution fixing the model saving issue.

Lucathiel avatar Apr 03 '24 11:04 Lucathiel

@Lucathiel The latest version of the PR should include the fix @mybouhssina proposed, was there anything else you added?

Voltra avatar Apr 03 '24 14:04 Voltra

as a side note, there is another problem I encountered while using Repeaters/Builders with this plugin. If my memory serves me well, it was whenever I switch language and save, the repeater/builder elements orders will change. From my understanding, it was due to saving the builder/repeaters in the old local data as objects with UUID keys and that JS doesn't guarantee the object properties order, so what I ended up doing is transforming these Objects to Arrays and the problem was solved, I can share the code if someone is interested.

mybouhssina avatar Apr 03 '24 15:04 mybouhssina

I did encounter a very similar problem with filament-navigation. That one was package specific, but maybe something similar is still in the core filament components. The fix is simply to use an array and to push items onto it (instead of adding a new key using a UUID).

The ordering not being preserved due to JSON objects being unordered key-value pairs, and going through many different layers of serialization and deserialization (e.g. app and DB have their own JSON engines).

That being said, it's not specific to this issue and possibly not to this (sub-)package.

Voltra avatar Apr 03 '24 15:04 Voltra

Same problem here 👋

I've tried to apply the changes suggested on PR #11450 and worked well for updating. But for creating, when I try to change the language, the FileUpload component remains with the previous state: https://d.pr/v/kMz2bs

How did you solve this issue when creating?

devmatheus avatar Apr 10 '24 20:04 devmatheus

Oh... we hadn't, yet. It's the same fix, I'm adding it now.

Voltra avatar Apr 10 '24 20:04 Voltra

Is there any workaround for current latest version?

abdukhashimov avatar Apr 22 '24 17:04 abdukhashimov

@abdukhashimov applying the patch derived from my PR should do the trick

Voltra avatar Apr 28 '24 11:04 Voltra

I did the trick of creating a json file and tabs with field.lang I tried the patch, it raised me issues with disabled fields. Disabled field was not populated even though it was returned from DB.

abdukhashimov avatar Apr 29 '24 05:04 abdukhashimov

I did the trick of creating a json file and tabs with field.lang I tried the patch, it raised me issues with disabled fields. Disabled field was not populated even though it was returned from DB.

The disabled field was quite basic: It was the combo of Title and slug

abdukhashimov avatar Apr 29 '24 05:04 abdukhashimov

I solved the problem with a walk around where I was using the latest version of filament which is 3.2.74, I solved it with downgrade filament version 3.1.8 and it work fine with me.

mohammed9895 avatar May 06 '24 19:05 mohammed9895

this also fixable with #11450 when using $this->form->getRawState() 👍

atmonshi avatar May 09 '24 19:05 atmonshi

I am posting this same message across all Spatie Translatable issues & PRs

Hey all! Wanted to update you on where we're at with the translatable plugin.

I really appreciate your patience while this issue has been active. While I created the plugin for the community, I've never actually had a project where I needed to use it, and that's the same for the rest of the Filament team. As such, it's the reason why the plugin hasn't had as much attention as the others, and is much more unstable: I just don't have the environment to test all the use cases, nor the motivation to make it truly great.

As such, I put out a post a month ago and asked who in the community uses the plugin and has knowledge of plugin development. Luckily, Lara Zeus and Mohamed Sabil stepped forward, who are both authors of popular Filament plugins and are trusted by the community.

We are strongly considering handing over maintenance of the plugin to those developers, for the good of the community. You can find their fork at https://github.com/lara-zeus/translatable.

Since the new developers have lots of experience with the plugin and active projects that use it, they should be able to help debug issues easier and make a much more stable experience for other users.

If their work goes well until v4 is released, we will likely retire the plugin at that point and recommend the fork as an official replacement. If it does not go as expected and the community is unhappy, then we will reconsider this decision. I am closing this for now, and if we decide to take maintenance back officially then we will probably reopen it.

The existing plugin will continue to receive security updates indefinitely. Please let me know if you have any further questions.

Many thanks, Dan

danharrin avatar May 09 '24 21:05 danharrin

this an attempt to fix the issue if anyone willing to test this PR I would appreciate the feedback.

atmonshi avatar May 12 '24 00:05 atmonshi