From ae49c0f5d091bd10ad3e8d390957be606c3705be Mon Sep 17 00:00:00 2001 From: echoyang7 <50300391+echoyang7@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:56:25 +0800 Subject: [PATCH] Bugfix/fix v2 bug (#843) * fix,inspector request miss data * fix v2 bug --- .../components/DocumentTreeDialogDelete.vue | 4 ++- lyrebird/mock/dm/__init__.py | 31 +++++++++++++++---- lyrebird/mock/dm/file_data_adapter.py | 6 +--- lyrebird/version.py | 2 +- tests/test_dm_config.py | 2 +- tests/test_plugins.py | 3 +- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/DocumentTreeDialogDelete.vue b/frontend/src/components/DocumentTreeDialogDelete.vue index 930f6268..65379902 100644 --- a/frontend/src/components/DocumentTreeDialogDelete.vue +++ b/frontend/src/components/DocumentTreeDialogDelete.vue @@ -163,7 +163,7 @@ export default { } else { for (const item of this.deleteItem) { this.groupListToDelete.push(item.id) - if (!item.type === 'group') { + if (item.type !== 'group') { this.dataListToDelete.push(item.id) } } @@ -173,6 +173,8 @@ export default { } this.$store.dispatch('deleteByQuery', payload) this.$store.commit('setIsSelectableStatus', false) + this.dataListToDelete = [] + this.groupListToDelete = [] } this.isShown = false }, diff --git a/lyrebird/mock/dm/__init__.py b/lyrebird/mock/dm/__init__.py index 147346db..079699ce 100644 --- a/lyrebird/mock/dm/__init__.py +++ b/lyrebird/mock/dm/__init__.py @@ -41,7 +41,7 @@ def __init__(self): self.add_group_ignore_keys = set(['id', 'type', 'children']) self.update_group_ignore_keys = set(['id', 'parent_id', 'type', 'children']) - self.supported_data_type = ['data', 'json', 'config'] + self.supported_data_type = self.get_supported_data_type() self.virtual_node_data_type = set(['config']) # TODO Next is `super`` self.virtual_base_config_id = None @@ -69,6 +69,12 @@ def snapshot_workspace(self): def snapshot_workspace(self, workspace): self._snapshot_workspace = workspace + def get_supported_data_type(self): + supported_data_type = ['data', 'json'] + if application.config.get(CONFIG_TREE_SHOW_CONFIG): + supported_data_type.append('config') + return supported_data_type + def get_default_root(self): return { 'id': str(uuid.uuid4()), @@ -1202,7 +1208,9 @@ def _delete_remove_from_parent(self, id_): # batch action def delete_by_query(self, query): - all_id_list = query.get('id') or [] + node_delete_group_ids = query.get('data', []) + node_delete_data_ids = query.get('groups', []) + all_id_list = list(set(node_delete_group_ids + node_delete_data_ids)) times = math.ceil(len(all_id_list) / self.DELETE_STEP) for index in range(times): @@ -1215,9 +1223,6 @@ def delete_by_query(self, query): 'state': 'process' }) - type_map = self._get_type_hashmap(id_list) - node_delete_group_ids = type_map['group'] + type_map['data'] + type_map['json'] + type_map['config'] - node_delete_data_ids = type_map['data'] + type_map['json'] + type_map['config'] for id_ in id_list: # Delete from parent @@ -1289,9 +1294,23 @@ def reset(self): def _get_group_children(self, group_id): result = self._adapter._get_group_children(group_id) + self.handle_group_config(result, group_id) self.add_open_node(group_id) return result - + + def handle_group_config(self, node_list, node_id): + has_config_index = -1 + for index, node in enumerate(node_list): + if node['type'] == 'config': + has_config_index = index + break + + is_show_config = application.config.get(CONFIG_TREE_SHOW_CONFIG) + has_config = has_config_index != -1 + if has_config and not is_show_config: + del node_list[has_config_index] + return + def get_group(self, _id): return self._adapter._load_group(_id) diff --git a/lyrebird/mock/dm/file_data_adapter.py b/lyrebird/mock/dm/file_data_adapter.py index 4ac4b721..c8498151 100644 --- a/lyrebird/mock/dm/file_data_adapter.py +++ b/lyrebird/mock/dm/file_data_adapter.py @@ -487,11 +487,7 @@ def _activate(self, search_id): for node in node_list: node_in_map = self.context.id_map.get(node.get('id')) if node_in_map['type'] == 'config': - try: - config = json.loads(node['json']) - break - except Exception: - logger.error(f'Load config {node["id"]} error! \n {traceback.format_exc()}') + config = node return { 'config': config, 'flows': node_list, diff --git a/lyrebird/version.py b/lyrebird/version.py index 7b9fc6c6..a6642b7b 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (2, 26, 1) +IVERSION = (2, 26, 2) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION diff --git a/tests/test_dm_config.py b/tests/test_dm_config.py index ed2106aa..8fbcb8f8 100644 --- a/tests/test_dm_config.py +++ b/tests/test_dm_config.py @@ -86,7 +86,7 @@ def data_manager(root, tmpdir): application._cm = ConfigManager() lyrebird.mock.context.application.socket_io = FakeSocketio() application.encoders_decoders = EncoderDecoder() - _dm = dm.DataManager() + _dm = dm.DataManagerV2() _dm.snapshot_workspace = tmpdir _dm.set_adapter(data_adapter) _dm.set_root(root) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 5d67dda8..99a4d1fc 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -1,5 +1,5 @@ import pytest -from .utils import FakeEvnetServer +from .utils import FakeEvnetServer, FakeBackgroundTaskServer from lyrebird.mock.mock_server import LyrebirdMockServer from lyrebird import application from lyrebird.plugins import PluginManager @@ -119,6 +119,7 @@ def mock_server(): application._cm = ConfigManager() application._cm.config = copy.deepcopy(conf) server = LyrebirdMockServer() + application.server['task'] = FakeBackgroundTaskServer() application.server['mock'] = server yield server del server