* [WEB-5134] refactor: update `web` ESLint configuration and refactor imports to use type imports - Enhanced ESLint configuration by adding new rules for import consistency and type imports. - Refactored multiple files to replace regular imports with type imports for better clarity and performance. - Ensured consistent use of type imports across the application to align with TypeScript best practices. * refactor: replace ee regular imports with type imports for improved clarity * [WEB-5139] fix: custom menu item link (#7959) * fix: custom menu link action * chore: code refactor * chore: code refactor * [WEB-4999] feat: implement flexible data export utility with CSV, JSON, and XLSX support (#7884) * feat: implement flexible data export utility with CSV, JSON, and XLSX support - Introduced Exporter class for handling various data formats. - Added formatters for CSV, JSON, and XLSX exports. - Created schemas for defining export fields and their transformations. - Implemented IssueExportSchema for exporting issue data with nested attributes. - Enhanced issue export task to utilize the new exporter system for better data handling. * feat: enhance issue export functionality with new relations and context handling - Updated issue export task to utilize new IssueRelation model for better relationship management. - Refactored Exporter class to accept QuerySets directly, improving performance and flexibility. - Enhanced IssueExportSchema to include parent issues and relations in the export. - Improved documentation for exporting multiple projects and filtering fields during export. * feat: enhance export functionality with field filtering and context support - Updated Exporter class to merge fields into options for formatting. - Modified formatters to filter fields based on specified options. - Enhanced ExportSchema to support optional field selection during serialization. - Improved documentation for the serialize method to clarify field filtering capabilities. * fixed type * refactor: standardize type imports across components - Updated multiple files to replace regular imports with type imports for improved clarity and consistency. - Ensured adherence to TypeScript best practices in the rich filters and issue layouts components. * refactor: standardize type imports across rich filters components - Replaced regular imports with type imports in multiple files for improved clarity and consistency. - Ensured adherence to TypeScript best practices in the rich filters input components. * refactor: standardize type imports across various components - Updated multiple files to improve clarity and consistency by replacing regular imports with type imports. - Ensured adherence to TypeScript best practices in the sidebar filters, initiative header, teamspaces detail header, and workspace search item components. --------- Co-authored-by: Anmol Singh Bhatia <[email protected]> Co-authored-by: Dheeraj Kumar Ketireddy <[email protected]>
172 lines
5.7 KiB
TypeScript
172 lines
5.7 KiB
TypeScript
import { getWeekOfMonth, isValid } from "date-fns";
|
|
import { CHART_X_AXIS_DATE_PROPERTIES, ChartXAxisDateGrouping, TO_CAPITALIZE_CHART_PROPERTIES } from "@plane/constants";
|
|
import type { ChartXAxisProperty, TChart, TChartDatum } from "@plane/types";
|
|
import {
|
|
capitalizeFirstLetter,
|
|
hexToHsl,
|
|
hslToHex,
|
|
renderFormattedDate,
|
|
renderFormattedDateWithoutYear,
|
|
} from "@plane/utils";
|
|
|
|
const getDateGroupingName = (date: string, dateGrouping: ChartXAxisDateGrouping): string => {
|
|
if (!date || ["none", "null"].includes(date.toLowerCase())) return "None";
|
|
|
|
const formattedData = new Date(date);
|
|
const isValidDate = isValid(formattedData);
|
|
|
|
if (!isValidDate) return date;
|
|
|
|
const year = formattedData.getFullYear();
|
|
const currentYear = new Date().getFullYear();
|
|
|
|
const isCurrentYear = year === currentYear;
|
|
|
|
let parsedName: string | undefined;
|
|
|
|
switch (dateGrouping) {
|
|
case ChartXAxisDateGrouping.DAY:
|
|
if (isCurrentYear) parsedName = renderFormattedDateWithoutYear(formattedData);
|
|
else parsedName = renderFormattedDate(formattedData);
|
|
break;
|
|
case ChartXAxisDateGrouping.WEEK: {
|
|
const month = renderFormattedDate(formattedData, "MMM");
|
|
parsedName = `${month}, Week ${getWeekOfMonth(formattedData)}`;
|
|
break;
|
|
}
|
|
case ChartXAxisDateGrouping.MONTH:
|
|
if (isCurrentYear) parsedName = renderFormattedDate(formattedData, "MMM");
|
|
else parsedName = renderFormattedDate(formattedData, "MMM, yyyy");
|
|
break;
|
|
case ChartXAxisDateGrouping.YEAR:
|
|
parsedName = `${year}`;
|
|
break;
|
|
default:
|
|
parsedName = date;
|
|
}
|
|
|
|
return parsedName ?? date;
|
|
};
|
|
|
|
export const parseChartData = (
|
|
data: TChart | null | undefined,
|
|
xAxisProperty: ChartXAxisProperty | null | undefined,
|
|
groupByProperty: ChartXAxisProperty | null | undefined,
|
|
xAxisDateGrouping: ChartXAxisDateGrouping | null | undefined
|
|
): TChart => {
|
|
if (!data) {
|
|
return {
|
|
data: [],
|
|
schema: {},
|
|
};
|
|
}
|
|
const widgetData = structuredClone(data.data);
|
|
const schema = structuredClone(data.schema);
|
|
const allKeys = Object.keys(schema);
|
|
const updatedWidgetData: TChartDatum[] = widgetData.map((datum) => {
|
|
const keys = Object.keys(datum);
|
|
const missingKeys = allKeys.filter((key) => !keys.includes(key));
|
|
const missingValues: Record<string, number> = Object.fromEntries(missingKeys.map((key) => [key, 0]));
|
|
|
|
if (xAxisProperty) {
|
|
// capitalize first letter if xAxisProperty is in TO_CAPITALIZE_CHART_PROPERTIES and no groupByProperty is set
|
|
if (TO_CAPITALIZE_CHART_PROPERTIES.includes(xAxisProperty)) {
|
|
datum.name = capitalizeFirstLetter(datum.name);
|
|
}
|
|
|
|
// parse timestamp to visual date if xAxisProperty is in WIDGET_X_AXIS_DATE_PROPERTIES
|
|
if (CHART_X_AXIS_DATE_PROPERTIES.includes(xAxisProperty)) {
|
|
datum.name = getDateGroupingName(datum.name, xAxisDateGrouping ?? ChartXAxisDateGrouping.DAY);
|
|
}
|
|
}
|
|
|
|
return {
|
|
...datum,
|
|
...missingValues,
|
|
};
|
|
});
|
|
|
|
// capitalize first letter if groupByProperty is in TO_CAPITALIZE_CHART_PROPERTIES
|
|
const updatedSchema = schema;
|
|
if (groupByProperty) {
|
|
if (TO_CAPITALIZE_CHART_PROPERTIES.includes(groupByProperty)) {
|
|
Object.keys(updatedSchema).forEach((key) => {
|
|
updatedSchema[key] = capitalizeFirstLetter(updatedSchema[key]);
|
|
});
|
|
}
|
|
|
|
if (CHART_X_AXIS_DATE_PROPERTIES.includes(groupByProperty)) {
|
|
Object.keys(updatedSchema).forEach((key) => {
|
|
updatedSchema[key] = getDateGroupingName(updatedSchema[key], xAxisDateGrouping ?? ChartXAxisDateGrouping.DAY);
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
data: updatedWidgetData,
|
|
schema: updatedSchema,
|
|
};
|
|
};
|
|
|
|
export const generateExtendedColors = (baseColorSet: string[], targetCount: number) => {
|
|
const colors = [...baseColorSet];
|
|
const baseCount = baseColorSet.length;
|
|
|
|
if (targetCount <= baseCount) {
|
|
return colors.slice(0, targetCount);
|
|
}
|
|
|
|
// Convert base colors to HSL
|
|
const baseHSL = baseColorSet.map(hexToHsl);
|
|
|
|
// Calculate average saturation and lightness from base colors
|
|
const avgSat = baseHSL.reduce((sum, hsl) => sum + hsl.s, 0) / baseHSL.length;
|
|
const avgLight = baseHSL.reduce((sum, hsl) => sum + hsl.l, 0) / baseHSL.length;
|
|
|
|
// Sort base colors by hue for better distribution
|
|
const sortedBaseHSL = [...baseHSL].sort((a, b) => a.h - b.h);
|
|
|
|
// Generate additional colors for each base color
|
|
const colorsNeeded = targetCount - baseCount;
|
|
const colorsPerBase = Math.ceil(colorsNeeded / baseCount);
|
|
|
|
for (let i = 0; i < baseCount; i++) {
|
|
const baseColor = sortedBaseHSL[i];
|
|
const nextBaseColor = sortedBaseHSL[(i + 1) % baseCount];
|
|
|
|
// Calculate hue distance to next base color
|
|
const hueDistance = (nextBaseColor.h - baseColor.h + 360) % 360;
|
|
const hueParts = colorsPerBase + 1;
|
|
|
|
// Narrower ranges for more consistency
|
|
const satRange = [Math.max(40, avgSat - 5), Math.min(60, avgSat + 5)];
|
|
const lightRange = [Math.max(40, avgLight - 5), Math.min(60, avgLight + 5)];
|
|
|
|
for (let j = 1; j <= colorsPerBase; j++) {
|
|
if (colors.length >= targetCount) break;
|
|
|
|
// Create evenly spaced hue variations between base colors
|
|
const hueStep = (hueDistance / hueParts) * j;
|
|
const newHue = (baseColor.h + hueStep) % 360;
|
|
|
|
// Keep saturation and lightness closer to base color
|
|
const newSat = baseColor.s * 0.8 + avgSat * 0.2;
|
|
const newLight = baseColor.l * 0.8 + avgLight * 0.2;
|
|
|
|
// Ensure values stay within desired ranges
|
|
const finalSat = Math.max(satRange[0], Math.min(satRange[1], newSat));
|
|
const finalLight = Math.max(lightRange[0], Math.min(lightRange[1], newLight));
|
|
|
|
colors.push(
|
|
hslToHex({
|
|
h: newHue,
|
|
s: finalSat,
|
|
l: finalLight,
|
|
})
|
|
);
|
|
}
|
|
}
|
|
|
|
return colors.slice(0, targetCount);
|
|
};
|