Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adds external costs page, reorganizes for longevity #43

Merged
Merged
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
8,357 changes: 4,245 additions & 4,112 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -23,10 +23,7 @@ const useStyles = makeStyles({

const Header = (props) => {
const classes = useStyles();
const { title, breadcrumbs } = props;
const { pathname } = useLocation();

const headerTitle = pathname === "/cloud" ? "Cloud Costs" : "Cost Allocation";
const { title, breadcrumbs, headerTitle } = props;

return (
<div className={classes.root}>
@@ -36,7 +33,7 @@ const Header = (props) => {
<div className={classes.context}>
{title && (
<Typography variant="h4" className={classes.title}>
{props.title}
{title}
</Typography>
)}
{breadcrumbs && breadcrumbs.length > 0 && (
1 change: 1 addition & 0 deletions src/components/Nav/SidebarNav.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ const SidebarNav = ({ active }) => {
icon: <BarChart />,
},
{ name: "Cloud Costs", href: "cloud", icon: <Cloud /> },
{ name: "External Costs", href: "external-costs", icon: <Cloud /> },
];

return (
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import {
TableBody,
} from "@material-ui/core";

import { toCurrency } from "../util";
import { toCurrency } from "../../util";
import CloudCostChart from "./cloudCostChart";
import { CloudCostRow } from "./cloudCostRow";

@@ -31,8 +31,6 @@ const CloudCost = ({
},
});



const classes = useStyles();

function descendingComparator(a, b, orderBy) {
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ import {
ResponsiveContainer,
Cell,
} from "recharts";
import { primary, greyscale, browns } from "../../constants/colors";
import { toCurrency } from "../../util";
import { primary, greyscale, browns } from "../../../constants/colors";
import { toCurrency } from "../../../util";

const RangeChart = ({ data, currency, height }) => {
const useStyles = makeStyles({
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Modal, Paper, Typography } from "@material-ui/core";
import Warnings from "../components/Warnings";
import Warnings from "../../components/Warnings";
import CircularProgress from "@material-ui/core/CircularProgress";

import {
@@ -13,8 +13,8 @@ import {
BarChart,
Bar,
} from "recharts";
import { toCurrency } from "../util";
import cloudCostDayTotals from "../services/cloudCostDayTotals";
import { toCurrency } from "../../util";
import cloudCostDayTotals from "../../services/cloudCostDayTotals";

const CloudCostDetails = ({
onClose,
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import * as React from "react";

import { TableCell, TableRow } from "@material-ui/core";

import { toCurrency } from "../util";
import { primary } from "../constants/colors";
import { toCurrency } from "../../util";
import { primary } from "../../constants/colors";

const displayCurrencyAsLessThanPenny = (amount, currency) =>
amount > 0 && amount < 0.01
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Select from "@material-ui/core/Select";

import * as React from "react";

import SelectWindow from "../../components/SelectWindow";
import SelectWindow from "../../SelectWindow";

const useStyles = makeStyles({
wrapper: {
File renamed without changes.
93 changes: 93 additions & 0 deletions src/components/externalCosts/externalCostDetailModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Modal, Paper } from "@material-ui/core";
import {
TableContainer,
TableCell,
TableRow,
Table,
TableBody,
} from "@material-ui/core";

// for now, we can assume that the "Name" is resourceType
export const ExternalCostDetails = ({ row, onClose }) => (
<div>
<Modal
open={true}
onClose={onClose}
title={row.resource_type}
style={{ margin: "10%" }}
>
<Paper style={{ padding: 20 }}>
<TableContainer>
<Table>
<TableBody>
<TableRow>
<TableCell>account_name</TableCell>
<TableCell>{row.account_name}</TableCell>
</TableRow>
<TableRow>
<TableCell>aggregate</TableCell>
<TableCell>{row.aggregate}</TableCell>
</TableRow>
<TableRow>
<TableCell>charge_category</TableCell>
<TableCell>{row.charge_category}</TableCell>
</TableRow>
<TableRow>
<TableCell>cost</TableCell>
<TableCell>{row.cost}</TableCell>
</TableRow>
<TableRow>
<TableCell>cost_source</TableCell>
<TableCell>{row.cost_source}</TableCell>
</TableRow>
<TableRow>
<TableCell>cost_type</TableCell>
<TableCell>{row.cost_type}</TableCell>
</TableRow>
<TableRow>
<TableCell>description</TableCell>
<TableCell>{row.description}</TableCell>
</TableRow>
<TableRow>
<TableCell>domain</TableCell>
<TableCell>{row.domain}</TableCell>
</TableRow>
<TableRow>
<TableCell>id</TableCell>
<TableCell>{row.id}</TableCell>
</TableRow>
<TableRow>
<TableCell>list_unit_price</TableCell>
<TableCell>{row.list_unit_price}</TableCell>
</TableRow>
<TableRow>
<TableCell>provider_id</TableCell>
<TableCell>{row.provider_id}</TableCell>
</TableRow>
<TableRow>
<TableCell>resource_name</TableCell>
<TableCell>{row.resource_name}</TableCell>
</TableRow>
<TableRow>
<TableCell>resource_type</TableCell>
<TableCell>{row.resource_type}</TableCell>
</TableRow>
<TableRow>
<TableCell>usage_quantity</TableCell>
<TableCell>{row.usage_quantity}</TableCell>
</TableRow>
<TableRow>
<TableCell>usage_unit</TableCell>
<TableCell>{row.usage_unit}</TableCell>
</TableRow>
<TableRow>
<TableCell>zone</TableCell>
<TableCell>{row.zone}</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Paper>
</Modal>
</div>
);
43 changes: 43 additions & 0 deletions src/components/externalCosts/externalCostRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from "react";

import { TableCell, TableRow } from "@material-ui/core";

import { toCurrency } from "../../util";
import { primary } from "../../constants/colors";

const displayCurrencyAsLessThanPenny = (amount, currency) =>
amount > 0 && amount < 0.01
? `<${toCurrency(0.01, currency)}`
: toCurrency(amount, currency);

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

const ExternalCostRow = ({
cost,
currency,
onClick,
name,
costType,
}) => {
return (
<TableRow onClick={onClick}>
<TableCell
align={"left"}
style={{ cursor: "pointer", color: "#346ef2", padding: "1rem" }}
>
{name}
</TableCell>
<TableCell align={"right"} style={{ paddingRight: "2em" }}>
{capitalizeFirstLetter(costType)}
</TableCell>
{/* total cost */}
<TableCell align={"right"} style={{ paddingRight: "2em" }}>
{`${displayCurrencyAsLessThanPenny(cost, currency)}`}
</TableCell>
</TableRow>
);
};

export { ExternalCostRow };
31 changes: 31 additions & 0 deletions src/components/externalCosts/externalCostsChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from "react";

import Typography from "@material-ui/core/Typography";

import RangeChart from "./rangeChart";

const ExternalCostsChart = ({
graphData,
currency,
n,
height,
aggregateBy,
}) => {
if (graphData.length === 0) {
return (
<Typography variant="body2" style={{ padding: "4em" }}>
No data
</Typography>
);
}
return (
<RangeChart
data={graphData}
currency={currency}
height={height}
aggregateBy={aggregateBy}
/>
);
};

export default React.memo(ExternalCostsChart);
78 changes: 78 additions & 0 deletions src/components/externalCosts/externalCostsControls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { makeStyles } from "@material-ui/styles";
import FormControl from "@material-ui/core/FormControl";
import InputLabel from "@material-ui/core/InputLabel";
import MenuItem from "@material-ui/core/MenuItem";
import Select from "@material-ui/core/Select";

import * as React from "react";

import SelectWindow from "../../components/SelectWindow";
import {
windowOptions,
aggregationOptions,
costTypeOptions
} from '../../components/externalCosts/tokens'

const useStyles = makeStyles({
wrapper: {
display: "inline-flex",
},
formControl: {
margin: 8,
minWidth: 120,
},
});

function ExternalCostsControls({
window,
setWindow,
aggregateBy,
setAggregateBy,
costType,
setCostType
}) {
const classes = useStyles();
return (
<div className={classes.wrapper}>
<SelectWindow
windowOptions={windowOptions}
window={window}
setWindow={setWindow}
/>
<FormControl className={classes.formControl}>
<InputLabel id="aggregation-select-label">Breakdown</InputLabel>
<Select
id="aggregation-select"
value={aggregateBy}
onChange={(e) => {
setAggregateBy(e.target.value);
}}
>
{aggregationOptions.map((opt) => (
<MenuItem key={opt.value} value={opt.value}>
{opt.name}
</MenuItem>
))}
</Select>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel id="aggregation-select-label">Cost Type</InputLabel>
<Select
id="cost-type-select"
value={costType}
onChange={(e) => {
setCostType(e.target.value);
}}
>
{costTypeOptions.map((opt) => (
<MenuItem key={opt.value} value={opt.value}>
{opt.name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}

export default React.memo(ExternalCostsControls);
Loading