user()->current_project_id, auth()->user()->id); } protected function getTableColumns(): array { return [ TextColumn::make('name') ->searchable() ->sortable(), TextColumn::make('id') ->label('Global') ->badge() ->color(fn ($record) => $record->project_id ? 'gray' : 'success') ->formatStateUsing(function (Script $record) { return $record->project_id ? 'No' : 'Yes'; }), TextColumn::make('created_at') ->label('Created At') ->formatStateUsing(fn (Script $record) => $record->created_at_by_timezone) ->searchable() ->sortable(), ]; } public function table(Table $table): Table { return $table ->heading(null) ->query($this->getTableQuery()) ->columns($this->getTableColumns()) ->recordUrl(fn (Script $record) => Executions::getUrl(['script' => $record])) ->actions([ EditAction::make('edit') ->label('Edit') ->modalHeading('Edit Script') ->mutateRecordDataUsing(function (array $data, Script $record) { return [ 'name' => $record->name, 'content' => $record->content, 'global' => $record->project_id === null, ]; }) ->form([ TextInput::make('name') ->rules(EditScript::rules()['name']), CodeEditorField::make('content') ->rules(EditScript::rules()['content']) ->helperText('You can use variables like ${VARIABLE_NAME} in the script. The variables will be asked when executing the script'), Checkbox::make('global') ->label('Is Global (Accessible in all projects)'), ]) ->authorize(fn (Script $record) => auth()->user()->can('update', $record)) ->using(function (array $data, Script $record) { app(EditScript::class)->edit($record, auth()->user(), $data); $this->dispatch('$refresh'); }) ->modalWidth(MaxWidth::ThreeExtraLarge), DeleteAction::make('delete') ->label('Delete') ->modalHeading('Delete Script') ->authorize(fn (Script $record) => auth()->user()->can('delete', $record)) ->using(function (array $data, Script $record) { $record->delete(); }), ]); } }