Skip to content

Commit

Permalink
Merge pull request #151 from stat-kwon/master
Browse files Browse the repository at this point in the history
Refactor response logic when loading Widget
  • Loading branch information
stat-kwon authored Jan 3, 2025
2 parents 77bcc46 + 243632f commit bf1566b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/spaceone/dashboard/manager/data_table_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ def load_from_widget(

response = {
"results": self.df.copy(deep=True).to_dict(orient="records"),
"labels_info": labels_info,
"data_info": data_info,
"order": self.label_keys + self.data_keys,
}

if labels_info:
response["labels_info"] = labels_info

if data_info:
response["data_info"] = data_info

if self.label_keys and self.data_keys:
order = self.label_keys + self.data_keys
response["order"] = order

cache.set(
f"dashboard:widget:load:{self.domain_id}:{self.widget_id}:{cache_hash_key}",
response,
Expand All @@ -102,9 +110,6 @@ def response_data_from_widget(
page: dict = None,
) -> dict:
data = response["results"]
labels_info = response["labels_info"]
data_info = response["data_info"]
order = response["order"]

total_count = len(data)

Expand All @@ -114,14 +119,20 @@ def response_data_from_widget(
if page:
data = self.apply_page(data, page)

return {
results = {
"results": data,
"total_count": total_count,
"labels_info": labels_info,
"data_info": data_info,
"order": order,
}

if "labels_info" in response:
results["labels_info"] = response["labels_info"]
if "data_info" in response:
results["data_info"] = response["data_info"]
if "order" in response:
results["order"] = response["order"]

return results

def response_sum_data_from_widget(self, response: dict) -> dict:
data = response["results"]
if self.data_keys:
Expand Down

0 comments on commit bf1566b

Please sign in to comment.