Skip to content

Commit

Permalink
introducing envbar:show command
Browse files Browse the repository at this point in the history
  • Loading branch information
devajmeireles committed Sep 17, 2024
1 parent a513282 commit a8e3649
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 18 deletions.
8 changes: 4 additions & 4 deletions config/envbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
| When set, the EnvBar will wait the set minutes to appear again.
|
*/
'timeout' => env('ENVBAR_CLOSABLE_TIMEOUT'),
'timeout' => env('ENVBAR_CLOSABLE_TIMEOUT', 10),
],

/*
Expand Down Expand Up @@ -188,19 +188,19 @@
'github' => [
'token' => env('ENVBAR_GITHUB_TOKEN'),
'repository' => env('ENVBAR_GITHUB_REPOSITORY'),
'cached_for' => env('ENVBAR_GITHUB_CACHED_FOR', 1),
'cached_for' => env('ENVBAR_GITHUB_DAYS_FOR_CACHE', 1),
],

'bitbucket' => [
'token' => env('ENVBAR_BITBUCKET_TOKEN'),
'repository' => env('ENVBAR_BITBUCKET_REPOSITORY'),
'cached_for' => env('ENVBAR_BITBUCKET_CACHED_FOR', 1),
'cached_for' => env('ENVBAR_BITBUCKET_DAYS_FOR_CACHE', 1),
],

'envoyer' => [
'token' => env('ENVBAR_ENVOYER_TOKEN', null),
'project_id' => env('ENVBAR_ENVOYER_PROJECT_ID', null),
'cached_for' => env('ENVBAR_BITBUCKET_CACHED_FOR', 1),
'cached_for' => env('ENVBAR_BITBUCKET_DAYS_FOR_CACHE', 1),
],
],
];
2 changes: 1 addition & 1 deletion dist/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Almost all the configuration is done through environment variables. Here are the
12. `ENVBAR_PROVIDER` - The provider to be used for fetching the last release. Allowed: github, bitbucket, envoyer. Default is `null`.
13. `ENVBAR_GITHUB_TOKEN` - GitHub token to be used for fetching the last release.
14. `ENVBAR_GITHUB_REPOSITORY` - GitHub repository to be used for fetching the last release.
15. `ENVBAR_GITHUB_CACHED_FOR` - The time in days to cache the last release. Default is `1`.
15. `ENVBAR_GITHUB_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`.
16. `ENVBAR_BITBUCKET_TOKEN` - BitBucket token to be used for fetching the last release.
17. `ENVBAR_BITBUCKET_REPOSITORY` - BitBucket repository to be used for fetching the last release.
18. `ENVBAR_BITBUCKET_CACHED_FOR` - The time in days to cache the last release. Default is `1`.
18. `ENVBAR_BITBUCKET_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`.
19. `ENVBAR_ENVOYER_TOKEN` - Envoyer token to be used for fetching the last release.
20. `ENVBAR_ENVOYER_PROJECT_ID` - Envoyer project id to be used for fetching the last release.
21. `ENVBAR_BITBUCKET_CACHED_FOR` - The time in days to cache the last release. Default is `1`.
21. `ENVBAR_ENVOYER_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`.


### Other Configurations:
Expand Down Expand Up @@ -72,10 +72,16 @@ You can ignore the EnvBar for specific pages:
```
Behind the scenes, this feature uses `Request::is` to check the current route.

### Clear Release Cache:
### Commands:

To avoid multiple requests to the git provider, the latest release is cached. If you want to clear the release cache, you can clear the entire application cache or run the following command to clear the release cache only:
To avoid multiple requests to the git provider, the latest release is cached for `ENVBAR_*_CACHED_FOR` day(s). If you want to clear the release cache, you can clear the entire application cache or run the following command to clear the release cache only, without affecting the other cache:

```bash
php artisan envbar:flush-release-cache
php artisan envbar:flush
```

If you are using `ENVBAR_CLOSABLE_TIMEOUT` and you closed the EnvBar, you can use the command below to show the EnvBar again without waiting for the final minutes timeout to run out:

```bash
php artisan envbar:show
```
10 changes: 8 additions & 2 deletions resources/js/modules/envbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export default (configuration) => ({
export default (configuration, show) => ({
init() {
const closedAt = localStorage.getItem('envbar::closed');
let closedAt = localStorage.getItem('envbar::closed');

if (show === true) {
closedAt = null;

localStorage.removeItem('envbar::closed');
}

if (closedAt && Date.now() < parseInt(closedAt)) {
this.element().style.display = 'none';
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/envbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
</div>

<script>
document.addEventListener('DOMContentLoaded', () => window.$envbar(@js($configuration)).init());
document.addEventListener('livewire:navigated', () => window.$envbar(@js($configuration)).init());
document.addEventListener('DOMContentLoaded', () => window.$envbar(@js($configuration), @js($show)).init());
document.addEventListener('livewire:navigated', () => window.$envbar(@js($configuration), @js($show)).init());
(function() {
window.hide = () => window.$envbar(@js($configuration)).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class ClearCacheCommand extends Command
class FlushCommand extends Command
{
public $signature = 'envbar:flush-release-cache';
public $signature = 'envbar:flush';

public $description = 'Flush the cache for the EnvBar releases.';

Expand Down
22 changes: 22 additions & 0 deletions src/Console/ShowCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace TallStackUi\EnvBar\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class ShowCommand extends Command
{
public $signature = 'envbar:show';

public $description = 'Show the EnvBar again regardless of the close timeout.';

public function handle(): int
{
Cache::put('envbar::show', true);

$this->components->info('EnvBar will be shown again. Refresh the browser!');

return self::SUCCESS;
}
}
5 changes: 4 additions & 1 deletion src/EnvBarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function registerCommands(): void
return;
}

$this->commands(Console\ClearCacheCommand::class);
$this->commands([
Console\ShowCommand::class,
Console\FlushCommand::class,
]);
}
}
2 changes: 2 additions & 0 deletions src/Response/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\HtmlString;
use Symfony\Component\HttpFoundation\Response;
use TallStackUi\EnvBar\Compilers\EnvBarComponentCompiler;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function component(): View
{
return view('envbar::components.envbar', [
'id' => uniqid(),
'show' => Cache::pull('envbar::show'),
...app(EnvBarComponentCompiler::class)(),
]);
}
Expand Down

0 comments on commit a8e3649

Please sign in to comment.