widgetLegendNameEncoderDecoder.tsx 941 B

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