Skip to content

Commit

Permalink
3845 - handle Section->hidden per cycle / hide panEU sections only in…
Browse files Browse the repository at this point in the history
… 2025
  • Loading branch information
minotogna committed Jun 26, 2024
1 parent cb13647 commit 212c89e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/meta/assessment/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type SubSectionHints = {
export interface SubSectionProps extends SectionProps {
dataExport?: boolean
descriptions: Descriptions
hidden?: boolean
hidden?: Record<CycleUuid, boolean>
hints?: Record<CycleUuid, SubSectionHints>
name: SectionName
showTitle: boolean
Expand Down
3 changes: 2 additions & 1 deletion src/server/repository/adapter/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface SubSectionDB {
export const SubSectionAdapter = (subSection: SubSectionDB): SubSection => {
// eslint-disable-next-line camelcase
const { parent_id, props, ...restSubSection } = subSection
const { anchors, descriptions, hints, labels, ...restProps } = props
const { anchors, descriptions, hidden, hints, labels, ...restProps } = props

return {
...restSubSection,
Expand All @@ -29,6 +29,7 @@ export const SubSectionAdapter = (subSection: SubSectionDB): SubSection => {
...Objects.camelize(restProps),
anchors,
descriptions,
hidden,
hints,
labels,
},
Expand Down
4 changes: 2 additions & 2 deletions src/server/repository/assessment/section/getMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getMany = async (
from ${schemaName}.section s
where s.parent_id is not null
and props -> 'cycles' ? $1
and ($2 = true or (coalesce(s.props ->> 'hidden', 'false')::boolean = false and $2 = false))
and ($2 = true or (coalesce(s.props -> 'hidden' ->> '${cycle.uuid}', 'false', 'false')::boolean = false and $2 = false))
group by s.parent_id
order by s.parent_id),
s as (select s.*,
Expand All @@ -27,7 +27,7 @@ export const getMany = async (
where s.parent_id is null
and props -> 'cycles' ? $1
and ss.sub_sections is not null
and ($2 = true or (coalesce(s.props ->> 'hidden', 'false')::boolean = false and $2 = false))
and ($2 = true or (coalesce(s.props -> 'hidden' ->> '${cycle.uuid}', 'false', 'false')::boolean = false and $2 = false))
order by (s.props ->> 'index')::numeric)
select jsonb_agg(s.*) as data
from s
Expand Down
4 changes: 3 additions & 1 deletion src/server/repository/assessment/section/getManyMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const getManyMetadata = async (
and t.props -> 'cycles' ? $2
and r.props -> 'cycles' ? $2
and c.props -> 'cycles' ? $2
and ($3 = true or (coalesce(s.props ->> 'hidden', 'false')::boolean = false and $3 = false))
and ($3 = true or (coalesce(s.props -> 'hidden' ->> '${
cycle.uuid
}', 'false')::boolean = false and $3 = false))
${sectionNames?.length ? `and s.props ->> 'name' in ($1:list)` : ''}
group by s.props ->> 'name',
to_jsonb(ts.*),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AssessmentNames } from 'meta/assessment'

import { AssessmentController } from 'server/controller/assessment'
import { BaseProtocol, Schemas } from 'server/db'

export default async (client: BaseProtocol) => {
const assessmentName = AssessmentNames.panEuropean
const { assessment, cycle } = await AssessmentController.getOneWithCycle(
{ assessmentName, cycleName: '2025' },
client
)
const schemaAssessment = Schemas.getName(assessment)

await client.query(`
update ${schemaAssessment}.section s
set props = props || jsonb_build_object('hidden', jsonb_build_object('${cycle.uuid}', to_jsonb(true)))
from (select s.id
from ${schemaAssessment}.section s
where s.props ->> 'hidden' = 'true') as src
where s.id = src.id
`)

await AssessmentController.generateMetaCache(client)

const assessmentUpdate = await AssessmentController.getOne({ assessmentName }, client)
await AssessmentController.generateMetadataCache({ assessment: assessmentUpdate }, client)
}

0 comments on commit 212c89e

Please sign in to comment.