Skip to content

Commit

Permalink
Only show carbon emissions reports when enabled in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Renni771 committed Mar 5, 2024
1 parent 3fd33f4 commit 5a1a610
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { useCarbonEmissions } from "@/composables/carbonEmissions";
import { useHistoryStore } from "@/stores/historyStore";
import HistoriesStorageOverview from "./HistoriesStorageOverview.vue";
Expand All @@ -8,6 +9,7 @@ import Heading from "@/components/Common/Heading.vue";
const props = defineProps<{ historyId: string }>();
const { getHistoryNameById } = useHistoryStore();
const { shouldShowCarbonEmissionsReports } = useCarbonEmissions();
</script>

<template>
Expand All @@ -32,7 +34,7 @@ const { getHistoryNameById } = useHistoryStore();
<HistoriesStorageOverview />
</section>

<section class="mt-3">
<section v-if="shouldShowCarbonEmissionsReports" class="mt-3">
<Heading h2 bold separator> Carbon Emissions </Heading>
<HistoryCarbonEmissions :history-id="props.historyId" />
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
:loading="!invocationAndJobTerminal"
class="jobs-progress" />

<div>
<div v-if="shouldShowCarbonEmissionsReports">
<strong>Carbon Emissions:</strong>

<CarbonEmissions
Expand Down Expand Up @@ -178,7 +178,11 @@ export default {
},
},
setup(props) {
const { carbonIntensity, geographicalServerLocationName } = useCarbonEmissions();
const {
carbonIntensity,
geographicalServerLocationName,
shouldShowCarbonEmissionsReports
} = useCarbonEmissions();
const invocationId = computed(() => props.invocation?.id);
Expand Down Expand Up @@ -208,7 +212,7 @@ export default {
watch(
() => invocationId.value,
() => {
if (invocationId.value) {
if (shouldShowCarbonEmissionsReports && invocationId.value) {
fetchEnergyUsageData();
}
},
Expand All @@ -219,6 +223,7 @@ export default {
carbonIntensity,
energyUsage,
geographicalServerLocationName,
shouldShowCarbonEmissionsReports,
invocationId,
worldwideCarbonIntensity,
worldwidePowerUsageEffectiveness,
Expand Down
2 changes: 2 additions & 0 deletions client/src/composables/carbonEmissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { useConfig } from "./config";
export function useCarbonEmissions() {
const { config } = useConfig(true);
const carbonIntensity = computed(() => (config.value?.carbon_intensity as number) ?? worldwideCarbonIntensity);
const shouldShowCarbonEmissionsReports = computed(() => (config.value?.carbon_emission_estimates as boolean) ?? true);
const geographicalServerLocationName = computed(
() => (config.value?.geographical_server_location_name as string) ?? "GLOBAL"
);

return {
carbonIntensity,
geographicalServerLocationName,
shouldShowCarbonEmissionsReports,
};
}

0 comments on commit 5a1a610

Please sign in to comment.