-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UI to better handle different roles (#3733)
- Loading branch information
Showing
23 changed files
with
283 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.15.16" | ||
__version__ = "0.15.17" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,72 @@ | ||
import { Stack, Shimmer, TooltipHost, Icon } from "@fluentui/react"; | ||
import { useContext } from "react"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import { CostsContext } from "../../contexts/CostsContext"; | ||
import { LoadingState } from "../../models/loadingState"; | ||
import { WorkspaceContext } from "../../contexts/WorkspaceContext"; | ||
import { CostResource } from "../../models/costs"; | ||
import { useAuthApiCall, HttpMethod, ResultType } from '../../hooks/useAuthApiCall'; | ||
import { ApiEndpoint } from "../../models/apiEndpoints"; | ||
|
||
interface CostsTagProps { | ||
resourceId: string | ||
resourceId: string; | ||
} | ||
|
||
export const CostsTag: React.FunctionComponent<CostsTagProps> = (props: CostsTagProps) => { | ||
const costsCtx = useContext(CostsContext); | ||
const resourceCosts = costsCtx?.costs?.find((resourceCost) => { | ||
return resourceCost.id === props.resourceId; | ||
}); | ||
let costBadge = <></>; | ||
switch(costsCtx.loadingState) { | ||
case LoadingState.Loading: | ||
costBadge = <Stack.Item style={{maxHeight: 18, width: 30}} className="tre-badge"><Shimmer/></Stack.Item> | ||
break; | ||
case LoadingState.Ok: | ||
const workspaceCtx = useContext(WorkspaceContext); | ||
const [loadingState, setLoadingState] = useState(LoadingState.Loading); | ||
const apiCall = useAuthApiCall(); | ||
const [formattedCost, setFormattedCost] = useState<string | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
async function fetchCostData() { | ||
let costs: CostResource[] = []; | ||
if (workspaceCtx.costs.length > 0) { | ||
costs = workspaceCtx.costs; | ||
} else if (costsCtx.costs.length > 0) { | ||
costs = costsCtx.costs; | ||
} else { | ||
let scopeId = (await apiCall(`${ApiEndpoint.Workspaces}/${props.resourceId}/scopeid`, HttpMethod.Get)).workspaceAuth.scopeId; | ||
const r = await apiCall(`${ApiEndpoint.Workspaces}/${props.resourceId}/${ApiEndpoint.Costs}`, HttpMethod.Get, scopeId, undefined, ResultType.JSON); | ||
costs = [{costs: r.costs, id: r.id, name: r.name }]; | ||
} | ||
|
||
const resourceCosts = costs.find((cost) => { | ||
return cost.id === props.resourceId; | ||
}); | ||
|
||
if (resourceCosts && resourceCosts.costs.length > 0) { | ||
const formattedCost = new Intl.NumberFormat(undefined, { | ||
style: 'currency', | ||
currency: resourceCosts?.costs[0].currency, | ||
currencyDisplay: 'narrowSymbol', | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2 | ||
}).format(resourceCosts?.costs[0].cost); | ||
costBadge = <Stack.Item style={{maxHeight: 18}} className="tre-badge">{formattedCost}</Stack.Item> | ||
} else { | ||
costBadge = ( | ||
<Stack.Item style={{maxHeight: 18}} className="tre-badge"> | ||
}).format(resourceCosts.costs[0].cost); | ||
setFormattedCost(formattedCost); | ||
setLoadingState(LoadingState.Ok); | ||
} | ||
} | ||
fetchCostData(); | ||
}, [apiCall, costsCtx.loadingState, props.resourceId, workspaceCtx.costs, costsCtx.costs]); | ||
|
||
const costBadge = ( | ||
<Stack.Item style={{ maxHeight: 18 }} className="tre-badge"> | ||
{loadingState === LoadingState.Loading ? ( | ||
<Shimmer /> | ||
) : ( | ||
<> | ||
{formattedCost ? ( | ||
formattedCost | ||
) : ( | ||
<TooltipHost content="Cost data not yet available"> | ||
<Icon iconName="Clock" /> | ||
</TooltipHost> | ||
</Stack.Item> | ||
); | ||
} | ||
break; | ||
} | ||
)} | ||
</> | ||
)} | ||
</Stack.Item> | ||
); | ||
|
||
return (costBadge); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.