widgetLegendNameEncoderDecoder.tsx 803 B

1234567891011121314151617181920212223242526
  1. import type {Series} from 'sentry/types/echarts';
  2. import type {Widget} from 'sentry/views/dashboards/types';
  3. class WidgetLegendNameEncoderDecoder {
  4. static encodeSeriesNameForLegend(seriesName: string, widgetId?: string) {
  5. return `${seriesName}:${widgetId}`;
  6. }
  7. static decodeSeriesNameForLegend(encodedSeriesName: string) {
  8. return encodedSeriesName.split(':')[0];
  9. }
  10. // change timeseries names to SeriesName:widgetID
  11. static modifyTimeseriesNames(widget: Widget, timeseriesResults?: Series[]) {
  12. return timeseriesResults
  13. ? timeseriesResults.map(series => {
  14. return {
  15. ...series,
  16. seriesName: this.encodeSeriesNameForLegend(series.seriesName, widget.id),
  17. };
  18. })
  19. : [];
  20. }
  21. }
  22. export default WidgetLegendNameEncoderDecoder;