You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

The Dynamic Fields Framework is meant to be used with the Dynamic Results Stage. This framework is meant for UI only hence it requires that the UI project knows how to interpret properly the Dynamic Fields sent in the response.

Each Dynamic Field type has two Pydantic BaseModel, the _{type}FieldUI model which inherits from the BaseModel in the _DynamicFieldUI class and from the _DynamicFieldUI on the typed field sub classes, and the {type}Field which inherits from it's own _{type}FieldUI. The idea of that is to have separated models for the things that are required for UI which will affect the returned fields in the response, and the things required for data transformations in the backend which are going to modify the data before being sent in the response.

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]FalseTrueSort order for values in an array.
uniqueboolFalseTrueIf the values are in an array, remove duplicates.
show_blankboolFalseTrueIf 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