Skip to content

Commit

Permalink
Merge pull request #677 from ruilisi/addSheet-signature
Browse files Browse the repository at this point in the history
feat: add optional sheetId param to addSheet
  • Loading branch information
sanchit3008 authored Feb 17, 2025
2 parents 0cc1827 + ee8f08d commit ea4e065
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/react/src/components/Workbook/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,18 @@ export function generateAPIs(
getSheet: (options: api.CommonOptions = {}) =>
api.getSheetWithLatestCelldata(context, options),

addSheet: () => setContext((draftCtx) => api.addSheet(draftCtx, settings)),
addSheet: (sheetId?: string) => {
const existingSheetIds = api
.getAllSheets(context)
.map((sheet) => sheet.id || "");
if (sheetId && existingSheetIds.includes(sheetId)) {
console.error(
`Failed to add new sheet: A sheet with the id "${sheetId}" already exists. Please use a unique sheet id.`
);
} else {
setContext((draftCtx) => api.addSheet(draftCtx, settings, sheetId));
}
},

deleteSheet: (options: api.CommonOptions = {}) =>
setContext((draftCtx) => api.deleteSheet(draftCtx, options)),
Expand Down

0 comments on commit ea4e065

Please sign in to comment.