Skip to content

Commit

Permalink
Feature/issue 154 attach components to incidents on create (#158)
Browse files Browse the repository at this point in the history
Co-authored-by: AlexJump24 <[email protected]>
Co-authored-by: James Brooks <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2024
1 parent 4482f9d commit 2391521
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"+:count Update": "+:count Update|+:count Updates",
":count Incident": ":count Incident|:count Incidents",
":name RSS Feed": ":name RSS Feed",
"Add Component": "Add Component",
"Admin": "Admin",
"Always Hidden": "Always Hidden",
"Always collapsed": "Always collapsed",
Expand All @@ -12,6 +13,7 @@
"Complete Maintenance": "Complete Maintenance",
"Complete": "Complete",
"Component Group": "Component Group",
"Components": "Components",
"Custom CSS": "Custom CSS",
"Custom Footer HTML": "Custom Footer HTML",
"Custom Header HTML": "Custom Header HTML",
Expand Down
25 changes: 20 additions & 5 deletions src/Filament/Resources/IncidentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cachet\Actions\Update\CreateUpdate as CreateIncidentUpdateAction;
use Cachet\Data\IncidentUpdate\CreateIncidentUpdateData;
use Cachet\Enums\ComponentStatusEnum;
use Cachet\Enums\IncidentStatusEnum;
use Cachet\Enums\ResourceVisibilityEnum;
use Cachet\Filament\Resources\IncidentResource\Pages;
Expand Down Expand Up @@ -54,11 +55,25 @@ public static function form(Form $form): Form
->options(ResourceVisibilityEnum::class)
->default(ResourceVisibilityEnum::guest)
->required(),
// Forms\Components\Select::make('component')
// ->multiple()
// ->relationship('components', 'name')
// ->searchable()
// ->preload(),
Forms\Components\Repeater::make('incidentComponents')
->visibleOn('create')
->relationship()
->defaultItems(0)
->addActionLabel(__('Add Component'))
->schema([
Forms\Components\Select::make('component_id')
->preload()
->required()
->relationship('component', 'name')
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->label(__('Component')),
Forms\Components\ToggleButtons::make('component_status')
->label(__('Status'))
->inline()
->options(ComponentStatusEnum::class)
->required(),
])
->label(__('Components'))
])
->columnSpan(3),
Section::make()->schema([
Expand Down
9 changes: 9 additions & 0 deletions src/Models/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -117,6 +118,14 @@ public function components(): BelongsToMany
->withPivot(['component_status']);
}

/**
* Get the impacted components for this incident.
*/
public function incidentComponents(): HasMany
{
return $this->hasMany(IncidentComponent::class);
}

/**
* Get the updates for this incident.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Models/IncidentComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @property int $id
* @property int $incident_id
* @property int $component_id
* @property ?ComponentStatusEnum $status
* @property ?ComponentStatusEnum $component_status
* @property ?Carbon $created_at
* @property ?Carbon $updated_at
* @property Incident $incident
Expand All @@ -24,6 +24,8 @@
*/
class IncidentComponent extends Pivot
{
protected $table = 'incident_components';

/** @use HasFactory<IncidentComponentFactory> */
use HasFactory;

Expand Down

0 comments on commit 2391521

Please sign in to comment.