Skip to content

Commit

Permalink
handle GlobalSelectFilter::authorize()
Browse files Browse the repository at this point in the history
  • Loading branch information
aguingand committed Nov 19, 2024
1 parent f807507 commit bea6295
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
13 changes: 7 additions & 6 deletions demo/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class AppServiceProvider extends ServiceProvider
public function register(): void
{
// $this->app->bind(SharpUploadModel::class, Media::class)

$this->app->register(SharpInternalServiceProvider::class);
$this->app->register(DemoSharpServiceProvider::class);

if (class_exists(SharpDevServiceProvider::class)) {
$this->app->register(SharpDevServiceProvider::class);
}

$this->app->bind(SharpViteComponent::class, function () {
return new SharpViteComponent(hotFile: base_path('../dist/hot'));
Expand All @@ -20,11 +27,5 @@ public function register(): void

public function boot(): void
{
$this->app->register(SharpInternalServiceProvider::class);
$this->app->register(DemoSharpServiceProvider::class);

if (class_exists(SharpDevServiceProvider::class)) {
$this->app->register(SharpDevServiceProvider::class);
}
}
}
5 changes: 1 addition & 4 deletions demo/app/Providers/DemoSharpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ protected function configureSharp(SharpConfigBuilder $config): void
->addEntity('profile', ProfileEntity::class)
->addEntity('dashboard', DemoDashboardEntity::class)
->addEntity('test', TestEntity::class)
->when(
auth()->id() === 1,
fn (SharpConfigBuilder $config) => $config->addGlobalFilter(DummyGlobalFilter::class)
)
->addGlobalFilter(DummyGlobalFilter::class)
->configureUploadsThumbnailCreation(uploadModelClass: Media::class)
->setSharpMenu(SharpMenu::class)
->setThemeColor('#004c9b')
Expand Down
5 changes: 5 additions & 0 deletions demo/app/Sharp/DummyGlobalFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public function defaultValue(): mixed
{
return '1';
}

public function authorize(): bool
{
return auth()->id() === 1;
}
}
6 changes: 3 additions & 3 deletions resources/js/form/components/FormFieldLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@
<slot v-bind="{ id, ariaDescribedBy }" />

<template v-if="field.helpMessage || $slots['help-message'] || form.fieldHasError(field, fieldErrorKey)">
<div class="mt-2.5 grid grid-cols-1 gap-y-2">
<div class="mt-2 grid grid-cols-1 gap-y-2">
<template v-if="field.helpMessage || $slots['help-message']">
<div :id="`${id}-help-message`" class="grid grid-cols-1 gap-y-2">
<template v-if="field.helpMessage">
<p class="text-sm text-muted-foreground leading-4">
<p class="text-xs text-muted-foreground leading-4">
{{ field.helpMessage }}
</p>
</template>
<template v-if="$slots['help-message']">
<p class="text-sm text-muted-foreground leading-4">
<p class="text-xs text-muted-foreground leading-4">
<slot name="help-message" />
</p>
</template>
Expand Down
28 changes: 14 additions & 14 deletions resources/js/form/components/fields/editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,20 @@
/>
</template>

<!-- Commenting this for now because it causes infinite loop on HMR -->

<!-- <template v-if="editor && field.showCharacterCount">-->
<!-- <div class="card-footer fs-8 text-muted bg-white">-->
<!-- <template v-if="field.maxLength">-->
<!-- <span :class="{ 'text-danger': editor.storage.characterCount.characters() > field.maxLength }">-->
<!-- {{ __('sharp::form.editor.character_count', { count: `${editor.storage.characterCount.characters()} / ${field.maxLength}` }) }}-->
<!-- </span>-->
<!-- </template>-->
<!-- <template v-else>-->
<!-- {{ __('sharp::form.editor.character_count', { count: editor.storage.characterCount.characters() }) }}-->
<!-- </template>-->
<!-- </div>-->
<!-- </template>-->
<template v-if="editor && field.showCharacterCount">
<div class="mt-2 text-xs text-muted-foreground">
<template v-if="field.maxLength">
<div :class="{ 'text-destructive': editor.storage.characterCount.characters() > field.maxLength }">
{{ __('sharp::form.editor.character_count', { count: `${editor.storage.characterCount.characters()} / ${field.maxLength}` }) }}
</div>
</template>
<template v-else>
<div>
{{ __('sharp::form.editor.character_count', { count: editor.storage.characterCount.characters() }) }}
</div>
</template>
</div>
</template>
</div>
</FormFieldLayout>
</template>
4 changes: 3 additions & 1 deletion src/Utils/Filters/GlobalFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ final class GlobalFilters implements Arrayable

public function getFilters(): array
{
return sharp()->config()->get('global_filters');
return collect(sharp()->config()->get('global_filters'))
->filter(fn (GlobalRequiredFilter $filter) => $filter->authorize())
->all();
}

public function isEnabled(): bool
Expand Down
5 changes: 5 additions & 0 deletions src/Utils/Filters/GlobalRequiredFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ private function getSessionKey(): string
{
return '_sharp_retained_global_filter_'.$this->getKey();
}

public function authorize(): bool
{
return true;
}
}

0 comments on commit bea6295

Please sign in to comment.