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.

refactor: Group and sort fields in StackForm by service name and password status

Andras Bacsai17d55630d51a
diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.php
index 04bb136dbf..7f2416e3e3 100644
--- a/app/Livewire/Project/Service/StackForm.php
+++ b/app/Livewire/Project/Service/StackForm.php
@@ -33,7 +33,7 @@ class StackForm extends Component
$key = data_get($field, 'key');
$value = data_get($field, 'value');
$rules = data_get($field, 'rules', 'nullable');
- $isPassword = data_get($field, 'isPassword');
+ $isPassword = data_get($field, 'isPassword', false);
$this->fields->put($key, [
'serviceName' => $serviceName,
'key' => $key,
@@ -47,7 +47,15 @@ class StackForm extends Component
$this->validationAttributes["fields.$key.value"] = $fieldKey;
}
}
- $this->fields = $this->fields->sortBy('name');
+ $this->fields = $this->fields->groupBy('serviceName')->map(function ($group) {
+ return $group->sortBy(function ($field) {
+ return data_get($field, 'isPassword') ? 1 : 0;
+ })->mapWithKeys(function ($field) {
+ return [$field['key'] => $field];
+ });
+ })->flatMap(function ($group) {
+ return $group;
+ });
}
public function saveCompose($raw)