Skip to content

Commit 6993b0d

Browse files
authored
Merge pull request #4323 from James-Baloyi/james/b/datatable
James/b/datatable
2 parents a8e32bd + ac492a0 commit 6993b0d

File tree

9 files changed

+291
-26
lines changed

9 files changed

+291
-26
lines changed

shesha-reactjs/src/components/dataTable/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface IIndexTableProps extends IShaDataTableProps, TableProps {
9090
rowHeight?: string;
9191
rowPadding?: string;
9292
rowBorder?: string;
93+
rowBorderStyle?: IBorderValue;
9394

9495
// Overall table styling
9596
boxShadow?: string;
@@ -149,6 +150,7 @@ export const DataTable: FC<Partial<IIndexTableProps>> = ({
149150
rowHeight,
150151
rowPadding,
151152
rowBorder,
153+
rowBorderStyle,
152154
boxShadow,
153155
sortableIndicatorColor,
154156
...props
@@ -943,6 +945,7 @@ export const DataTable: FC<Partial<IIndexTableProps>> = ({
943945
rowHeight,
944946
rowPadding,
945947
rowBorder,
948+
rowBorderStyle,
946949
boxShadow,
947950
sortableIndicatorColor,
948951

shesha-reactjs/src/components/reactTable/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const ReactTable: FC<IReactTableProps> = ({
104104
rowHeight,
105105
rowPadding,
106106
rowBorder,
107+
rowBorderStyle,
107108
boxShadow,
108109
sortableIndicatorColor,
109110
striped = true,
@@ -132,6 +133,7 @@ export const ReactTable: FC<IReactTableProps> = ({
132133
rowHeight,
133134
rowPadding,
134135
rowBorder,
136+
rowBorderStyle,
135137
boxShadow,
136138
sortableIndicatorColor,
137139
striped,

shesha-reactjs/src/components/reactTable/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ export interface IReactTableProps extends ITableRowDragProps {
242242
rowSelectedBackgroundColor?: string;
243243
rowHeight?: string;
244244
rowPadding?: string;
245-
rowBorder?: string;
245+
rowBorder?: string; // Deprecated: use rowBorderStyle for full border control
246+
rowBorderStyle?: IBorderValue; // Full border configuration with per-side control
246247

247248
// Overall table styling
248249
borderRadius?: string;

shesha-reactjs/src/components/reactTable/styles/styles.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const useMainStyles = createStyles(({ css, cx, token, prefixCls, iconPref
5252
rowHeight,
5353
rowPadding,
5454
rowBorder,
55+
rowBorderStyle,
5556
boxShadow,
5657
sortableIndicatorColor,
5758
striped: _striped,
@@ -69,6 +70,7 @@ export const useMainStyles = createStyles(({ css, cx, token, prefixCls, iconPref
6970
rowHeight?: string;
7071
rowPadding?: string;
7172
rowBorder?: string;
73+
rowBorderStyle?: IBorderValue;
7274
boxShadow?: string;
7375
sortableIndicatorColor?: string;
7476
striped?: boolean;
@@ -239,7 +241,17 @@ export const useMainStyles = createStyles(({ css, cx, token, prefixCls, iconPref
239241
}
240242
.${tr} {
241243
${rowHeight ? `height: ${rowHeight};` : 'height: 100%;'}
242-
${rowBorder ? `border: ${rowBorder};` : ''}
244+
${(() => {
245+
// Prefer rowBorderStyle over rowBorder for full border control
246+
if (rowBorderStyle) {
247+
const borderStyles = getBorderStyle(rowBorderStyle, {});
248+
return Object.entries(borderStyles)
249+
.map(([key, value]) => `${key.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${value};`)
250+
.join(' ');
251+
}
252+
// Fallback to simple border string
253+
return rowBorder ? `border: ${rowBorder};` : '';
254+
})()}
243255
244256
&.${trHead} {
245257
box-shadow: 0 2px 15px 0 rgb(0 0 0 / 15%);

shesha-reactjs/src/designer-components/dataTable/table/models.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,39 @@ export interface ITableComponentBaseProps extends IShaDataTableInlineEditablePro
4545
rowAlternateBackgroundColor?: string;
4646
rowHoverBackgroundColor?: string;
4747
rowSelectedBackgroundColor?: string;
48+
49+
// Row dimensions
50+
rowDimensions?: {
51+
height?: string;
52+
minHeight?: string;
53+
maxHeight?: string;
54+
};
55+
56+
// Row padding using styling box
57+
rowStylingBox?: {
58+
margin?: {
59+
top?: string;
60+
right?: string;
61+
bottom?: string;
62+
left?: string;
63+
};
64+
padding?: {
65+
top?: string;
66+
right?: string;
67+
bottom?: string;
68+
left?: string;
69+
};
70+
};
71+
72+
// Row border using standard border controls
73+
rowBorderStyle?: IBorderValue;
74+
75+
// Deprecated properties - kept for backward compatibility
76+
/** @deprecated Use rowDimensions.height instead */
4877
rowHeight?: string;
78+
/** @deprecated Use rowStylingBox.padding instead */
4979
rowPadding?: string;
80+
/** @deprecated Use rowBorderStyle instead */
5081
rowBorder?: string;
5182

5283
// Overall table styling

shesha-reactjs/src/designer-components/dataTable/table/tableComponent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ const TableComponent: TableComponentDefinition = {
141141
actualModelPropertyFilter: (name, value) => {
142142
// Allow all styling properties through to the settings form
143143
const allowedStyleProperties = [
144+
// Old properties (deprecated but kept for backward compatibility)
144145
'rowHeight', 'rowPadding', 'rowBorder',
146+
// New structured properties
147+
'rowDimensions', 'rowStylingBox', 'rowBorderStyle',
145148
'headerFontSize', 'headerFontWeight',
146149
'tableSettings', // For nested structure
147150
];

shesha-reactjs/src/designer-components/dataTable/table/tableSettings.ts

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,29 +555,94 @@ export const getSettings: SettingsFormMarkupFactory = ({ fbf }) => {
555555
content: {
556556
id: nanoid(),
557557
components: [...fbf()
558-
.addSettingsInput({
558+
.addCollapsiblePanel({
559559
id: nanoid(),
560-
propertyName: 'rowHeight',
561-
label: 'Row Height',
562-
inputType: 'textField',
563-
tooltip: 'Height for table rows (e.g., 40px, 3rem)',
564-
jsSetting: false,
560+
propertyName: 'pnlRowDimensions',
561+
label: 'Row Dimensions',
562+
labelAlign: 'right',
563+
ghost: true,
564+
collapsible: 'header',
565+
content: {
566+
id: nanoid(),
567+
components: [...fbf()
568+
.addSettingsInputRow({
569+
id: nanoid(),
570+
inline: true,
571+
inputs: [
572+
{
573+
type: 'textField',
574+
id: nanoid(),
575+
label: "Height",
576+
width: 85,
577+
propertyName: "rowDimensions.height",
578+
icon: "heightIcon",
579+
tooltip: "Row height. You can use any unit (%, px, em, etc). px by default if without unit",
580+
},
581+
{
582+
type: 'textField',
583+
id: nanoid(),
584+
label: "Min Height",
585+
width: 85,
586+
hideLabel: true,
587+
propertyName: "rowDimensions.minHeight",
588+
icon: "minHeightIcon",
589+
},
590+
{
591+
type: 'textField',
592+
id: nanoid(),
593+
label: "Max Height",
594+
width: 85,
595+
hideLabel: true,
596+
propertyName: "rowDimensions.maxHeight",
597+
icon: "maxHeightIcon",
598+
},
599+
],
600+
})
601+
.toJson(),
602+
],
603+
},
565604
})
566-
.addSettingsInput({
605+
.addCollapsiblePanel({
567606
id: nanoid(),
568-
propertyName: 'rowPadding',
569-
label: 'Cell Padding',
570-
inputType: 'textField',
571-
tooltip: 'Padding for table cells (e.g., 8px, 0.5rem 1rem)',
572-
jsSetting: false,
607+
propertyName: 'rowStylingBox',
608+
label: 'Row Padding',
609+
labelAlign: 'right',
610+
ghost: true,
611+
collapsible: 'header',
612+
content: {
613+
id: nanoid(),
614+
components: [...fbf()
615+
.addStyleBox({
616+
id: nanoid(),
617+
label: 'Cell Padding',
618+
hideLabel: true,
619+
propertyName: 'rowStylingBox',
620+
})
621+
.toJson(),
622+
],
623+
},
573624
})
574-
.addSettingsInput({
625+
.addCollapsiblePanel({
575626
id: nanoid(),
576-
propertyName: 'rowBorder',
627+
propertyName: 'pnlRowBorderStyle',
577628
label: 'Row Border',
578-
inputType: 'textField',
579-
tooltip: 'Border style for table rows (e.g., 1px solid #ccc)',
580-
jsSetting: false,
629+
labelAlign: 'right',
630+
ghost: true,
631+
collapsible: 'header',
632+
content: {
633+
id: nanoid(),
634+
components: [...fbf()
635+
.addContainer({
636+
id: nanoid(),
637+
components: getBorderInputs(fbf, 'rowBorderStyle'),
638+
})
639+
.addContainer({
640+
id: nanoid(),
641+
components: getCornerInputs(fbf, 'rowBorderCorner'),
642+
})
643+
.toJson(),
644+
],
645+
},
581646
})
582647
.toJson(),
583648
],

shesha-reactjs/src/designer-components/dataTable/table/tableWrapper.tsx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {
55
useRef,
66
useEffect,
77
} from 'react';
8-
import { filterVisibility, calculateDefaultColumns } from './utils';
8+
import { filterVisibility, calculateDefaultColumns, convertRowDimensionsToHeight, convertRowStylingBoxToPadding, convertRowBorderStyleToBorder } from './utils';
99
import { getStyle } from '@/providers/form/utils';
1010
import { ITableComponentProps } from './models';
1111
import { getShadowStyle } from '@/designer-components/_settings/utils/shadow/utils';
@@ -67,6 +67,34 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
6767
return props?.shadow ? shadowStyles?.boxShadow : props?.boxShadow;
6868
}, [props?.shadow, shadowStyles?.boxShadow, props?.boxShadow]);
6969

70+
// Convert new property structures to old format for backward compatibility
71+
const effectiveRowHeight = useMemo(() => {
72+
// Prefer new rowDimensions over old rowHeight
73+
const converted = convertRowDimensionsToHeight(props?.rowDimensions);
74+
if (isDesignMode) {
75+
console.warn('Row Height - rowDimensions:', props?.rowDimensions, 'converted:', converted, 'fallback:', props?.rowHeight);
76+
}
77+
return converted || props?.rowHeight;
78+
}, [props?.rowDimensions, props?.rowHeight, isDesignMode]);
79+
80+
const effectiveRowPadding = useMemo(() => {
81+
// Prefer new rowStylingBox over old rowPadding
82+
const converted = convertRowStylingBoxToPadding(props?.rowStylingBox);
83+
if (isDesignMode) {
84+
console.warn('Row Padding - rowStylingBox:', props?.rowStylingBox, 'converted:', converted, 'fallback:', props?.rowPadding);
85+
}
86+
return converted || props?.rowPadding;
87+
}, [props?.rowStylingBox, props?.rowPadding, isDesignMode]);
88+
89+
const effectiveRowBorder = useMemo(() => {
90+
// Prefer new rowBorderStyle over old rowBorder
91+
const converted = convertRowBorderStyleToBorder(props?.rowBorderStyle);
92+
if (isDesignMode) {
93+
console.warn('Row Border - rowBorderStyle:', props?.rowBorderStyle, 'converted:', converted, 'fallback:', props?.rowBorder);
94+
}
95+
return converted || props?.rowBorder;
96+
}, [props?.rowBorderStyle, props?.rowBorder, isDesignMode]);
97+
7098
const { styles } = useStyles({
7199
fontFamily: props?.font?.type,
72100
fontWeight: props?.font?.weight,
@@ -88,9 +116,9 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
88116
headerFontWeight: props?.headerFontWeight,
89117
headerBackgroundColor: props?.headerBackgroundColor,
90118
headerTextColor: props?.headerTextColor,
91-
rowHeight: props?.rowHeight,
92-
rowPadding: props?.rowPadding,
93-
rowBorder: props?.rowBorder,
119+
rowHeight: effectiveRowHeight,
120+
rowPadding: effectiveRowPadding,
121+
rowBorder: effectiveRowBorder,
94122
boxShadow: finalBoxShadow,
95123
sortableIndicatorColor: props?.sortableIndicatorColor,
96124
});
@@ -359,9 +387,10 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
359387
headerFontWeight={props.headerFontWeight}
360388
headerBackgroundColor={props.headerBackgroundColor}
361389
headerTextColor={props.headerTextColor}
362-
rowHeight={props.rowHeight}
363-
rowPadding={props.rowPadding}
364-
rowBorder={props.rowBorder}
390+
rowHeight={effectiveRowHeight}
391+
rowPadding={effectiveRowPadding}
392+
rowBorder={effectiveRowBorder}
393+
rowBorderStyle={props.rowBorderStyle}
365394
boxShadow={finalBoxShadow}
366395
sortableIndicatorColor={props.sortableIndicatorColor}
367396
/>

0 commit comments

Comments
 (0)