Overview
Widget server actions handle CRUD operations for dashboard widgets, including creation, updates, deletion, reordering, and data retrieval for widget rendering.createWidget
Creates a new widget and adds it to the project’s widget order.Parameters
Widget creation data following Prisma schema
ID of the project this widget belongs to
Widget type (e.g., “chart”, “table”, “metric”)Note: Type and subtype are automatically normalized via
extractWidgetTypeInfoWidget subtype (e.g., “bar”, “line”, “pie” for charts)
Widget title displayed in the dashboard
Widget configuration object containing:
- Chart settings (axes, colors, legends)
- Data source configuration
- Display options
- Query parameters
Response
Returns the createdWidget object with all fields populated.
Unique widget identifier
Parent project ID
Normalized widget type
Normalized widget subtype
Widget title
Widget configuration object
Creation timestamp
Last update timestamp
Behavior
- Type normalization: Automatically normalizes
typeandsubtypeusingextractWidgetTypeInfo - Order management: Automatically appends widget ID to project’s
orderedWidgetIdsarray - Transaction safety: Widget creation and order update occur in sequence
Example
updateWidget
Updates an existing widget’s properties and configuration.Parameters
ID of the widget to update
Response
Returns the updatedWidget object.
Behavior
- Type normalization: Automatically normalizes
typeandsubtype - Config replacement: Configs are replaced entirely, not merged
- Partial updates: Only provided fields are updated
Example
UpsertWidget
Creates a new widget or updates an existing one based on whether awidgetId is provided.
Parameters
Widget data (will be cast to
WidgetCreateInput or WidgetUpdateInput)Widget ID (if updating). Omit to create a new widget.
Response
Returns the created or updatedWidget object.
Example
upsertWidgetAction
Server action wrapper forUpsertWidget (marked with "use server").
Parameters
Same asUpsertWidget.
Response
Returns the created or updatedWidget object.
Example
Use
upsertWidgetAction in client components. Use UpsertWidget directly in server-side code.getWidgetById
Retrieves a single widget by its ID.Parameters
ID of the widget to retrieve
Response
Returns aWidget object if found, or null if the widget doesn’t exist.
Example
deleteWidget
Deletes a widget and removes it from the project’s widget order.Parameters
ID of the widget to delete
Response
Returnstrue if deletion was successful, or throws an error on failure.
Behavior
- Order cleanup: Automatically removes widget ID from project’s
orderedWidgetIdsarray - Cascade deletion: Widget is permanently deleted from the database
- Error handling: Throws error if widget not found or deletion fails
Example
deleteWidgetAction
Server action wrapper fordeleteWidget with structured error handling.
Parameters
ID of the widget to delete
Response
Indicates if deletion was successful
Error message (only when success is false)
Example
updateWidgetOrder
Updates the order of widgets in a project’s dashboard.Parameters
ID of the project to update widget order for
Array of widget IDs in the desired order
Response
Indicates if order update was successful
Error message (only when success is false)
Behavior
- Complete replacement: Replaces the entire
orderedWidgetIdsarray - No validation: Does not verify widget IDs exist or belong to the project
- Persistence: Immediately saves to database
Example
Widget order is stored in the
Project.orderedWidgetIds field as an array of widget IDs.GetTableData
Retrieves data from a database table for widget rendering.Parameters
Encrypted database connection credentials (from
DbConnection.dbAccess)Name of the table to query
Response
Array of table rows (only when success)Each row is an object with column names as keys. Values are normalized:
- Numeric types:
numberornull - Other types:
stringornull
Error message (only when error occurs)Possible errors:
"Missing database access or table name.""Table \"tableName\" could not be queried.""Failed to retrieve data for table tableName: {error}"
Behavior
- Connection pooling: Uses
withKnexConnectionfor automatic connection management - Type normalization: Converts all values to
stringornumberbased on column type - Column introspection: Automatically detects column types from database schema
- NULL handling: Converts undefined and invalid values to
null - Special type handling:
- Numeric types (int, float, decimal) →
number - Date types → ISO string
- Boolean →
"true"or"false" - All others →
string
- Numeric types (int, float, decimal) →
Example
Type Definitions
Widget Configuration
Theconfigs field structure varies by widget type:
- Chart Widget
- Table Widget
- Metric Widget
