Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Units: Format currency with negative before the symbol #65152

Merged
merged 3 commits into from Mar 22, 2023
Merged

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented Mar 22, 2023

What is this feature?

We currently format negative monies as $-100 and it should be -$100

Why do we need this feature?

to be more normal

image

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #65123

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.
  • There are no known compatibility issues with older supported versions of Grafana, or plugins.
  • It passes the Hosted Grafana feature readiness review for observability, scalability, performance, and security.

@ryantxu ryantxu added this to the 9.5.0 milestone Mar 22, 2023
@ryantxu ryantxu requested a review from baldm0mma March 22, 2023 07:24
@ryantxu ryantxu requested review from a team as code owners March 22, 2023 07:24
@ryantxu ryantxu requested review from tskarhed, JoaoSilvaGrafana and mckn and removed request for a team March 22, 2023 07:24
@github-advanced-security
Copy link

You have successfully added a new CodeQL configuration .github/workflows/pr-codeql-analysis-javascript.yml:analyze. As part of the setup process, we have scanned this repository and found 29 existing alerts. Please check the repository Security tab to see all alerts.

Copy link
Contributor

@leventebalogh leventebalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👏

packages/grafana-data/src/valueFormats/symbolFormatters.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@baldm0mma baldm0mma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fast and elegant solution! Played around with it, and works great. LGTM!

@@ -5,16 +5,23 @@ import { scaledUnits, ValueFormatter } from './valueFormats';
export function currency(symbol: string, asSuffix?: boolean): ValueFormatter {
const units = ['', 'K', 'M', 'B', 'T'];
const scaler = scaledUnits(1000, units);
return (size: number, decimals?: DecimalCount, scaledDecimals?: DecimalCount) => {
if (size === null) {
return (value: number, decimals?: DecimalCount, scaledDecimals?: DecimalCount) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change here, value makes way more sense.

ryantxu and others added 2 commits March 22, 2023 07:28
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
@ryantxu ryantxu merged commit 01a5d50 into main Mar 22, 2023
14 checks passed
@ryantxu ryantxu deleted the negative-currency branch March 22, 2023 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants