Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ temp/

# AI/IDE directories
.cursor/
.agents/
28 changes: 26 additions & 2 deletions src/pages/CloudBilling/Billing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ const detailsProviderId = ref('')
const detailsAccountId = ref('')
const showPreviewModal = ref(false)
const selectedBilling = ref(null)
const isInitializing = ref(true)

// Prevent multiple concurrent calls
let isStatsLoading = false
let isDetailsLoading = false

// Initialize date range: details tab default is last 3 days (from 3 days ago to today)
const initDateRange = () => {
Expand Down Expand Up @@ -574,6 +579,9 @@ const loadProviders = async () => {

// Load statistics
const loadStatistics = async () => {
if (isStatsLoading) return

isStatsLoading = true
statsLoading.value = true
try {
const params = {}
Expand Down Expand Up @@ -615,6 +623,7 @@ const loadStatistics = async () => {
statistics.value = null
} finally {
statsLoading.value = false
isStatsLoading = false
}
}

Expand Down Expand Up @@ -678,6 +687,9 @@ const loadDailyBillingData = async () => {

// Load billing details
const loadBillings = async (query = '') => {
if (isDetailsLoading) return

isDetailsLoading = true
detailsLoading.value = true
try {
const params = {}
Expand Down Expand Up @@ -797,13 +809,22 @@ const loadBillings = async (query = '') => {
billings.value = []
} finally {
detailsLoading.value = false
isDetailsLoading = false
}
}

const { debouncedFn: debouncedSearch } = useDebounce((query) => {
loadBillings(query)
}, 300)

const { debouncedFn: debouncedLoadStatistics } = useDebounce(() => {
loadStatistics()
}, 100)

const { debouncedFn: debouncedLoadBillings } = useDebounce(() => {
loadBillings(searchQuery.value)
}, 100)

const handleSearch = (query) => {
searchQuery.value = query
debouncedSearch(query)
Expand Down Expand Up @@ -833,20 +854,23 @@ watch(activeTab, (newTab) => {

// Watch statistics filter changes for real-time updates
watch([statsPeriodType, statsSelectedPeriod, statsSelectedYear, statsProviderId, statsAccountId], () => {
if (isInitializing.value) return
if (activeTab.value === 'statistics') {
loadStatistics()
debouncedLoadStatistics()
}
})

// Watch details filter changes
watch([detailsStartDate, detailsEndDate, detailsProviderId, detailsAccountId], () => {
if (isInitializing.value) return
if (activeTab.value === 'details') {
loadBillings(searchQuery.value)
debouncedLoadBillings()
}
})

onMounted(() => {
initDateRange()
isInitializing.value = false
loadProviders()
loadStatistics()
})
Expand Down