-
Notifications
You must be signed in to change notification settings - Fork 6
Spreadsheet optimizations #4180
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
Changes from 6 commits
9203a40
51a6f08
cc5d140
d983f44
a1445bc
36132e6
0b68c1d
0284737
61e5729
f3a84d0
ceb21a3
242900f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,24 +24,26 @@ export const SPREADSHEET_INVALID_CELL_CLASS = 'spreadsheet-invalid-cell'; | |
|
|
||
| const createValueGetter = | ||
| (colDef: ColumnDefinition) => | ||
| (params: ValueGetterParams): CustomAggridValue | undefined => { | ||
| (params: ValueGetterParams): CustomAggridValue | null => { | ||
| try { | ||
| // Skip formula processing for pinned rows and use raw value | ||
| if (isCalculationRow(params.node?.data?.rowType)) { | ||
| return params.data[colDef.id]; | ||
| return params.data[colDef.id] ?? null; | ||
| } | ||
| const scope = { ...params.data }; | ||
| const colDependencies = colDef.dependencies ?? []; | ||
|
|
||
| //Empty values are assumed to be equal to "undefined" by users | ||
| colDependencies.forEach((dep) => { | ||
| scope[dep] = params.getValue(dep); | ||
| scope[dep] = params.getValue(dep) ?? undefined; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This undefined is crucial to keep existing formulas having this type of syntax "typeOf(IT10_Or) == 'undefined' ? IT10_Ex : typeOf(IT10_Ex) == 'undefined' ? IT10_Or : max(IT10_Or, IT10_Ex)" which are largely used in production.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay thanks, maybe update the comment to make it more explicit ? |
||
| }); | ||
| const result = limitedEvaluate(colDef.formula, scope); | ||
| return result == null ? undefined : validateFormulaResult(result, colDef.type); | ||
| const result = limitedEvaluate(colDef.formula, scope, params.context?.compiledFormulaCache); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return result != null ? validateFormulaResult(result, colDef.type) : null; | ||
| } catch (e) { | ||
| if (e instanceof MathJsValidationError) { | ||
| return { error: e.error }; | ||
| } | ||
| return undefined; | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |||||||||||||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| import { FunctionComponent, useCallback, useMemo } from 'react'; | ||||||||||||||
| import { FunctionComponent, useCallback, useMemo, useRef } from 'react'; | ||||||||||||||
| import { ListItemIcon, ListItemText, Menu, MenuItem, useTheme } from '@mui/material'; | ||||||||||||||
| import { useIntl } from 'react-intl'; | ||||||||||||||
| import { CustomAGGrid } from '@gridsuite/commons-ui'; | ||||||||||||||
|
|
@@ -21,6 +21,7 @@ | |||||||||||||
| import { AGGRID_LOCALES } from '../../../../translations/not-intl/aggrid-locales'; | ||||||||||||||
| import { refreshSpreadsheetAfterFilterChanged } from './hooks/use-spreadsheet-gs-filter'; | ||||||||||||||
| import { useEquipmentContextMenu } from './hooks/useEquipmentContextMenu'; | ||||||||||||||
| import { createCompiledFormulaCache } from '../../columns/utils/math'; | ||||||||||||||
|
|
||||||||||||||
| const DEFAULT_ROW_HEIGHT = 28; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -134,7 +135,13 @@ | |||||||||||||
| [currentNode?.type, theme, isDataEditable] | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| const gridContext = useMemo(() => ({ theme, currentNode, studyUuid }), [currentNode, studyUuid, theme]); | ||||||||||||||
| // The Map lives in a distinct memo, NOT in the memo below: gridContext is rebuilt on every currentNode | ||||||||||||||
| // change, and creating the cache there would silently flush all compiled formulas per rebuild. | ||||||||||||||
| const compiledFormulaCache = useMemo(() => createCompiledFormulaCache(), []); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
using useRef to guarantee a unique creation of the cache for the life of the component ? useMemo() should do the same in practice, but this is not guaranteed by React. This may be worth it because the cache is the whole point of your PR.. |
||||||||||||||
| const gridContext = useMemo( | ||||||||||||||
| () => ({ theme, currentNode, studyUuid, compiledFormulaCache }), | ||||||||||||||
| [currentNode, studyUuid, theme, compiledFormulaCache] | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <> | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.