Skip to content

Bind List/MultipleSelect/Checkboxes to a repeating group #3236

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

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

paal2707
Copy link
Contributor

@paal2707 paal2707 commented Apr 4, 2025

Description

Bind List/MultipleSelect/Checkboxes to a list of Objects/a repeating group.
Added a group, checked and deletionStrategy property to the List/MultipleSelect/Checkboxes, to support saving to a list of Objects and to support toggling soft deletion.

Related Issue(s)

Verification/QA

  • Manual functionality testing

    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests

    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)

    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs

    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio

    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board

    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels

    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

walldenfilippa and others added 30 commits February 6, 2025 11:30
Co-authored-by: Johanne Lie <joli@patentstyret.no>
Co-authored-by: adamhaeger <adamgullerud@gmail.com>
# Conflicts:
#	src/layout/List/ListComponent.tsx
# Conflicts:
#	src/layout/List/ListComponent.tsx
@paal2707 paal2707 added the kind/product-feature Pull requests containing new features label Apr 4, 2025
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
32.2% Coverage on New Code (required ≥ 45%)
40.2% Duplication on New Code (required ≤ 3%)
17.72% Condition Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

@paal2707 paal2707 added the backport-ignore This PR is a new feature and should not be cherry-picked onto release branches label Apr 14, 2025
@paal2707 paal2707 moved this to In Progress in Issues SSB Apr 14, 2025
@paal2707 paal2707 moved this to 👷 In Progress in Team Apps Apr 14, 2025
@paal2707 paal2707 marked this pull request as ready for review April 14, 2025 13:32
Copy link
Contributor

@olemartinorg olemartinorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should go the extra mile to support varying depths of properties inside these rows, so that we can support any data model instead of apps having to tailor their data model to our functionality. We don't currently have any such limitations elsewhere in the product (at least that I know), and these limitations in List was previously removed in #3136.

We can also team up to pair-program the rest of this, if you want, or if my suggestions were unclear. 🙌

Comment on lines 89 to 92
//TODO: excluding from List now??
} else if (binding !== 'group' && binding !== 'checked' && binding !== 'label' && binding !== 'metadata') {
next[binding] = row[binding];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the TODO here still relevant?

Also, i find this checking for other bindings brittle. When we introduce a new binding to Checkboxes or MultipleSelect, this will have to be updated (and then possibly be a breaking change for existing List component configurations). It will be difficult to notice (TypeScript won't warn us in any way, and no tests will catch this unless configured along with a group binding). I would prefer something like:

if (componentType !== 'List' && binding === 'simpleBinding') {
  ...
} else if (componentType === 'List' && binding !== 'group' && binding !== 'checked') {
  ...
}

Also, same goes here, use dot.str() to put values in the object when supporting any-depth properties:

dot.str(relativeBinding, newValue, next);

Comment on lines +80 to +90
const simpleBindingPath = dataModelBindings.simpleBinding?.field.split('.');
const groupBinding = ctx.lookupBinding(dataModelBindings?.group);
const items = groupBinding[0]?.items;
const properties =
items && !Array.isArray(items) && typeof items === 'object' && 'properties' in items
? items.properties
: undefined;

if (!(properties && simpleBindingPath[1] in properties)) {
errors.push(`The property ${simpleBindingPath[1]} must be present in group`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also only supports one level deep structures. I recently fixed the validatior in src/layout/List/index.tsx to work with any levels of properties, you could take a look at how that does it.

import { NodesInternal } from 'src/utils/layout/NodesContext';
import type { NodeValidationProps } from 'src/layout/layout';

export function ListLayoutValidator(props: NodeValidationProps<'List'>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this duplicated now? Might be better to make one that works the same for all components. If I'm not mistaken, it's as simple as:

Suggested change
export function ListLayoutValidator(props: NodeValidationProps<'List'>) {
export function LayoutValidatorForGroupAndChecked(props: NodeValidationProps<'List' | 'Checkboxes' | 'MultipleSelect'>) {

validateDataModelBindings(ctx: LayoutValidationCtx<'MultipleSelect'>): string[] {
return this.validateDataModelBindingsSimple(ctx);
const errors: string[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copy-pasting this, you can also extract it to a function in a separate file and import it. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-ignore This PR is a new feature and should not be cherry-picked onto release branches kind/product-feature Pull requests containing new features
Projects
Status: In Progress
Status: 👷 In Progress
Development

Successfully merging this pull request may close these issues.

Binde MultipleSelect/Checkboxes til en repeterende gruppe i datamodellen
4 participants