fix(dashboard): stabilize four-column widget placement
This commit is contained in:
@@ -15,11 +15,29 @@ class DashboardWidgetPlacementPayload(BaseModel):
|
||||
instance_id: str = Field(min_length=1, max_length=120)
|
||||
widget_id: WidgetId
|
||||
size: Literal["small", "medium", "wide", "full"] = "medium"
|
||||
column_start: int | None = Field(default=None, ge=1, le=4)
|
||||
configuration: dict[str, ConfigurationValue] = Field(
|
||||
default_factory=dict,
|
||||
max_length=40,
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_column_span(self) -> "DashboardWidgetPlacementPayload":
|
||||
if self.column_start is None:
|
||||
return self
|
||||
span = {
|
||||
"small": 1,
|
||||
"medium": 2,
|
||||
"wide": 3,
|
||||
"full": 4,
|
||||
}[self.size]
|
||||
if self.column_start + span - 1 > 4:
|
||||
raise ValueError(
|
||||
f"A {self.size} widget cannot start in column "
|
||||
f"{self.column_start} of a four-column Dashboard."
|
||||
)
|
||||
return self
|
||||
|
||||
@field_validator("configuration")
|
||||
@classmethod
|
||||
def validate_configuration(
|
||||
|
||||
Reference in New Issue
Block a user