* refactor: apply biome formatting to apps/web (batch 1) Formats apps/web non-modules directories: - apps/web/app - apps/web/lib - apps/web/pages - apps/web/styles - apps/web/server - apps/web/test - Root-level .ts and .mjs files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to apps/web/modules (batch 2) Formats smaller apps/web/modules directories: - onboarding, data-table, users, apps, auth - integration-attribute-sync, shell, availability - feature-flags, team, webhooks, getting-started - feature-opt-in, troubleshooter, schedules, notifications - signup-view.tsx Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to apps/web/modules (batch 3) Formats medium apps/web/modules directories: - bookings - event-types - insights - embed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to apps/web/modules/ee (batch 4) Formats apps/web/modules/ee directory. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to apps/web (batch 5) Formats remaining apps/web directories: - apps/web/modules/settings - apps/web/modules/booking-audit - apps/web/playwright Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to apps/web/components (batch 6) Formats remaining apps/web/components files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to new apps/web files from main Formats newly added/modified files from main merge: - WorkflowStepContainer.tsx (resolved merge conflicts) - Newly moved files (blocklist, form-builder, schedules, etc.) - Other files modified in main Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: apply biome formatting to new apps/web files from main Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import type { Table } from "@tanstack/react-table";
|
|
|
|
import { sanitizeValue } from "@calcom/lib/csvUtils";
|
|
import type { UserTableUser } from "@calcom/web/modules/users/components/UserTable/types";
|
|
|
|
export const generateHeaderFromReactTable = (table: Table<UserTableUser>): string[] | null => {
|
|
const headerGroups = table.getHeaderGroups();
|
|
if (!headerGroups.length) {
|
|
return null;
|
|
}
|
|
|
|
const { headers } = headerGroups[0];
|
|
const HEADER_IDS_TO_EXCLUDE = ["select", "actions"]; // these columns only make sense in web page
|
|
const filteredHeaders = headers.filter((header) => !HEADER_IDS_TO_EXCLUDE.includes(header.id));
|
|
const headerNames = filteredHeaders.map((header) => {
|
|
const h = header.column.columnDef.header;
|
|
if (typeof h === "string") {
|
|
return sanitizeValue(h);
|
|
}
|
|
if (typeof h === "function") {
|
|
return sanitizeValue(h(header.getContext()));
|
|
}
|
|
return "Unknown";
|
|
});
|
|
|
|
// Add "Link" column (member's public page)
|
|
const MEMBERS_COLUMN = "Members";
|
|
const LINK_COLUMN = "Link";
|
|
const memberIndex = headerNames.findIndex((name) => name === MEMBERS_COLUMN);
|
|
if (memberIndex > -1) {
|
|
headerNames.splice(memberIndex + 1, 0, LINK_COLUMN);
|
|
}
|
|
|
|
return headerNames;
|
|
};
|
|
|
|
export const generateCsvRawForMembersTable = (
|
|
headers: string[],
|
|
rows: UserTableUser[],
|
|
ATTRIBUTE_IDS: string[],
|
|
orgDomain: string
|
|
): string => {
|
|
if (!headers.length) {
|
|
throw new Error("The header is empty.");
|
|
}
|
|
|
|
const REQUIRED_HEADERS = ["Members", "Link", "Role", "Teams"] as const;
|
|
// Validate required headers are present and in correct order
|
|
const firstFourHeaders = headers.slice(0, REQUIRED_HEADERS.length);
|
|
if (!REQUIRED_HEADERS.every((header, index) => header === firstFourHeaders[index])) {
|
|
throw new Error(
|
|
`Invalid headers structure. Expected headers to start with: ${JSON.stringify(REQUIRED_HEADERS)}`
|
|
);
|
|
}
|
|
|
|
// Body formation
|
|
const csvRows = rows.map((row) => {
|
|
const { email, role, teams, username, attributes } = row;
|
|
|
|
// Create a map of attributeId to array of values
|
|
const attributeMap = (attributes ?? []).reduce(
|
|
(acc, attr) => {
|
|
if (!acc[attr.attributeId]) {
|
|
acc[attr.attributeId] = [];
|
|
}
|
|
acc[attr.attributeId].push({
|
|
value: attr.value,
|
|
weight: attr.weight ?? undefined,
|
|
});
|
|
return acc;
|
|
},
|
|
{} as Record<string, { value: string; weight: number | undefined }[]>
|
|
);
|
|
|
|
const requiredColumns = [
|
|
email, // Members column
|
|
`${orgDomain}/${username}`, // Link column
|
|
role, // Role column
|
|
sanitizeValue(teams.map((team) => team.name).join(",")), // Teams column
|
|
];
|
|
|
|
// Add attribute columns
|
|
const attributeColumns = ATTRIBUTE_IDS.map((attrId) => {
|
|
const attributes = attributeMap[attrId];
|
|
if (!attributes?.length) return "";
|
|
|
|
return sanitizeValue(
|
|
attributes.map((attr) => (attr.weight ? `${attr.value} (${attr.weight}%)` : attr.value)).join(",")
|
|
);
|
|
});
|
|
|
|
return [...requiredColumns, ...attributeColumns];
|
|
});
|
|
|
|
return [headers.join(","), ...csvRows.map((row) => row.join(","))].join("\n");
|
|
};
|