superset
superset copied to clipboard
feat(formatters): Add custom d3-time-format locale
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:
With brazilian portuguese time format configuration:
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
Codecov Report
Merging #24263 (3ad0d63) into master (0836000) will decrease coverage by
0.02%
. The diff coverage is63.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
Also ccing @villebro since he is working on some other localization features.
Oh big fan of this! Any updates on this?
Any updates on this review?
Any updates on this review?
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?
/testenv up
@eschutho Container image not yet published for this PR. Please try again when build is complete.
@eschutho Ephemeral environment creation failed. Please check the Actions logs for details.
this feature is mandatory to onboard business users who want to see, for ex. months, in the correct language in time series charts.
@eschutho I fixed the conflicts. If there is anything that I can do to help with the review, let me know :+1:
any updates on this one?
There are a handful of linting errors to contend with still that are blocking this.
any updates on this one?
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.
Thansk for the reply @rusackas, I'll fix the linting errors soon.
@rusackas I've fixed the linting errors and checked all the linters locally, everything is fine.
Running CI. Fingers crossed! 🤞
@rusackas I added more tests to fix the coverage issue reported in the last CI run.
@rusackas Is there anything else that I can do to help with the review?
/testenv up
@rusackas Ephemeral environment spinning up at http://52.33.93.221:8080. Credentials are admin
/admin
. Please allow several minutes for bootstrapping and startup.
up
Running CI again - fingers crossed! Last chance, @kgabryje / @justinpark / @michael-s-molina / @villebro
@rusackas I fixed some linting errors caused by merge conflict.