mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 19:22:14 +01:00
Compare commits
2 Commits
claude/fix
...
feature/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47f6131d88 | ||
|
|
496ccbc45c |
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TimeEntryResource\Pages;
|
||||
use App\Models\Member;
|
||||
use App\Models\TimeEntry;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -17,7 +16,6 @@ use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TimeEntryResource extends Resource
|
||||
{
|
||||
@@ -53,20 +51,6 @@ class TimeEntryResource extends Resource
|
||||
->rules([
|
||||
'after_or_equal:start',
|
||||
]),
|
||||
Select::make('organization_id')
|
||||
->relationship(name: 'organization', titleAttribute: 'name')
|
||||
->searchable(['name'])
|
||||
->required(),
|
||||
Select::make('member_id')
|
||||
->relationship(
|
||||
name: 'member',
|
||||
titleAttribute: 'id',
|
||||
modifyQueryUsing: fn (Builder $query) => $query->with(['user', 'organization'])
|
||||
)
|
||||
->getOptionLabelFromRecordUsing(fn (Member $record): string => $record->user->email.' ('.$record->organization->name.')')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Select::make('user_id')
|
||||
->relationship(name: 'user', titleAttribute: 'email')
|
||||
->searchable(['name', 'email'])
|
||||
@@ -75,10 +59,7 @@ class TimeEntryResource extends Resource
|
||||
->relationship(name: 'project', titleAttribute: 'name')
|
||||
->searchable(['name'])
|
||||
->nullable(),
|
||||
Select::make('task_id')
|
||||
->relationship(name: 'task', titleAttribute: 'name')
|
||||
->searchable(['name'])
|
||||
->nullable(),
|
||||
// TODO
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,28 +5,9 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\TimeEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TimeEntryResource;
|
||||
use App\Models\Member;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTimeEntry extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TimeEntryResource::class;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
if (isset($data['member_id'])) {
|
||||
/** @var Member|null $member */
|
||||
$member = Member::query()->find($data['member_id']);
|
||||
if ($member !== null) {
|
||||
$data['user_id'] = $member->user_id;
|
||||
$data['organization_id'] = $member->organization_id;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\TimeEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TimeEntryResource;
|
||||
use App\Models\Member;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
@@ -20,22 +19,4 @@ class EditTimeEntry extends EditRecord
|
||||
->icon('heroicon-m-trash'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
if (isset($data['member_id'])) {
|
||||
/** @var Member|null $member */
|
||||
$member = Member::query()->find($data['member_id']);
|
||||
if ($member !== null) {
|
||||
$data['user_id'] = $member->user_id;
|
||||
$data['organization_id'] = $member->organization_id;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import type { Dayjs } from 'dayjs';
|
||||
|
||||
const props = defineProps<{
|
||||
date: Dayjs;
|
||||
totalSeconds?: number;
|
||||
totalMinutes?: number;
|
||||
}>();
|
||||
|
||||
const totalSecondsValue = computed(() => props.totalSeconds ?? 0);
|
||||
const totalSeconds = computed(() => (props.totalMinutes ?? 0) * 60);
|
||||
|
||||
// Injected organization for formatting settings
|
||||
const organization = inject('organization') as ComputedRef<Organization | undefined> | undefined;
|
||||
@@ -25,7 +25,7 @@ const dateFormat = computed(() => organization?.value?.date_format);
|
||||
</div>
|
||||
<span class="text-xs">{{ formatDate(date.toISOString(), dateFormat) }}</span>
|
||||
<span class="block text-xs text-muted-foreground font-medium mt-1">
|
||||
{{ formatHumanReadableDuration(totalSecondsValue, intervalFormat, numberFormat) }}
|
||||
{{ formatHumanReadableDuration(totalSeconds, intervalFormat, numberFormat) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -179,20 +179,20 @@ const dailyTotals = computed(() => {
|
||||
const totals: Record<string, number> = {};
|
||||
props.timeEntries.forEach((entry) => {
|
||||
const date = getDayJsInstance()(entry.start).format('YYYY-MM-DD');
|
||||
let durationSeconds: number;
|
||||
let duration: number;
|
||||
|
||||
if (entry.end !== null) {
|
||||
// Completed entry
|
||||
durationSeconds = getDayJsInstance()(entry.end).diff(
|
||||
duration = getDayJsInstance()(entry.end).diff(
|
||||
getDayJsInstance()(entry.start),
|
||||
'seconds'
|
||||
'minutes'
|
||||
);
|
||||
} else {
|
||||
// Running entry - use current time
|
||||
durationSeconds = currentTime.value.diff(getDayJsInstance()(entry.start), 'seconds');
|
||||
duration = currentTime.value.diff(getDayJsInstance()(entry.start), 'minutes');
|
||||
}
|
||||
|
||||
totals[date] = (totals[date] || 0) + durationSeconds;
|
||||
totals[date] = (totals[date] || 0) + duration;
|
||||
});
|
||||
return totals;
|
||||
});
|
||||
@@ -444,7 +444,7 @@ onUnmounted(() => {
|
||||
:date="
|
||||
getDayJsInstance()(arg.date.toISOString()).utc().tz(getUserTimezone(), true)
|
||||
"
|
||||
:total-seconds="
|
||||
:total-minutes="
|
||||
dailyTotals[
|
||||
getDayJsInstance()(arg.date)
|
||||
.utc()
|
||||
|
||||
@@ -5,8 +5,6 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TimeEntryResource;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
@@ -52,149 +50,4 @@ class TimeEntryResourceTest extends FilamentTestCase
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_can_see_create_page_of_time_entry(): void
|
||||
{
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntryResource\Pages\CreateTimeEntry::class);
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_can_create_time_entry(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$member = Member::factory()
|
||||
->forOrganization($organization)
|
||||
->forUser($user)
|
||||
->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntryResource\Pages\CreateTimeEntry::class)
|
||||
->fillForm([
|
||||
'description' => 'Test time entry',
|
||||
'billable' => true,
|
||||
'start' => '2024-01-01 08:00:00',
|
||||
'end' => '2024-01-01 10:00:00',
|
||||
'member_id' => $member->getKey(),
|
||||
])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$timeEntry = TimeEntry::where('description', 'Test time entry')->first();
|
||||
$this->assertNotNull($timeEntry);
|
||||
$this->assertSame($member->getKey(), $timeEntry->member_id);
|
||||
$this->assertSame($user->getKey(), $timeEntry->user_id);
|
||||
$this->assertSame($organization->getKey(), $timeEntry->organization_id);
|
||||
$this->assertTrue($timeEntry->billable);
|
||||
}
|
||||
|
||||
public function test_can_create_time_entry_and_derives_user_and_organization_from_member(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$member = Member::factory()
|
||||
->forOrganization($organization)
|
||||
->forUser($user)
|
||||
->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntryResource\Pages\CreateTimeEntry::class)
|
||||
->fillForm([
|
||||
'description' => 'Derived fields test',
|
||||
'billable' => false,
|
||||
'start' => '2024-03-01 09:00:00',
|
||||
'end' => '2024-03-01 11:00:00',
|
||||
'member_id' => $member->getKey(),
|
||||
'user_id' => $otherUser->getKey(),
|
||||
'organization_id' => $otherOrganization->getKey(),
|
||||
])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$timeEntry = TimeEntry::where('description', 'Derived fields test')->first();
|
||||
$this->assertNotNull($timeEntry);
|
||||
$this->assertSame($user->getKey(), $timeEntry->user_id);
|
||||
$this->assertSame($organization->getKey(), $timeEntry->organization_id);
|
||||
}
|
||||
|
||||
public function test_can_update_time_entry(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$member = Member::factory()
|
||||
->forOrganization($organization)
|
||||
->forUser($user)
|
||||
->create();
|
||||
$timeEntry = TimeEntry::factory()->forMember($member)->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntryResource\Pages\EditTimeEntry::class, ['record' => $timeEntry->getKey()])
|
||||
->fillForm([
|
||||
'description' => 'Updated description',
|
||||
'billable' => true,
|
||||
'start' => '2024-02-01 08:00:00',
|
||||
'end' => '2024-02-01 12:00:00',
|
||||
'member_id' => $member->getKey(),
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$timeEntry->refresh();
|
||||
$this->assertSame('Updated description', $timeEntry->description);
|
||||
$this->assertTrue($timeEntry->billable);
|
||||
$this->assertSame($user->getKey(), $timeEntry->user_id);
|
||||
$this->assertSame($organization->getKey(), $timeEntry->organization_id);
|
||||
}
|
||||
|
||||
public function test_update_time_entry_derives_user_and_organization_from_new_member(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$member = Member::factory()
|
||||
->forOrganization($organization)
|
||||
->forUser($user)
|
||||
->create();
|
||||
$timeEntry = TimeEntry::factory()->create();
|
||||
|
||||
$newOrganization = Organization::factory()->create();
|
||||
$newUser = User::factory()->create();
|
||||
$newMember = Member::factory()
|
||||
->forOrganization($newOrganization)
|
||||
->forUser($newUser)
|
||||
->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntryResource\Pages\EditTimeEntry::class, ['record' => $timeEntry->getKey()])
|
||||
->fillForm([
|
||||
'description' => 'Reassigned entry',
|
||||
'billable' => false,
|
||||
'start' => '2024-02-01 08:00:00',
|
||||
'end' => '2024-02-01 12:00:00',
|
||||
'member_id' => $newMember->getKey(),
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$timeEntry->refresh();
|
||||
$this->assertSame($newMember->getKey(), $timeEntry->member_id);
|
||||
$this->assertSame($newUser->getKey(), $timeEntry->user_id);
|
||||
$this->assertSame($newOrganization->getKey(), $timeEntry->organization_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user