@littlebearapps/platform-admin-sdk 2.1.0 → 2.3.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 +2 -5
- package/dist/check-upgrade.d.ts +29 -0
- package/dist/check-upgrade.js +97 -0
- package/dist/index.js +59 -4
- package/dist/manifest.d.ts +2 -0
- package/dist/scaffold.js +5 -1
- package/dist/templates.d.ts +6 -1
- package/dist/templates.js +141 -3
- package/dist/upgrade.d.ts +1 -0
- package/dist/upgrade.js +21 -2
- 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/FeatureUsageReport.tsx +339 -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/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/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/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/types.ts +283 -0
- package/templates/shared/dashboard/src/components/usage/usage-colors.ts +292 -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-export.test.ts +784 -0
- package/templates/shared/tests/e2e/usage-mobile.test.ts +531 -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/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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Dashboard Design Tokens
|
|
3
|
+
*
|
|
4
|
+
* Theme-aware colour palette and design system values.
|
|
5
|
+
* Uses CSS custom properties with [data-theme="dark"] selector.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const tokens = {
|
|
9
|
+
light: {
|
|
10
|
+
bg: {
|
|
11
|
+
primary: '#ffffff',
|
|
12
|
+
secondary: '#f6f8fa',
|
|
13
|
+
tertiary: '#f0f2f4',
|
|
14
|
+
hover: '#eaeef2',
|
|
15
|
+
},
|
|
16
|
+
text: {
|
|
17
|
+
primary: '#1f2328',
|
|
18
|
+
secondary: '#656d76',
|
|
19
|
+
muted: '#8c959f',
|
|
20
|
+
},
|
|
21
|
+
accent: {
|
|
22
|
+
blue: '#0969da',
|
|
23
|
+
green: '#1a7f37',
|
|
24
|
+
yellow: '#9a6700',
|
|
25
|
+
red: '#cf222e',
|
|
26
|
+
purple: '#8250df',
|
|
27
|
+
},
|
|
28
|
+
border: {
|
|
29
|
+
default: '#d1d9e0',
|
|
30
|
+
hover: '#b3bcc6',
|
|
31
|
+
subtle: '#e8ecef',
|
|
32
|
+
},
|
|
33
|
+
status: {
|
|
34
|
+
ok: '#1a7f37',
|
|
35
|
+
okBg: '#dafbe1',
|
|
36
|
+
warning: '#9a6700',
|
|
37
|
+
warningBg: '#fff8c5',
|
|
38
|
+
critical: '#cf222e',
|
|
39
|
+
criticalBg: '#ffebe9',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
dark: {
|
|
43
|
+
bg: {
|
|
44
|
+
primary: '#0d1117',
|
|
45
|
+
secondary: '#161b22',
|
|
46
|
+
tertiary: '#21262d',
|
|
47
|
+
hover: '#262c36',
|
|
48
|
+
},
|
|
49
|
+
text: {
|
|
50
|
+
primary: '#e6edf3',
|
|
51
|
+
secondary: '#8b949e',
|
|
52
|
+
muted: '#484f58',
|
|
53
|
+
},
|
|
54
|
+
accent: {
|
|
55
|
+
blue: '#58a6ff',
|
|
56
|
+
green: '#3fb950',
|
|
57
|
+
yellow: '#d29922',
|
|
58
|
+
red: '#f85149',
|
|
59
|
+
purple: '#a371f7',
|
|
60
|
+
},
|
|
61
|
+
border: {
|
|
62
|
+
default: '#30363d',
|
|
63
|
+
hover: '#484f58',
|
|
64
|
+
subtle: '#21262d',
|
|
65
|
+
},
|
|
66
|
+
status: {
|
|
67
|
+
ok: '#3fb950',
|
|
68
|
+
okBg: '#1b4721',
|
|
69
|
+
warning: '#d29922',
|
|
70
|
+
warningBg: '#4d3a00',
|
|
71
|
+
critical: '#f85149',
|
|
72
|
+
criticalBg: '#5c1e1e',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
fonts: {
|
|
76
|
+
mono: "'JetBrains Mono', 'SF Mono', 'Fira Code', monospace",
|
|
77
|
+
sans: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
78
|
+
},
|
|
79
|
+
spacing: {
|
|
80
|
+
xs: '0.25rem',
|
|
81
|
+
sm: '0.5rem',
|
|
82
|
+
md: '1rem',
|
|
83
|
+
lg: '1.5rem',
|
|
84
|
+
xl: '2rem',
|
|
85
|
+
'2xl': '3rem',
|
|
86
|
+
},
|
|
87
|
+
radius: {
|
|
88
|
+
sm: '4px',
|
|
89
|
+
md: '6px',
|
|
90
|
+
lg: '8px',
|
|
91
|
+
xl: '12px',
|
|
92
|
+
},
|
|
93
|
+
shadows: {
|
|
94
|
+
sm: '0 1px 2px rgba(0, 0, 0, 0.05)',
|
|
95
|
+
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1)',
|
|
96
|
+
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1)',
|
|
97
|
+
},
|
|
98
|
+
transitions: {
|
|
99
|
+
fast: '150ms ease',
|
|
100
|
+
normal: '200ms ease',
|
|
101
|
+
slow: '300ms ease',
|
|
102
|
+
},
|
|
103
|
+
} as const;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Generate CSS custom properties for injection into stylesheets.
|
|
107
|
+
* Call this in the page's <style> block or use inline.
|
|
108
|
+
*/
|
|
109
|
+
export function generateCSSVariables(): string {
|
|
110
|
+
return `
|
|
111
|
+
:root {
|
|
112
|
+
/* Light theme (default) */
|
|
113
|
+
--usage-bg-primary: ${tokens.light.bg.primary};
|
|
114
|
+
--usage-bg-secondary: ${tokens.light.bg.secondary};
|
|
115
|
+
--usage-bg-tertiary: ${tokens.light.bg.tertiary};
|
|
116
|
+
--usage-bg-hover: ${tokens.light.bg.hover};
|
|
117
|
+
|
|
118
|
+
--usage-text-primary: ${tokens.light.text.primary};
|
|
119
|
+
--usage-text-secondary: ${tokens.light.text.secondary};
|
|
120
|
+
--usage-text-muted: ${tokens.light.text.muted};
|
|
121
|
+
|
|
122
|
+
--usage-accent-blue: ${tokens.light.accent.blue};
|
|
123
|
+
--usage-accent-green: ${tokens.light.accent.green};
|
|
124
|
+
--usage-accent-yellow: ${tokens.light.accent.yellow};
|
|
125
|
+
--usage-accent-red: ${tokens.light.accent.red};
|
|
126
|
+
--usage-accent-purple: ${tokens.light.accent.purple};
|
|
127
|
+
|
|
128
|
+
--usage-border-default: ${tokens.light.border.default};
|
|
129
|
+
--usage-border-hover: ${tokens.light.border.hover};
|
|
130
|
+
--usage-border-subtle: ${tokens.light.border.subtle};
|
|
131
|
+
|
|
132
|
+
--usage-status-ok: ${tokens.light.status.ok};
|
|
133
|
+
--usage-status-ok-bg: ${tokens.light.status.okBg};
|
|
134
|
+
--usage-status-warning: ${tokens.light.status.warning};
|
|
135
|
+
--usage-status-warning-bg: ${tokens.light.status.warningBg};
|
|
136
|
+
--usage-status-critical: ${tokens.light.status.critical};
|
|
137
|
+
--usage-status-critical-bg: ${tokens.light.status.criticalBg};
|
|
138
|
+
|
|
139
|
+
--usage-font-mono: ${tokens.fonts.mono};
|
|
140
|
+
--usage-font-sans: ${tokens.fonts.sans};
|
|
141
|
+
|
|
142
|
+
--usage-radius-sm: ${tokens.radius.sm};
|
|
143
|
+
--usage-radius-md: ${tokens.radius.md};
|
|
144
|
+
--usage-radius-lg: ${tokens.radius.lg};
|
|
145
|
+
--usage-radius-xl: ${tokens.radius.xl};
|
|
146
|
+
|
|
147
|
+
--usage-shadow-sm: ${tokens.shadows.sm};
|
|
148
|
+
--usage-shadow-md: ${tokens.shadows.md};
|
|
149
|
+
--usage-shadow-lg: ${tokens.shadows.lg};
|
|
150
|
+
|
|
151
|
+
--usage-transition-fast: ${tokens.transitions.fast};
|
|
152
|
+
--usage-transition-normal: ${tokens.transitions.normal};
|
|
153
|
+
--usage-transition-slow: ${tokens.transitions.slow};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
[data-theme="dark"] {
|
|
157
|
+
--usage-bg-primary: ${tokens.dark.bg.primary};
|
|
158
|
+
--usage-bg-secondary: ${tokens.dark.bg.secondary};
|
|
159
|
+
--usage-bg-tertiary: ${tokens.dark.bg.tertiary};
|
|
160
|
+
--usage-bg-hover: ${tokens.dark.bg.hover};
|
|
161
|
+
|
|
162
|
+
--usage-text-primary: ${tokens.dark.text.primary};
|
|
163
|
+
--usage-text-secondary: ${tokens.dark.text.secondary};
|
|
164
|
+
--usage-text-muted: ${tokens.dark.text.muted};
|
|
165
|
+
|
|
166
|
+
--usage-accent-blue: ${tokens.dark.accent.blue};
|
|
167
|
+
--usage-accent-green: ${tokens.dark.accent.green};
|
|
168
|
+
--usage-accent-yellow: ${tokens.dark.accent.yellow};
|
|
169
|
+
--usage-accent-red: ${tokens.dark.accent.red};
|
|
170
|
+
--usage-accent-purple: ${tokens.dark.accent.purple};
|
|
171
|
+
|
|
172
|
+
--usage-border-default: ${tokens.dark.border.default};
|
|
173
|
+
--usage-border-hover: ${tokens.dark.border.hover};
|
|
174
|
+
--usage-border-subtle: ${tokens.dark.border.subtle};
|
|
175
|
+
|
|
176
|
+
--usage-status-ok: ${tokens.dark.status.ok};
|
|
177
|
+
--usage-status-ok-bg: ${tokens.dark.status.okBg};
|
|
178
|
+
--usage-status-warning: ${tokens.dark.status.warning};
|
|
179
|
+
--usage-status-warning-bg: ${tokens.dark.status.warningBg};
|
|
180
|
+
--usage-status-critical: ${tokens.dark.status.critical};
|
|
181
|
+
--usage-status-critical-bg: ${tokens.dark.status.criticalBg};
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type ThemeMode = 'light' | 'dark';
|
|
187
|
+
export type TokenColors = typeof tokens.light;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* InlineDateRange Component
|
|
4
|
+
*
|
|
5
|
+
* Inline date inputs shown when period === 'custom'.
|
|
6
|
+
* Uses native <input type="date"> for accessibility and mobile support.
|
|
7
|
+
* Enforces max 90 day range with user feedback.
|
|
8
|
+
*
|
|
9
|
+
* Part of task-21.2: Add inline Custom date inputs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** Initial start date (YYYY-MM-DD) */
|
|
14
|
+
initialStart?: string;
|
|
15
|
+
/** Initial end date (YYYY-MM-DD) */
|
|
16
|
+
initialEnd?: string;
|
|
17
|
+
/** Max days allowed in range */
|
|
18
|
+
maxDays?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { initialStart = '', initialEnd = '', maxDays = 90 } = Astro.props;
|
|
22
|
+
|
|
23
|
+
// Calculate default dates (last 7 days) if not provided
|
|
24
|
+
const today = new Date();
|
|
25
|
+
const defaultEnd = today.toISOString().split('T')[0];
|
|
26
|
+
const weekAgo = new Date(today);
|
|
27
|
+
weekAgo.setDate(weekAgo.getDate() - 7);
|
|
28
|
+
const defaultStart = weekAgo.toISOString().split('T')[0];
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
<div
|
|
32
|
+
class="inline-date-range"
|
|
33
|
+
data-component="inline-date-range"
|
|
34
|
+
data-max-days={maxDays}
|
|
35
|
+
style="display: none;"
|
|
36
|
+
>
|
|
37
|
+
<div class="date-inputs">
|
|
38
|
+
<div class="date-field">
|
|
39
|
+
<label for="custom-start-date" class="date-label">From</label>
|
|
40
|
+
<input
|
|
41
|
+
type="date"
|
|
42
|
+
id="custom-start-date"
|
|
43
|
+
class="date-input"
|
|
44
|
+
value={initialStart || defaultStart}
|
|
45
|
+
max={defaultEnd}
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
<span class="date-separator">-</span>
|
|
49
|
+
<div class="date-field">
|
|
50
|
+
<label for="custom-end-date" class="date-label">To</label>
|
|
51
|
+
<input
|
|
52
|
+
type="date"
|
|
53
|
+
id="custom-end-date"
|
|
54
|
+
class="date-input"
|
|
55
|
+
value={initialEnd || defaultEnd}
|
|
56
|
+
max={defaultEnd}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="date-error" id="date-range-error" style="display: none;"></div>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<style>
|
|
64
|
+
.inline-date-range {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: 0.25rem;
|
|
68
|
+
animation: slideIn 0.15s ease-out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@keyframes slideIn {
|
|
72
|
+
from {
|
|
73
|
+
opacity: 0;
|
|
74
|
+
transform: translateX(-8px);
|
|
75
|
+
}
|
|
76
|
+
to {
|
|
77
|
+
opacity: 1;
|
|
78
|
+
transform: translateX(0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.date-inputs {
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
gap: 0.5rem;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.date-field {
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
gap: 0.125rem;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.date-label {
|
|
95
|
+
font-size: 0.625rem;
|
|
96
|
+
font-weight: 600;
|
|
97
|
+
color: var(--usage-text-muted);
|
|
98
|
+
text-transform: uppercase;
|
|
99
|
+
letter-spacing: 0.05em;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.date-input {
|
|
103
|
+
padding: 0.375rem 0.5rem;
|
|
104
|
+
font-size: 0.8125rem;
|
|
105
|
+
font-family: inherit;
|
|
106
|
+
color: var(--usage-text-primary);
|
|
107
|
+
background-color: var(--usage-bg-primary);
|
|
108
|
+
border: 1px solid var(--usage-border-primary);
|
|
109
|
+
border-radius: 0.375rem;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
transition:
|
|
112
|
+
border-color 0.15s ease,
|
|
113
|
+
box-shadow 0.15s ease;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.date-input:hover {
|
|
117
|
+
border-color: var(--usage-border-hover);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.date-input:focus {
|
|
121
|
+
outline: none;
|
|
122
|
+
border-color: var(--usage-accent-primary);
|
|
123
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--usage-accent-primary) 25%, transparent);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.date-input::-webkit-calendar-picker-indicator {
|
|
127
|
+
filter: var(--usage-calendar-icon-filter, none);
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.date-separator {
|
|
132
|
+
color: var(--usage-text-muted);
|
|
133
|
+
font-size: 0.875rem;
|
|
134
|
+
padding-top: 1rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.date-error {
|
|
138
|
+
font-size: 0.75rem;
|
|
139
|
+
color: var(--usage-error-text, #dc2626);
|
|
140
|
+
padding: 0.25rem 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (max-width: 480px) {
|
|
144
|
+
.date-inputs {
|
|
145
|
+
flex-direction: column;
|
|
146
|
+
align-items: stretch;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.date-separator {
|
|
150
|
+
display: none;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.date-field {
|
|
154
|
+
flex-direction: row;
|
|
155
|
+
align-items: center;
|
|
156
|
+
gap: 0.5rem;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.date-label {
|
|
160
|
+
min-width: 2.5rem;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.date-input {
|
|
164
|
+
flex: 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Dark mode overrides */
|
|
169
|
+
:global([data-theme='dark']) .date-label,
|
|
170
|
+
:global(.dark) .date-label {
|
|
171
|
+
color: #8b949e;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
:global([data-theme='dark']) .date-input,
|
|
175
|
+
:global(.dark) .date-input {
|
|
176
|
+
background-color: #161b22;
|
|
177
|
+
border-color: #30363d;
|
|
178
|
+
color: #e6edf3;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
:global([data-theme='dark']) .date-input:hover,
|
|
182
|
+
:global(.dark) .date-input:hover {
|
|
183
|
+
border-color: #484f58;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
:global([data-theme='dark']) .date-input::-webkit-calendar-picker-indicator,
|
|
187
|
+
:global(.dark) .date-input::-webkit-calendar-picker-indicator {
|
|
188
|
+
filter: invert(0.8);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
:global([data-theme='dark']) .date-separator,
|
|
192
|
+
:global(.dark) .date-separator {
|
|
193
|
+
color: #484f58;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
:global([data-theme='dark']) .date-error,
|
|
197
|
+
:global(.dark) .date-error {
|
|
198
|
+
color: #f85149;
|
|
199
|
+
}
|
|
200
|
+
</style>
|
|
201
|
+
|
|
202
|
+
<script>
|
|
203
|
+
import { $period, $customDateRange } from '../state/usageStore';
|
|
204
|
+
import { setCustomDateRange } from '../state/usageActions';
|
|
205
|
+
|
|
206
|
+
function initInlineDateRange(): void {
|
|
207
|
+
const container = document.querySelector<HTMLElement>('[data-component="inline-date-range"]');
|
|
208
|
+
if (!container) return;
|
|
209
|
+
|
|
210
|
+
const startInput = container.querySelector<HTMLInputElement>('#custom-start-date');
|
|
211
|
+
const endInput = container.querySelector<HTMLInputElement>('#custom-end-date');
|
|
212
|
+
const errorEl = container.querySelector<HTMLElement>('#date-range-error');
|
|
213
|
+
const maxDays = parseInt(container.dataset.maxDays || '90', 10);
|
|
214
|
+
|
|
215
|
+
if (!startInput || !endInput || !errorEl) return;
|
|
216
|
+
|
|
217
|
+
// Show/hide based on period
|
|
218
|
+
$period.subscribe((period) => {
|
|
219
|
+
container.style.display = period === 'custom' ? 'flex' : 'none';
|
|
220
|
+
|
|
221
|
+
// Set default dates when switching to custom
|
|
222
|
+
if (period === 'custom') {
|
|
223
|
+
const { start, end } = $customDateRange.get();
|
|
224
|
+
if (!start || !end) {
|
|
225
|
+
// Use current input values as defaults
|
|
226
|
+
setCustomDateRange(startInput.value, endInput.value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Sync inputs with store
|
|
232
|
+
$customDateRange.subscribe(({ start, end }) => {
|
|
233
|
+
if (start && startInput.value !== start) {
|
|
234
|
+
startInput.value = start;
|
|
235
|
+
}
|
|
236
|
+
if (end && endInput.value !== end) {
|
|
237
|
+
endInput.value = end;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Validate date range
|
|
242
|
+
function validateRange(): boolean {
|
|
243
|
+
const start = new Date(startInput.value);
|
|
244
|
+
const end = new Date(endInput.value);
|
|
245
|
+
|
|
246
|
+
// Check if end is after start
|
|
247
|
+
if (end < start) {
|
|
248
|
+
errorEl.textContent = 'End date must be after start date';
|
|
249
|
+
errorEl.style.display = 'block';
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Check max range
|
|
254
|
+
const diffDays = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
|
255
|
+
if (diffDays > maxDays) {
|
|
256
|
+
errorEl.textContent = `Maximum range is ${maxDays} days`;
|
|
257
|
+
errorEl.style.display = 'block';
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
errorEl.style.display = 'none';
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Handle date changes
|
|
266
|
+
function handleDateChange(): void {
|
|
267
|
+
if (validateRange() && startInput.value && endInput.value) {
|
|
268
|
+
setCustomDateRange(startInput.value, endInput.value);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
startInput.addEventListener('change', handleDateChange);
|
|
273
|
+
endInput.addEventListener('change', handleDateChange);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Initialize on DOM ready
|
|
277
|
+
if (document.readyState === 'loading') {
|
|
278
|
+
document.addEventListener('DOMContentLoaded', initInlineDateRange);
|
|
279
|
+
} else {
|
|
280
|
+
initInlineDateRange();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Re-initialize on Astro page transitions
|
|
284
|
+
document.addEventListener('astro:page-load', initInlineDateRange);
|
|
285
|
+
</script>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* PeriodButtons Component
|
|
4
|
+
*
|
|
5
|
+
* Period selection buttons (24h, 7d, 30d, Custom) that use nanostores
|
|
6
|
+
* for reactive state management. No page reload on selection.
|
|
7
|
+
*
|
|
8
|
+
* Part of task-21: Usage Dashboard Refactor Phase 3 - Integrated Filter Bar
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** Initial period from URL (for SSR hydration) */
|
|
13
|
+
initialPeriod?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { initialPeriod = '30d' } = Astro.props;
|
|
17
|
+
|
|
18
|
+
const periods = [
|
|
19
|
+
{ value: '24h', label: '24h' },
|
|
20
|
+
{ value: '7d', label: '7d' },
|
|
21
|
+
{ value: '30d', label: '30d' },
|
|
22
|
+
{ value: 'custom', label: 'Custom' },
|
|
23
|
+
];
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<div class="period-buttons" data-component="period-buttons" data-initial={initialPeriod}>
|
|
27
|
+
<div class="button-group" role="group" aria-label="Select time period">
|
|
28
|
+
{
|
|
29
|
+
periods.map((period) => (
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
class:list={['period-btn', { active: initialPeriod === period.value }]}
|
|
33
|
+
data-period={period.value}
|
|
34
|
+
aria-pressed={initialPeriod === period.value}
|
|
35
|
+
>
|
|
36
|
+
{period.label}
|
|
37
|
+
</button>
|
|
38
|
+
))
|
|
39
|
+
}
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.period-buttons {
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.button-group {
|
|
50
|
+
display: flex;
|
|
51
|
+
background-color: var(--usage-bg-tertiary, #eaeef2);
|
|
52
|
+
border-radius: 0.5rem;
|
|
53
|
+
padding: 0.25rem;
|
|
54
|
+
border: 1px solid var(--usage-border-default, #d0d7de);
|
|
55
|
+
gap: 0.125rem;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.period-btn {
|
|
59
|
+
padding: 0.5rem 0.875rem;
|
|
60
|
+
font-size: 0.8125rem;
|
|
61
|
+
font-weight: 500;
|
|
62
|
+
color: var(--usage-text-secondary, #656d76);
|
|
63
|
+
border: none;
|
|
64
|
+
background: transparent;
|
|
65
|
+
border-radius: 0.375rem;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
transition: all 0.15s ease;
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.period-btn:hover:not(.active) {
|
|
72
|
+
background-color: var(--usage-bg-secondary, #f6f8fa);
|
|
73
|
+
color: var(--usage-text-primary, #1f2328);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.period-btn.active {
|
|
77
|
+
background-color: var(--usage-accent-primary, #2563eb);
|
|
78
|
+
color: white;
|
|
79
|
+
box-shadow: var(--usage-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.period-btn:focus-visible {
|
|
83
|
+
outline: 2px solid var(--usage-accent-primary, #2563eb);
|
|
84
|
+
outline-offset: 2px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@media (max-width: 640px) {
|
|
88
|
+
.period-btn {
|
|
89
|
+
padding: 0.375rem 0.625rem;
|
|
90
|
+
font-size: 0.75rem;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Dark mode overrides */
|
|
95
|
+
:global([data-theme='dark']) .button-group,
|
|
96
|
+
:global(.dark) .button-group {
|
|
97
|
+
background-color: #21262d;
|
|
98
|
+
border-color: #30363d;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
:global([data-theme='dark']) .period-btn,
|
|
102
|
+
:global(.dark) .period-btn {
|
|
103
|
+
color: #8b949e;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
:global([data-theme='dark']) .period-btn:hover:not(.active),
|
|
107
|
+
:global(.dark) .period-btn:hover:not(.active) {
|
|
108
|
+
background-color: #161b22;
|
|
109
|
+
color: #e6edf3;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
:global([data-theme='dark']) .period-btn.active,
|
|
113
|
+
:global(.dark) .period-btn.active {
|
|
114
|
+
background-color: #58a6ff;
|
|
115
|
+
color: white;
|
|
116
|
+
}
|
|
117
|
+
</style>
|
|
118
|
+
|
|
119
|
+
<script>
|
|
120
|
+
import { $period, type Period } from '../state/usageStore';
|
|
121
|
+
|
|
122
|
+
function initPeriodButtons(): void {
|
|
123
|
+
const container = document.querySelector('[data-component="period-buttons"]');
|
|
124
|
+
if (!container) return;
|
|
125
|
+
|
|
126
|
+
const buttons = container.querySelectorAll<HTMLButtonElement>('.period-btn');
|
|
127
|
+
|
|
128
|
+
// Handle button clicks
|
|
129
|
+
buttons.forEach((btn) => {
|
|
130
|
+
btn.addEventListener('click', () => {
|
|
131
|
+
const period = btn.dataset.period as Period;
|
|
132
|
+
if (period) {
|
|
133
|
+
$period.set(period);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Subscribe to store changes and update UI
|
|
139
|
+
$period.subscribe((period) => {
|
|
140
|
+
buttons.forEach((btn) => {
|
|
141
|
+
const isActive = btn.dataset.period === period;
|
|
142
|
+
btn.classList.toggle('active', isActive);
|
|
143
|
+
btn.setAttribute('aria-pressed', String(isActive));
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Initialize on DOM ready
|
|
149
|
+
if (document.readyState === 'loading') {
|
|
150
|
+
document.addEventListener('DOMContentLoaded', initPeriodButtons);
|
|
151
|
+
} else {
|
|
152
|
+
initPeriodButtons();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Re-initialize on Astro page transitions
|
|
156
|
+
document.addEventListener('astro:page-load', initPeriodButtons);
|
|
157
|
+
</script>
|