feat: Add default value support for table columns (#4043)
* Add 'type', 'description', and 'default' fields to Table schema and enhance formatter validation * Add type-based mapping to formatter validator in table schema * Add default value support for new table rows in TableNodeComponent * Add optional 'description' and 'default' fields to ColumnField interface * Add default value inference for table columns in utils.ts - Initialize 'default' property for table columns to null. - Infer default value from the first row of data if available. - Adjust column formatter determination based on sample value. * Add default table input validation and update formatter logic in Column model * Add unit tests for Column class in table schema module --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
90b2c9d577
commit
65153374ed
5 changed files with 100 additions and 10 deletions
|
|
@ -92,7 +92,7 @@ export default function TableNodeComponent({
|
|||
function addRow() {
|
||||
const newRow = {};
|
||||
componentColumns.forEach((column) => {
|
||||
newRow[column.name] = null;
|
||||
newRow[column.name] = column.default ?? null; // Use the default value if available
|
||||
});
|
||||
handleOnNewValue({ value: [...value, newRow] });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@ export enum FormatterType {
|
|||
json = "json",
|
||||
}
|
||||
|
||||
export type ColumnField = {
|
||||
display_name: string;
|
||||
export interface ColumnField {
|
||||
name: string;
|
||||
display_name: string;
|
||||
sortable: boolean;
|
||||
filterable: boolean;
|
||||
formatter?: FormatterType;
|
||||
};
|
||||
description?: string;
|
||||
default?: any; // Add this line
|
||||
}
|
||||
|
|
|
|||
|
|
@ -528,7 +528,18 @@ export function generateBackendColumnsFromValue(rows: Object[]): ColumnField[] {
|
|||
display_name: column.headerName ?? "",
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
default: null, // Initialize default to null or appropriate value
|
||||
};
|
||||
|
||||
// Attempt to infer the default value from the data, if possible
|
||||
if (rows.length > 0) {
|
||||
const sampleValue = rows[0][column.field ?? ""];
|
||||
if (sampleValue !== undefined) {
|
||||
newColumn.default = sampleValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the formatter based on the sample value
|
||||
if (rows[0] && rows[0][column.field ?? ""]) {
|
||||
const value = rows[0][column.field ?? ""] as any;
|
||||
if (typeof value === "string") {
|
||||
|
|
@ -538,7 +549,6 @@ export function generateBackendColumnsFromValue(rows: Object[]): ColumnField[] {
|
|||
newColumn.formatter = FormatterType.text;
|
||||
}
|
||||
} else if (typeof value === "object" && value !== null) {
|
||||
// Check if the object is a Date object
|
||||
if (
|
||||
Object.prototype.toString.call(value) === "[object Date]" ||
|
||||
value instanceof Date
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue