Skip to content

Commit

Permalink
[652] Update create app templates. Bonus: New script for making creat…
Browse files Browse the repository at this point in the history
…e app template updates
  • Loading branch information
4upz-tw committed Jan 6, 2022
1 parent e8169ba commit 73d505f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { FunctionComponent, useState } from 'react'
import { FlightTakeoff, PhonelinkRing, Eco } from '@material-ui/icons'
import { EstimationResult } from '@cloud-carbon-footprint/common'
import { sumEstimate } from 'utils/helpers'
import { sumEstimates } from 'utils/helpers'
import NoDataMessage from 'common/NoDataMessage'
import DashboardCard from 'layout/DashboardCard'
import { Source, ComparisonItem } from 'Types'
Expand Down Expand Up @@ -46,7 +46,7 @@ const CarbonComparisonCard: FunctionComponent<CarbonComparisonCardProps> = ({
: Number(number.toExponential(decimalPlaces)).toString()
}

const totalMetricTons = sumEstimate(data, 'co2e')
const totalMetricTons = sumEstimates(data, 'co2e')
const totalFlights = toFlights(totalMetricTons)
const totalPhones = toPhones(totalMetricTons)
const totalTrees = toTrees(totalMetricTons)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@cloud-carbon-footprint/common'
import useStyles from './forecastStyles'
import {
sumEstimate,
sumEstimates,
sumRecommendations,
calculatePercentChange,
formattedNumberWithCommas,
Expand All @@ -35,8 +35,8 @@ const Forecast: FunctionComponent<ForecastProps> = ({

const forecastMultiplier = useKilograms ? 1000 : 1

const sumCurrentCo2e = sumEstimate(emissionsData, 'co2e')
const sumCurrentCost = sumEstimate(emissionsData, 'cost')
const sumCurrentCo2e = sumEstimates(emissionsData, 'co2e')
const sumCurrentCost = sumEstimates(emissionsData, 'cost')

const currentCo2eFormatted = formattedNumberWithCommas(
sumCurrentCo2e * forecastMultiplier,
Expand All @@ -49,11 +49,15 @@ const Forecast: FunctionComponent<ForecastProps> = ({
const projectedSavingsCo2e = sumCurrentCo2e - sumSavingsCo2e
const projectedSavingsCost = sumCurrentCost - sumSavingsCost

const projectedCo2eFormatted = formattedNumberWithCommas(
const formatProjectedSavings = (projectedSavings: number): string =>
projectedSavings > 0 ? formattedNumberWithCommas(projectedSavings) : '0'

const projectedCo2eFormatted = formatProjectedSavings(
projectedSavingsCo2e * forecastMultiplier,
)
const projectedCostFormatted = `$${formattedNumberWithCommas(
projectedSavingsCost,

const projectedCostFormatted = `$${formatProjectedSavings(
projectedSavingsCo2e * forecastMultiplier,
)}`

const co2ePercentChange = calculatePercentChange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

export {
sumEstimate,
sumEstimates,
sumRecommendations,
calculatePercentChange,
formattedNumberWithCommas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const sumCO2ByServiceOrRegion = (
}, Object.create({}))
}

const sumEstimate = (
const sumEstimates = (
data: (EstimationResult | ServiceData)[],
key: string,
): number => {
Expand Down Expand Up @@ -297,7 +297,7 @@ function tableFormatRawCo2e(useKilograms: boolean, rawValue: number): string {
}

export {
sumEstimate,
sumEstimates,
sumRecommendations,
calculatePercentChange,
formattedNumberWithCommas,
Expand Down
26 changes: 26 additions & 0 deletions scripts/update_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

#
# © 2021 Thoughtworks, Inc.
#

#Intended to be executed from project root directory
templatePath="packages/create-app/templates/default-app/packages/$1"
targetPath="packages/$1/src"

if [ -d $templatePath ]
then
cp -r $targetPath $templatePath
cd "$templatePath/src"
find . -name "*.test.tsx" -type f -delete
find . -name "*.test.tsx.snap" -type f -delete
find . -name "*.test.ts" -type f -delete
echo -e "Successfully copied files from [$1] package into $templatePath.\nMake sure to double check before committing! :D"
else
echo "Error: Directory \"$templatePath\" does not exists. Please specify an appropriate template package."
exit 1
fi

#git diff --cached --name-status | while read x file; do
# cp $file "\"$templatePath\"/src"
# done

0 comments on commit 73d505f

Please sign in to comment.