Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 67 additions & 17 deletions docs/guide/sharp-breadcrumb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@

Under the hood Sharp manages a breadcrumb to keep track of stacked pages.

## Display the breadcrumb

You can activate the breadcrumb display in sharp's configuration:

```php
class SharpServiceProvider extends SharpAppServiceProvider
{
protected function configureSharp(SharpConfigBuilder $config): void
{
$config
->displayBreadcrumb()
// [...]
}
}
```

## Configure entity label

In Entity classes, you can define how an entity should be labeled in the breadcrumb with the `label` attribute:
Expand Down Expand Up @@ -74,6 +58,72 @@ class PostShow extends \Code16\Sharp\Show\SharpShow
In the Form, the breadcrumb label is only used in one particular case: when coming from an embedded Entity List inside a Show Page. In this case, the Show Page and the Form entity are different, and the breadcrumb helps to keep track of the current edited entity.
:::

## Configure custom labels cache

Breadcrumb labels are cached for 30 minutes to reduce DB queries between each navigation. If you don't want to cache them, which means all `SharpShow` in breadcrumb are loaded on every navigation, you can update the config in the SharpServiceProvider:

```php
class SharpServiceProvider extends SharpAppServiceProvider
{
protected function configureSharp(SharpConfigBuilder $config): void
{
$config
->configureBreadcrumbLabelsCache(false)
// ...
}
}
```

Alternatively, you can change the cache duration (default is 30 minutes):

```php
class SharpServiceProvider extends SharpAppServiceProvider
{
protected function configureSharp(SharpConfigBuilder $config): void
{
$config
->configureBreadcrumbLabelsCache(duration: 10)
// ...
}
}
```

### Lazy loading

In some cases, having the labels replaced by the default Entity label is acceptable and you want to have less DB queries, you can activate the lazy loading:

```php
class SharpServiceProvider extends SharpAppServiceProvider
{
protected function configureSharp(SharpConfigBuilder $config): void
{
$config
->enableBreadcrumbLabelsLazyLoading()
}
}
```
::: warning
Be aware that the user may see the breadcrumb with default entity labels (e.g. "Posts > Post > Category > Edit") when :
- a nested page is accessed directly (e.g. direct link)
- cached labels are expired
:::

## Hide the breadcrumb

If you don't want any breadcrumb, you can hide it in sharp's configuration:

```php
class SharpServiceProvider extends SharpAppServiceProvider
{
protected function configureSharp(SharpConfigBuilder $config): void
{
$config
->displayBreadcrumb(false)
// [...]
}
}
```

## Interact with Sharp's Breadcrumb

Refer to [the Context documentation](context.md) to find out how to interact with Sharp's breadcrumb.
Refer to [the Context documentation](context.md) to find out how to interact with Sharp's breadcrumb.
2 changes: 1 addition & 1 deletion resources/js/Pages/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<Title :entity-key="dashboardKey" />

<template #breadcrumb>
<template v-if="config('sharp.display_breadcrumb')">
<template v-if="config('sharp.breadcrumb.display')">
<PageBreadcrumb :breadcrumb="breadcrumb" />
</template>
</template>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Title :breadcrumb="breadcrumb" />

<template #breadcrumb>
<template v-if="config('sharp.display_breadcrumb')">
<template v-if="config('sharp.breadcrumb.display')">
<PageBreadcrumb :breadcrumb="breadcrumb" />
</template>
</template>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Show/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<Title :breadcrumb="breadcrumb" />

<template #breadcrumb>
<template v-if="config('sharp.display_breadcrumb')">
<template v-if="config('sharp.breadcrumb.display')">
<PageBreadcrumb :breadcrumb="breadcrumb" />
</template>
</template>
Expand Down
26 changes: 24 additions & 2 deletions src/Config/SharpConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class SharpConfigBuilder
'name' => 'Sharp',
'custom_url_segment' => 'sharp',
'display_sharp_version_in_title' => true,
'display_breadcrumb' => true,
'breadcrumb' => [
'display' => true,
'labels' => [
'lazy_loading' => false,
'cache' => true,
'cache_duration' => 30,
],
],
'entities' => [],
'entity_resolver' => null,
'global_filters' => [],
Expand Down Expand Up @@ -132,7 +139,22 @@ public function displaySharpVersionInTitle(bool $displaySharpVersionInTitle = tr

public function displayBreadcrumb(bool $displayBreadcrumb = true): self
{
$this->config['display_breadcrumb'] = $displayBreadcrumb;
$this->config['breadcrumb']['display'] = $displayBreadcrumb;

return $this;
}

public function enableBreadcrumbLabelsLazyLoading(bool $lazyLoading = true): self
{
$this->config['breadcrumb']['labels']['lazy_loading'] = $lazyLoading;

return $this;
}

public function configureBreadcrumbLabelsCache(bool $cache = true, int $duration = 30): self
{
$this->config['breadcrumb']['labels']['cache'] = $cache;
$this->config['breadcrumb']['labels']['cache_duration'] = $duration;

return $this;
}
Expand Down
1 change: 0 additions & 1 deletion src/Data/BreadcrumbItemData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
final class BreadcrumbItemData extends Data
{
public function __construct(
public string $type,
public string $label,
public ?string $documentTitleLabel,
public string $entityKey,
Expand Down
Loading
Loading