Skip to content

Commit 17d5563

Browse files
committed
refactor: Group and sort fields in StackForm by service name and password status
1 parent 70dfa10 commit 17d5563

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/Livewire/Project/Service/StackForm.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function mount()
3333
$key = data_get($field, 'key');
3434
$value = data_get($field, 'value');
3535
$rules = data_get($field, 'rules', 'nullable');
36-
$isPassword = data_get($field, 'isPassword');
36+
$isPassword = data_get($field, 'isPassword', false);
3737
$this->fields->put($key, [
3838
'serviceName' => $serviceName,
3939
'key' => $key,
@@ -47,7 +47,15 @@ public function mount()
4747
$this->validationAttributes["fields.$key.value"] = $fieldKey;
4848
}
4949
}
50-
$this->fields = $this->fields->sortBy('name');
50+
$this->fields = $this->fields->groupBy('serviceName')->map(function ($group) {
51+
return $group->sortBy(function ($field) {
52+
return data_get($field, 'isPassword') ? 1 : 0;
53+
})->mapWithKeys(function ($field) {
54+
return [$field['key'] => $field];
55+
});
56+
})->flatMap(function ($group) {
57+
return $group;
58+
});
5159
}
5260

5361
public function saveCompose($raw)

0 commit comments

Comments
 (0)