Skip to content
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

Feat/265 url param instantiation #2951

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

Conversation

adamhaeger
Copy link
Contributor

@adamhaeger adamhaeger commented Jan 28, 2025

Description

Allows users to configure query params that will prefill the datamodel.

Depends on this backend PR: Altinn/app-lib-dotnet#1068

Query params will prefill datamodel according to this flow diagram:

Team Apps - General - Query param prefill flyt (1)

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/* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

@adamhaeger adamhaeger added the kind/feature-request New feature or request label Jan 28, 2025
@adamhaeger adamhaeger added the kind/product-feature Pull requests containing new features label Jan 30, 2025
@adamhaeger
Copy link
Contributor Author

/publish

Copy link
Contributor

github-actions bot commented Jan 31, 2025

PR release:

  • <link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/4.15.2-pr.426.265-url-param-instantiation.ab6c6920/altinn-app-frontend.css">
  • <script src="https://altinncdn.no/toolkits/altinn-app-frontend/4.15.2-pr.426.265-url-param-instantiation.ab6c6920/altinn-app-frontend.js"></script>

⚙️ Building...
✅ Done!

@adamhaeger adamhaeger marked this pull request as ready for review January 31, 2025 13:48
@adamhaeger
Copy link
Contributor Author

/publish

Copy link
Contributor

github-actions bot commented Jan 31, 2025

PR release:

  • <link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/4.15.2-pr.430.265-url-param-instantiation.0353aad7/altinn-app-frontend.css">
  • <script src="https://altinncdn.no/toolkits/altinn-app-frontend/4.15.2-pr.430.265-url-param-instantiation.0353aad7/altinn-app-frontend.js"></script>

⚙️ Building...
✅ Done!

Copy link

sonarqubecloud bot commented Feb 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
21.8% Coverage on New Code (required ≥ 45%)
16.67% Condition Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

}: DataModelDeps & DataModelProps) {
if (prefillFromQueryParams && isStateless && !isAnonymous && dataType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why we should limit this not to work for anonymous stateless? 🤔

includeRowIds: boolean,
prefillFromQueryParams: string,
) =>
`${appPath}/v1/data?dataType=${dataType}&includeRowId=${includeRowIds.toString()}&prefill=${prefillFromQueryParams}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

So you're passing prefill to the backend so that backend fills that into the model when first reading it? That's not quite what I expected here - I thought we talked about sending the first request as a POST with the prefill data in it, not sending a GET with prefill data for the backend to figure out. This works, I guess, but it adds complexity when we could have done this with existing APIs already (but then via POST).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uuuhm well wouldnt that require a new implementation instead of adding to what already happens?

Wouldnt that add even more complexity?

Either way I think it makes sense to remove the GET /data endpoint altogether in this task: #2065 as the GET and POST do more or less the same thing, so could merge this and fix it as part of that I guess.

Copy link
Contributor Author

@adamhaeger adamhaeger Feb 7, 2025

Choose a reason for hiding this comment

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

Or did you mean that we just do a setValue or something? We also have to let TE run validation code of the queryparam values so that would have to hook into it somehow also, see line 132 here: https://github.com/Altinn/app-lib-dotnet/pull/1068/files#diff-57722a0d58a9aa420ee547af44fab41e404a5a7fb409e39c6e749569410644fd

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha! Yep, I think it makes sense to never call the GET endpoint at all, and just start off by POSTing an empty object (or one with prefill) in stateless. Might want to double-check that with Ivar as well, but I think that would work.

Copy link
Member

@ivarne ivarne Feb 10, 2025

Choose a reason for hiding this comment

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

So to summarise:

  • Stateless currently create the initial data model with a call to GET, and does subsequent updates with POST
  • We think that the initial data model can be an empty object {} and then we can use POST all the time.

One disadvantage is that this means that backend can only have one hook, instead of initialize and update. It can run initialisation on update, if it sets {"isInitalized": true}, so I think we can accept that for future extensibility.

Seems like for some reason we do prefill on both POST and GET,

https://github.com/Altinn/app-lib-dotnet/blob/main/src/Altinn.App.Api/Controllers/StatelessDataController.cs#L131

https://github.com/Altinn/app-lib-dotnet/blob/main/src/Altinn.App.Api/Controllers/StatelessDataController.cs#L257

Copy link
Contributor Author

@adamhaeger adamhaeger Feb 10, 2025

Choose a reason for hiding this comment

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

After a huddle we have decided it makes sense to switch to using the POST endpoint and deprecate the GET endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request New feature or request kind/product-feature Pull requests containing new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support instantiation based on url params
3 participants