-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: checkbox for inversion of visibility value
* feat: implement visible entity
- Loading branch information
1 parent
72ab762
commit 564d35b
Showing
12 changed files
with
879 additions
and
483 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
This module allows you to migrate obsolete data structures to newer data structures. | ||
For example, when loading the ui. | ||
""" | ||
|
||
|
||
def fix_components(components: dict) -> dict: | ||
""" | ||
Migrates obsolete components to their newer format and avoids errors in Pydantic. | ||
""" | ||
components = _fix_visible_fields(components) | ||
return components | ||
|
||
|
||
def _fix_visible_fields(components: dict) -> dict: | ||
""" | ||
Migrates the component visibility attribute to a more descriptive format. | ||
>>> components['root']['visible'] = True | ||
>>> components['root']['visible'] = { | ||
>>> 'expression': True, | ||
>>> 'binding': "", | ||
>>> 'reversed': False | ||
>>> } | ||
If the visible attribute does not exist, it remains absent. | ||
""" | ||
for key, value in components.items(): | ||
visible = value.get('visible') | ||
|
||
if visible is not None and isinstance(visible, bool): | ||
components[key]['visible'] = { | ||
'expression': visible, | ||
'binding': "", | ||
"reversed": False | ||
} | ||
|
||
if visible is not None and isinstance(visible, str): | ||
components[key]['visible'] = { | ||
'expression': "custom", | ||
'binding': visible, | ||
'reversed': False | ||
} | ||
|
||
return components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import io | ||
import os.path | ||
|
||
fixture_path = os.path.realpath(os.path.dirname(__file__)) | ||
|
||
def load_fixture_content(path) -> str: | ||
""" | ||
Load the contents of a file from the fixture folder | ||
>>> c = load_fixture_content('obsoletes/ui_obsolete_visible.json') | ||
""" | ||
with io.open(os.path.join(fixture_path, path), 'r', encoding='utf-8') as f: | ||
return f.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"root": { | ||
"id": "root", | ||
"type": "root", | ||
"content": { | ||
"appName": "Hello", | ||
"emptinessColor": "#ffffff" | ||
}, | ||
"isCodeManaged": false, | ||
"position": 0 | ||
}, | ||
"bb4d0e86-619e-4367-a180-be28ab6059f4": { | ||
"id": "root", | ||
"type": "page", | ||
"content": { | ||
"pageMode": "", | ||
"key": "main" | ||
}, | ||
"isCodeManaged": false, | ||
"position": 0, | ||
"parentId": "root", | ||
"visible": true | ||
}, | ||
"bb4d0e86-619e-4367-a180-be28abxxxx": { | ||
"id": "root", | ||
"type": "page", | ||
"content": { | ||
"pageMode": "", | ||
"key": "main" | ||
}, | ||
"isCodeManaged": false, | ||
"position": 0, | ||
"parentId": "root", | ||
"visible": "value" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
|
||
from writer import audit_and_fix | ||
|
||
from backend.fixtures import load_fixture_content | ||
|
||
|
||
def test_fix_components_should_fix_visible_fields(): | ||
# Given | ||
obsolete_components = load_fixture_content('obsoletes/ui_obsolete_visible.json') | ||
components = json.loads(obsolete_components) | ||
|
||
# When | ||
final_components = audit_and_fix.fix_components(components) | ||
|
||
# Then | ||
assert "visible" not in final_components["root"] | ||
assert final_components['bb4d0e86-619e-4367-a180-be28ab6059f4']['visible'] == { | ||
'expression': True, | ||
'binding': "", | ||
'reversed': False | ||
} | ||
assert final_components['bb4d0e86-619e-4367-a180-be28abxxxx']['visible'] == { | ||
'expression': "custom", | ||
'binding': "value", | ||
'reversed': False | ||
} |
Oops, something went wrong.