briangann/grafana-datatable-panel

View on GitHub
src/hooks/useApplyTransformation.ts

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
import { DataFrame } from '@grafana/data';
import React from 'react';
import { transformData } from 'transformations';
import { TransformationOptions } from 'types';

export const useApplyTransformation = (dataSeries: DataFrame[]) => {
  const [dataFrames, setDataFrames] = React.useState<DataFrame[] | undefined>();

  React.useEffect(() => {
    async function fetchData() {
      //TODO: Use the actual panel option instead of this hardcoded one
      const rows = await transformData(dataSeries, TransformationOptions.TimeSeriesToColumns);
      setDataFrames(rows);
    }
    fetchData();
  }, [dataSeries]);

  return dataFrames;
};