Skip to content

Commit

Permalink
feat: improved the user friendliness (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Oct 2, 2024
1 parent b75caa4 commit 1475c47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
47 changes: 26 additions & 21 deletions app/Filament/Dashboard/Resources/ReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ public static function form(Form $form): Form
true => 'Request Changes to Data',
])
->inline()
->hidden(function () {
return request()->has('type');
})
->columnSpan(2),
Actions::make([
Action::make('approve')
->form([
Textarea::make('reason'),
])
->hidden(function (Get $get, string $operation) {
return ! auth()->user()->roles()->exists() || $get('status') == 'rejected' || $get('status') == 'approved' || $operation != 'edit';
})
->action(function (array $data, Report $record, Molecule $molecule, $set, $livewire): void {
self::approveReport($data, $record, $molecule, $livewire);
$set('status', 'approved');
Expand All @@ -75,14 +81,18 @@ public static function form(Form $form): Form
->form([
Textarea::make('reason'),
])
->hidden(function (Get $get, string $operation) {
return ! auth()->user()->roles()->exists() || $get('status') == 'rejected' || $get('status') == 'approved' || $operation != 'edit';
})
->action(function (array $data, Report $record, $set): void {
self::rejectReport($data, $record);
$set('status', 'rejected');
}),
Action::make('viewCompoundPage')
->color('info')
->url(fn (): string => env('APP_URL').'/compounds/'.request()->compound_id)
->openUrlInNewTab(),
])
->hidden(function (Get $get, string $operation) {
return ! auth()->user()->roles()->exists() || $get('status') == 'rejected' || $get('status') == 'approved' || $operation != 'edit';
})
->verticalAlignment(VerticalAlignment::End)
->columnStart(4),
])
Expand All @@ -96,14 +106,15 @@ public static function form(Form $form): Form
return getReportTypes();
})
->hidden(function (string $operation) {
if ($operation == 'create') {
return false;
} else {
return true;
}
return $operation != 'create' || request()->has('type');
}),
TextInput::make('title')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Title of the report. This is required.')
->default(function () {
if (request()->type == 'change' && request()->has('compound_id')) {
return 'Request changes';
}
})
->required(),
Textarea::make('evidence')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Please provide Evidence/Comment to support your claims in this report. This will help our Curators in reviewing your report.')
Expand Down Expand Up @@ -384,16 +395,6 @@ public static function form(Form $form): Form
->columns(7),

]),

Tabs\Tab::make('Chemical Classifications')
->schema([
Checkbox::make('approve')
->inline(false)
->hidden(function (string $operation) {
return ! auth()->user()->roles()->exists() || $operation == 'create';
}),
// ...
]),
])
->hidden(function (Get $get) {
return ! $get('is_change');
Expand All @@ -409,7 +410,10 @@ public static function form(Form $form): Form
$state,
shouldOpenInNewTab: true,
),
),
)
->hidden(function () {
return request()->has('type') && request()->type == 'change';
}),
Select::make('collections')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Select the Collections you want to report. This will help our Curators in reviewing your report.')
->relationship('collections', 'title')
Expand Down Expand Up @@ -497,9 +501,10 @@ public static function form(Form $form): Form
})
->live()
->hidden(function (Get $get, string $operation) {
if ($operation != 'create') {
if ($operation != 'create' || request()->type == 'change') {
return true;
} elseif (! request()->has('compound_id') && $get('report_type') != 'molecule') {
}
if (! request()->has('compound_id') && $get('report_type') != 'molecule') {
return true;
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class CreateReport extends CreateRecord
{
protected static string $resource = ReportResource::class;

public function getTitle(): string
{
$title = 'Create Report';
request()->type == 'change' ? $title = 'Request Changes' : $title = 'Report ';
if (request()->has('compound_id')) {
$molecule = Molecule::where('identifier', request()->compound_id)->first();
$title = $title.' - '.$molecule->name.' ('.$molecule->identifier.')';
}

return __($title);
}

protected function afterFill(): void
{
$request = request();
Expand Down

0 comments on commit 1475c47

Please sign in to comment.