Optimisations to improve the layout of the view using the Block-API
| 30 | |
| 31 | |
| 32 | class PreProcessView(BaseProcessor): |
| 33 | """Optimisations to improve the layout of the view using the Block-API""" |
| 34 | |
| 35 | def __init__(self, *, is_finalised: bool = True) -> None: |
| 36 | self.is_finalised = is_finalised |
| 37 | super().__init__() |
| 38 | |
| 39 | def __call__(self, _: t.Any) -> None: |
| 40 | # AST checks |
| 41 | if len(self.s.blocks.blocks) == 0: |
| 42 | raise InvalidReportError("Empty blocks object - must contain at least one block") |
| 43 | |
| 44 | # convert Page -> Select + Group |
| 45 | v = copy(self.s.blocks) |
| 46 | if all(isinstance(blk, b.Page) for blk in v.blocks): |
| 47 | # convert to top-level Select |
| 48 | p: b.Page # noqa: F842 |
| 49 | v.blocks = [ |
| 50 | b.Select( |
| 51 | blocks=[b.Group(blocks=p.blocks, label=p.title, name=p.name) for p in v.blocks], |
| 52 | type=b.SelectType.TABS, |
| 53 | ) |
| 54 | ] |
| 55 | |
| 56 | # Block-API visitors |
| 57 | pp = PreProcess(is_finalised=self.is_finalised) |
| 58 | v.accept(pp) |
| 59 | v1 = pp.root |
| 60 | # v1 = copy(v) |
| 61 | |
| 62 | # update the processor state |
| 63 | self.s.blocks = v1 |
| 64 | |
| 65 | return None |
| 66 | |
| 67 | |
| 68 | class ConvertXML(BaseProcessor): |
no outgoing calls