Skip to content

Commit

Permalink
4001 - Datatable use Datagrid - Fix Growing Stock Composition 2025 he…
Browse files Browse the repository at this point in the history
…ader row & Minor fixes (#4190)

* 4001 - Fix Growing Stock Composition 2025 header rows

* 4001 - Fix table_1_4b_2020 labels

* 4001 - Remove unnecessary section -> table styles

* 4001 - Make RowNoticeMessage span entire row
  • Loading branch information
yaguzmang authored Dec 25, 2024
1 parent 4c2cffa commit 325b649
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import 'src/client/style/partials';

.table-grid__notice-message-cell {
grid-column: 1 / -1;
padding: $spacing-xxs $spacing-xxxs;
vertical-align: top;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ const RowNoticeMessage: React.FC<RowProps> = (props) => {
return (
<DataRow>
{cols.map((col) => {
const { gridColumn, gridRow } = Cols.getStyle({ col, cycle })
const message = Cols.getLabel({ cycle, col, t })

if (!message) return null

return (
<DataCell
key={col.uuid}
className="table-grid__notice-message-cell"
gridColumn={gridColumn}
gridRow={gridRow}
noBorder
>
<DataCell key={col.uuid} className="table-grid__notice-message-cell" noBorder>
{message}
</DataCell>
)
Expand Down
14 changes: 0 additions & 14 deletions src/client/pages/Section/Section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@
justify-self: start;
}

&.section__degradedForest {
.fra-table {
tr:nth-child(2) {
th:first-child {
min-width: 72px;
}
}
}
}

&.section__sustainableDevelopment {
.subhead {
margin-bottom: $spacing-xs;
}

.fra-secondary-table__wrapper {
width: 100%;

.fra-table__header-cell-left {
width: 25%;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,27 @@ const _fixPanEuropean2020GridLayouts = async (client: BaseProtocol) => {
)
`
)

// Fix table_1_4b_2020 label keys missing a "."
await client.query(
`update ${schemaAssessment}.col c
set props = jsonb_set(
props,
'{labels,${cycleUuid},key}',
'"panEuropean.carbonStockInHarvestedWoodProductsHWP.harvested_wood_products"',
false
)
where c.props -> 'labels' -> '${cycleUuid}' ->> 'key' = 'panEuropean.carbonStockInHarvestedWoodProductsHWPharvested_wood_products'
and c.props ->> 'colType' = 'header'
and c.props ->> 'index' = 'header_0'
and c.row_id in (
select r.id
from ${schemaAssessment}.row r
join ${schemaAssessment}."table" t on r.table_id = t.id
where t.props ->> 'name' = 'table_1_4b_2020'
)
`
)
}

const _fixPanEuropean2025GridLayouts = async (client: BaseProtocol) => {
Expand Down Expand Up @@ -678,9 +699,59 @@ const _fixFraTaxonCodes = async (client: BaseProtocol) => {
)
}

const _fixGrowingStockComposition2025HeaderRows = async (client: BaseProtocol) => {
const assessment = await AssessmentController.getOne({ assessmentName: AssessmentNames.fra }, client)

const schemaAssessment = Schemas.getName(assessment)

// Move 'header_1' row cols to 'header_0' row
await client.query(
`with target_row as (
select
r.id as target_row_id
from ${schemaAssessment}.row r
join ${schemaAssessment}.table t on r.table_id = t.id
where r.props ->> 'index' = 'header_0'
and t.props ->> 'name' = 'growingStockComposition2025'
),
cols_to_update as (
select
c.id as col_id,
target_row.target_row_id,
(c.props ->> 'index')::int + 3 as new_index -- number of cols in header_0 + index
from ${schemaAssessment}.col c
join ${schemaAssessment}.row r on c.row_id = r.id
join ${schemaAssessment}.table t on r.table_id = t.id
join target_row on true
where r.props ->> 'index' = 'header_1'
and t.props ->> 'name' = 'growingStockComposition2025'
)
update ${schemaAssessment}.col
set row_id = cols_to_update.target_row_id,
props = jsonb_set(
props,
'{index}',
to_jsonb(cols_to_update.new_index)
)
from cols_to_update
where ${schemaAssessment}.col.id = cols_to_update.col_id;
delete from ${schemaAssessment}.row
where id in (
select
r.id
from ${schemaAssessment}.row r
join ${schemaAssessment}.table t on r.table_id = t.id
where r.props ->> 'index' = 'header_1'
and t.props ->> 'name' = 'growingStockComposition2025'
);`
)
}

export default async (client: BaseProtocol) => {
await _fixFraTaxonCodes(client)
await _fixFRA2025GridLayouts(client)
await _fixGrowingStockComposition2025HeaderRows(client)
await _fixFRA2020GridLayouts(client)
await _fixPanEuropean2020GridLayouts(client)
await _fixPanEuropean2025GridLayouts(client)
Expand Down

0 comments on commit 325b649

Please sign in to comment.