RFC: SDTF Schema Creation Guide
RFC: SDTF Schema Creation Guide
- Authors: - Prathik Shetty(@pshettydev), Shaik Noorullah(@pnow-devsupreme)
- Date: 2025-03-18
- Status: Accepted
Introduction
The Schema-Driven Table Framework (SDTF) is an advanced frontend architecture that enables dynamic rendering and management of tabular data through declarative schema configurations. This guide provides a structured approach to creating SDTF schemas based on API response objects or field requirements.
Initially this was referred to as dynamic tables, however, that just led more confusion, since it was unclear whether it referred to the frontend component or the backend data structure. To avoid ambiguity, we now refer to it as the Schema-Driven Table Framework (SDTF).
Creating an effective SDTF schema requires understanding:
- The structure of your API response
- The relationship between different data entities
- The desired UI presentation and interactions
- Field types and their configuration options
Schema Structure
An SDTF schema consists of several key components:
Metadata and Configuration
[!IMPORTANT] The
db_table_namemust exactly match the property name in the API response. The frontend code accesses the data usingtableData.data[schemaData.data.db_table_name].
Context Options
These define actions available for items in the table:
Fields Configuration
Each field in the schema represents a property in your data:
Step-by-Step Process
1. Analyze the API Response
Start by examining the structure of your API response:
[!NOTE]
- The name of the array containing your entities (e.g.,
data.entity_name)- The structure of each entity object
- Any nested objects or arrays that represent relations
- The primary key (usually
id)
2. Set Up Basic Schema Configuration
Configure the top-level properties of your schema:
Important notes:
table_nameshould be a user-friendly, capitalized, plural noundb_table_namemust exactly match the property name in the API response- Use the exact icon name from Icons.tsx (e.g., "MagnetSvg" for leads, not just any icon)
- The endpoint URL should match your API structure
3. Define Context Options
Add standard and domain-specific actions:
Common context options include:
- Edit: Opens a form to edit the entity
- View: Opens a detailed view of the entity
- Delete: Triggers deletion of the entity
- Domain-specific actions (e.g., "Convert to Company" for leads)
4. Map Fields
Create field definitions for each relevant property in the API response. The field types must match the ZPrismaFieldTypes and ZPrismaDBFieldTypes enums:
5. Configure Special Properties
Define any additional configuration needed:
Field Types Reference
SDTF strictly uses the following field types as defined in the ZPrismaFieldTypes enum:
Text Field Types
SHORT_TEXT: Short text strings (names, titles, etc.)LONG_TEXT: Longer text content (descriptions, notes)EMAIL: Email addressesPHONE: Phone numbersURL: Web URLs
Numeric Field Types
NUMBER: General numeric valuesPERCENT: Percentage valuesCURRENCY: Monetary values
Date Field Types
DATE: Date valuesDATETIME: Date and time values
Boolean Field Types
CHECKBOX: True/false values
Spatial Field Types
GEOLOCATION: Geographic coordinates
Relational Field Types
SINGLE_SELECT: One-to-one relationshipsMULTI_SELECT: One-to-many relationships
Special Field Types
USER: References to usersATTACHMENT: File attachmentsFORMULA: Computed values
Database Field Types
The following database field types must be used (from ZPrismaDBFieldTypes enum):
VARCHAR: Variable-length stringsTEXT: Longer text contentTIMESTAMP: Date and time valuesBOOLEAN: True/false valuesINTEGER: Whole numbersDECIMAL: Decimal numbersPOINT: Geographic pointsRELATION: References to other entities
Multiple Relations to the Same Table
A key pattern in SDTF is configuring multiple relation fields to the same table but displaying different attributes. For example, showing different aspects of a company:
Notice the differences:
- Same
db_field_name("company") - Different
display_name("Company" vs "Company Size") - Different
format.fieldsandtemplateto show different attributes - Different
display_fieldsto include the needed attributes
Display Configuration Options
The relation display configuration has several important parts:
Complete Working Example: Leads Schema
Here's a complete working example for a Leads SDTF schema:
Key Features in the Example:
-
Multiple Company Relations: Notice how there are multiple fields that all use
db_field_name: "company"but display different attributes:- One displays the company name
- Another displays the LinkedIn URL
- Another displays the company size
- Another displays the industry
-
Specific Icon: Uses "MagnetSvg" specifically for leads
-
Field Types: Uses proper field types from the ZPrismaFieldTypes enum:
- "EMAIL" for email addresses
- "PHONE" for phone numbers
- "SINGLE_SELECT" for relational fields
- "DATETIME" for timestamp fields
-
Custom Actions: The "Convert to Company" action is domain-specific to leads
Best Practices
-
Field Names and Types
- Use exact field types from the ZPrismaFieldTypes enum
- Use exact database field types from the ZPrismaDBFieldTypes enum
- Make sure
db_field_namematches the API response property exactly
-
Multiple Relations to the Same Entity
- You can have multiple fields pointing to the same relation (e.g., multiple company fields)
- Use different
display_namevalues to clarify the purpose - Configure different
format.fieldsandtemplateto show different attributes - Include all needed fields in
display_fields
-
Icon Selection
- Use exact icon names from Icons.tsx (e.g., "MagnetSvg" for leads)
- Stick to the established conventions (BuildingSvg for companies, etc.)
-
Performance Considerations
- Be aware that each relational field increases the load on the frontend
- For simple formatting, prefer formula fields over multiple relations
- Only include the necessary fields in
display_fields
-
API Response Mapping
db_table_namemust match the property in the API response- The frontend code accesses data via
tableData.data[schemaData.data.db_table_name]
Icon Reference
The "icon" field must use exactly one of the icon names available in Icons.tsx:
[!NOTE]
Could have been updated, so make sure to check out Icons.tsx
Troubleshooting
Common Issues
-
Field not appearing in the table
- Check if the field is in the
hidden_fieldsarray - Verify the
db_field_namematches the API response property exactly - Ensure the field type is one of the ZPrismaFieldTypes enum values
- Check if the field is in the
-
Relation not displaying properly
- Check if the related entity exists and is properly configured
- Verify the
display_fieldsinclude all fields referenced in the template - Ensure the
templateuses the correct field names in braces
-
Formula not working
- Check the formula syntax for errors
- Verify that referenced fields exist in the row data
- Ensure the
returnTypeis one of: "TEXT", "NUMBER", "BOOLEAN" (case-sensitive)
-
API data not loading
- Verify the
endpoint_urlis correct - Check that
db_table_nameexactly matches the property in the API response - Examine the network request to see the actual API response structure
- Verify the
Data Flow Debugging
Understanding how data flows through the system is crucial:
- The frontend loads the schema using the tableId parameter
- From the schema, it gets
endpoint_urlto fetch the table data - The API responds with data in a structure like
data.leads(for leads) - The code accesses the data using
tableData.data[schemaData.data.db_table_name] - This is why
db_table_namemust exactly match the property in the API response
Conclusion
Creating effective SDTF schemas requires understanding both the data structure and the technical requirements of the framework. By following this guide and referencing the working examples, you can create schemas that properly integrate with the SDTF system.
Remember to use the correct enumerated values for field types, configure relations properly, and ensure field names match the API response exactly. This attention to detail will help avoid common issues and ensure your SDTF schemas work as expected.