feature flag management by admins

This commit is contained in:
Doar Mihai
2026-02-21 15:10:37 +02:00
parent 0f17570476
commit b936a14a1f
4 changed files with 333 additions and 0 deletions
@@ -0,0 +1,186 @@
@extends('layouts.app')
@section('content')
<div class="bg-gray-50 dark:bg-gray-900 min-h-screen">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Header -->
<div class="mb-8">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-gray-900 dark:text-white">Feature Flags</h1>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Manage application feature flags</p>
</div>
<a
href="{{ route('admin.dashboard') }}"
class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-md font-medium transition-colors"
>
Back to Dashboard
</a>
</div>
</div>
<!-- Success/Error Messages -->
@if(session('success'))
<div class="mb-6 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 text-green-800 dark:text-green-200 px-4 py-3 rounded-lg">
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="mb-6 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-800 dark:text-red-200 px-4 py-3 rounded-lg">
{{ session('error') }}
</div>
@endif
<!-- Info Box -->
<div class="mb-6 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
<div class="flex items-start">
<svg class="h-5 w-5 text-blue-400 mt-0.5 mr-3" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
</svg>
<div class="flex-1">
<p class="text-sm text-blue-800 dark:text-blue-200">
Feature flags allow you to enable or disable features across the application without deploying new code.
Toggle flags on/off to control feature availability.
</p>
</div>
</div>
</div>
<!-- Feature Flags Table -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
<thead class="bg-gray-50 dark:bg-gray-900">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
Feature
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
Status
</th>
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
@forelse($features as $feature)
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors">
<td class="px-6 py-4">
<div class="flex items-start">
<div>
<div class="text-sm font-medium text-gray-900 dark:text-white">
{{ $feature['name'] }}
</div>
@if($feature['description'])
<div class="text-sm text-gray-500 dark:text-gray-400 mt-1">
{{ $feature['description'] }}
</div>
@endif
<div class="text-xs text-gray-400 dark:text-gray-500 mt-1 font-mono">
{{ $feature['class'] }}
</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($feature['is_active'])
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200">
<svg class="mr-1.5 h-2 w-2" fill="currentColor" viewBox="0 0 8 8">
<circle cx="4" cy="4" r="3" />
</svg>
Active
</span>
@else
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-300">
<svg class="mr-1.5 h-2 w-2" fill="currentColor" viewBox="0 0 8 8">
<circle cx="4" cy="4" r="3" />
</svg>
Inactive
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<div class="flex items-center justify-end gap-3">
<!-- Toggle Form -->
<form
action="{{ route('admin.feature-flags.toggle') }}"
method="POST"
class="inline"
>
@csrf
<input type="hidden" name="feature" value="{{ $feature['name'] }}">
<input type="hidden" name="active" value="{{ $feature['is_active'] ? '0' : '1' }}">
<button
type="submit"
class="inline-flex items-center px-3 py-1.5 {{ $feature['is_active'] ? 'bg-red-600 hover:bg-red-700 text-white' : 'bg-green-600 hover:bg-green-700 text-white' }} rounded-md text-sm font-medium transition-colors"
>
@if($feature['is_active'])
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
</svg>
Deactivate
@else
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
Activate
@endif
</button>
</form>
<!-- Purge Form -->
<form
action="{{ route('admin.feature-flags.purge') }}"
method="POST"
onsubmit="return confirm('Are you sure you want to purge this feature flag? This will remove all stored values.');"
class="inline"
>
@csrf
<input type="hidden" name="feature" value="{{ $feature['name'] }}">
<button
type="submit"
class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200"
title="Purge feature flag"
>
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
</button>
</form>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="3" class="px-6 py-12 text-center">
<div class="flex flex-col items-center">
<svg class="h-12 w-12 text-gray-400 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 21v-4m0 0V5a2 2 0 012-2h6.5l1 1H21l-3 6 3 6h-8.5l-1-1H5a2 2 0 00-2 2zm9-13.5V9"></path>
</svg>
<p class="text-sm text-gray-500 dark:text-gray-400">No feature flags found</p>
<p class="text-xs text-gray-400 dark:text-gray-500 mt-1">
Add feature flag classes to the <code class="bg-gray-100 dark:bg-gray-700 px-1 rounded">app/Features</code> directory
</p>
</div>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<!-- Help Section -->
<div class="mt-6 bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-6">
<h3 class="text-sm font-medium text-gray-900 dark:text-white mb-3">How Feature Flags Work</h3>
<div class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<p><strong class="text-gray-900 dark:text-white">Activate/Deactivate:</strong> Toggle a feature on or off globally for all users.</p>
<p><strong class="text-gray-900 dark:text-white">Purge:</strong> Remove all stored values for a feature flag. The feature will revert to its default state defined in the code.</p>
<p><strong class="text-gray-900 dark:text-white">Adding Features:</strong> Create new feature flag classes in <code class="bg-gray-100 dark:bg-gray-700 px-1 rounded text-xs">app/Features</code> directory.</p>
</div>
</div>
</div>
</div>
@endsection