Skip to content

Commit 7765020

Browse files
committed
Require explicit flag to enable mock data usage
Signed-off-by: Rahim <[email protected]>
1 parent 7b43cc6 commit 7765020

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/services/allocation.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { parseFilters } from "../util";
22
import client from "./api_client";
33

4+
// Flag to enable mock data - must be explicitly set via REACT_APP_USE_MOCK_DATA environment variable
5+
const USE_MOCK_DATA = process.env.REACT_APP_USE_MOCK_DATA === "true";
6+
47
// Mock data for testing drilldown functionality when backend is not available
8+
// Only used when REACT_APP_USE_MOCK_DATA=true is explicitly set
59
const getMockData = (aggregate, filters) => {
610
const mockNamespaces = [
711
{ name: "default", totalCost: 150.50, cpuCost: 50.0, ramCost: 60.0, pvCost: 40.5, gpuCost: 0, totalEfficiency: 0.85 },
@@ -66,9 +70,10 @@ class AllocationService {
6670
});
6771
return result.data;
6872
} catch (error) {
69-
// If backend is not available, return mock data for testing
70-
if (error.message && (error.message.includes("Network Error") || error.message.includes("ECONNREFUSED"))) {
71-
console.warn("Backend not available, using mock data for testing");
73+
// Only use mock data if explicitly enabled via REACT_APP_USE_MOCK_DATA=true
74+
// This prevents confusion for users who misconfigured their backend
75+
if (USE_MOCK_DATA && error.message && (error.message.includes("Network Error") || error.message.includes("ECONNREFUSED"))) {
76+
console.warn("Backend not available, using mock data (REACT_APP_USE_MOCK_DATA is enabled)");
7277
return getMockData(aggregate, filters);
7378
}
7479
throw error;

0 commit comments

Comments
 (0)