featureFlagUtils.tsx 836 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. export type RawFlag = {
  2. action: string;
  3. createdAt: string;
  4. createdBy: string;
  5. createdByType: string;
  6. flag: string;
  7. id: number;
  8. tags: Record<string, any>;
  9. };
  10. export type RawFlagData = {data: RawFlag[]};
  11. type FlagSeriesDatapoint = {
  12. // flag action
  13. label: {formatter: () => string};
  14. // flag name
  15. name: string;
  16. // unix timestamp
  17. xAxis: number;
  18. };
  19. export function hydrateToFlagSeries(
  20. rawFlagData: RawFlagData | undefined
  21. ): FlagSeriesDatapoint[] {
  22. if (!rawFlagData) {
  23. return [];
  24. }
  25. // transform raw flag data into series data
  26. // each data point needs to be type FlagSeriesDatapoint
  27. const flagData = rawFlagData.data.map<FlagSeriesDatapoint>(f => {
  28. return {
  29. xAxis: Date.parse(f.createdAt),
  30. label: {formatter: () => f.action},
  31. name: f.flag,
  32. };
  33. });
  34. return flagData;
  35. }