Skip to content

Commit

Permalink
Update firstname lastname to have underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
adevade committed Nov 25, 2024
1 parent 896a6e4 commit da452eb
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the docs at https://lunar-panel.vercel.app/
- [ ] Tax Zone types are "country", "states", "postcodes" -> would prefer it to be "countries" so it's consistent
- [ ] `ListField` FieldType shouldn't really have "Field" in its name -> change to simply "List"
- [ ] Sometimes we use "Enabled" other times "Active". Do we want to consider consistency here also?
- [ ] Staff "firstname" "lastname" I think should have underscores, e.g. "first_name"
- [x] Staff "firstname" "lastname" I think should have underscores, e.g. "first_name"
- [x] How to allow devs to extend Lunar's forms and tables
- [x] How to allow devs to overide validation rules
- [x] Allow devs to extend by adding their own pages/resources
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/database/factories/StaffFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class StaffFactory extends Factory
public function definition(): array
{
return [
'firstname' => $this->faker->firstName(),
'lastname' => $this->faker->lastName(),
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName(),
'admin' => $this->faker->boolean(5),
'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Lunar\Base\Migration;

return new class extends Migration
{
public function up(): void
{
Schema::table($this->prefix.'staff', function (Blueprint $table) {
$table->renameColumn('firstname', 'first_name');
$table->renameColumn('lastname', 'last_name');
});
}

public function down(): void
{
Schema::table($this->prefix.'staff', function (Blueprint $table) {
$table->renameColumn('first_name', 'firstname');
$table->renameColumn('last_name', 'lastname');
});
}
};
8 changes: 4 additions & 4 deletions packages/admin/resources/lang/en/staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
'plural_label' => 'Staff',

'table' => [
'firstname' => [
'first_name' => [
'label' => 'First Name',
],
'lastname' => [
'last_name' => [
'label' => 'Last Name',
],
'email' => [
Expand All @@ -22,10 +22,10 @@
],

'form' => [
'firstname' => [
'first_name' => [
'label' => 'First Name',
],
'lastname' => [
'last_name' => [
'label' => 'Last Name',
],
'email' => [
Expand Down
8 changes: 4 additions & 4 deletions packages/admin/resources/lang/es/staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
'plural_label' => 'Personal',

'table' => [
'firstname' => [
'first_name' => [
'label' => 'Nombre',
],
'lastname' => [
'last_name' => [
'label' => 'Apellido',
],
'email' => [
Expand All @@ -22,10 +22,10 @@
],

'form' => [
'firstname' => [
'first_name' => [
'label' => 'Nombre',
],
'lastname' => [
'last_name' => [
'label' => 'Apellido',
],
'email' => [
Expand Down
8 changes: 4 additions & 4 deletions packages/admin/resources/lang/fr/staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
'plural_label' => 'Personnel',

'table' => [
'firstname' => [
'first_name' => [
'label' => 'Prénom',
],
'lastname' => [
'last_name' => [
'label' => 'Nom de famille',
],
'email' => [
Expand All @@ -22,10 +22,10 @@
],

'form' => [
'firstname' => [
'first_name' => [
'label' => 'Prénom',
],
'lastname' => [
'last_name' => [
'label' => 'Nom de famille',
],
'email' => [
Expand Down
8 changes: 4 additions & 4 deletions packages/admin/resources/lang/nl/staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
'plural_label' => 'Personeel',

'table' => [
'firstname' => [
'first_name' => [
'label' => 'Voornaam',
],
'lastname' => [
'last_name' => [
'label' => 'Achternaam',
],
'email' => [
Expand All @@ -22,10 +22,10 @@
],

'form' => [
'firstname' => [
'first_name' => [
'label' => 'Voornaam',
],
'lastname' => [
'last_name' => [
'label' => 'Achternaam',
],
'email' => [
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Console/Commands/MakeLunarAdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class MakeLunarAdminCommand extends Command
protected function getUserData(): array
{
return [
'firstname' => $this->options['firstname'] ?? text(
'first_name' => $this->options['firstname'] ?? text(
label: 'First Name',
required: true,
),

'lastname' => $this->options['lastname'] ?? text(
'last_name' => $this->options['lastname'] ?? text(
label: 'Last Name',
required: true,
),
Expand Down
16 changes: 8 additions & 8 deletions packages/admin/src/Filament/Resources/StaffResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ protected static function getMainFormComponents(): array

protected static function getFirstNameFormComponent(): Component
{
return Forms\Components\TextInput::make('firstname')
->label(__('lunarpanel::staff.form.firstname.label'))
return Forms\Components\TextInput::make('first_name')
->label(__('lunarpanel::staff.form.first_name.label'))
->required()
->maxLength(255)
->autofocus();
}

protected static function getLastNameFormComponent(): Component
{
return Forms\Components\TextInput::make('lastname')
->label(__('lunarpanel::staff.form.lastname.label'))
return Forms\Components\TextInput::make('last_name')
->label(__('lunarpanel::staff.form.last_name.label'))
->required()
->maxLength(255)
->autofocus();
Expand Down Expand Up @@ -169,10 +169,10 @@ public static function getDefaultTable(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('firstname')
->label(__('lunarpanel::staff.table.firstname.label')),
Tables\Columns\TextColumn::make('lastname')
->label(__('lunarpanel::staff.table.lastname.label')),
Tables\Columns\TextColumn::make('first_name')
->label(__('lunarpanel::staff.table.first_name.label')),
Tables\Columns\TextColumn::make('last_name')
->label(__('lunarpanel::staff.table.last_name.label')),
Tables\Columns\TextColumn::make('email')
->label(__('lunarpanel::staff.table.email.label')),
Tables\Columns\TextColumn::make('admin')
Expand Down
12 changes: 6 additions & 6 deletions packages/admin/src/Models/Staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/**
* @property int $id
* @property bool $admin
* @property string $firstname
* @property string $lastname
* @property string $first_name
* @property string $last_name
* @property string $full_name
* @property string $email
* @property string $password
Expand All @@ -40,8 +40,8 @@ class Staff extends Authenticatable implements FilamentUser, HasName
protected $guard_name = 'staff';

protected $fillable = [
'firstname',
'lastname',
'first_name',
'last_name',
'admin',
'email',
'password',
Expand All @@ -65,7 +65,7 @@ class Staff extends Authenticatable implements FilamentUser, HasName
protected function fullName(): Attribute
{
return Attribute::get(
fn (): string => "{$this->firstname} {$this->lastname}",
fn (): string => "{$this->first_name} {$this->last_name}",
);
}

Expand All @@ -92,7 +92,7 @@ public function scopeSearch(Builder $query, ?string $terms): void
}

foreach (explode(' ', $terms) as $term) {
$query->whereAny(['email', 'firstname', 'lastname'], 'LIKE', "%{$term}%");
$query->whereAny(['email', 'first_name', 'last_name'], 'LIKE', "%{$term}%");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
$staff->assignRole('staff');

$formData = [
'firstname' => $staff->firstname,
'lastname' => $staff->lastname,
'first_name' => $staff->first_name,
'last_name' => $staff->last_name,
'email' => 'test@example.com',
'password' => 'password',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
'record' => $staff->getRouteKey(),
])
->assertFormSet([
'firstname' => $staff->firstname,
'lastname' => $staff->lastname,
'first_name' => $staff->first_name,
'last_name' => $staff->last_name,
'email' => $staff->email,
]);
});
Expand All @@ -39,16 +39,16 @@
'record' => $staff->getRouteKey(),
])
->fillForm([
'firstname' => $newData->firstname,
'lastname' => $newData->lastname,
'first_name' => $newData->first_name,
'last_name' => $newData->last_name,
'email' => $newData->email,
])
->call('save')
->assertHasNoFormErrors();

expect($staff->refresh())
->firstname->toBe($newData->firstname)
->lastname->toBe($newData->lastname)
->first_name->toBe($newData->first_name)
->last_name->toBe($newData->last_name)
->email->toBe($newData->email);
});

Expand Down
17 changes: 8 additions & 9 deletions tests/admin/Unit/Models/StaffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@

test('can get full name', function () {
$staff = \Lunar\Admin\Models\Staff::factory()->create([
'firstname' => 'Joe',
'lastname' => 'Bloggs',
'first_name' => 'Joe',
'last_name' => 'Bloggs',
]);

expect($staff->full_name)->toBe('Joe Bloggs');
});

test('can search staff by name', function () {
\Lunar\Admin\Models\Staff::factory()->create([
'firstname' => 'Joe',
'lastname' => 'Bloggs',
'first_name' => 'Joe',
'last_name' => 'Bloggs',
]);

\Lunar\Admin\Models\Staff::factory()->create([
'firstname' => 'Tim',
'lastname' => 'Bloggs',
'first_name' => 'Tim',
'last_name' => 'Bloggs',
]);

\Lunar\Admin\Models\Staff::factory()->create([
'firstname' => 'Bill',
'lastname' => 'Chance',
'first_name' => 'Bill',
'last_name' => 'Chance',
]);

expect(\Lunar\Admin\Models\Staff::search('Bloggs')->get())->toHaveCount(2)
->and(\Lunar\Admin\Models\Staff::search('Bill')->get())->toHaveCount(1)
->and(\Lunar\Admin\Models\Staff::search('Joe Bloggs')->get())->toHaveCount(1);
});

0 comments on commit da452eb

Please sign in to comment.