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

Added macro helpers for export availability #100

Conversation

rickgoemans
Copy link

Intro

I've added some useful macros to the Nova Field which helps to determine a whether a field is available on the export or not.

There are 3 macros:

  • hideOnExport - The field can be available on index requests but will not be shown on export requests
  • onlyOnExport - The field is only available on export requests
  • showOnExport - The field is available on export requests and maybe create/update requests, depending on the defined logic.

Reason

The reason for this is on the index and/or detail requests you'll want to format fields like email addresses and phone numbers as HTML using a displayUsing callback. But this results in errors saying that the displayUsing callback is receiving a null value where it expects a string. You could change the type hinting to ?string or remove the type hinting, but that is not a good solution in my opinion.

Example (which throws errors):

Text::make(__('Email'), 'email')
  ->rules('required', 'email')
  ->displayUsing(fn(string $email): string => "<a target='_blank' href='mailto:{$email}'>{$email}</a>")
  ->asHtml(),

Solution (after this being merged):

Text::make(__('Email'), 'email')
  ->rules('required', 'email')
  ->displayUsing(fn(string $email): string => "<a target='_blank' href='mailto:{$email}'>{$email}</a>")
  ->asHtml()
  ->hideOnExport(),

Text::make(__('Email'), 'email')
  ->onlyOnExport(),

Outro

I'm wondering what others think of this solution and maybe this can get merged so others can enjoy these helpful macros.

@patrickbrouwers
Copy link
Member

Nice! I've had a similar idea for a while. Nice PR. I'll review it soon!

@vesper8
Copy link

vesper8 commented Dec 22, 2020

I need this as well.. either that or a way to transform before export so I can strip the html tags

Any chance you'll merge this soon @patrickbrouwers ?

@patrickbrouwers
Copy link
Member

I'll review it after my holiday is over

@GautierDele
Copy link

@patrickbrouwers did you have any time to review this ? This is a really needed feature if you can have a look 😄
Either #114 or this one.

Thanks

@patrickbrouwers
Copy link
Member

Not yet, but I think I'll be happy to add both solutions.

@GautierDele
Copy link

Yes I agree, this one is more clean but mine allows to join external table easily. might be good to merge both yes

@rickgoemans
Copy link
Author

Any progress on the merge? I don't understand the reason for the styleci to fail, is it because of the no newline at the end of the file?

@patrickbrouwers
Copy link
Member

@rickgoemans no worries about styleci, it will run after merge anyway.

I haven't gotten around to it yet, but still on my planning to merge it.

@patrickbrouwers patrickbrouwers merged commit 94b03b8 into SpartnerNL:1.2 May 21, 2021
@patrickbrouwers
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants