Skip to content

Commit

Permalink
Merge pull request #464 from canyongbs/feature/advapp-232-knowledge-e…
Browse files Browse the repository at this point in the history
…nhancement

[ADVAPP-232]: Enhance knowledge management capabilities.
  • Loading branch information
Orrison authored Jan 24, 2024
2 parents 3781f21 + ef2803a commit e5aa128
Show file tree
Hide file tree
Showing 22 changed files with 403 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class KnowledgeBaseItemFactory extends Factory
public function definition(): array
{
return [
'question' => fake()->sentence(),
'public' => fake()->boolean(),
'solution' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => fake()->paragraph]]]]],
'notes' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => fake()->paragraph]]]]],
'title' => fake()->sentence(),
'article_details' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => fake()->paragraph()]]]]],
'notes' => fake()->paragraph(),
'quality_id' => KnowledgeBaseQuality::inRandomOrder()->first() ?? KnowledgeBaseQuality::factory(),
'status_id' => KnowledgeBaseStatus::inRandomOrder()->first() ?? KnowledgeBaseStatus::factory(),
'category_id' => KnowledgeBaseCategory::inRandomOrder()->first() ?? KnowledgeBaseCategory::factory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function up(): void
{
Schema::create('knowledge_base_items', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('question');
$table->boolean('public');
$table->jsonb('solution')->nullable();
$table->jsonb('notes')->nullable();
$table->string('title');
$table->json('article_details')->nullable();
$table->longText('notes')->nullable();
$table->uuid('quality_id')->nullable();
$table->uuid('status_id')->nullable();
$table->uuid('category_id')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

namespace AdvisingApp\KnowledgeBase\Filament\Resources;

use Filament\Forms\Form;
use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -61,11 +62,11 @@ class KnowledgeBaseItemResource extends Resource

protected static ?int $navigationSort = 20;

protected static ?string $recordTitleAttribute = 'question';
protected static ?string $recordTitleAttribute = 'title';

public static function getGloballySearchableAttributes(): array
{
return ['question', 'solution'];
return ['title', 'article_details'];
}

public static function getGlobalSearchEloquentQuery(): Builder
Expand All @@ -89,11 +90,15 @@ public static function getGlobalSearchResultUrl(Model $record): ?string
return static::getUrl('view', ['record' => $record]);
}

public static function form(Form $form): Form
{
return resolve(CreateKnowledgeBaseItem::class)->form($form);
}

public static function getPages(): array
{
return [
'index' => ListKnowledgeBaseItems::route('/'),
'create' => CreateKnowledgeBaseItem::route('/create'),
'view' => ViewKnowledgeBaseItem::route('/{record}'),
'edit' => EditKnowledgeBaseItem::route('/{record}/edit'),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
namespace AdvisingApp\KnowledgeBase\Filament\Resources\KnowledgeBaseItemResource\Pages;

use Filament\Forms\Form;
use Filament\Forms\Components\Radio;
use App\Filament\Fields\TiptapEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use AdvisingApp\Division\Models\Division;
use Filament\Resources\Pages\CreateRecord;
Expand All @@ -56,54 +57,48 @@ public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('question')
->label('Question/Issue/Feature')
->translateLabel()
->required()
->string(),
Select::make('quality_id')
->label('Quality')
->translateLabel()
->relationship('quality', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseQuality())->getTable(), (new KnowledgeBaseQuality())->getKeyName()),
Select::make('status_id')
->label('Status')
->relationship('status', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseStatus())->getTable(), (new KnowledgeBaseStatus())->getKeyName()),
Select::make('category_id')
->label('Category')
->translateLabel()
->relationship('category', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseCategory())->getTable(), (new KnowledgeBaseCategory())->getKeyName()),
Radio::make('public')
->label('Public')
->translateLabel()
->boolean()
->default(false)
->rules(['boolean']),
Select::make('division')
->label('Division')
->translateLabel()
->relationship('division', 'name')
->searchable(['name', 'code'])
->preload()
->exists((new Division())->getTable(), (new Division())->getKeyName()),
TiptapEditor::make('solution')
->label('Solution')
->translateLabel()
->columnSpanFull()
->extraInputAttributes(['style' => 'min-height: 12rem;']),
TiptapEditor::make('notes')
->label('Notes')
->translateLabel()
->columnSpanFull()
->extraInputAttributes(['style' => 'min-height: 12rem;']),
Section::make()
->schema([
TextInput::make('title')
->label('Article Title')
->required()
->string(),
Toggle::make('public')
->label('Public')
->default(false)
->onColor('success')
->offColor('gray'),
Textarea::make('notes')
->label('Notes')
->string(),
]),
Section::make()
->schema([
Select::make('quality_id')
->label('Quality')
->relationship('quality', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseQuality())->getTable(), (new KnowledgeBaseQuality())->getKeyName()),
Select::make('status_id')
->label('Status')
->relationship('status', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseStatus())->getTable(), (new KnowledgeBaseStatus())->getKeyName()),
Select::make('category_id')
->label('Category')
->relationship('category', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseCategory())->getTable(), (new KnowledgeBaseCategory())->getKeyName()),
Select::make('division')
->label('Division')
->relationship('division', 'name')
->searchable(['name', 'code'])
->preload()
->exists((new Division())->getTable(), (new Division())->getKeyName()),
]),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@

namespace AdvisingApp\KnowledgeBase\Filament\Resources\KnowledgeBaseItemResource\Pages;

use Filament\Actions;
use Filament\Forms\Form;
use Filament\Forms\Components\Radio;
use Filament\Actions\EditAction;
use App\Filament\Fields\TiptapEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Section;
use Illuminate\Database\Eloquent\Model;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use AdvisingApp\Division\Models\Division;
use AdvisingApp\KnowledgeBase\Models\KnowledgeBaseStatus;
use AdvisingApp\KnowledgeBase\Models\KnowledgeBaseQuality;
use AdvisingApp\KnowledgeBase\Models\KnowledgeBaseCategory;
use Filament\Actions\Action as BaseAction;
use Filament\Forms\Components\Actions\Action;
use AdvisingApp\KnowledgeBase\Filament\Resources\KnowledgeBaseItemResource;

class EditKnowledgeBaseItem extends EditRecord
Expand All @@ -57,54 +56,41 @@ public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('question')
->label('Question/Issue/Feature')
->translateLabel()
->required()
->string(),
Select::make('quality_id')
->label('Quality')
->translateLabel()
->relationship('quality', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseQuality())->getTable(), (new KnowledgeBaseQuality())->getKeyName()),
Select::make('status_id')
->label('Status')
->relationship('status', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseStatus())->getTable(), (new KnowledgeBaseStatus())->getKeyName()),
Select::make('category_id')
->label('Category')
->translateLabel()
->relationship('category', 'name')
->searchable()
->preload()
->exists((new KnowledgeBaseCategory())->getTable(), (new KnowledgeBaseCategory())->getKeyName()),
Radio::make('public')
->label('Public')
->translateLabel()
->boolean()
->default(false)
->rules(['boolean']),
Select::make('division')
->label('Division')
->translateLabel()
->relationship('division', 'name')
->searchable(['name', 'code'])
->preload()
->exists((new Division())->getTable(), (new Division())->getKeyName()),
TiptapEditor::make('solution')
->label('Solution')
->translateLabel()
->columnSpanFull()
->extraInputAttributes(['style' => 'min-height: 12rem;']),
TiptapEditor::make('notes')
->label('Notes')
->translateLabel()
Section::make()
->schema([
TextInput::make('title')
->label('Article Title')
->required()
->string()
->suffixAction(
Action::make('saveArticleTitle')
->icon('heroicon-o-check')
->action(function (Model $record, $state) {
if ($record->title === $state) {
return;
}

$record->update([
'title' => $state,
]);

if ($record->wasChanged('title')) {
Notification::make()
->title("Title successfully updated to '{$record->title}'")
->success()
->duration(3000)
->send();
}
}),
),
]),
TiptapEditor::make('article_details')
->label('Article Details')
->columnSpanFull()
->extraInputAttributes(['style' => 'min-height: 12rem;']),
->extraInputAttributes([
'style' => 'min-height: 32rem;',
'class' => 'text-gray-900 dark:bg-gray-800 dark:text-gray-100 border-2 dark:border-0 border-gray-200 rounded-none mx-4 my-2 px-8 py-4',
]),
]);
}

Expand All @@ -115,11 +101,33 @@ public function afterSave(): void
$this->fillForm();
}

protected function getSavedNotificationTitle(): ?string
{
return 'Article details successfully saved';
}

protected function getFormActions(): array
{
return [
$this->getSubmitFormAction()->label('Save Article Details'),
];
}

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
BaseAction::make('save')
->action('save')
->button()
->color('primary')
->label('Save Article Details'),
EditAction::make()
->label('Edit Article Metadata')
->button()
->outlined()
->record($this->record)
->form(resolve(EditKnowledgeBaseItemMetadata::class)->form())
->successNotificationTitle('Article metadata successfully updated'),
];
}
}
Loading

0 comments on commit e5aa128

Please sign in to comment.