Skip to content

Commit 2977142

Browse files
committed
v 0.6.0
Add option to categories the blocks in a sub-menu.
1 parent 581a1e0 commit 2977142

File tree

13 files changed

+67
-32
lines changed

13 files changed

+67
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
Release dates are in YYYY-MM-DD
88

9+
## [0.6.0] - 2022-07-19
10+
11+
- Add option to categories the Blocks with a category in a sub-menu in the context menu on right-click>add-node.
12+
913
## [0.5.0] - 2022-03-19
1014

1115
- Add Block option.

Developer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Development notes
22

3-
Following are the notes for working on the development of the component.
3+
Following are the notes for working on the development of the barfi.
44

55
## Quickstart for development
66

@@ -57,7 +57,7 @@ twine upload --verbose --skip-existing dist/*
5757

5858
## Checklist before building new package
5959
- [ ] Run unittest by running `make test`
60-
- [ ] Change `Node` to `Block` here `barfi/frontend/node_modules/@baklavajs/plugin-renderer-vue/dist/index.js`
60+
- [ ] Change `Node` to `Block` here `barfi/frontend/node_modules/@baklavajs/plugin-renderer-vue/dist/index.js` @ `this.contextMenu.items`
6161
- [ ] Build the frontend: `cd frontend/` and run `npm run build`
6262
- [ ] Set `release = True` in */barfi/__init__.py*
6363
- [ ] Bump version number in `setup.py`

barfi/__init__.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import streamlit.components.v1 as components
2-
from typing import List, Dict
2+
from typing import List, Dict, Union
33

44
# import barfi components
55
from .block_builder import Block
@@ -46,7 +46,7 @@
4646
# "name" argument without having it get recreated.
4747

4848

49-
def st_barfi(base_blocks: List[Block], load_schema: str = None, compute_engine: bool = True, key=None):
49+
def st_barfi(base_blocks: Union[List[Block], Dict], load_schema: str = None, compute_engine: bool = True, key=None):
5050
if load_schema:
5151
editor_schema = load_schema_name(load_schema)
5252
else:
@@ -55,12 +55,30 @@ def st_barfi(base_blocks: List[Block], load_schema: str = None, compute_engine:
5555
schemas_in_db = load_schemas()
5656
schema_names_in_db = schemas_in_db['schema_names']
5757

58-
editor_setting = {'compute_engine': compute_engine}
58+
editor_setting = {'compute_engine': compute_engine}
59+
60+
# base_blocks_data = [block._export() for block in base_blocks]
61+
62+
if isinstance(base_blocks, List):
63+
base_blocks_data = [block._export() for block in base_blocks]
64+
elif isinstance(base_blocks, Dict):
65+
base_blocks_data = []
66+
for category, block_list in base_blocks.items():
67+
if isinstance(block_list, List):
68+
for block in block_list:
69+
block_data = block._export()
70+
block_data['category'] = category
71+
base_blocks_data.append(block_data)
72+
else:
73+
raise TypeError(
74+
'Invalid type for base_blocks passed to the st_barfi component.')
75+
else:
76+
raise TypeError(
77+
'Invalid type for base_blocks passed to the st_barfi component.')
5978

60-
base_blocks_data = [block._export() for block in base_blocks]
61-
_from_client = _component_func(base_blocks=base_blocks_data, load_editor_schema=editor_schema,
62-
load_schema_names=schema_names_in_db, load_schema_name=load_schema, editor_setting = editor_setting,
63-
key=key, default={'command': 'skip', 'editor_state': {}})
79+
_from_client = _component_func(base_blocks=base_blocks_data, load_editor_schema=editor_schema,
80+
load_schema_names=schema_names_in_db, load_schema_name=load_schema, editor_setting=editor_setting,
81+
key=key, default={'command': 'skip', 'editor_state': {}})
6482

6583
if _from_client['command'] == 'execute':
6684
if compute_engine:
@@ -72,7 +90,7 @@ def st_barfi(base_blocks: List[Block], load_schema: str = None, compute_engine:
7290
else:
7391
_ce = ComputeEngine(blocks=base_blocks)
7492
_ce.add_editor_state(_from_client['editor_state'])
75-
_ce._map_block_link()
93+
_ce._map_block_link()
7694
# return _ce.get_result()
7795
return _from_client
7896
if _from_client['command'] == 'save':
@@ -86,8 +104,9 @@ def st_barfi(base_blocks: List[Block], load_schema: str = None, compute_engine:
86104

87105
return {}
88106

107+
89108
def barfi_schemas():
90-
schemas_in_db = load_schemas()
91-
schema_names_in_db = schemas_in_db['schema_names']
92-
109+
schemas_in_db = load_schemas()
110+
schema_names_in_db = schemas_in_db['schema_names']
111+
93112
return schema_names_in_db

barfi/client/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>frontend</title><link href="css/app.51aff32b.css" rel="preload" as="style"><link href="js/app.0728c432.js" rel="preload" as="script"><link href="js/chunk-vendors.eb7fca41.js" rel="preload" as="script"><link href="css/app.51aff32b.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.eb7fca41.js"></script><script src="js/app.0728c432.js"></script></body></html>
1+
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>frontend</title><link href="css/app.51aff32b.css" rel="preload" as="style"><link href="js/app.4b1442b7.js" rel="preload" as="script"><link href="js/chunk-vendors.eb7fca41.js" rel="preload" as="script"><link href="css/app.51aff32b.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.eb7fca41.js"></script><script src="js/app.4b1442b7.js"></script></body></html>

barfi/client/js/app.0728c432.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)