@actionexec/dashboards 0.1.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 ADDED
@@ -0,0 +1,51 @@
1
+ # @actionexec/dashboards
2
+
3
+ Biblioteca React para consumo de dashboards servidos pela API `action-data`.
4
+ Exporta o componente top-level `<Dashboard>`, renderizadores de widgets individuais,
5
+ tipos e utilitarios de paleta.
6
+
7
+ ## Instalacao
8
+
9
+ ```bash
10
+ npm install @actionexec/dashboards
11
+ ```
12
+
13
+ Peer dependencies: `react`, `react-dom`, `recharts`, `react-datepicker`.
14
+
15
+ ## Uso basico
16
+
17
+ ```tsx
18
+ import { Dashboard } from '@actionexec/dashboards';
19
+ import '@actionexec/dashboards/styles.css';
20
+
21
+ function App() {
22
+ return (
23
+ <Dashboard
24
+ apiUrl="https://action.example.com/api"
25
+ token="token-de-acesso"
26
+ />
27
+ );
28
+ }
29
+ ```
30
+
31
+ ## Fetcher customizado (auth proprio)
32
+
33
+ ```tsx
34
+ import { Dashboard, type DashboardFetcher } from '@actionexec/dashboards';
35
+
36
+ const fetcher: DashboardFetcher = {
37
+ layout: async () => (await myClient.get('/dashboards/layout')).data,
38
+ render: async (params) => (await myClient.get('/dashboards/render', { params })).data,
39
+ };
40
+
41
+ <Dashboard fetcher={fetcher} />
42
+ ```
43
+
44
+ ## API publica
45
+
46
+ - `<Dashboard>` — orquestrador completo (token + fetcher)
47
+ - `<WidgetRenderer>` — dispatch por tipo (consumo avancado)
48
+ - Widgets individuais: `KPIWidget`, `GaugeWidget`, `ChartWidget`, `FilterWidget`, `VariableWidget`, `ColorPaletteWidget`
49
+ - `<ColorPaletteSelector>` — seletor de paletas (presets + custom)
50
+ - Utils: `getPaletteCssVars`, `getSeries`, `ensurePaletteShape`, `PALETTES`
51
+ - Tipos: `WidgetDefinition`, `LayoutConfig`, `RenderResponse`, configs por tipo, etc.
@@ -0,0 +1,20 @@
1
+ import type { DashboardFetcher } from './api/fetcher';
2
+ type AuthProps = {
3
+ apiUrl: string;
4
+ token: string;
5
+ fetcher?: never;
6
+ } | {
7
+ fetcher: DashboardFetcher;
8
+ apiUrl?: never;
9
+ token?: never;
10
+ };
11
+ type DashboardProps = AuthProps & {
12
+ /** Altura de cada linha do grid em pixels. Default 40. */
13
+ rowHeight?: number;
14
+ /** Gap entre widgets em pixels. Default 6. */
15
+ gridGap?: number;
16
+ /** Renderer customizado para cada widget (avancado). */
17
+ className?: string;
18
+ };
19
+ export declare function Dashboard(props: DashboardProps): import("react/jsx-runtime").JSX.Element;
20
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { LayoutResponse, RenderResponse } from '../types';
2
+ export interface DashboardFetcher {
3
+ /** Retorna estrutura do dashboard (widgets, paleta, grid, date bounds). */
4
+ layout(): Promise<LayoutResponse>;
5
+ /** Retorna dados computados aplicando filtros/variaveis via query params. */
6
+ render(params?: Record<string, string>): Promise<RenderResponse>;
7
+ }
8
+ export declare class ApiError extends Error {
9
+ status?: number | undefined;
10
+ payload?: unknown | undefined;
11
+ constructor(message: string, status?: number | undefined, payload?: unknown | undefined);
12
+ }
13
+ interface TokenFetcherOptions {
14
+ /** URL base da API (ex: "https://action.example.com/api"). */
15
+ apiUrl: string;
16
+ /** Token de acesso do dashboard (Bearer). */
17
+ token: string;
18
+ /** Fetch customizado (default: globalThis.fetch). */
19
+ fetch?: typeof fetch;
20
+ /** Prefixo dos endpoints (default: "/external/dashboards"). */
21
+ endpointPrefix?: string;
22
+ }
23
+ /** Cria um fetcher baseado em token Bearer, consumindo /external/dashboards. */
24
+ export declare function createTokenFetcher(options: TokenFetcherOptions): DashboardFetcher;
25
+ export {};
@@ -0,0 +1,9 @@
1
+ interface Props {
2
+ selected?: string[];
3
+ onSelect: (colors: string[]) => void;
4
+ customMode?: boolean;
5
+ onCustomModeChange?: (custom: boolean) => void;
6
+ disabled?: boolean;
7
+ }
8
+ export declare function ColorPaletteSelector({ selected, onSelect, customMode, onCustomModeChange, disabled, }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,18 @@
1
+ import 'react-datepicker/dist/react-datepicker.css';
2
+ export declare function isoToDate(iso?: string | null): Date | null;
3
+ export declare function dateToIso(date?: Date | null): string;
4
+ interface Props {
5
+ value: string;
6
+ onChange: (iso: string) => void;
7
+ minIso?: string | null;
8
+ maxIso?: string | null;
9
+ placeholder?: string;
10
+ selectsStart?: boolean;
11
+ selectsEnd?: boolean;
12
+ startIso?: string | null;
13
+ endIso?: string | null;
14
+ className?: string;
15
+ disabled?: boolean;
16
+ }
17
+ export declare function DashboardDatePicker({ value, onChange, minIso, maxIso, placeholder, selectsStart, selectsEnd, startIso, endIso, className, disabled, }: Props): import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { DashboardFetcher } from '../api/fetcher';
2
+ import type { LayoutResponse, RenderResponse } from '../types';
3
+ export interface UseDashboardDataResult {
4
+ layout: LayoutResponse | null;
5
+ renderData: RenderResponse | null;
6
+ loading: boolean;
7
+ error: string | null;
8
+ /** Filtros selecionados (formato string por widget — date_range como "start|end"). */
9
+ filters: Record<string, string>;
10
+ /** Overrides de variaveis por widget. */
11
+ variables: Record<string, number>;
12
+ /** Paleta efetiva (override local substitui a do layout). */
13
+ palette: string[];
14
+ setFilter(widgetId: string, value: string): void;
15
+ setVariable(widgetId: string, value: number): void;
16
+ setPalette(colors: string[]): void;
17
+ }
18
+ export declare function useDashboardData(fetcher: DashboardFetcher): UseDashboardDataResult;
@@ -0,0 +1,21 @@
1
+ import './styles/index.css';
2
+ export { Dashboard } from './Dashboard';
3
+ export { WidgetRenderer } from './widgets/WidgetRenderer';
4
+ export { KPIWidget } from './widgets/KPIWidget';
5
+ export { GaugeWidget } from './widgets/GaugeWidget';
6
+ export { ChartWidget } from './widgets/ChartWidget';
7
+ export { FilterWidget } from './widgets/FilterWidget';
8
+ export { VariableWidget } from './widgets/VariableWidget';
9
+ export { ColorPaletteWidget } from './widgets/ColorPaletteWidget';
10
+ export { ColorPaletteSelector } from './components/ColorPaletteSelector';
11
+ export { DashboardDatePicker, isoToDate, dateToIso } from './components/DashboardDatePicker';
12
+ export { useDashboardData } from './hooks/useDashboardData';
13
+ export type { UseDashboardDataResult } from './hooks/useDashboardData';
14
+ export { createTokenFetcher, ApiError } from './api/fetcher';
15
+ export type { DashboardFetcher } from './api/fetcher';
16
+ export { PALETTES, DEFAULT_PALETTE as DEFAULT_PALETTE_KEY, DEFAULT_PALETTE_COLORS, SLOT_INDEX, SLOT_LABELS, SERIES_COUNT, TOTAL_SLOTS, ensurePaletteShape, getSeries, getPaletteCssVars, } from './palettes';
17
+ export type { Palette, PaletteKey } from './palettes';
18
+ export { MONTH_NAMES_SHORT, MONTH_NAMES_FULL, getFullYearRange, getMonthRange, getWeekRange, getISOWeek, getWeeksInMonth, getMonthWeeks, parseYearFromRange, parseMonthFromRange, parseWeekFromRange, parseMonthWeekFromRange, getYearRange, } from './utils/date';
19
+ export type { MonthWeek } from './utils/date';
20
+ export type { AggregationType, ComparisonType, FilterType, WidgetType, DataWidgetType, ControlWidgetType, ChartType, FormatType, DateFilterMode, Granularity, FilterDefinition, TargetDefinition, GridPosition, ComparisonConfig, AggregationStep, ColumnExpressionTerm, KpiOperand, KpiTerm, ChartSeriesConfig, ChartAxisConfig, KpiCardConfig, GaugeConfig, ChartConfig, FilterConfig, VariableConfig, PaletteConfig, AnyWidgetConfig, WidgetDefinition, WidgetConfigOf, DashboardLayout, FilterValuesResponse, RenderResponse, LayoutResponse, } from './types';
21
+ export { DEFAULT_PALETTE, DEFAULT_GRID_COLUMNS, DEFAULT_GRID_ROWS, EMPTY_LAYOUT, WIDGET_TYPE_LABELS, DATA_WIDGET_TYPES, CONTROL_WIDGET_TYPES, CONTROL_WIDGET_SET, AGGREGATION_LABELS, FORMAT_LABELS, NUMERIC_FORMAT_OPTIONS, COMPARISON_LABELS, CHART_TYPE_LABELS, FILTER_TYPE_LABELS, DEFAULT_GRID, DEFAULT_CONFIG, } from './types';