metaforecast/src/web/platforms.ts
2022-04-06 00:36:38 +03:00

22 lines
575 B
TypeScript

import { Forecast, PlatformConfig } from "../backend/platforms";
export type FrontendForecast = Forecast & {
platformLabel: string;
visualization?: any;
};
// ok on client side
export const addLabelsToForecasts = (
forecasts: Forecast[],
platformsConfig: PlatformConfig[]
): FrontendForecast[] => {
const platformNameToLabel = Object.fromEntries(
platformsConfig.map((platform) => [platform.name, platform.label])
);
return forecasts.map((result) => ({
...result,
platformLabel: platformNameToLabel[result.platform] || result.platform,
}));
};