Skip to content

Commit

Permalink
fix: change filter when loading DT and Widget
Browse files Browse the repository at this point in the history
Signed-off-by: seolmin <[email protected]>
  • Loading branch information
stat-kwon committed Jan 14, 2025
1 parent 39cb641 commit e93aee7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
32 changes: 16 additions & 16 deletions src/spaceone/dashboard/manager/data_table_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import logging
import ast
import re
from typing import Union, Literal, Tuple
from typing import Union, Tuple
from jinja2 import Environment, meta
import pandas as pd

from spaceone.core import cache, utils
from spaceone.core.manager import BaseManager
from spaceone.dashboard.error.data_table import (
ERROR_NO_FIELDS_TO_GLOBAL_VARIABLES,
ERROR_NOT_GLOBAL_VARIABLE_KEY,
ERROR_QUERY_OPTION,
ERROR_QUERY_GROUP_BY_OPTION,
ERROR_EMPTY_DATA_FIELD,
Expand Down Expand Up @@ -294,24 +292,26 @@ def change_global_variables(self, expression: str, vars: dict):
jinja_variables = meta.find_undeclared_variables(parsed_content)

global_variables = jinja_variables - exclude_keys
for global_variable_key in global_variables and vars:

global_variable_value = vars[global_variable_key]
gv_type = type(global_variable_value)
if vars:
for global_variable_key in global_variables:

if isinstance(global_variable_value, int) or isinstance(
global_variable_value, float
):
global_variable_value = str(global_variable_value)
global_variable_value = vars[global_variable_key]
gv_type = type(global_variable_value)

if isinstance(global_variable_value, list):
global_variable_value = str(global_variable_value)
if isinstance(global_variable_value, int) or isinstance(
global_variable_value, float
):
global_variable_value = str(global_variable_value)

gv_type_map[global_variable_value] = gv_type
if isinstance(global_variable_value, list):
global_variable_value = str(global_variable_value)

expression = expression.replace(
global_variable_key, global_variable_value
)
gv_type_map[global_variable_value] = gv_type

expression = expression.replace(
global_variable_key, global_variable_value
)

return expression, gv_type_map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,25 +345,28 @@ def _make_query(
vars: dict = None,
):
if self.filter:

new_filter = []
for filter_info in self.filter:

query_value = filter_info.get("v") or filter_info.get("value")
query_key = filter_info.get("k") or filter_info.get("key")
if self.is_jinja_expression(query_value):
query_value, gv_type_map = self.change_global_variables(
query_value, vars
)

query_value = self.remove_jinja_braces(query_value, gv_type_map)
if (
isinstance(query_value, str)
or isinstance(query_value, int)
or isinstance(query_value, float)
):
if isinstance(query_value, (str, int, float)):
filter_info["v"] = [query_value]
elif isinstance(query_value, list):
filter_info["v"] = query_value

if query_key == query_value:
self.filter = None
if not gv_type_map:
continue

new_filter.append(filter_info)

self.filter = new_filter

return {
"granularity": granularity,
Expand Down

0 comments on commit e93aee7

Please sign in to comment.