@littlebearapps/platform-admin-sdk 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -7
- package/dist/templates.d.ts +1 -1
- package/dist/templates.js +206 -4
- package/package.json +1 -1
- package/templates/full/dashboard/src/components/notifications/NotificationDropdown.tsx +130 -0
- package/templates/full/dashboard/src/components/notifications/NotificationItem.tsx +264 -0
- package/templates/full/dashboard/src/components/patterns/PatternInfoButton.tsx +60 -0
- package/templates/full/dashboard/src/components/reports/DigestStats.tsx +151 -0
- package/templates/full/dashboard/src/components/reports/FeatureUsageReport.tsx +339 -0
- package/templates/full/dashboard/src/components/reports/HealthTrendsReport.tsx +192 -0
- package/templates/full/dashboard/src/components/search/SearchResultGroup.tsx +46 -0
- package/templates/full/dashboard/src/components/search/SearchResultItem.tsx +212 -0
- package/templates/full/dashboard/src/components/usage/AIModelBreakdown.tsx +364 -0
- package/templates/full/dashboard/src/components/usage/unified/Recommendations.tsx +149 -0
- package/templates/full/dashboard/src/lib/cloudflare/alerting.ts +486 -0
- package/templates/full/dashboard/src/lib/cloudflare/graphql.ts +4785 -0
- package/templates/full/dashboard/src/lib/cloudflare/project-registry.ts +451 -0
- package/templates/full/dashboard/src/lib/notifications/api.ts +197 -0
- package/templates/full/dashboard/src/lib/notifications/types.ts.hbs +97 -0
- package/templates/full/dashboard/src/lib/patterns/api.ts +120 -0
- package/templates/full/dashboard/src/lib/patterns/types.ts +127 -0
- package/templates/full/dashboard/src/lib/reports/types.ts +231 -0
- package/templates/full/dashboard/src/lib/search/api.ts +258 -0
- package/templates/full/dashboard/src/lib/search/types.ts.hbs +115 -0
- package/templates/full/dashboard/src/lib/settings/api.ts.hbs +201 -0
- package/templates/full/dashboard/src/lib/settings/types.ts.hbs +104 -0
- package/templates/full/dashboard/src/lib/usage/allowance-config.ts.hbs +547 -0
- package/templates/full/dashboard/src/lib/usage/providers.ts +331 -0
- package/templates/full/dashboard/src/pages/api/patterns/[id]/approve.ts +49 -0
- package/templates/full/dashboard/src/pages/api/patterns/[id]/reject.ts +50 -0
- package/templates/full/dashboard/src/pages/api/reports/digests/stats.ts +38 -0
- package/templates/full/dashboard/src/pages/api/reports/digests.ts +39 -0
- package/templates/full/dashboard/src/pages/api/search/reindex/[type].ts +56 -0
- package/templates/full/dashboard/src/pages/api/test-reports/[id].ts +102 -0
- package/templates/full/dashboard/src/pages/feedback.astro +365 -0
- package/templates/full/dashboard/src/pages/kiosk.astro +206 -0
- package/templates/full/dashboard/src/pages/map.astro +561 -0
- package/templates/full/dashboard/src/pages/revenue.astro +72 -0
- package/templates/full/dashboard/src/pages/tests.astro +431 -0
- package/templates/full/scripts/ops/audit-cost-anomaly.ts +430 -0
- package/templates/full/scripts/ops/verify-account-total.ts +256 -0
- package/templates/full/tests/integration/feedback-schema.test.ts +361 -0
- package/templates/full/tests/integration/r2-archive.test.ts +108 -0
- package/templates/shared/.github/workflows/dependabot-automerge.yml +41 -0
- package/templates/shared/.github/workflows/validate-controls.yml +27 -0
- package/templates/shared/dashboard/src/components/Breadcrumbs.astro +101 -0
- package/templates/shared/dashboard/src/components/EmptyState.astro +46 -0
- package/templates/shared/dashboard/src/components/ErrorBoundary.astro +79 -0
- package/templates/shared/dashboard/src/components/LoadingSkeleton.astro +105 -0
- package/templates/shared/dashboard/src/components/PageShell.astro +72 -0
- package/templates/shared/dashboard/src/components/SkipLinks.astro +22 -0
- package/templates/shared/dashboard/src/components/Toast.astro +170 -0
- package/templates/shared/dashboard/src/components/ToastContainer.astro +156 -0
- package/templates/shared/dashboard/src/components/costs/ProviderCostsGrid.tsx +401 -0
- package/templates/shared/dashboard/src/components/costs/index.ts +4 -0
- package/templates/shared/dashboard/src/components/overview/AlertBanner.tsx +94 -0
- package/templates/shared/dashboard/src/components/overview/index.ts +9 -0
- package/templates/shared/dashboard/src/components/reports/ReportInfoButton.tsx +98 -0
- package/templates/shared/dashboard/src/components/resources/CostChart.tsx +170 -0
- package/templates/shared/dashboard/src/components/resources/ProviderCard.tsx +272 -0
- package/templates/shared/dashboard/src/components/resources/ProviderDetail.tsx +293 -0
- package/templates/shared/dashboard/src/components/settings/SettingsCard.astro +102 -0
- package/templates/shared/dashboard/src/components/usage/AllowanceGauge.astro +170 -0
- package/templates/shared/dashboard/src/components/usage/AnomalyAlerts.astro +633 -0
- package/templates/shared/dashboard/src/components/usage/BillingCycleCountdown.astro +192 -0
- package/templates/shared/dashboard/src/components/usage/BurnRateHero.astro +539 -0
- package/templates/shared/dashboard/src/components/usage/CircuitBreakerEventLog.astro +542 -0
- package/templates/shared/dashboard/src/components/usage/CircuitBreakerPanel.tsx +292 -0
- package/templates/shared/dashboard/src/components/usage/CircuitBreakerStatus.astro +669 -0
- package/templates/shared/dashboard/src/components/usage/CompactThresholdBanner.astro +531 -0
- package/templates/shared/dashboard/src/components/usage/ComparisonModeSelector.astro +651 -0
- package/templates/shared/dashboard/src/components/usage/CostBreakdownChart.astro +381 -0
- package/templates/shared/dashboard/src/components/usage/CostBreakdownTable.astro +210 -0
- package/templates/shared/dashboard/src/components/usage/CostDataTable.astro +0 -0
- package/templates/shared/dashboard/src/components/usage/CostDonutChart.astro +311 -0
- package/templates/shared/dashboard/src/components/usage/DailyCostChart.astro +632 -0
- package/templates/shared/dashboard/src/components/usage/ExportButton.astro +114 -0
- package/templates/shared/dashboard/src/components/usage/FeatureBudgetsTable.astro +872 -0
- package/templates/shared/dashboard/src/components/usage/FilterBar.astro +190 -0
- package/templates/shared/dashboard/src/components/usage/FilterToggles.astro +175 -0
- package/templates/shared/dashboard/src/components/usage/GitHubUsageCard.astro +537 -0
- package/templates/shared/dashboard/src/components/usage/OverageCostCard.astro +212 -0
- package/templates/shared/dashboard/src/components/usage/PlanUtilizationCard.astro +193 -0
- package/templates/shared/dashboard/src/components/usage/ProjectCard.astro +640 -0
- package/templates/shared/dashboard/src/components/usage/ProjectCardsGrid.astro +272 -0
- package/templates/shared/dashboard/src/components/usage/ResourceSearch.astro +279 -0
- package/templates/shared/dashboard/src/components/usage/ServiceUtilizationList.astro +604 -0
- package/templates/shared/dashboard/src/components/usage/SparklineCard.astro +399 -0
- package/templates/shared/dashboard/src/components/usage/StatsHero.astro +600 -0
- package/templates/shared/dashboard/src/components/usage/TableFilters.astro +1033 -0
- package/templates/shared/dashboard/src/components/usage/ThresholdAlert.astro +271 -0
- package/templates/shared/dashboard/src/components/usage/ThresholdSettings.astro +618 -0
- package/templates/shared/dashboard/src/components/usage/TopSpenderCard.astro +170 -0
- package/templates/shared/dashboard/src/components/usage/UnifiedResourceTable.astro +1737 -0
- package/templates/shared/dashboard/src/components/usage/UsageCard.astro +135 -0
- package/templates/shared/dashboard/src/components/usage/UsageHealthBanner.astro +387 -0
- package/templates/shared/dashboard/src/components/usage/UtilizationBar.astro +159 -0
- package/templates/shared/dashboard/src/components/usage/WorkersBreakdownTable.astro +659 -0
- package/templates/shared/dashboard/src/components/usage/daily/CostChart.astro +461 -0
- package/templates/shared/dashboard/src/components/usage/daily/CostTable.astro +946 -0
- package/templates/shared/dashboard/src/components/usage/daily/DailyOverview.astro +1079 -0
- package/templates/shared/dashboard/src/components/usage/design-tokens.ts +187 -0
- package/templates/shared/dashboard/src/components/usage/filters/InlineDateRange.astro +285 -0
- package/templates/shared/dashboard/src/components/usage/filters/PeriodButtons.astro +157 -0
- package/templates/shared/dashboard/src/components/usage/filters/ProjectSelect.astro +284 -0
- package/templates/shared/dashboard/src/components/usage/react/DashboardShell.tsx +263 -0
- package/templates/shared/dashboard/src/components/usage/react/StatusBadge.tsx +77 -0
- package/templates/shared/dashboard/src/components/usage/react/UsageChart.tsx +391 -0
- package/templates/shared/dashboard/src/components/usage/react/index.ts.hbs +30 -0
- package/templates/shared/dashboard/src/components/usage/react/types.ts +137 -0
- package/templates/shared/dashboard/src/components/usage/scripts/ai-tab-controller.ts +419 -0
- package/templates/shared/dashboard/src/components/usage/scripts/constants.ts +60 -0
- package/templates/shared/dashboard/src/components/usage/scripts/formatters.ts +62 -0
- package/templates/shared/dashboard/src/components/usage/scripts/overview-controller.ts +1633 -0
- package/templates/shared/dashboard/src/components/usage/scripts/resource-table-builder.ts +294 -0
- package/templates/shared/dashboard/src/components/usage/scripts/tabs-filters-controller.ts +464 -0
- package/templates/shared/dashboard/src/components/usage/state/index.ts +55 -0
- package/templates/shared/dashboard/src/components/usage/state/usageActions.ts +439 -0
- package/templates/shared/dashboard/src/components/usage/state/usageStore.ts +376 -0
- package/templates/shared/dashboard/src/components/usage/transformers.ts +478 -0
- package/templates/shared/dashboard/src/components/usage/types.ts +283 -0
- package/templates/shared/dashboard/src/components/usage/unified/AlertBanner.tsx +172 -0
- package/templates/shared/dashboard/src/components/usage/unified/HeroCardsRow.tsx +757 -0
- package/templates/shared/dashboard/src/components/usage/unified/LiveHeader.tsx +169 -0
- package/templates/shared/dashboard/src/components/usage/unified/ProjectsTable.tsx +448 -0
- package/templates/shared/dashboard/src/components/usage/unified/ResourceBreakdown.tsx +236 -0
- package/templates/shared/dashboard/src/components/usage/unified/Sparkline.tsx +127 -0
- package/templates/shared/dashboard/src/components/usage/unified/UnifiedShell.tsx +893 -0
- package/templates/shared/dashboard/src/components/usage/unified/index.ts.hbs +50 -0
- package/templates/shared/dashboard/src/components/usage/unified/types.ts +416 -0
- package/templates/shared/dashboard/src/components/usage/usage-colors.ts +292 -0
- package/templates/shared/dashboard/src/lib/cloudflare/analytics.ts +310 -0
- package/templates/shared/dashboard/src/lib/cloudflare/d1.ts +55 -0
- package/templates/shared/dashboard/src/lib/cloudflare/index.ts.hbs +120 -0
- package/templates/shared/dashboard/src/lib/infrastructure/types.ts +116 -0
- package/templates/shared/dashboard/src/lib/usage/fetchWithDedup.ts +101 -0
- package/templates/shared/dashboard/src/lib/usage/index.ts.hbs +12 -0
- package/templates/shared/dashboard/src/pages/api/usage/ai-models.ts +235 -0
- package/templates/shared/dashboard/src/pages/api/usage/billing-context.ts +296 -0
- package/templates/shared/scripts/test-telemetry-flow.ts +464 -0
- package/templates/shared/tests/e2e/usage-api.test.ts +909 -0
- package/templates/shared/tests/e2e/usage-export.test.ts +784 -0
- package/templates/shared/tests/e2e/usage-mobile.test.ts +531 -0
- package/templates/shared/tests/helpers/mock-storage.ts +166 -0
- package/templates/shared/tests/integration/kv-cache.test.ts +252 -0
- package/templates/shared/tests/integration/platform-usage.test.ts +956 -0
- package/templates/shared/tests/unit/billing.test.ts +331 -0
- package/templates/shared/tests/unit/cloudflare/graphql.test.ts +217 -0
- package/templates/shared/tests/unit/components/usage-transformers.test.ts +473 -0
- package/templates/shared/tests/unit/control.test.ts +226 -0
- package/templates/shared/tests/unit/cost-calculator.test.ts +141 -0
- package/templates/shared/tests/unit/economics.test.ts +365 -0
- package/templates/shared/tests/unit/telemetry-sampling.test.ts +401 -0
- package/templates/standard/dashboard/src/components/errors/PriorityBadge.astro +27 -0
- package/templates/standard/dashboard/src/components/infrastructure/HealthchecksStatus.tsx +293 -0
- package/templates/standard/dashboard/src/components/infrastructure/InfrastructureTabs.tsx +268 -0
- package/templates/standard/dashboard/src/components/reports/CircuitBreakerReport.tsx +474 -0
- package/templates/standard/dashboard/src/components/reports/CostTrendsReport.tsx +229 -0
- package/templates/standard/dashboard/src/components/reports/ErrorTrendsReport.tsx +244 -0
- package/templates/standard/dashboard/src/components/reports/ProjectHealthTable.tsx +251 -0
- package/templates/standard/dashboard/src/components/reports/WarningDigestsTable.tsx +298 -0
- package/templates/standard/dashboard/src/components/usage/react/UsageTable.tsx +385 -0
- package/templates/standard/dashboard/src/components/usage/unified/CircuitBreakerEvents.tsx +305 -0
- package/templates/standard/dashboard/src/components/usage/unified/FeatureBudgets.tsx +472 -0
- package/templates/standard/dashboard/src/lib/errors/api.ts +84 -0
- package/templates/standard/dashboard/src/lib/errors/types.ts +75 -0
- package/templates/standard/dashboard/src/lib/infrastructure/api.ts +141 -0
- package/templates/standard/dashboard/src/lib/infrastructure/gatus.ts.hbs +112 -0
- package/templates/standard/dashboard/src/lib/services/proxy/index.ts +20 -0
- package/templates/standard/dashboard/src/lib/services/proxy/proxy.ts +244 -0
- package/templates/standard/dashboard/src/lib/services/proxy/types.ts +81 -0
- package/templates/standard/dashboard/src/pages/analytics.astro +64 -0
- package/templates/standard/dashboard/src/pages/api/infrastructure/alerts.ts +85 -0
- package/templates/standard/dashboard/src/pages/api/infrastructure/healthchecks/[id]/flips.ts +110 -0
- package/templates/standard/dashboard/src/pages/api/infrastructure/healthchecks.ts +101 -0
- package/templates/standard/dashboard/src/pages/api/infrastructure/uptime/[id]/response-times.ts +121 -0
- package/templates/standard/dashboard/src/pages/api/infrastructure/uptime.ts +89 -0
- package/templates/standard/dashboard/src/pages/api/test/service-auth.ts +178 -0
- package/templates/standard/tests/integration/connectors.test.ts +241 -0
- package/templates/standard/tests/integration/github-monitor.test.ts +143 -0
- package/templates/standard/tests/integration/ingestion.test.ts +211 -0
- package/templates/standard/tests/integration/platform-sentinel.test.ts +497 -0
- package/templates/standard/tests/unit/cloudflare/alerting.test.ts +480 -0
- package/templates/standard/tests/unit/error-collector/dedup.test.ts +350 -0
- package/templates/standard/tests/unit/error-collector/github.test.ts +187 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* FilterBar Component
|
|
4
|
+
*
|
|
5
|
+
* Unified filter bar for the Usage Dashboard. Composes micro-components
|
|
6
|
+
* that each subscribe to nanostores independently. Layout container only.
|
|
7
|
+
*
|
|
8
|
+
* Part of task-21: Usage Dashboard Refactor Phase 3 - Integrated Filter Bar
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```astro
|
|
12
|
+
* <FilterBar
|
|
13
|
+
* initialPeriod={period}
|
|
14
|
+
* initialProject={project}
|
|
15
|
+
* initialStartDate={startDate}
|
|
16
|
+
* initialEndDate={endDate}
|
|
17
|
+
* />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import PeriodButtons from './filters/PeriodButtons.astro';
|
|
22
|
+
import InlineDateRange from './filters/InlineDateRange.astro';
|
|
23
|
+
import ProjectSelect from './filters/ProjectSelect.astro';
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
/** Initial period from URL query params */
|
|
27
|
+
initialPeriod?: string;
|
|
28
|
+
/** Initial project from URL query params */
|
|
29
|
+
initialProject?: string;
|
|
30
|
+
/** Initial custom start date (YYYY-MM-DD) */
|
|
31
|
+
initialStartDate?: string;
|
|
32
|
+
/** Initial custom end date (YYYY-MM-DD) */
|
|
33
|
+
initialEndDate?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
initialPeriod = '30d',
|
|
38
|
+
initialProject = 'all',
|
|
39
|
+
initialStartDate = '',
|
|
40
|
+
initialEndDate = '',
|
|
41
|
+
} = Astro.props;
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<div class="filter-bar" data-component="filter-bar">
|
|
45
|
+
<div class="filter-bar-primary">
|
|
46
|
+
<PeriodButtons initialPeriod={initialPeriod} />
|
|
47
|
+
<InlineDateRange initialStart={initialStartDate} initialEnd={initialEndDate} maxDays={90} />
|
|
48
|
+
<ProjectSelect initialProject={initialProject} />
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<!-- Loading indicator (shown during data fetch) -->
|
|
52
|
+
<div class="filter-bar-status">
|
|
53
|
+
<div class="loading-indicator" id="filter-loading" style="display: none;">
|
|
54
|
+
<svg
|
|
55
|
+
class="spinner"
|
|
56
|
+
width="16"
|
|
57
|
+
height="16"
|
|
58
|
+
viewBox="0 0 16 16"
|
|
59
|
+
fill="none"
|
|
60
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
61
|
+
>
|
|
62
|
+
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="2" stroke-opacity="0.25"
|
|
63
|
+
></circle>
|
|
64
|
+
<path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
|
65
|
+
></path>
|
|
66
|
+
</svg>
|
|
67
|
+
<span class="loading-text">Loading...</span>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
.filter-bar {
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: space-between;
|
|
77
|
+
gap: 1rem;
|
|
78
|
+
padding: 0.75rem 1rem;
|
|
79
|
+
background-color: var(--usage-bg-secondary);
|
|
80
|
+
border: 1px solid var(--usage-border-primary);
|
|
81
|
+
border-radius: 0.75rem;
|
|
82
|
+
flex-wrap: wrap;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.filter-bar-primary {
|
|
86
|
+
display: flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
gap: 1rem;
|
|
89
|
+
flex-wrap: wrap;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.filter-bar-status {
|
|
93
|
+
display: flex;
|
|
94
|
+
align-items: center;
|
|
95
|
+
gap: 0.75rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.loading-indicator {
|
|
99
|
+
display: flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
gap: 0.375rem;
|
|
102
|
+
font-size: 0.75rem;
|
|
103
|
+
color: var(--usage-text-secondary);
|
|
104
|
+
animation: fadeIn 0.2s ease;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@keyframes fadeIn {
|
|
108
|
+
from {
|
|
109
|
+
opacity: 0;
|
|
110
|
+
}
|
|
111
|
+
to {
|
|
112
|
+
opacity: 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.spinner {
|
|
117
|
+
animation: spin 0.8s linear infinite;
|
|
118
|
+
color: var(--usage-accent-primary);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@keyframes spin {
|
|
122
|
+
to {
|
|
123
|
+
transform: rotate(360deg);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.loading-text {
|
|
128
|
+
font-weight: 500;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Responsive: stack vertically on mobile */
|
|
132
|
+
@media (max-width: 768px) {
|
|
133
|
+
.filter-bar {
|
|
134
|
+
flex-direction: column;
|
|
135
|
+
align-items: stretch;
|
|
136
|
+
gap: 0.75rem;
|
|
137
|
+
padding: 0.5rem 0.75rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.filter-bar-primary {
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
align-items: stretch;
|
|
143
|
+
gap: 0.75rem;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.filter-bar-status {
|
|
147
|
+
justify-content: center;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Tablet: partial wrap */
|
|
152
|
+
@media (min-width: 769px) and (max-width: 1024px) {
|
|
153
|
+
.filter-bar-primary {
|
|
154
|
+
gap: 0.75rem;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
</style>
|
|
158
|
+
|
|
159
|
+
<script>
|
|
160
|
+
import { $isLoading } from './state/usageStore';
|
|
161
|
+
import { syncFromURL, initSubscriptions } from './state/usageActions';
|
|
162
|
+
|
|
163
|
+
function initFilterBar(): void {
|
|
164
|
+
const container = document.querySelector('[data-component="filter-bar"]');
|
|
165
|
+
if (!container) return;
|
|
166
|
+
|
|
167
|
+
const loadingIndicator = container.querySelector<HTMLElement>('#filter-loading');
|
|
168
|
+
|
|
169
|
+
// Show/hide loading indicator
|
|
170
|
+
if (loadingIndicator) {
|
|
171
|
+
$isLoading.subscribe((isLoading) => {
|
|
172
|
+
loadingIndicator.style.display = isLoading ? 'flex' : 'none';
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Sync store from URL and initialise subscriptions
|
|
177
|
+
syncFromURL();
|
|
178
|
+
initSubscriptions();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Initialize on DOM ready
|
|
182
|
+
if (document.readyState === 'loading') {
|
|
183
|
+
document.addEventListener('DOMContentLoaded', initFilterBar);
|
|
184
|
+
} else {
|
|
185
|
+
initFilterBar();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Re-initialize on Astro page transitions
|
|
189
|
+
document.addEventListener('astro:page-load', initFilterBar);
|
|
190
|
+
</script>
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* FilterToggles Component (task-17.13)
|
|
4
|
+
*
|
|
5
|
+
* Quick filter toggles for common use cases.
|
|
6
|
+
* - "Only changed" - Show resources with significant changes
|
|
7
|
+
* - "Non-zero cost only" - Hide zero-cost resources
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface Props {
|
|
11
|
+
onlyChanged?: boolean;
|
|
12
|
+
nonZeroCost?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { onlyChanged = false, nonZeroCost = false } = Astro.props;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<div class="filter-toggles" data-component="filter-toggles">
|
|
19
|
+
<button
|
|
20
|
+
type="button"
|
|
21
|
+
class:list={['toggle-button', onlyChanged && 'active']}
|
|
22
|
+
id="toggle-only-changed"
|
|
23
|
+
aria-pressed={onlyChanged}
|
|
24
|
+
title="Show only resources with significant changes (>5% cost change or NEW)"
|
|
25
|
+
>
|
|
26
|
+
<span class="toggle-icon">Δ</span>
|
|
27
|
+
<span class="toggle-label">Only Changed</span>
|
|
28
|
+
</button>
|
|
29
|
+
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
class:list={['toggle-button', nonZeroCost && 'active']}
|
|
33
|
+
id="toggle-non-zero-cost"
|
|
34
|
+
aria-pressed={nonZeroCost}
|
|
35
|
+
title="Hide resources with zero cost"
|
|
36
|
+
>
|
|
37
|
+
<span class="toggle-icon">$</span>
|
|
38
|
+
<span class="toggle-label">Non-zero Cost</span>
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.filter-toggles {
|
|
44
|
+
display: flex;
|
|
45
|
+
gap: 0.5rem;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.toggle-button {
|
|
50
|
+
display: inline-flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: 0.375rem;
|
|
53
|
+
padding: 0.375rem 0.75rem;
|
|
54
|
+
border: 1px solid #d1d5db;
|
|
55
|
+
border-radius: 9999px;
|
|
56
|
+
background-color: white;
|
|
57
|
+
color: #6b7280;
|
|
58
|
+
font-size: 0.75rem;
|
|
59
|
+
font-weight: 500;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
transition: all 0.15s ease;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:global(.dark) .toggle-button {
|
|
66
|
+
background-color: #1f2937;
|
|
67
|
+
border-color: #374151;
|
|
68
|
+
color: #9ca3af;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.toggle-button:hover {
|
|
72
|
+
border-color: #9ca3af;
|
|
73
|
+
background-color: #f9fafb;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
:global(.dark) .toggle-button:hover {
|
|
77
|
+
border-color: #4b5563;
|
|
78
|
+
background-color: #111827;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.toggle-button.active {
|
|
82
|
+
border-color: #3b82f6;
|
|
83
|
+
background-color: #eff6ff;
|
|
84
|
+
color: #1d4ed8;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:global(.dark) .toggle-button.active {
|
|
88
|
+
border-color: #3b82f6;
|
|
89
|
+
background-color: #1e3a8a40;
|
|
90
|
+
color: #93c5fd;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.toggle-button:focus {
|
|
94
|
+
outline: none;
|
|
95
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.toggle-icon {
|
|
99
|
+
font-size: 0.75rem;
|
|
100
|
+
font-weight: 700;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.toggle-label {
|
|
104
|
+
font-weight: 500;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@media (max-width: 480px) {
|
|
108
|
+
.filter-toggles {
|
|
109
|
+
width: 100%;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.toggle-button {
|
|
113
|
+
flex: 1;
|
|
114
|
+
justify-content: center;
|
|
115
|
+
min-width: 120px;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
</style>
|
|
119
|
+
|
|
120
|
+
<script>
|
|
121
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
122
|
+
const container = document.querySelector('[data-component="filter-toggles"]');
|
|
123
|
+
if (!container) return;
|
|
124
|
+
|
|
125
|
+
const onlyChangedBtn = container.querySelector('#toggle-only-changed') as HTMLButtonElement;
|
|
126
|
+
const nonZeroCostBtn = container.querySelector('#toggle-non-zero-cost') as HTMLButtonElement;
|
|
127
|
+
|
|
128
|
+
function updateUrl(onlyChanged: boolean, nonZeroCost: boolean) {
|
|
129
|
+
const url = new URL(window.location.href);
|
|
130
|
+
|
|
131
|
+
if (onlyChanged) {
|
|
132
|
+
url.searchParams.set('onlyChanged', '1');
|
|
133
|
+
} else {
|
|
134
|
+
url.searchParams.delete('onlyChanged');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (nonZeroCost) {
|
|
138
|
+
url.searchParams.set('nonZeroCost', '1');
|
|
139
|
+
} else {
|
|
140
|
+
url.searchParams.delete('nonZeroCost');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Update URL without reload
|
|
144
|
+
window.history.pushState({}, '', url);
|
|
145
|
+
|
|
146
|
+
// Dispatch custom event for parent to handle
|
|
147
|
+
const event = new CustomEvent('filter-toggle-change', {
|
|
148
|
+
bubbles: true,
|
|
149
|
+
detail: { onlyChanged, nonZeroCost },
|
|
150
|
+
});
|
|
151
|
+
container.dispatchEvent(event);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function getState() {
|
|
155
|
+
return {
|
|
156
|
+
onlyChanged: onlyChangedBtn.classList.contains('active'),
|
|
157
|
+
nonZeroCost: nonZeroCostBtn.classList.contains('active'),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
onlyChangedBtn.addEventListener('click', () => {
|
|
162
|
+
const isActive = onlyChangedBtn.classList.toggle('active');
|
|
163
|
+
onlyChangedBtn.setAttribute('aria-pressed', String(isActive));
|
|
164
|
+
const state = getState();
|
|
165
|
+
updateUrl(state.onlyChanged, state.nonZeroCost);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
nonZeroCostBtn.addEventListener('click', () => {
|
|
169
|
+
const isActive = nonZeroCostBtn.classList.toggle('active');
|
|
170
|
+
nonZeroCostBtn.setAttribute('aria-pressed', String(isActive));
|
|
171
|
+
const state = getState();
|
|
172
|
+
updateUrl(state.onlyChanged, state.nonZeroCost);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
</script>
|