-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add header=colId option for the table-schema API #719 #749
Add header=colId option for the table-schema API #719 #749
Conversation
166bfb6
to
083ef80
Compare
083ef80
to
870bf3a
Compare
app/server/lib/ExportTableSchema.ts
Outdated
@@ -51,21 +51,21 @@ export async function collectTableSchemaInFrictionlessFormat( | |||
} | |||
|
|||
const data = await exportTable(activeDoc, tableRef, req); | |||
const tableSchema = columnsToTableSchema(tableId, data, settings.locale); | |||
const tableSchema = columnsToTableSchema(tableId, data, {locale: settings.locale, header: options.header}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place calling columnsToTableSchema, and having it as a separate function which is just one statement doesn't feel like it improves readability. Here's a simplified rewrite of this whole function:
const {tableId, header} = options;
if (!activeDoc.docData) {
throw new Error('No docData in active document');
}
// Look up the table to make a CSV from.
const settings = activeDoc.docData.docSettings();
const tables = activeDoc.docData.getMetaTable('_grist_Tables');
const tableRef = tables.findRow('tableId', tableId);
if (tableRef === 0) {
throw new ApiError(`Table ${tableId} not found.`, 404);
}
const {tableName, columns} = await exportTable(activeDoc, tableRef, req);
return {
name: tableId.toLowerCase().replace(/_/g, '-'),
title: tableName,
schema: {
fields: columns.map(col => ({
name: col[header || "label"],
...(col.description ? {description: col.description} : {}),
...buildTypeField(col, settings.locale),
})),
}
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, done :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Resolves #719
Introduce header parameter so we can either retrieve the colId or the label properties for the headers.
The documentation is provided here: gristlabs/grist-help#287