This repository was archived by the owner on Jul 1, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlookupBotsOnIdsGrid.ts
More file actions
59 lines (50 loc) · 1.76 KB
/
Copy pathlookupBotsOnIdsGrid.ts
File metadata and controls
59 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { cleanEffectivePathsCategoryName, isBotsWorkbookName } from './effectivePathsCategoryNames'
import { pickSpreadsheetIdFromIdsCategoryRow } from './pickIdsRowSpreadsheetId'
import type { EffectivePathsLinkedWorkbook, IdsMasterSheetGrid } from './parseIdsMasterWorkbooks'
function cellAt(
rows: readonly (readonly string[])[],
rowIndex: number,
colIndex: number,
): string {
return rows[rowIndex]?.[colIndex]?.trim() ?? ''
}
/** Find the Bots workbook spreadsheet ID on the IDS gateway tab. */
export function lookupBotsWorkbookOnIdsGrid(
grid: IdsMasterSheetGrid,
): EffectivePathsLinkedWorkbook | null {
const { formatted, formulas } = grid
for (let rowIndex = 0; rowIndex < formatted.length; rowIndex++) {
const formulaRow = formulas?.[rowIndex]
const maxCols = Math.max(formatted[rowIndex]?.length ?? 0, formulaRow?.length ?? 0)
let botsRow = false
let name = ''
for (let col = 0; col < maxCols; col++) {
const cell = cellAt(formatted, rowIndex, col)
if (!cell) continue
if (isBotsWorkbookName(cell)) {
botsRow = true
name = cleanEffectivePathsCategoryName(cell)
break
}
if (/go to my bots\b/i.test(cell)) {
botsRow = true
name = name || 'Bots'
}
}
if (!botsRow) continue
const rowFormatted: string[] = []
const rowFormulas: string[] = []
for (let col = 0; col < maxCols; col++) {
rowFormatted[col] = cellAt(formatted, rowIndex, col)
rowFormulas[col] = formulaRow?.[col]?.trim() ?? ''
}
const spreadsheetId = pickSpreadsheetIdFromIdsCategoryRow(
rowFormatted,
rowFormulas,
grid.columnDHyperlinks?.[rowIndex],
)
if (!spreadsheetId) continue
return { name: name || 'Bots', spreadsheetId }
}
return null
}