Skip to content

Expressions #540

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

Merged
merged 148 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
86ab955
Picked some parts from the hackaton/dynamics branch, implemented a ve…
Jul 29, 2022
b691e0e
Adding support for applicationSettings and instanceContext (at least …
Jul 29, 2022
4f89efc
Extending the DSL to support boolean, number and string constants
Jul 29, 2022
d378d12
Extending the DSL to support null, as well as requiring quoted string…
Jul 29, 2022
5a82e6e
Implementing a runner. This was pretty easy, but then again it sort-o…
Jul 29, 2022
e470674
Merge branch 'main' into feat/layout-expressions
Aug 1, 2022
6b2a893
Porting over 3 levels of hierarchical layout tools/functions from the…
Aug 2, 2022
024138a
Since I rewrote nodesInLayout() from the hackathon to use a LayoutRoo…
Aug 2, 2022
5fbcb4c
Implementing an index for quickly finding components using their id a…
Aug 2, 2022
4f52a7f
More improvements to the hierarchy functions:
Aug 2, 2022
6f1a9bf
Merge branch 'main' into feat/layout-expressions
Aug 2, 2022
f7350fe
Minor type cleanup, inlining a function
Aug 3, 2022
1d04ede
Renaming some types, making the ILayoutExpression either a structured…
Aug 3, 2022
28c9952
Layout expressions now work(!), at least in my example app where I ca…
Aug 3, 2022
c4f973e
Implementing support for one-argument lookup expressions (the functio…
Aug 3, 2022
cbb6ae8
Implementing support for mapping one expected result to another outpu…
Aug 3, 2022
0c0519d
Implementing support for transposing a data model path (or whatever I…
Aug 8, 2022
1020287
Adding validation errors when failing to validate/parse a layout expr…
Aug 8, 2022
fd27fb9
Fixing crash when edit is not an object (and does not have .filter)
Aug 9, 2022
bc716e1
Merge branch 'main' into feat/layout-expressions
Aug 11, 2022
ef8d13c
Removing DSL implementation
Aug 11, 2022
3cc7675
Removing mapping implementation
Aug 11, 2022
46ab3ba
Removing lookup function and aliases (leftovers from the DSL implemen…
Aug 11, 2022
a1cd3e5
Adding resolving of layout expressions in GenericComponent.tsx, addin…
Aug 11, 2022
4beaa5f
Squashing types, as formData only stores strings. When comparing true…
Aug 12, 2022
4e77416
Implementing lookups for instanceContext, applicationSettings and com…
Aug 12, 2022
312671c
Hacky quick-fix for enabling 'hidden' to work during the demo later t…
Aug 12, 2022
1923af3
Moving the validation code out from expressions.ts
Aug 12, 2022
98c4b7a
Moving the implementations for lookup functions into a broader Expres…
Aug 12, 2022
347d344
Started implementing recursive expressions, with native functions for…
Aug 15, 2022
8a20ae9
Merge branch 'main' into feat/layout-expressions
Aug 15, 2022
09cdb43
Fixing new Map component to match the others
Aug 15, 2022
abfe5f5
Printing pretty errors to console when something goes wrong while exe…
Aug 17, 2022
4357f3c
Printing pretty errors even when failing hard
Aug 17, 2022
1ad9124
Merge branch 'main' into feat/layout-expressions
Aug 17, 2022
528ff2c
Major refactoring in prettyErrors.ts in order to support CSS in conso…
Aug 18, 2022
4a65921
Implementing CSS styling in console for error messages
Aug 18, 2022
05639a7
Implementing some pretty magic types that requires you to fill in all…
Aug 19, 2022
8620fc1
Removing option for controlling the edit button. Not sure if this mak…
Aug 19, 2022
3f3b4d4
Testing the useLayoutExpressions() hook, making sure the default valu…
Aug 22, 2022
889aaac
More strict equals functions, and allowing null values for all data t…
Aug 23, 2022
2b135a3
Adding some more tests, getting 100% coverage
Aug 23, 2022
4c3ed19
Fixing the test to make sure the underline character is the same one …
Aug 23, 2022
0322821
Moving error classes into a separate file, for cleanliness
Aug 23, 2022
c690f25
Restructuring: Moving layoutExpressionLookupFunctions close to the ot…
Aug 23, 2022
895a950
Restructuring: Using explicit error type/object instead of generic st…
Aug 23, 2022
755a67c
Restructuring: Moving the heart of useLayoutExpression() out into a f…
Aug 23, 2022
feebc81
Extracting types from hierarchy.ts into hierarchy.types.d.ts, and rew…
Aug 24, 2022
5d46222
Implementing resolvedNodesInLayout() that works just like nodesInLayo…
Aug 24, 2022
87d55d8
Extracting some variables so it's easier to attach the debugger and i…
Aug 25, 2022
4e5a7b0
Implementing shared test from plain JSON files (these files should in…
Aug 30, 2022
d76e697
Extending the shared tests to read files from sub-folders for each fu…
Aug 30, 2022
8770056
Matching the error message string instead of just checking if the eva…
Aug 30, 2022
7dd177a
The cast to string did not cast numbers to strings properly - fixing …
Aug 30, 2022
bf71036
Merge branch 'main' into feat/layout-expressions
Aug 30, 2022
1502e30
Re-installing utility-types after merging from main
Aug 30, 2022
1599e70
Moving the directory for shared tests, adding a README
Aug 30, 2022
660bc72
Adding more tests for notEquals, fixing some for equals
Aug 30, 2022
0b2a1c5
Adding more tests for equals and notEquals, for other possible input …
Aug 31, 2022
d08cdeb
Adding tests for greaterThan. Adjusting the behaviour of comparing wi…
Aug 31, 2022
0f269cf
Adding tests for greaterThanEq, lessThan and lessThanEq
Aug 31, 2022
ab0bd53
Removing older tests, preferring newer shared unit tests for expressi…
Aug 31, 2022
11c8219
Adding shared tests for dataModel, adding nested group test, adjustin…
Aug 31, 2022
da887d6
Adding more shared tests for applicationSettings, dataModel and insta…
Aug 31, 2022
82c0de3
Implementing concat(), adding tests for it, extracting the common cod…
Aug 31, 2022
2028f0e
Somewhat finishing the validation work I started earlier and never qu…
Aug 31, 2022
d71d322
Removing the test generation script. It's done its job now, and new t…
Aug 31, 2022
b8b4486
Implementing and/or
Aug 31, 2022
a671fd4
Removing no-context test, as it just crashes hard on the backend anyw…
Sep 2, 2022
aafa9e5
Adding shared tests for some invalid expressions
Sep 2, 2022
37ce0b7
Adding shared tests for testing case-sensitiveness, and comparing nul…
Sep 2, 2022
8c81763
Rewriting layouts inside shared tests to reflect what we're actually …
Sep 2, 2022
edc4c43
Updating tests to match changes in layout
Sep 2, 2022
9d7e1ad
Adding a test for direct data model references, used inside groups (b…
Sep 2, 2022
dd1ff47
Merge branch 'main' into feat/layout-expressions
Sep 2, 2022
c58b625
Adding support for less arguments than the number specified in the 'a…
Sep 2, 2022
73c1807
Moving all the function implementations into the same place, so we do…
Sep 2, 2022
285f279
Moving some code into the type-casting function to make the functiona…
Sep 2, 2022
52e7ba6
Renaming some interfaces/types, shortening, adding more JsDoc
Sep 2, 2022
40e39b1
Merge branch 'main' into feat/layout-expressions
Sep 2, 2022
9d04490
Adding some more tests for the casting behaviour of and/or, and suffi…
Sep 3, 2022
7ceea2e
Fixing the direct-reference-in-group.json test, and adding some more …
Sep 3, 2022
a5a0484
Some more documentation, and rewriting the LayoutNode.resolveExpressi…
Sep 3, 2022
5a967a6
Pulling shared tests from app-lib-dotnet and updating my error string…
Sep 12, 2022
417b081
Renaming applicationSettings to frontendSettings, as discussed last w…
Sep 12, 2022
7faa89d
Deleting some tests that are no longer relevant (deleted from app-lib…
Sep 12, 2022
ad652b6
Moving shared tests into sub-folder, to prepare for the new context l…
Sep 12, 2022
77d572d
Adding context-list tests, ready for test runner implementation
Sep 12, 2022
7786994
Implementing test-runner for context lists, and fixing errors in the …
Sep 12, 2022
57ee829
Merge branch 'main' into feat/layout-expressions
Sep 12, 2022
1bc72b0
Re-installing utility-types after merge from main
Sep 12, 2022
3286856
Using resolvedNodesInLayout() inside validation, so that field valida…
Sep 13, 2022
5bd1215
Rewriting resolvedNodesInLayout() to work without creating new object…
Sep 14, 2022
f950351
Changing to use a Set<string> for the list of hidden fields read in v…
Sep 15, 2022
649db4d
Rewriting the conditional rendering code to use Set<string> instead o…
Sep 15, 2022
04f2639
Fixing the test to work with Set<string> instead of arrays
Sep 15, 2022
9755208
Running layout expressions to calculate hidden fields and populate th…
Sep 15, 2022
2dd0389
Cleaning up complexities by extracting methods (work mostly done by W…
Sep 15, 2022
28b21f1
Adding deprecation warning for my earlier findChildren() function tha…
Sep 15, 2022
513a1a4
Implementing a lisp-like simplified version of expressions, which is …
Sep 16, 2022
a0fd7f7
Removing some tests that have been implemented as shared tests
Sep 16, 2022
0875528
Merge branch 'main' into feat/layout-expressions
Sep 16, 2022
28b5d5d
Moving shared test runner out of the folder with the tests in them. T…
Sep 19, 2022
9375376
Adding a new redux store item in uiconfig for storing layout expressi…
Sep 19, 2022
d8cbd0f
Implementing basic support for controlling the page order using layou…
Sep 19, 2022
21f126c
Pulling latest changes from app-lib-dotnet and updating the context-l…
Sep 22, 2022
f8e9d20
Pulling latest shared unit tests and merging them into frontend. One …
Sep 22, 2022
88d2f3a
Simplifying transposeDataModel() dramatically by introducing utility …
Sep 26, 2022
1ec39be
Merge branch 'main' into feat/layout-expressions
Sep 27, 2022
db81b65
Docker compose (#492)
ivarne Oct 3, 2022
837c0d8
Merge remote-tracking branch 'origin/feat/layout-expressions' into fe…
Oct 3, 2022
6b534dd
Rewriting all expressions to use the lisp-like format, and removing s…
Oct 4, 2022
23ba0c9
Merge branch 'main' into feat/layout-expressions
Oct 4, 2022
76b269f
Fixing the broken usage of getVariableTextKeysForRepeatingGroupCompon…
Oct 4, 2022
e09085c
Merge branch 'main' into feat/layout-expressions
Oct 4, 2022
cb37640
Implementing support for calculating hidden layouts/pages (aka. 'trac…
Oct 5, 2022
8e7ead9
Fixing issues where "triggers": ["validation"] was interpreted as a l…
Oct 5, 2022
11297e5
Moving the getLayoutOrderFromTracks to primarily be used as a memoize…
Oct 5, 2022
f04e1f8
Found out why hiding layouts didn't work! The state was just set to t…
Oct 5, 2022
073e470
Huge code move and renaming from 'layout expressions' to just 'expres…
Oct 5, 2022
559c6ad
Using memoization to prevent infinite loop re-rendering in SummaryCom…
Oct 6, 2022
2da70c7
Fixing failing test: layouts can be null
Oct 6, 2022
15b8190
Reducing complexity
Oct 11, 2022
8bed429
More renaming of stuff I prefixed with `LE` (for Layout Expressions).…
Oct 11, 2022
fb38eda
Changing the implementation to return the default value (if one is se…
Oct 11, 2022
32f2998
The derived type that should indicate that expressions have been reso…
Oct 11, 2022
7f59c57
Merge branch 'main' into feat/layout-expressions
Oct 12, 2022
6f79e0c
Installing utility-types again
Oct 12, 2022
38a3f0e
Showing the banner for required fields on the top of the form if ther…
Oct 12, 2022
281e4c9
Removing the good old hack
Oct 12, 2022
2c033f1
Removing TODO for a wanted test. This already has some test coverage …
Oct 12, 2022
3c1135b
Adding a tiny test for the useLayoutsAsNodes hook
Oct 12, 2022
08affed
Making sure expressions can be used on the saveAndNextButton feature,…
Oct 13, 2022
248cae0
Adding a last-minute 'if' function. I'm not entirely happy with the w…
Oct 13, 2022
21e3417
Removing irrelevant variant for abstract function (thanks to LGTM.com!)
Oct 13, 2022
dd63eaf
Merge branch 'main' into feat/layout-expressions
Oct 18, 2022
b4fa653
Fixing 'cannot assign to read only property of object' bug that only …
Oct 19, 2022
4b9c7a5
Merge branch 'main' into feat/layout-expressions
Oct 20, 2022
0a26db3
Fixing import
Oct 20, 2022
a77bb3d
Merge branch 'main' into feat/layout-expressions
Oct 20, 2022
4fd17de
Adding support for expressions on `alertOnDelete`, but adding a TODO …
Oct 20, 2022
9fd63c8
Merge branch 'main' into feat/layout-expressions
Oct 24, 2022
082634e
The repeatingGroups redux state can now be null, so this failed hard …
Oct 24, 2022
3c3459b
Merge branch 'main' into feat/layout-expressions
Oct 25, 2022
c1ead78
Re-using LayoutNode objects instead of creating new ones, as the dupl…
Oct 25, 2022
83c7f0f
Fixing the hierarchy tools to properly respect and set rowIndex when …
Oct 25, 2022
0887d0a
Fixing potentially infinite loop when rendering summary, as the insta…
Oct 25, 2022
7dae397
Even better fix for memoizing the options argument, as the previous f…
Oct 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/altinn-app-frontend/src/components/GenericComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';

import { useAppDispatch, useAppSelector } from 'src/common/hooks';
import components, { FormComponentContext } from 'src/components';
import { useExpressionsForComponent } from 'src/features/expressions/useExpressions';
import Description from 'src/features/form/components/Description';
import Label from 'src/features/form/components/Label';
import Legend from 'src/features/form/components/Legend';
Expand All @@ -29,11 +30,13 @@ import type {
IFormComponentContext,
PropsFromGenericComponent,
} from 'src/components';
import type { ExprResolved } from 'src/features/expressions/types';
import type {
ComponentExceptGroup,
ComponentTypes,
IGridStyling,
ILayoutCompBase,
ILayoutComponent,
} from 'src/features/form/layout';
import type { IComponentValidations, ILabelSettings } from 'src/types';

Expand Down Expand Up @@ -101,8 +104,14 @@ const useStyles = makeStyles((theme) => ({
}));

export function GenericComponent<Type extends ComponentExceptGroup>(
props: IActualGenericComponentProps<Type>,
_props: IActualGenericComponentProps<Type>,
) {
const props = useExpressionsForComponent(
_props as ILayoutComponent,
) as ExprResolved<IActualGenericComponentProps<Type>> & {
type: Type;
};

const { id, ...passThroughProps } = props;
const dispatch = useAppDispatch();
const classes = useStyles(props);
Expand Down
2 changes: 1 addition & 1 deletion src/altinn-app-frontend/src/components/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useEffect, useState } from 'react';
import { shallowEqual } from 'react-redux';

import { useAppSelector } from 'src/common/hooks';
import { buildInstanceContext } from 'src/utils/instanceContext';
import {
getOptionLookupKey,
getRelevantFormDataForOptionSource,
setupSourceOptions,
} from 'src/utils/options';
import type { IMapping, IOption, IOptionSource } from 'src/types';

import { buildInstanceContext } from 'altinn-shared/utils/instanceContext';
import type { IDataSources, IInstanceContext } from 'altinn-shared/types';

interface IUseGetOptionsParams {
Expand Down
3 changes: 2 additions & 1 deletion src/altinn-app-frontend/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TextAreaComponent } from 'src/components/base/TextAreaComponent';
import CustomComponent from 'src/components/custom/CustomWebComponent';
import { NavigationButtons as NavigationButtonsComponent } from 'src/components/presentation/NavigationButtons';
import type { IGenericComponentProps } from 'src/components/GenericComponent';
import type { ExprResolved } from 'src/features/expressions/types';
import type {
ComponentExceptGroup,
ComponentExceptGroupAndSummary,
Expand Down Expand Up @@ -84,7 +85,7 @@ export interface IComponentProps extends IGenericComponentProps {
}

export type PropsFromGenericComponent<T extends ComponentExceptGroup> =
IComponentProps & Omit<ILayoutComponent<T>, 'type'>;
IComponentProps & ExprResolved<Omit<ILayoutComponent<T>, 'type'>>;

export interface IFormComponentContext {
grid?: IGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cn from 'classnames';
import { useAppDispatch, useAppSelector } from 'src/common/hooks';
import ErrorPaper from 'src/components/message/ErrorPaper';
import SummaryComponentSwitch from 'src/components/summary/SummaryComponentSwitch';
import { useExpressionsForComponent } from 'src/features/expressions/useExpressions';
import { FormLayoutActions } from 'src/features/form/layout/formLayoutSlice';
import { makeGetHidden } from 'src/selectors/getLayoutData';
import {
Expand Down Expand Up @@ -80,9 +81,11 @@ export function SummaryComponent({
const attachments = useAppSelector(
(state: IRuntimeState) => state.attachments.attachments,
);
const formComponent = useAppSelector((state) => {
const _formComponent = useAppSelector((state) => {
return state.formLayout.layouts[pageRef].find((c) => c.id === componentRef);
});
const formComponent = useExpressionsForComponent(_formComponent);

const goToCorrectPageLinkText = useAppSelector((state) => {
return getTextFromAppOrDefault(
'form_filler.summary_go_to_correct_page',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MultipleChoiceSummary from 'src/components/summary/MultipleChoiceSummary'
import SingleInputSummary from 'src/components/summary/SingleInputSummary';
import SummaryBoilerplate from 'src/components/summary/SummaryBoilerplate';
import SummaryGroupComponent from 'src/components/summary/SummaryGroupComponent';
import type { ExprResolved } from 'src/features/expressions/types';
import type {
ILayoutComponent,
ILayoutCompSummary,
Expand All @@ -19,7 +20,7 @@ export interface ISummaryComponentSwitch
onChangeClick: () => void;
changeText: string;
};
formComponent: ILayoutComponent | ILayoutGroup;
formComponent: ExprResolved<ILayoutComponent | ILayoutGroup>;
hasValidationMessages?: boolean;
label?: any;
formData?: any;
Expand Down
1 change: 1 addition & 0 deletions src/altinn-app-frontend/src/features/expressions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ export const ExprDefaultsForGroup: ExprDefaultValues<ILayoutGroup> = {
addButton: true,
deleteButton: true,
saveButton: true,
alertOnDelete: false,
saveAndNextButton: false,
},
};
34 changes: 18 additions & 16 deletions src/altinn-app-frontend/src/features/expressions/useExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ExprDefaultsForComponent,
ExprDefaultsForGroup,
} from 'src/features/expressions/index';
import { getInstanceContextSelector } from 'src/utils/instanceContext';
import { useLayoutsAsNodes } from 'src/utils/layout/useLayoutsAsNodes';
import type { ContextDataSources } from 'src/features/expressions/ExprContext';
import type { EvalExprInObjArgs } from 'src/features/expressions/index';
Expand All @@ -17,7 +18,7 @@ import type {
} from 'src/features/expressions/types';
import type { ILayoutComponentOrGroup } from 'src/features/form/layout';

import { buildInstanceContext } from 'altinn-shared/utils/instanceContext';
import type { IInstanceContext } from 'altinn-shared/types';

export interface UseExpressionsOptions<T> {
/**
Expand All @@ -42,20 +43,28 @@ export interface UseExpressionsOptions<T> {
* @param input Any input, object, value from the layout definitions, possibly containing expressions somewhere.
* This hook will look through the input (and recurse through objects), looking for expressions and resolve
* them to provide you with the base out value for the current component context.
* @param options Optional options (see their own docs)
* @param _options Optional options (see their own docs)
*/
export function useExpressions<T>(
input: T,
options?: UseExpressionsOptions<T>,
_options?: UseExpressionsOptions<T>,
): ExprResolved<T> {
// The options argument is an object, so it's natural to create a new one each time this function is called. As
// the equality function in React will assume a new object reference is an entirely new object, we'll memoize this
// argument as to prevent infinite looping when given a new (but identical) options argument.
// eslint-disable-next-line react-hooks/exhaustive-deps
const options = useMemo(() => _options, [JSON.stringify(_options)]);

const component = useContext(FormComponentContext);
const nodes = useLayoutsAsNodes();
const formData = useAppSelector((state) => state.formData?.formData);
const applicationSettings = useAppSelector(
(state) => state.applicationSettings?.applicationSettings,
);
const instance = useAppSelector((state) => state.instanceData?.instance);
const instanceContext = buildInstanceContext(instance);
const instanceContextSelector = getInstanceContextSelector();
const instanceContext: IInstanceContext = useAppSelector(
instanceContextSelector,
);
const id = (options && options.forComponentId) || component.id;

const node = useMemo(() => {
Expand Down Expand Up @@ -93,16 +102,9 @@ const componentDefaults: any = {

export function useExpressionsForComponent<T extends ILayoutComponentOrGroup>(
input: T,
options?: Omit<UseExpressionsOptions<T>, 'defaults'>,
): ExprResolved<T> {
const newOptions = useMemo(
() => ({
...options,
defaults: componentDefaults,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
Object.values(options),
);

return useExpressions(input, newOptions);
return useExpressions(input, {
forComponentId: input.id,
defaults: componentDefaults,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Grid, makeStyles } from '@material-ui/core';

import { useAppDispatch, useAppSelector } from 'src/common/hooks';
import ErrorPaper from 'src/components/message/ErrorPaper';
import { ExprDefaultsForGroup } from 'src/features/expressions';
import { useExpressions } from 'src/features/expressions/useExpressions';
import { RepeatingGroupAddButton } from 'src/features/form/components/RepeatingGroupAddButton';
import { RepeatingGroupsEditContainer } from 'src/features/form/containers/RepeatingGroupsEditContainer';
import { RepeatingGroupsLikertContainer } from 'src/features/form/containers/RepeatingGroupsLikertContainer';
Expand Down Expand Up @@ -70,6 +72,11 @@ export function GroupContainer({
JSON.stringify(components),
);

const edit = useExpressions(container.edit, {
forComponentId: id,
defaults: ExprDefaultsForGroup.edit,
});

const editIndex = useAppSelector(
(state: IRuntimeState) =>
state.formLayout.uiConfig.repeatingGroups[id]?.editIndex ?? -1,
Expand Down Expand Up @@ -109,13 +116,8 @@ export function GroupContainer({
const textResources = useAppSelector(
(state) => state.textResources.resources,
);
const getRepeatingGroupIndex = (containerId: string) => {
if (repeatingGroups && repeatingGroups[containerId]) {
return repeatingGroups[containerId].index;
}
return -1;
};
const repeatingGroupIndex = getRepeatingGroupIndex(id);
const repeatingGroupIndex =
repeatingGroups && repeatingGroups[id] ? repeatingGroups[id].index : -1;
const repeatingGroupDeepCopyComponents = useMemo(
() =>
createRepeatingGroupComponents(
Expand Down Expand Up @@ -157,24 +159,24 @@ export function GroupContainer({
React.useEffect(() => {
const filteredIndexList = getRepeatingGroupFilteredIndices(
formData,
container.edit?.filter,
edit?.filter,
);
if (filteredIndexList) {
setFilteredIndexList(filteredIndexList);
}
}, [formData, container]);
}, [formData, edit]);

const onClickAdd = useCallback(() => {
dispatch(FormLayoutActions.updateRepeatingGroups({ layoutElementId: id }));
if (container.edit?.mode !== 'showAll') {
if (edit?.mode !== 'showAll') {
dispatch(
FormLayoutActions.updateRepeatingGroupsEditIndex({
group: id,
index: repeatingGroupIndex + 1,
}),
);
}
}, [container.edit?.mode, dispatch, id, repeatingGroupIndex]);
}, [edit?.mode, dispatch, id, repeatingGroupIndex]);

React.useEffect(() => {
const { edit } = container;
Expand Down Expand Up @@ -242,7 +244,7 @@ export function GroupContainer({
return null;
}

if (container.edit?.mode === 'likert') {
if (edit?.mode === 'likert') {
return (
<>
<RepeatingGroupsLikertContainer
Expand Down Expand Up @@ -274,9 +276,9 @@ export function GroupContainer({
item={true}
className={classes.minusMargin}
>
{(!container.edit?.mode ||
container.edit?.mode === 'showTable' ||
(container.edit?.mode === 'hideTable' && editIndex < 0)) && (
{(!edit?.mode ||
edit?.mode === 'showTable' ||
(edit?.mode === 'hideTable' && editIndex < 0)) && (
<RepeatingGroupTable
components={components}
attachments={attachments}
Expand All @@ -295,7 +297,7 @@ export function GroupContainer({
deleting={deletingIndexes.includes(repeatingGroupIndex)}
setEditIndex={setEditIndex}
onClickRemove={onClickRemove}
hideDeleteButton={container.edit?.deleteButton === false}
hideDeleteButton={edit?.deleteButton === false}
setMultiPageIndex={setMultiPageIndex}
multiPageIndex={multiPageIndex}
textResources={textResources}
Expand All @@ -307,8 +309,8 @@ export function GroupContainer({
container={true}
justifyContent='flex-end'
/>
{container.edit?.mode !== 'showAll' &&
container.edit?.addButton !== false &&
{edit?.mode !== 'showAll' &&
edit?.addButton !== false &&
editIndex < 0 &&
repeatingGroupIndex + 1 < container.maxCount && (
<RepeatingGroupAddButton
Expand All @@ -320,7 +322,7 @@ export function GroupContainer({
textResources={textResources}
/>
)}
{editIndex >= 0 && container.edit?.mode === 'hideTable' && (
{editIndex >= 0 && edit?.mode === 'hideTable' && (
<RepeatingGroupsEditContainer
container={container}
editIndex={editIndex}
Expand All @@ -332,14 +334,14 @@ export function GroupContainer({
layout={layout}
onClickSave={onClickSave}
repeatingGroupDeepCopyComponents={repeatingGroupDeepCopyComponents}
hideSaveButton={container.edit?.saveButton === false}
hideSaveButton={edit?.saveButton === false}
multiPageIndex={multiPageIndex}
setMultiPageIndex={setMultiPageIndex}
showSaveAndNextButton={container.edit?.saveAndNextButton === true}
showSaveAndNextButton={edit?.saveAndNextButton === true}
filteredIndexes={filteredIndexList}
/>
)}
{container.edit?.mode === 'showAll' &&
{edit?.mode === 'showAll' &&
// Generate array of length repeatingGroupIndex and iterate over indexes
Array(repeatingGroupIndex + 1)
.fill(0)
Expand Down Expand Up @@ -369,12 +371,12 @@ export function GroupContainer({
repeatingGroupDeepCopyComponents
}
hideSaveButton={true}
hideDeleteButton={container.edit?.deleteButton === false}
hideDeleteButton={edit?.deleteButton === false}
/>
);
})}
{container.edit?.mode === 'showAll' &&
container.edit?.addButton !== false &&
{edit?.mode === 'showAll' &&
edit?.addButton !== false &&
repeatingGroupIndex + 1 < container.maxCount && (
<RepeatingGroupAddButton
id={`add-button-${id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import cn from 'classnames';

import { useAppDispatch } from 'src/common/hooks';
import { ExprDefaultsForGroup } from 'src/features/expressions';
import { useExpressions } from 'src/features/expressions/useExpressions';
import { RepeatingGroupsEditContainer } from 'src/features/form/containers/RepeatingGroupsEditContainer';
import { FormLayoutActions } from 'src/features/form/layout/formLayoutSlice';
import { Triggers } from 'src/types';
Expand Down Expand Up @@ -259,6 +261,11 @@ export function RepeatingGroupTable({
const classes = useStyles();
const mobileView = useMediaQuery('(max-width:992px)'); // breakpoint on altinn-modal

const edit = useExpressions(container.edit, {
forComponentId: id,
defaults: ExprDefaultsForGroup.edit,
});

const tableHeaderComponentIds =
container.tableHeaders ||
components.map((c) => c.baseComponentId || c.id) ||
Expand Down Expand Up @@ -312,7 +319,7 @@ export function RepeatingGroupTable({
};

const handleDeleteClick = (index: number) => {
if (container.edit?.alertOnDelete) {
if (edit?.alertOnDelete) {
onOpenChange(index);
} else {
onClickRemove(index);
Expand Down Expand Up @@ -391,10 +398,10 @@ export function RepeatingGroupTable({
layout={layout}
onClickSave={handleSaveClick}
repeatingGroupDeepCopyComponents={repeatingGroupDeepCopyComponents}
hideSaveButton={container.edit?.saveButton === false}
hideSaveButton={edit?.saveButton === false}
multiPageIndex={multiPageIndex}
setMultiPageIndex={setMultiPageIndex}
showSaveAndNextButton={container.edit?.saveAndNextButton === true}
showSaveAndNextButton={edit?.saveAndNextButton === true}
filteredIndexes={filteredIndexes}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export function* updateFormDataSaga({
);
}

if (state.formDynamics.conditionalRendering) {
yield put(FormDynamicsActions.checkIfConditionalRulesShouldRun({}));
}
yield put(FormDynamicsActions.checkIfConditionalRulesShouldRun({}));
} catch (error) {
console.error(error);
yield put(FormDataActions.updateRejected({ error }));
Expand Down
Loading