From a4f45e938526af60588ab353448a6cc07af26f0b Mon Sep 17 00:00:00 2001 From: Sooyoung98 Date: Tue, 30 Apr 2024 17:18:13 +0900 Subject: [PATCH 1/2] feat: added metadata features to support search labels and data_types Signed-off-by: Sooyoung98 --- .../collector/lib/metadata_generator.py | 30 +++++++++++++------ .../inventory/plugin/collector/model/field.py | 17 +++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py b/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py index ce864de..7b9dfb2 100644 --- a/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py +++ b/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py @@ -49,7 +49,7 @@ def _separate_metadata(self): return query_sets_meta, search_meta, table_meta, tabs_meta, widget_meta def _generate_search(self, search_meta: dict) -> list: - return self._generate_fields(search_meta["fields"]) + return self._generate_fields(search_meta["fields"], is_search=True) def _generate_table(self, table_meta: dict) -> dict: table_metadata = self._generate_default_dynamic_view( @@ -91,9 +91,9 @@ def _generate_tabs(self, tabs_meta: list) -> dict: del inner_tab_meta["root_path"] if "sort" in inner_tab_meta: - inner_dynamic_view["options"][ - "default_sort" - ] = self._generate_sort(inner_tab_meta["sort"]) + inner_dynamic_view["options"]["default_sort"] = ( + self._generate_sort(inner_tab_meta["sort"]) + ) if "root_path" in inner_tab_meta: inner_dynamic_view["options"]["root_path"] = inner_tab_meta[ @@ -145,10 +145,13 @@ def _generate_sort(table: dict) -> dict: return Sort(**sort_option).dict() - def _generate_fields(self, fields: list) -> list: + def _generate_fields(self, fields: list, is_search=False) -> list: gen_fields = [] for field in fields: - if "type" not in field: + if "data_type" in field: + gen_fields.append(self._generate_data_type_field(field)) + + elif "type" not in field: gen_fields.append(self._generate_text_field(field)) elif field["type"] == "text": @@ -176,7 +179,7 @@ def _generate_fields(self, fields: list) -> list: gen_fields.append(self._generate_image_field(field)) elif field["type"] == "enum": - gen_fields.append(self._generate_enum_field(field)) + gen_fields.append(self._generate_enum_field(field, is_search)) elif field["type"] == "more": gen_fields.append(self._generate_more_field(field)) @@ -346,7 +349,7 @@ def _generate_image_field(self, field: dict, is_enum: bool = False) -> dict: else: return EnumImageField(**field).dict(exclude_none=True) - def _generate_enum_field(self, field: dict) -> dict: + def _generate_enum_field(self, field: dict, is_search=False) -> dict: if "key" not in field: field = self._add_key_name_fields(field) @@ -376,6 +379,12 @@ def _generate_enum_field(self, field: dict) -> dict: key for key in enum.keys() if key not in enable_enum_options ][0] + if enum["type"] == "label": + enum["label"] = enum[main_key] + del enum[main_key] + del enum["type"] + enums[main_key] = enum + if enum["type"] == "badge": enum["outline_color"] = enum[main_key] del enum[main_key] @@ -408,7 +417,10 @@ def _generate_enum_field(self, field: dict) -> dict: else: field["options"] = enums - del field["enums"] + del field["enums"] + + if is_search: + return SearchEnumField(**field).dict(exclude_none=True) return EnumField(**field).dict(exclude_none=True) diff --git a/src/spaceone/inventory/plugin/collector/model/field.py b/src/spaceone/inventory/plugin/collector/model/field.py index bf00799..e936117 100644 --- a/src/spaceone/inventory/plugin/collector/model/field.py +++ b/src/spaceone/inventory/plugin/collector/model/field.py @@ -16,6 +16,8 @@ "EnumStateField", "EnumDatetimeField", "EnumImageField", + "DataTypeField", + "SearchEnumField", ] BACKGROUND_COLORS = ( @@ -169,6 +171,13 @@ class MoreOptions(BaseModel): layout: MoreOptionsLayout = None +class DataTypeField(BaseModel): + name: str + key: str + data_type: str + options: Union[dict, None] = None + + class TextField(BaseModel): name: str key: str @@ -232,6 +241,14 @@ class EnumField(BaseModel): options: dict +class SearchEnumField(BaseModel): + name: str + key: str + type: str = "enum" + enums: dict + options: dict = None + + class MoreField(BaseModel): name: str key: str From 45f0a6fd04d55fb6e0c13e7129074be42d94b7f8 Mon Sep 17 00:00:00 2001 From: Sooyoung98 Date: Tue, 30 Apr 2024 17:22:38 +0900 Subject: [PATCH 2/2] feat: added additional codes to support search labels and data_types Signed-off-by: Sooyoung98 --- .../plugin/collector/lib/metadata_generator.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py b/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py index 7b9dfb2..e44d39e 100644 --- a/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py +++ b/src/spaceone/inventory/plugin/collector/lib/metadata_generator.py @@ -185,6 +185,12 @@ def _generate_fields(self, fields: list, is_search=False) -> list: gen_fields.append(self._generate_more_field(field)) return gen_fields + def _generate_data_type_field(self, field: dict) -> dict: + if "key" not in field: + field = self._add_key_name_fields(field) + + return DataTypeField(**field).dict(exclude_none=True) + def _generate_text_field(self, field: dict) -> dict: if "key" not in field: field = self._add_key_name_fields(field) @@ -412,12 +418,16 @@ def _generate_enum_field(self, field: dict, is_search=False) -> dict: enums[main_key] = self._generate_datetime_field( field=enum, is_enum=True ) - if "options" in field: - field["options"].update(enums) + + if is_search: + field["enums"] = enums else: - field["options"] = enums + if "options" in field: + field["options"].update(enums) + else: + field["options"] = enums - del field["enums"] + del field["enums"] if is_search: return SearchEnumField(**field).dict(exclude_none=True)