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

fix Cluster Dashboard timerange filtering in Financial Overview #471

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public function __construct(
) {}

public function index() {
return ApiResource::make($this->clustersDashboardCacheDataService->getData());
$cachedData = $this->clustersDashboardCacheDataService->getData();

// If cache is empty, initialize it before returning
if (empty($cachedData)) {
$this->clustersDashboardCacheDataService->setData();
$cachedData = $this->clustersDashboardCacheDataService->getData();
}

return ApiResource::make($cachedData);
}

public function show($clusterId) {
Expand Down
52 changes: 34 additions & 18 deletions src/frontend/src/modules/Dashboard/FinancialOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export default {
mixins: [notify],
props: {
clusterId: {
// eslint-disable-next-line vue/require-prop-type-constructor
type: Number | null,
type: [Number, null],
default: null,
},
revenue: {
Expand All @@ -122,7 +121,6 @@ export default {
customPredictor: function (date) {
let today = new Date()
let minDate = new Date("2018-01-01")
// disables the date if it is a multiple of 5
if (date > today || date < minDate) {
return true
}
Expand All @@ -138,7 +136,6 @@ export default {
},
mounted() {
let currentDate = new Date()
// Set the time frame to show past 3 month until today
let startDate = new Date(
currentDate.getFullYear(),
currentDate.getMonth() - 2,
Expand All @@ -147,11 +144,25 @@ export default {
let endDate = currentDate
this.setDate(startDate, "from")
this.setDate(endDate, "to")
this.getClusterFinancialData()
},
watch: {
// eslint-disable-next-line no-unused-vars
revenue(newVal, oldVal) {
this.clusterService.financialData = newVal
"clusterService.financialData": {
handler(newVal) {
if (newVal) {
this.lineChartData = this.clusterService.lineChartData(true)
this.columnChartData = this.clusterService.columnChartData(
false,
"cluster",
)
this.pieChartData = this.clusterService.columnChartData(
false,
"cluster",
)
}
},
deep: true,
immediate: true,
},
},
methods: {
Expand All @@ -164,18 +175,23 @@ export default {
return
}
this.loading = true
console.log(this.period.from)
console.log(this.period.to)
this.periodChanged(this.period.from, this.period.to)
this.setPeriod = false
this.loading = false
},

dateSelectedFrom(date) {
this.setDate(date, "from")
},
dateSelectedTo(date) {
this.setDate(date, "to")
try {
const financialData = await this.clusterService.getAllRevenues(
"monthly",
this.period.from,
this.period.to,
)
this.clusterService.financialData = financialData

this.periodChanged(this.period.from, this.period.to)

this.setPeriod = false
} catch (error) {
console.error("Error fetching financial data:", error)
} finally {
this.loading = false
}
},
setDate(dateData, target) {
let date = moment(dateData)
Expand Down
6 changes: 0 additions & 6 deletions src/frontend/src/services/ClusterService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ErrorHandler } from "@/Helpers/ErrorHandler"
import i18n from "../i18n"
import { convertObjectKeysToSnakeCase } from "@/Helpers/Utils"

import ClusterRepository from "@/repositories/ClusterRepository"

export class ClusterService {
Expand Down Expand Up @@ -103,10 +102,8 @@ export class ClusterService {
this.trendChartData.base = [Object.keys(this.clusterTrends)]
this.trendChartData.base[0].unshift("Date")
for (let i in this.clusterTrends[trendKeys[0]]) {
// iterate over periods
let tmpData = []
for (let j in trendKeys) {
//iterate over connection names
tmpData.push(this.clusterTrends[trendKeys[j]][i])
}
tmpData.unshift(i)
Expand Down Expand Up @@ -158,9 +155,6 @@ export class ClusterService {
return data
}

/**
* Generates data array for column and donut chart
*/
columnChartData(summary, type) {
let data = []
let summaryRevenue = 0
Expand Down
Loading