Skip to content

Commit

Permalink
fix: add 'table.options.default_filters' to metadata_generator.py
Browse files Browse the repository at this point in the history
Signed-off-by: kangwork <[email protected]>
  • Loading branch information
kangwork committed Aug 13, 2024
1 parent a8fc257 commit 827c4f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/spaceone/inventory/plugin/collector/lib/metadata_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def _generate_table(self, table_meta: dict) -> dict:
table_metadata = self._generate_default_dynamic_view(
"Main Table", "query-search-table"
)
if "options" in table_meta:
if "default_filters" in table_meta["options"]:
table_metadata["options"]["default_filters"] = self._generate_filters(table_meta)

if "sort" in table_meta:
table_metadata["options"]["default_sort"] = self._generate_sort(table_meta)
Expand Down Expand Up @@ -142,6 +145,19 @@ def _generate_default_dynamic_view(name, view_type="list", options=None):

return {"name": name, "type": view_type, "options": options}

@staticmethod
def _generate_filters(table: dict) -> list[dict]:
filters = []
filters_field = table["options"]["default_filters"]
for filter_dict in filters_field:
filter_options = {
"key": filter_dict["key"],
"value": filter_dict["value"],
"operator": filter_dict.get("operator", "eq"),
}
filters.append(Filter(**filter_options).dict())
return filters

@staticmethod
def _generate_sort(table: dict) -> dict:
sort_field = table["sort"]
Expand Down
7 changes: 7 additions & 0 deletions src/spaceone/inventory/plugin/collector/model/dynamic_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ class Sort(BaseModel):
desc: bool = False


class Filter(BaseModel):
key: str
value: str
operator: str = 'eq'


class Options(BaseModel):
default_sort: Sort
default_filter: list[Filter]
fields: list


Expand Down

0 comments on commit 827c4f0

Please sign in to comment.