Skip to content

Commit

Permalink
Fix processing of dsl based children elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dankilman committed Feb 6, 2019
1 parent e36545d commit 0541dc8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions awe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def get(ctx, element_id):
@option('-o', '--obj', required=True, help='Element definition.')
@option('-p', '--params', help='Keyword arguments to use when creating ``obj``.')
@option('-e', '--element-id', help='Optionally specify an element ID. (one will be generated otherwise)')
@option('-r', '--root-id', help="Optionally specify a different root to creat the element under. "
"If not specified, and ``parent_id`` is not supplied, the main ``page`` root "
"will be used.")
@option('-r', '--root-id', help='Optionally specify a different root to creat the element under. '
'If not specified, and ``parent_id`` is not supplied, the main ``page`` root '
'will be used.')
@option('-c', '--parent-id', help='Optionally specify the element create the new element under.')
@option('-n', '--new-root', is_flag=True, help='Create element under a new root.')
@click.pass_obj
Expand Down
2 changes: 1 addition & 1 deletion awe/resources/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.37.0
0.37.1
2 changes: 1 addition & 1 deletion awe/resources/client/awe/src/Awe.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Awe {
this.finishedInitialFetch = false;
this.clientId = null;
this.pendingActions = [];
this.ws = new WebSocket(`ws://${window.location.hostname}:${port}`);
this.ws = new WebSocket(`ws://${window.location.hostname}:${port || 9000}`);
this.ws.onmessage = this.onMessage.bind(this);
this.ws.onerror = (error) => console.error('ws error', error);
Awe.fetchInitialState().then((initialState) => {
Expand Down
3 changes: 1 addition & 2 deletions awe/resources/client/awe/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ const updateElementActions = {
};

function processElement(map, element, rootId) {
const {children, id} = element;
const {children} = element;
element.rootId = rootId;
map = newElement(map, element);
if (children) {
for (const child of children) {
child.parentId = id;
map = processElement(map, child, rootId);
}
}
Expand Down
18 changes: 6 additions & 12 deletions awe/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,6 @@ def _init(self, **kwargs):
"""
pass

def _get_view(self):
return {
'id': self.id,
'rootId': self.root_id,
'index': self.index,
'elementType': self.element_type,
'data': self.data,
'children': [t._get_view() for t in self.children],
'props': self.props,
'propChildren': self._prop_children
}

def _get_new_element_action(self):
return {
'type': 'newElement',
Expand All @@ -431,6 +419,12 @@ def _get_new_element_action(self):
'propChildren': self._prop_children
}

def _get_view(self):
result = self._get_new_element_action()
result.pop('type')
result['children'] = [t._get_view() for t in self.children]
return result

def _new_children(self, element_configuration, **kwargs):
element_configuration['kwargs'].update(kwargs)
roots = {}
Expand Down
15 changes: 14 additions & 1 deletion tests/view/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_dsl(element_tester):
def builder(page):
top_level = page.new('''
- Text: [[text1, text: Text 1, className: text1]]
- Card: [[card1, className: card1]]
''')
state['top_level'] = top_level

Expand All @@ -27,9 +28,21 @@ def verify_change(driver):
assert text_element.text == 'Text 11'
assert text_element2.text == 'Text 2'

def add_child_to_card(page):
top_level = state['top_level']
card = top_level.ref.card1
card.new('Text: [[text: Hello, className: text3]]')

def find_child_text(driver):
card_element = driver.find_element_by_class_name('card1')
child_text_element = card_element.find_element_by_class_name('text3')
assert child_text_element.text == 'Hello'

element_tester(
builder,
finder,
dynamic_change,
verify_change
verify_change,
add_child_to_card,
find_child_text,
)

0 comments on commit 0541dc8

Please sign in to comment.