Skip to content

Commit

Permalink
Legg til sorteringer av brevblokker for å garantere riktig rekkefølge…
Browse files Browse the repository at this point in the history
… på brevblokekr fra Sanity
  • Loading branch information
ssaegrov committed Aug 27, 2024
1 parent 2b80bcd commit b616ee9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions app/sanity/sanity-queries.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
export function hentBrevBlokkerMedId(textIds: string[]) {
return `*[_type == "brevBlokk" && textId in ${JSON.stringify(textIds)}]{
...,
innhold[]{
const tekstBlokkSortering = textIds
.map((id, index) => `textId == "${id}" => ${index}`)
.join(", ");

return `*[_type == "brevBlokk" && textId in ${JSON.stringify(textIds)}] | order(select(
${tekstBlokkSortering},
${textIds.length}
)) {
...,
_type == "block" => {
innhold[]{
...,
children[]{
_type == "block" => {
...,
_type == "opplysningReference" => {
children[]{
...,
"behandlingOpplysning": @->{
...
}
},
_type == "opplysningReference" => {
...,
"behandlingOpplysning": @->{
...
}
},
}
}
}
},
}`;
},
}`;
}

export const hentBrevmalMedId = `*[_type == "brevMal" && textId == $brevmalId] | order(_createdAt desc)[0] {
Expand Down
2 changes: 1 addition & 1 deletion mocks/data/mock-melding-om-vedtak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const mockMeldingOmVedtak: IBrevBlokk[] = [
opplysninger: [{ tekstId: "Søknadsdato", type: "dato", verdi: "12-05-2024" }],
},
{
tekstId: "brev.blokk.rett-til-aa-klaage",
tekstId: "brev.blokk.rett-til-aa-klage",
opplysninger: [
{
tekstId: "Arbeidsinntekt siste 12 mnd",
Expand Down

0 comments on commit b616ee9

Please sign in to comment.