Files
calendar/apps/web/modules/users/lib/UserListTableUtils.ts
T
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ab21c7f805 refactor: Cal.diy (#28903)
* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com

This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main:

- Rebrand Cal.com to Cal.diy across the entire codebase
- Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions
- Switch license from AGPL-3.0 to MIT
- Remove docs/ directory (migrated to Nextra at cal.diy)
- Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc.
- Clean up .env.example for self-hosted Cal.diy
- Update Docker image references to calcom/cal.diy
- Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork
- Add PR welcome bot for Cal.diy contributors
- Fix API v2 breaking changes oasdiff ignore entries
- Replace Blacksmith CI runners with default GitHub Actions

3893 files changed, 20789 insertions(+), 411020 deletions(-)

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* rip out org related comments in api v2

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-15 09:52:36 -03:00

104 lines
3.4 KiB
TypeScript

import { sanitizeValue } from "@calcom/lib/csvUtils";
import type { UserTableUser } from "@calcom/web/modules/users/components/UserTable/types";
import type { Table } from "@tanstack/react-table";
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: Record<string, (string | { value: string; weight?: number })[]>,
attr: { attributeId: string; value: string; weight?: number }
) => {
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: { id: number; name: string }) => 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) => {
if (typeof attr === "string") return attr;
return attr.weight ? `${attr.value} (${attr.weight}%)` : attr.value;
})
.join(",")
);
});
return [...requiredColumns, ...attributeColumns];
});
return [headers.join(","), ...csvRows.map((row) => row.join(","))].join("\n");
};