Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change filter when loading DT and Widget #166

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading