Skip to content

Commit e0b8f90

Browse files
Limit spreadsheet column formula length to 1000 characters (#3429)
Signed-off-by: Franck LECUYER <[email protected]>
1 parent 65e7d68 commit e0b8f90

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/components/spreadsheet-view/columns/column-creation-dialog.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import {
4646
import { AppState } from 'redux/reducer';
4747
import { createSpreadsheetColumn, updateSpreadsheetColumn } from '../../../services/study/study-config';
4848
import { FloatingPopoverTreeviewWrapper } from './floating-treeview-list/floating-popover-treeview-wrapper';
49+
import { isFormulaContentSizeOk } from './utils/formula-validator';
50+
import { MAX_FORMULA_CHARACTERS } from '../constants';
4951

5052
export type ColumnCreationDialogProps = {
5153
open: UseStateBooleanReturn;
@@ -144,7 +146,9 @@ export default function ColumnCreationDialog({
144146
label="spreadsheet/custom_column/column_content"
145147
minRows={3}
146148
rows={3}
149+
maxCharactersNumber={MAX_FORMULA_CHARACTERS}
147150
sx={{ flexGrow: 1 }}
151+
acceptValue={isFormulaContentSizeOk}
148152
/>
149153
</FloatingPopoverTreeviewWrapper>
150154
);

src/components/spreadsheet-view/columns/utils/formula-validator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77
import { COLUMN_TYPES } from 'components/custom-aggrid/custom-aggrid-header.type';
8+
import { MAX_FORMULA_CHARACTERS } from '../../constants';
89

910
interface ValidationResult {
1011
isValid: boolean;
@@ -36,3 +37,7 @@ export const validateFormulaResult = (value: any, type: COLUMN_TYPES): Validatio
3637
return { isValid: false, error: 'Unknown column type' };
3738
}
3839
};
40+
41+
export const isFormulaContentSizeOk = (val: string) => {
42+
return val?.length <= MAX_FORMULA_CHARACTERS;
43+
};

src/components/spreadsheet-view/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { ColumnState } from 'ag-grid-community';
99

1010
export const ROW_INDEX_COLUMN_ID = 'rowIndex';
11+
export const MAX_FORMULA_CHARACTERS = 1000;
1112

1213
export const ROW_INDEX_COLUMN_STATE: ColumnState = {
1314
colId: ROW_INDEX_COLUMN_ID,

src/components/spreadsheet-view/spreadsheet/spreadsheet-toolbar/global-model-editor/formula-editor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { useTheme } from '@mui/material/styles';
1010
import { useMemo } from 'react';
1111
import { useFormContext, useWatch } from 'react-hook-form';
1212
import { useFormulaSearch } from './formula-search-context';
13+
import { isFormulaContentSizeOk } from 'components/spreadsheet-view/columns/utils/formula-validator';
14+
import { MAX_FORMULA_CHARACTERS } from '../../../constants';
1315

1416
const styles = {
1517
container: {
@@ -104,7 +106,15 @@ export default function FormulaEditor({ name }: Readonly<ExpandingTextFieldProps
104106
<Box aria-hidden sx={overlaySx}>
105107
{highlighted}
106108
</Box>
107-
<ExpandingTextField name={name} label="" minRows={3} rows={3} sx={styles.textField} />
109+
<ExpandingTextField
110+
name={name}
111+
label=""
112+
minRows={3}
113+
rows={3}
114+
maxCharactersNumber={MAX_FORMULA_CHARACTERS}
115+
sx={styles.textField}
116+
acceptValue={isFormulaContentSizeOk}
117+
/>
108118
</Box>
109119
);
110120
}

0 commit comments

Comments
 (0)