Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

order column added to track order of env in the UI

ayntk-ai4d1244771551
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
index 880d3e7059..95e2bfbbdc 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
@@ -48,7 +48,7 @@ class All extends Component
{
$this->resource->load(['environment_variables', 'environment_variables_preview']);
- $sortBy = $this->resource->settings->is_env_sorting_enabled ? 'key' : 'id';
+ $sortBy = $this->resource->settings->is_env_sorting_enabled ? 'key' : 'order';
$sortFunction = function ($variables) use ($sortBy) {
if ($sortBy === 'key') {
@@ -56,7 +56,7 @@ class All extends Component
return strtolower($item->key);
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
} else {
- return $variables->sortBy('id')->values();
+ return $variables->sortBy('order')->values();
}
};
@@ -102,12 +102,40 @@ class All extends Component
$this->handleSingleSubmit($data);
}
+ $this->updateOrder();
$this->sortEnvironmentVariables();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
+ private function updateOrder()
+ {
+ $variables = parseEnvFormatToArray($this->variables);
+ $order = 1;
+ foreach ($variables as $key => $value) {
+ $env = $this->resource->environment_variables()->where('key', $key)->first();
+ if ($env) {
+ $env->order = $order;
+ $env->save();
+ }
+ $order++;
+ }
+
+ if ($this->showPreview) {
+ $previewVariables = parseEnvFormatToArray($this->variablesPreview);
+ $order = 1;
+ foreach ($previewVariables as $key => $value) {
+ $env = $this->resource->environment_variables_preview()->where('key', $key)->first();
+ if ($env) {
+ $env->order = $order;
+ $env->save();
+ }
+ $order++;
+ }
+ }
+ }
+
private function handleBulkSubmit()
{
$variables = parseEnvFormatToArray($this->variables);
@@ -131,7 +159,9 @@ class All extends Component
return;
}
+ $maxOrder = $this->resource->environment_variables()->max('order') ?? 0;
$environment = $this->createEnvironmentVariable($data);
+ $environment->order = $maxOrder + 1;
$environment->save();
}
@@ -231,4 +261,4 @@ class All extends Component
$this->sortEnvironmentVariables();
$this->getDevView();
}
-}
+}
\ No newline at end of file
diff --git a/database/migrations/2024_08_14_183120_add_order_to_environment_variables_table.php b/database/migrations/2024_08_14_183120_add_order_to_environment_variables_table.php
new file mode 100644
index 0000000000..5275358275
--- /dev/null
+++ b/database/migrations/2024_08_14_183120_add_order_to_environment_variables_table.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('environment_variables', function (Blueprint $table) {
+ $table->integer('order')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('environment_variables', function (Blueprint $table) {
+ $table->dropColumn('order');
+ });
+ }
+};