Skip to content

Commit

Permalink
Merge pull request #1818 from CondeNast/stable-dataset-attributes
Browse files Browse the repository at this point in the history
fix: update column naming scheme in convert-html-tables helper
  • Loading branch information
colin-alexa authored Nov 12, 2024
2 parents 83fedc2 + 85959dc commit 1ba93fc
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,8 @@ function extractAlignment(tableCell: Annotation<{ style: string }>) {
* @param index the index of the column in the table
* @returns the unique column name as a string
*/
export function generateColumnName(columnName: string | null, index: number) {
let sqlizedColumnName = columnName
?.toLocaleLowerCase()
.replace(/[\s-]+/gmu, "_")
.replace(/[^a-zA-Z0-9_]/gm, "");

return (
// we could do more sophisticated deduplication here, but it would make the data
// less consistent and predictable and make this code more complex
(sqlizedColumnName?.length ? sqlizedColumnName : `column_${index + 1}`) +
`__${index + 1}`
);
export function generateColumnName(index: number) {
return `field_${index + 1}`;
}

export function convertHTMLTablesToDataSet(
Expand Down Expand Up @@ -152,7 +142,7 @@ export function convertHTMLTablesToDataSet(
});
doc.replaceAnnotation(headCell, slice);
let name = extractPlainContents(doc, slice);
let columnName = generateColumnName(name, index);
let columnName = generateColumnName(index);

dataSetSchemaEntries.push([columnName, ColumnType.RICH_TEXT]);

Expand Down Expand Up @@ -205,7 +195,7 @@ export function convertHTMLTablesToDataSet(
}

if (!hasColumnHeaders) {
let columnName = generateColumnName(null, index);
let columnName = generateColumnName(index);

let columnConfig: (typeof columnConfigs)[number] = {
columnName,
Expand Down

This file was deleted.

Loading

0 comments on commit 1ba93fc

Please sign in to comment.