Skip to content

Commit

Permalink
Update server dashboard configuration schema
Browse files Browse the repository at this point in the history
This moves the dashboard settings into an array. While this is a somewhat intrusive change, requiring user intervention due to the implicit deprecation, it helps make the configuration file cleaner by grouping semantically related elements. An added check makes sure to provide backwards compatibility with older configuration options.

The shortened editor/tips keys are not breaking, as they have not been released yet.
  • Loading branch information
caendesilva committed Oct 26, 2023
1 parent 4c90613 commit 2df96b1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
17 changes: 11 additions & 6 deletions config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@
|--------------------------------------------------------------------------
|
| Here you can configure settings for the built-in realtime compiler server.
| The server also includes a magic dashboard feature that supercharges
| your local development! This feature can alo be customised here.
|
*/

Expand All @@ -412,14 +414,17 @@
// Should preview pages be saved to the output directory?
'save_preview' => true,

// Should the realtime compiler dashboard be enabled?
'dashboard' => env('SERVER_DASHBOARD', true),
// Configure the realtime compiler dashboard
'dashboard' => [
// Should the realtime compiler dashboard be enabled?
'enabled' => env('SERVER_DASHBOARD', true),

// Can the dashboard make edits to the project file system?
'dashboard_editor' => true,
// Can the dashboard make edits to the project file system?
'interactive' => true,

// Should the dashboard show tips?
'dashboard_tips' => true,
// Should the dashboard show tips?
'tips' => true,
],

],

Expand Down
17 changes: 11 additions & 6 deletions packages/framework/config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@
|--------------------------------------------------------------------------
|
| Here you can configure settings for the built-in realtime compiler server.
| The server also includes a magic dashboard feature that supercharges
| your local development! This feature can alo be customised here.
|
*/

Expand All @@ -412,14 +414,17 @@
// Should preview pages be saved to the output directory?
'save_preview' => true,

// Should the realtime compiler dashboard be enabled?
'dashboard' => env('SERVER_DASHBOARD', true),
// Configure the realtime compiler dashboard
'dashboard' => [
// Should the realtime compiler dashboard be enabled?
'enabled' => env('SERVER_DASHBOARD', true),

// Can the dashboard make edits to the project file system?
'dashboard_editor' => true,
// Can the dashboard make edits to the project file system?
'interactive' => true,

// Should the dashboard show tips?
'dashboard_tips' => true,
// Should the dashboard show tips?
'tips' => true,
],

],

Expand Down
19 changes: 14 additions & 5 deletions packages/realtime-compiler/src/Http/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
use function rtrim;
use function strlen;
use function substr;
use function is_bool;
use function basename;
use function in_array;
use function json_decode;
use function json_encode;
use function substr_count;
use function array_combine;
use function trigger_error;
use function escapeshellarg;
use function file_get_contents;
use function str_starts_with;
Expand All @@ -67,8 +69,8 @@ class DashboardController
'This dashboard won\'t be saved to your static site.',
'Got stuck? Ask for help on [GitHub](https://github.com/hydephp/hyde)!',
'Found a bug? Please report it on [GitHub](https://github.com/hydephp/hyde)!',
'You can disable tips using by setting `server.dashboard_tips` to `false` in `config/hyde.php`.',
'The dashboard update your project files. You can disable this by setting `server.dashboard_editor` to `false` in `config/hyde.php`.',
'You can disable tips using by setting `server.dashboard.tips` to `false` in `config/hyde.php`.',
'The dashboard update your project files. You can disable this by setting `server.dashboard.interactive` to `false` in `config/hyde.php`.',
];

public function __construct()
Expand Down Expand Up @@ -227,7 +229,7 @@ public static function highlightMediaLibraryCode(string $contents): HtmlString

public function showTips(): bool
{
return config('hyde.server.dashboard_tips', true);
return config('hyde.server.dashboard.tips', true);
}

public function getTip(): HtmlString
Expand All @@ -237,7 +239,14 @@ public function getTip(): HtmlString

public static function enabled(): bool
{
return config('hyde.server.dashboard', true);
// Previously, the setting was hyde.server.dashboard, so for backwards compatability we need this
if (is_bool($oldConfig = config('hyde.server.dashboard'))) {
trigger_error('Using `hyde.server.dashboard` as boolean is deprecated. Please use `hyde.server.dashboard.enabled` instead.', E_USER_DEPRECATED);

return $oldConfig;
}

return config('hyde.server.dashboard.enabled', true);
}

// This method is called from the PageRouter and allows us to serve a dynamic welcome page
Expand Down Expand Up @@ -273,7 +282,7 @@ public static function renderIndexPage(HydePage $page): string

public function isInteractive(): bool
{
return config('hyde.server.dashboard_editor', true);
return config('hyde.server.dashboard.interactive', true);
}

public function getScripts(): string
Expand Down

0 comments on commit 2df96b1

Please sign in to comment.