The Dynamic Fields Framework is designed to be utilized in conjunction with the Dynamic Results Stage. This framework is primarily intended for use in the user interface (UI) layer of the application. Therefore, it assumes that the UI project is well-equipped to correctly interpret the Dynamic Fields that are sent as part of the response.

Each Dynamic Field type is associated with two Pydantic BaseModel classes:

  1. _{type}FieldUI model: This model inherits from the BaseModel in the _DynamicFieldUI class and also from the _DynamicFieldUI on the typed subclasses. This model is primarily concerned with defining the attributes and characteristics of the Dynamic Field that are relevant to the UI. It essentially determines how the field will be presented in the UI and what information will be displayed to the user.

  2. {type}Field model: This model inherits from its corresponding _{type}FieldUI model and also from the DynamicField model on the typed subclasses. It serves as an extension of the UI model, incorporating additional attributes and functionalities that are essential for data transformations in the backend. These transformations are carried out to modify the data before it is included in the response to be sent to the user. Essentially, this model defines how the data associated with the Dynamic Field is processed and transformed before being presented in the UI.

The separation of these two models, one for UI presentation and the other for backend data transformations, helps maintain clarity and modularity in the implementation of the Dynamic Fields Framework. It ensures that the concerns of the UI and data transformation are handled independently, allowing for flexibility and ease of maintenance in both areas.

DynamicField

ParameterTypeDefaultRequiredDescription
fieldstr...TruePath to field from which retrieve the value. Path with jmespath format (JMESPath documentation: https://github.com/jmespath/jmespath.py).
field_highlightUnion[str, None]NoneFalsePath to highlight field from which retrieve the value, in case it is not the same as the field parameter. Path with jmespath format (JMESPath documentation: https://github.com/jmespath/jmespath.py).
defaultUnion[Any, None]NoneFalseDefault value to use in case no value was found for the field.
transformOptional[List[Transformation]]NoneTrueList of transformations to be applied to the displayed values. The order in which the transformations are specified is the order in which the transformations will be applied.
_label_transformedbool-TrueInternal parameter.
suffixUnion[str, None]NoneFalseSuffix to append to the value or values.
prefixUnion[str, None]NoneFalsePrefix to append to the value or values.
suffix_labelUnion[str, None]NoneFalseSuffix to append to the label of the field.
prefix_labelUnion[str, None]NoneFalsePrefix to append to the label of the field.
sortUnion[SortOrder, bool]FalseFalseSort order for values in an array.
uniqueboolFalseFalseIf the values are in an array, remove duplicates.
show_blankboolFalseFalseIf there is no value, or value is none, and show_blank is true, keep the field.
replacementOptional[str]-FalseReplacement to replace matches in the transformations (used in TRANSFORM_REPLACE_FIRST, TRANSFORM_REPLACE_LAST, and TRANSFORM_REPLACE_ALL).
patternOptional[str]-FalsePattern used to look for matches in the transformations (used in TRANSFORM_REPLACE_FIRST, TRANSFORM_REPLACE_LAST, and TRANSFORM_REPLACE_ALL).

_DynamicFieldUI

ParameterTypeDefaultRequiredDescription
typeDynamicFieldTypeDynamicFieldType.TEXTTrueType of the dynamic field.
labelUnion[str, None]NoneFalseLabel to show for this field.
css_styleUnion[__CSSStyle, None]NoneFalseStyle to apply in the HTML of the UI.
css_classUnion[str, None]NoneFalseStyle to apply in the HTML component.
translateUnion[str, None]NoneFalse(TODO: Implement translation)
translate_labelUnion[str, None]NoneFalseTranslation label.
analyticsUnion[dict, None]NoneFalseAnalytics information.
if_not_existOptional[str]NoneFalseShow only if the specified field doesn't exist.
if_existOptional[str]NoneFalseShow only if the specified field does exist.
only_on_highlightboolFalseFalseShow only when the value is highlighted.
displayOptional[Any]-FalseValue from the field to display.

Transformation Enum

NameValue
LOWER_CASElowerCase
UPPER_CASEupperCase
CAMEL_CASEcamelCase
KEBAB_CASEkebabCase
CAPITALIZEcapitalize
LOWER_FIRSTlowerFirst
UPPER_FIRSTupperFirst
SNAKE_CASEsnakeCase
REPLACE_FIRSTreplaceFirst
REPLACE_LASTreplaceLast
REPLACE_ALLreplaceAll

DynamicFieldType Enum

NameValue
TEXTtext
URLurl
DATEdate
DATE_AGEdate_age
NUMBERnumber
SIZEsize
MIME_TYPEmime_type
IMAGEimage
THUMBNAILSthumbnails
BOOLbool
NESTEDnested
KEY_VALUEkey_value
TABLEtable
TAGStags
COLUMN_ACTIONcolumn_action
CHIPchip
CARROUSELcarrousel
CARROUSEL_VALUEcarrousel_value
INNER_HITSinner_hits

_CSSStyle Model

ParameterTypeRequiredDescription
labelDict[str, str]TrueDictionary for labels.
displayDict[str, str]TrueDictionary for display.
containerDict[str, str]TrueDictionary for containers.

Dynamic Results Workflow

The workflow is initiated when the Dynamic Results Stage is invoked. During this process, the Dynamic Results Stage proceeds to execute its configuration, going through each of the Dynamic Fields individually.

For each Dynamic Field, its implementation is determined based on the specified type. Subsequently, it generates a typed object that aligns with the configured type. This typed object serves as a representation of the data and enables further transformations.

In order to enhance the readability of the user-facing response, the Dynamic Field then calls its "transform_data" method. This method is responsible for modifying the data within the response, making it more user-friendly and easier to understand.

Finally, the objects replace the declaration of the Dynamic Fields in the configuration and this new configuration is the one used by the Dynamic Results Stage to provide the typed hits in the response.

  • No labels