superset icon indicating copy to clipboard operation
superset copied to clipboard

feat(formatters): Add custom d3-time-format locale

Open matheusbsilva opened this issue 1 year ago • 25 comments

SUMMARY

Adds a configuration option to change the default language of time related data on charts, including the option to translate months. This is related to issues: #3972 , https://github.com/apache/superset/issues/13442 and https://github.com/apache/superset/issues/17447.

During the implementation I had to change how the smart formatters were used across the application, because I had to ensure that they were instantiated with the right locale configuration. So instead of importing them directly, I got them through the TimeFormatterRegistry. I'm not sure if is the best option, let me know.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Without time format configuration: Captura de tela de 2023-06-01 09-49-00

With brazilian portuguese time format configuration: Captura de tela de 2023-06-01 09-47-58

TESTING INSTRUCTIONS

Add the D3_TIME_FORMAT with your locale configuration to superset_config.py following the definition expected by D3 (docs), for example, this is the definition for brazilian portuguese:

D3_TIME_FORMAT = {
  "dateTime": "%A, %e de %B de %Y. %X",
  "date": "%d/%m/%Y",
  "time": "%H:%M:%S",
  "periods": ["AM", "PM"],
  "days": ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
  "shortDays": ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
  "months": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
  "shortMonths": ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
}

ADDITIONAL INFORMATION

  • [X] Has associated issue:
  • [ ] Required feature flags:
  • [X] Changes UI
  • [ ] Includes DB Migration (follow approval process in SIP-59)
    • [ ] Migration is atomic, supports rollback & is backwards-compatible
    • [ ] Confirm DB migration upgrade and downgrade tested
    • [ ] Runtime estimates and downtime expectations provided
  • [X] Introduces new feature or API
  • [ ] Removes existing feature or API

matheusbsilva avatar Jun 01 '23 12:06 matheusbsilva

Codecov Report

Merging #24263 (3ad0d63) into master (0836000) will decrease coverage by 0.02%. The diff coverage is 63.43%.

:exclamation: Current head 3ad0d63 differs from pull request most recent head 38b4890. Consider uploading reports for the commit 38b4890 to get more accurate results

@@            Coverage Diff             @@
##           master   #24263      +/-   ##
==========================================
- Coverage   69.10%   69.08%   -0.02%     
==========================================
  Files        1906     1904       -2     
  Lines       74175    74155      -20     
  Branches     8163     8173      +10     
==========================================
- Hits        51259    51232      -27     
- Misses      20788    20806      +18     
+ Partials     2128     2117      -11     
Flag Coverage Δ
hive 54.15% <44.70%> (+0.21%) :arrow_up:
mysql 79.48% <84.70%> (+0.09%) :arrow_up:
postgres 79.57% <84.70%> (+0.09%) :arrow_up:
presto 54.04% <44.70%> (+0.21%) :arrow_up:
python 83.54% <85.88%> (+0.06%) :arrow_up:
sqlite 78.13% <72.35%> (+0.09%) :arrow_up:
unit 54.83% <48.23%> (+0.14%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...perset-ui-chart-controls/src/utils/D3Formatting.ts 100.00% <ø> (ø)
...t-ui-core/src/time-format/TimeFormatterRegistry.ts 100.00% <ø> (ø)
.../src/time-format/factories/createMultiFormatter.ts 100.00% <ø> (ø)
...plugins/legacy-plugin-chart-heatmap/src/Heatmap.js 0.00% <ø> (ø)
.../legacy-plugin-chart-heatmap/src/transformProps.js 0.00% <0.00%> (ø)
...gins/legacy-plugin-chart-world-map/src/WorldMap.js 0.00% <ø> (ø)
...egacy-plugin-chart-world-map/src/transformProps.js 0.00% <0.00%> (ø)
...nd/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js 0.00% <ø> (ø)
...tend/plugins/legacy-preset-chart-nvd3/src/utils.js 15.38% <ø> (-0.54%) :arrow_down:
...harts/src/BigNumber/BigNumberTotal/controlPanel.ts 30.00% <ø> (ø)
... and 93 more

... and 3 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Jun 01 '23 17:06 codecov[bot]

Also ccing @villebro since he is working on some other localization features.

eschutho avatar Jun 09 '23 22:06 eschutho

Oh big fan of this! Any updates on this?

lf-floriandin avatar Jul 12 '23 08:07 lf-floriandin

Any updates on this review?

matheusbsilva avatar Aug 24 '23 19:08 matheusbsilva

Any updates on this review?

Cmagno13 avatar Aug 25 '23 14:08 Cmagno13

Many thanks for this PR. I'm awaiting for this PR: To use Superset in France (public sector), this PR is mandatory. Do you have any idea when this PR will be merged in superset?

cchristofr avatar Sep 23 '23 08:09 cchristofr

/testenv up

eschutho avatar Oct 03 '23 20:10 eschutho

@eschutho Container image not yet published for this PR. Please try again when build is complete.

github-actions[bot] avatar Oct 03 '23 20:10 github-actions[bot]

@eschutho Ephemeral environment creation failed. Please check the Actions logs for details.

github-actions[bot] avatar Oct 03 '23 20:10 github-actions[bot]

this feature is mandatory to onboard business users who want to see, for ex. months, in the correct language in time series charts.

cchristofr avatar Oct 21 '23 09:10 cchristofr

@eschutho I fixed the conflicts. If there is anything that I can do to help with the review, let me know :+1:

matheusbsilva avatar Oct 22 '23 21:10 matheusbsilva

any updates on this one?

ImmortalLotus avatar Jan 29 '24 13:01 ImmortalLotus

There are a handful of linting errors to contend with still that are blocking this.

rusackas avatar Jan 31 '24 04:01 rusackas

any updates on this one?

rtotheb2000 avatar Mar 05 '24 07:03 rtotheb2000

Looks like this needs some linting AND a rebase at this point. If @matheusbsilva wants to follow through, that's awesome, but anyone else is also welcome to pick this up if they desire to.

rusackas avatar Mar 06 '24 00:03 rusackas

Thansk for the reply @rusackas, I'll fix the linting errors soon.

matheusbsilva avatar Mar 06 '24 13:03 matheusbsilva

@rusackas I've fixed the linting errors and checked all the linters locally, everything is fine.

matheusbsilva avatar Mar 28 '24 21:03 matheusbsilva

Running CI. Fingers crossed! 🤞

rusackas avatar Apr 02 '24 22:04 rusackas

@rusackas I added more tests to fix the coverage issue reported in the last CI run.

matheusbsilva avatar Apr 03 '24 15:04 matheusbsilva

@rusackas Is there anything else that I can do to help with the review?

matheusbsilva avatar Apr 17 '24 13:04 matheusbsilva

/testenv up

rusackas avatar Apr 18 '24 23:04 rusackas

@rusackas Ephemeral environment spinning up at http://52.33.93.221:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Apr 18 '24 23:04 github-actions[bot]

up

matheusbsilva avatar May 07 '24 16:05 matheusbsilva

Running CI again - fingers crossed! Last chance, @kgabryje / @justinpark / @michael-s-molina / @villebro

rusackas avatar May 07 '24 21:05 rusackas

@rusackas I fixed some linting errors caused by merge conflict.

matheusbsilva avatar May 08 '24 13:05 matheusbsilva