Skip to content

Commit

Permalink
Re-apply changes from PR #130 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
vimto authored Nov 1, 2023
1 parent 24c6781 commit f0ab038
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
DELETE
FROM council_plan_documents
WHERE council_id = 9;
DELETE FROM council_plan_documents
WHERE
council_id = 9;

INSERT INTO council_plan_documents (council_id, source_id, document)
VALUES (9, 'PRNP_2023',
'{
"id": "PRNP",
"name": "Proposed Natural Resource Plan",
INSERT INTO
council_plan_documents (council_id, source_id, document)
VALUES
(
9,
'NRP_2023',
'{
"id": "NRP_2023",
"name": "Natural Resources Plan",
"regions": [
{
"id": "b012dd3c-6b10-4db7-a332-e25c42667238",
Expand Down Expand Up @@ -1321,7 +1325,8 @@ VALUES (9, 'PRNP_2023',
"defaultFlowManagementLimit": "Refer to Policy WC.P1"
}
],
"defaultGroundwaterLimit": "Refer to Policy P121 of PRNP",
"defaultSurfaceWaterLimit": "Refer to Policy P121 of PRNP"
"defaultGroundwaterLimit": "Refer to Policy P121 of NRP",
"defaultSurfaceWaterLimit": "Refer to Policy P121 of NRP"
}
');
'
);
11 changes: 11 additions & 0 deletions packages/PlanLimitsUI/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ interface Council {
surfaceWaterChildLimit: string;
groundwaterLimit: string;
};
regionOverrides: {
sourceId: string;
swCMU: React.Element | string;
swCMSU: React.Element | string;
gwCMU: React.Element | string;
flowManagementSite: React.Element | string;
flowLimit: React.Element | string;
limitsTableFooter: React.Element | string;
groundwaterLimit: React.Element | string;
surfaceWaterLimit: React.Element | string;
}[];
}

interface Usage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import gwrcLogo from '../images/gwrc-logo-header.svg';
import horizonsLogo from '../images/horizons-logo-header.png';

const PendingElement = (
<>
<sup>1</sup>Pending change
</>
);

export const Councils: Council[] = [
{
id: 9,
Expand All @@ -22,7 +28,7 @@ export const Councils: Council[] = [
},
footerLinks: [
{
text: 'Natural Resource Plan',
text: 'Natural Resources Plan',
url: 'https://pnrp.gw.govt.nz/',
},
{
Expand All @@ -39,6 +45,33 @@ export const Councils: Council[] = [
surfaceWaterChildLimit: 'Surface Water Catchment Management Sub-unit',
groundwaterLimit: 'Groundwater Catchment Management Unit',
},
regionOverrides: [
{
sourceId: '0b247e41-d840-4a4e-98c3-0ff6d5c31efd',
swCMU: PendingElement,
swCMSU: PendingElement,
gwCMU: PendingElement,
flowManagementSite: PendingElement,
flowLimit: PendingElement,
limitsTableFooter: (
<>
<sup>1</sup>A change to the Natural Resources Plan has been notified
for this Whaitua, please{' '}
<a
target="_blank"
rel="noreferrer"
className="underline"
href="https://www.gw.govt.nz/your-council/contact-us/contact-form/"
>
contact Greater Wellington
</a>{' '}
for up to date advice.
</>
),
surfaceWaterLimit: PendingElement,
groundwaterLimit: PendingElement,
},
],
},
{
id: 8,
Expand Down Expand Up @@ -72,6 +105,7 @@ export const Councils: Council[] = [
surfaceWaterChildLimit: 'Surface Water Management Sub Zone',
groundwaterLimit: 'Ground Water Management Zone',
},
regionOverrides: [],
},
];

Expand Down
8 changes: 7 additions & 1 deletion packages/PlanLimitsUI/src/lib/useAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ export function useAppState(
...new Set(activeLimits.groundWaterLimits.map((gwl) => gwl.name)),
].join(', ');

const regionOverrides = council.regionOverrides.find(
(ro) => ro.sourceId === activeLimits.planRegion?.sourceId,
);

const defaultGroundWaterLimit =
regionOverrides?.groundwaterLimit ??
activeLimits.planRegion?.defaultGroundwaterLimit ??
allPlanData.plan.defaultGroundwaterLimit;

const defaultSurfaceWaterLimit =
regionOverrides?.surfaceWaterLimit ??
activeLimits.planRegion?.defaultSurfaceWaterLimit ??
allPlanData.plan.defaultSurfaceWaterLimit;

Expand Down Expand Up @@ -262,7 +268,7 @@ function unitLimitsToDisplay(
case 'B':
return {
unitLimitView: {
overrideText: 'Refer to Table 4.1 of PNRP',
overrideText: 'Refer to Table 4.1 of NRP',
limit: groundWaterLimit.allocationLimit,
allocated: groundWaterLimit.allocationAmount,
},
Expand Down
68 changes: 39 additions & 29 deletions packages/PlanLimitsUI/src/pages/Limits/Sidebar/LimitsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const footNoteTexts = [
{
number: 1,
id: 'PNRP41',
text: 'Refer to Table 4.1 of PNRP',
text: 'Refer to Table 4.1 of NRP',
href: 'https://www.gw.govt.nz/assets/Documents/2023/07/Natural-Resources-Plan-Appeals-Version.pdf#page=133',
footNoteText: 'Table 4.1 of the Natural Resource Plan',
footNoteText: 'Table 4.1 of the Natural Resources Plan',
},
{
number: 2,
id: 'PRNP121',
text: 'Refer to Policy P121 of PRNP',
id: 'PNRP121',
text: 'Refer to Policy P121 of NRP',
href: 'https://www.gw.govt.nz/assets/Documents/2023/07/Natural-Resources-Plan-Appeals-Version.pdf#page=139',
footNoteText: 'Policy P121 of the Natural Resource Plan',
footNoteText: 'Policy P121 of the Natural Resources Plan',
},
];

Expand All @@ -43,7 +43,7 @@ function FormattedTH(props: {
<th
className={twMerge(
'border p-2 text-left text-sm font-normal bg-gray-100',
className
className,
)}
{...otherProps}
>
Expand Down Expand Up @@ -126,12 +126,12 @@ function AllocatedAmount({ limitView }: { limitView: LimitView }) {

function LimitAmount({ limitView }: { limitView: LimitView }) {
const footNoteItem = footNoteTexts.find(
(item) => item.text === limitView.limitToDisplay
(item) => item.text === limitView.limitToDisplay,
);

if (footNoteItem) {
return (
<span className="text-xs">
<span>
{limitView.limitToDisplay}
<sup>
<a href={`#${footNoteItem.id}`}>{footNoteItem.number}</a>
Expand Down Expand Up @@ -166,10 +166,10 @@ export default function LimitsTable({
return <></>;

const showSurfaceWaterLimits = ['Combined', 'Surface'].includes(
waterTakeFilter
waterTakeFilter,
);
const showGroundWaterLimits = ['Combined', 'Ground'].includes(
waterTakeFilter
waterTakeFilter,
);

const showFootnote = true;
Expand All @@ -187,18 +187,22 @@ export default function LimitsTable({
(gwLimitView) =>
appState.surfaceWaterUnitLimit &&
gwLimitView.depletesFromUnitLimit?.id ===
appState.surfaceWaterUnitLimit?.id
appState.surfaceWaterUnitLimit?.id,
).length + 1;

surfaceAndGroundCatASubUnitRowSpan =
catALimits.filter(
(gwLimitView) =>
appState.surfaceWaterSubUnitLimit &&
gwLimitView.depletesFromSubunitLimit?.id ===
appState.surfaceWaterSubUnitLimit?.id
appState.surfaceWaterSubUnitLimit?.id,
).length + 1;
}

const regionOverrides = council.regionOverrides.find(
(ro) => ro.sourceId === appState.planRegion?.sourceId,
);

return (
<>
<h3 className="text-lg uppercase mb-2 tracking-wider">Allocations</h3>
Expand Down Expand Up @@ -254,7 +258,7 @@ export default function LimitsTable({
index + 1 < surfaceAndGroundCatAUnitRowSpan
}
/>
))
)),
)}
</tbody>
{showGroundWaterLimits &&
Expand Down Expand Up @@ -308,23 +312,29 @@ export default function LimitsTable({
</table>
{showFootnote && council.id === 9 && (
<>
{footNoteTexts.map(
({ number, id, text, href, footNoteText }, index) => (
<div key={number} className={index === 0 ? 'mt-3' : ''}>
<span id={id} className="underline">
<sup>{number}</sup>
</span>
<a
href={href}
className="text-sm flex-1 underline"
target="_blank"
rel="noreferrer"
>
{footNoteText}
</a>
</div>
)
{regionOverrides?.limitsTableFooter && (
<div className="mt-4 text-sm">
{regionOverrides?.limitsTableFooter}
</div>
)}
{!regionOverrides?.limitsTableFooter &&
footNoteTexts.map(
({ number, id, text, href, footNoteText }, index) => (
<div key={number} className={index === 0 ? 'mt-4' : ''}>
<span id={id} className="underline">
<sup>{number}</sup>
</span>
<a
href={href}
className="text-sm flex-1 underline"
target="_blank"
rel="noreferrer"
>
{footNoteText}
</a>
</div>
),
)}
</>
)}
</>
Expand Down
38 changes: 26 additions & 12 deletions packages/PlanLimitsUI/src/pages/Limits/Sidebar/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default function Overview({
appState: AppState;
waterTakeFilter: WaterTakeFilter;
}) {
const regionOverrides = council.regionOverrides.find(
(ro) => ro.sourceId === appState.planRegion?.sourceId,
);

return (
<>
<h3 className="text-lg uppercase mb-2 tracking-wider">Area</h3>
Expand All @@ -51,13 +55,21 @@ export default function Overview({
<>
<LimitsListItem
title={council.labels.surfaceWaterParentLimit}
text={appState.surfaceWaterUnitLimit?.name ?? 'None'}
text={
regionOverrides?.swCMU ??
appState.surfaceWaterUnitLimit?.name ??
'None'
}
/>
{/* <span>ID: {appState.surfaceWaterUnitLimit?.id}</span> */}

<LimitsListItem
title={council.labels.surfaceWaterChildLimit}
text={appState.surfaceWaterSubUnitLimit?.name ?? 'None'}
text={
regionOverrides?.swCMSU ??
appState.surfaceWaterSubUnitLimit?.name ??
'None'
}
/>
{/* <span>ID: {appState.surfaceWaterSubUnitLimit?.id}</span> */}
</>
Expand All @@ -67,21 +79,21 @@ export default function Overview({
<LimitsListItem
title={council.labels.groundwaterLimit}
text={
appState.groundWaterZoneName
? appState.groundWaterZoneName
: 'None'
regionOverrides?.gwCMU ?? appState.groundWaterZoneName ?? 'None'
}
/>
<span>
{/* IDS:{' '}
{appState.groundWaterLimits.map((limit) => limit.id).join(', ')} */}
</span>
{/* <span>
IDS:{' '}
{appState.groundWaterLimits.map((limit) => limit.id).join(', ')}
</span>*/}
</>
)}
<LimitsListItem
title={'Flow Management Site'}
text={
appState.flowLimit
regionOverrides?.flowManagementSite
? regionOverrides?.flowManagementSite
: appState.flowLimit
? appState.flowSite?.name
: appState.planRegion
? appState.planRegion.defaultFlowManagementLimit
Expand All @@ -91,10 +103,12 @@ export default function Overview({
<LimitsListItem
title={'Minimum Flow or Restriction Flow'}
text={
appState.flowLimit
regionOverrides?.flowLimit
? regionOverrides?.flowLimit
: appState.flowLimit
? formatWaterQuantity(
appState.flowLimit.minimumFlow,
council.unitTypes.flow
council.unitTypes.flow,
)
: appState.planRegion
? appState.planRegion.defaultFlowManagementLimit
Expand Down

0 comments on commit f0ab038

Please sign in to comment.