π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: update conditional cell color changes
Ramesh Mane4a523196e38e
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.tsindex 642e04ed25..85cfe28665 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts@@ -1,5 +1,5 @@import { type ColumnType, type TableType, UITypes, type UserType, type ViewType, isAIPromptCol } from 'nocodb-sdk'-import { renderSingleLineText, renderSpinner, roundedRect } from '../utils/canvas'+import { renderSingleLineText, renderSpinner, renderTag, roundedRect } from '../utils/canvas'import type { ActionManager } from '../loaders/ActionManager'import type { ImageWindowLoader } from '../loaders/ImageLoader'import type { MarkdownLoader } from '../loaders/markdownLoader'@@ -224,16 +224,16 @@ export function useGridCellHandler(params: {} else if (!rowMeta?.isValidationFailed && isRootCell) {// First check for cell-specific coloringconst cellColorInfo = isRowColouringEnabled.value ? getEvaluatedCellColorInfo(row, column.id) : null-+let backgroundColorToRender: string | null = nulllet hoverColorToRender: string | null = null-+if (cellColorInfo?.cellBgColor) {- // Cell-specific color takes precedence+ // Cell-specific background color takes precedencebackgroundColorToRender = cellColorInfo.cellBgColorhoverColorToRender = cellColorInfo.cellHoverColor- } else {- // Fall back to row coloring+ } else if (!cellColorInfo?.cellLeftBorderColor) {+ // Fall back to row coloring only if no cell-specific color at allconst rowColor =rowMeta?.is_set_as_background &&(selected || isRowHovered || isRowChecked || isCellInSelectionRange || isRowCellSelected)@@ -242,7 +242,7 @@ export function useGridCellHandler(params: {backgroundColorToRender = rowColor}- // Apply the final color (cell or row)+ // Apply the final background color (cell or row)const finalColor =selected || isRowHovered || isRowChecked || isCellInSelectionRange || isRowCellSelected? hoverColorToRender || backgroundColorToRender@@ -261,6 +261,21 @@ export function useGridCellHandler(params: {},})}++ // Render cell left-border indicator when not in background mode+ if (cellColorInfo?.cellLeftBorderColor && !cellColorInfo.is_set_as_background) {+ const cellBorderHeight = height - 8+ renderTag(ctx, {+ x: x + 2,+ radius: 4,+ y: y + (height - cellBorderHeight) / 2,+ height: cellBorderHeight,+ width: 3,+ fillStyle: cellColorInfo.cellLeftBorderColor,+ borderColor: cellColorInfo.cellLeftBorderColor,+ borderWidth: 0,+ })+ }}}const cellType = cellTypesRegistry.get(column.uidt!)diff --git a/packages/nocodb-sdk/src/lib/globals.ts b/packages/nocodb-sdk/src/lib/globals.tsindex b7af91a585..899015dc36 100644--- a/packages/nocodb-sdk/src/lib/globals.ts+++ b/packages/nocodb-sdk/src/lib/globals.ts@@ -308,7 +308,7 @@ export type RowColoringInfoFilterRow = {nc_order: number;color: string;type: string;- fk_column_id?: string;+ fk_target_column_id?: string;conditions: FilterType[];nestedConditions: FilterType[];};diff --git a/packages/nocodb/src/controllers/internal/modules/UiPost.operations.ts b/packages/nocodb/src/controllers/internal/modules/UiPost.operations.tsindex ae187b397c..2be10822a3 100644--- a/packages/nocodb/src/controllers/internal/modules/UiPost.operations.ts+++ b/packages/nocodb/src/controllers/internal/modules/UiPost.operations.ts@@ -271,6 +271,8 @@ export class UiPostOperationscolor: payload.color,is_set_as_background: payload.is_set_as_background,nc_order: payload.nc_order,+ type: payload.type,+ fk_target_column_id: payload.fk_target_column_id,filter: payload.filter,});case 'viewRowColorConditionUpdate':@@ -281,6 +283,8 @@ export class UiPostOperationscolor: payload.color,is_set_as_background: payload.is_set_as_background,nc_order: payload.nc_order,+ type: payload.type,+ fk_target_column_id: payload.fk_target_column_id,});case 'viewRowColorConditionDelete':return await this.viewRowColorService.deleteRowColoringCondition({diff --git a/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts b/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.tsindex 990bfc9074..3da17ec6d8 100644--- a/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts+++ b/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts@@ -17,6 +17,7 @@ import * as nc_016_automation_error_notifications from './v0/nc_016_automation_eimport * as nc_017_add_canonical_email_to_users from './v0/nc_017_add_canonical_email_to_users';import * as nc_018_add_enabled_to_filter_exp_v2 from './v0/nc_018_add_enabled_to_filter_exp_v2';import * as nc_019_sandboxes from './v0/nc_019_sandboxes';+import * as nc_020_add_cell_coloring_fields_to_row_color_conditions from './v0/nc_020_add_cell_coloring_fields_to_row_color_conditions';// Create a custom migration source classexport default class XcMigrationSourcev0 {@@ -45,6 +46,7 @@ export default class XcMigrationSourcev0 {'nc_017_add_canonical_email_to_users','nc_018_add_enabled_to_filter_exp_v2','nc_019_sandboxes',+ 'nc_020_add_cell_coloring_fields_to_row_color_conditions',]);}@@ -92,6 +94,8 @@ export default class XcMigrationSourcev0 {return nc_018_add_enabled_to_filter_exp_v2;case 'nc_019_sandboxes':return nc_019_sandboxes;+ case 'nc_020_add_cell_coloring_fields_to_row_color_conditions':+ return nc_020_add_cell_coloring_fields_to_row_color_conditions;}}}diff --git a/packages/nocodb/src/meta/migrations/v0/nc_016_add_cell_coloring_fields_to_row_color_conditions.ts b/packages/nocodb/src/meta/migrations/v0/nc_018_add_cell_coloring_fields_to_row_color_conditions.tssimilarity index 55%rename from packages/nocodb/src/meta/migrations/v0/nc_016_add_cell_coloring_fields_to_row_color_conditions.tsrename to packages/nocodb/src/meta/migrations/v0/nc_018_add_cell_coloring_fields_to_row_color_conditions.tsindex 324fc09ecb..221c77159a 100644--- a/packages/nocodb/src/meta/migrations/v0/nc_016_add_cell_coloring_fields_to_row_color_conditions.ts+++ b/packages/nocodb/src/meta/migrations/v0/nc_018_add_cell_coloring_fields_to_row_color_conditions.ts@@ -2,21 +2,21 @@ import type { Knex } from 'knex';import { MetaTable } from '~/utils/globals';const up = async (knex: Knex) => {- // Add 'type' and 'fk_column_id' columns to nc_row_color_conditions table+ // Add 'type' and 'fk_target_column_id' columns to nc_row_color_conditions table// 'type' defaults to 'row' for backward compatibility with existing data- // 'fk_column_id' is for cell-type coloring to specify which field to color+ // 'fk_target_column_id' is for cell-type coloring to specify which field to colorawait knex.schema.alterTable(MetaTable.ROW_COLOR_CONDITIONS, (table) => {table.string('type', 20).defaultTo('row');- table.string('fk_column_id', 20).nullable();+ table.string('fk_target_column_id', 20).nullable();});};const down = async (knex: Knex) => {- // Remove 'type' and 'fk_column_id' columns from nc_row_color_conditions table+ // Remove 'type' and 'fk_target_column_id' columns from nc_row_color_conditions tableawait knex.schema.alterTable(MetaTable.ROW_COLOR_CONDITIONS, (table) => {- table.dropColumn('fk_column_id');+ table.dropColumn('fk_target_column_id');table.dropColumn('type');});};-export { up, down };\ No newline at end of file+export { up, down };diff --git a/packages/nocodb/src/models/RowColorCondition.ts b/packages/nocodb/src/models/RowColorCondition.tsindex 644acd7536..77122704b3 100644--- a/packages/nocodb/src/models/RowColorCondition.ts+++ b/packages/nocodb/src/models/RowColorCondition.ts@@ -14,7 +14,7 @@ export interface IRowColorCondition {nc_order: number;is_set_as_background: boolean;type: string;- fk_column_id?: string;+ fk_target_column_id?: string;}const logger = new Logger('RowColorCondition');export default class RowColorCondition implements IRowColorCondition {@@ -26,7 +26,7 @@ export default class RowColorCondition implements IRowColorCondition {nc_order: number;is_set_as_background: boolean;type: string;- fk_column_id?: string;+ fk_target_column_id?: string;constructor(data: RowColorCondition) {Object.assign(this, data);