From ecf7da5852246213cb1d85529720b86d72bd6ceb Mon Sep 17 00:00:00 2001 From: Ayumi Tanaka <90415568+ayumi-oxd@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:56:49 -0800 Subject: [PATCH] CMS-49: Remove smoking ban from park access status table (#1541) * CMS-49: Remove smoking ban from park access status table * CMS-526: Remove natureAndCulture from protectedArea * CMS-522: Change park-activity, park-facility, and park-camping-type required * CMS-532: Remove subAreaTypeId from parkOperationSubArea * CMS-532: Remove parkSubAreaId from parkOperationSubArea * CMS-532: Add small fix * CMS-522: Add small fix --- .../page/parkAccessStatus/ParkAccessStatus.js | 1 - .../content-types/park-activity/lifecycles.js | 3 ++ .../content-types/park-activity/schema.json | 3 +- .../park-camping-type/lifecycles.js | 3 ++ .../park-camping-type/schema.json | 3 +- .../content-types/park-facility/lifecycles.js | 3 ++ .../content-types/park-facility/schema.json | 3 +- .../park-operation-sub-area/schema.json | 6 --- .../content-types/protected-area/schema.json | 7 ---- src/cms/src/helpers/validator.js | 38 ++++++++++++++++++- src/gatsby/src/components/park/about.js | 7 +--- src/gatsby/src/templates/park.js | 11 +----- 12 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/admin/src/components/page/parkAccessStatus/ParkAccessStatus.js b/src/admin/src/components/page/parkAccessStatus/ParkAccessStatus.js index fc4279f50..9e4c0f505 100644 --- a/src/admin/src/components/page/parkAccessStatus/ParkAccessStatus.js +++ b/src/admin/src/components/page/parkAccessStatus/ParkAccessStatus.js @@ -115,7 +115,6 @@ export default function ParkAccessStatus() { title: "Campfire Ban", field: "hasCampfireBan", }, - { title: "Smoking Ban", field: "hasSmokingBan" }, { title: "Campfire Ban Effective Date", field: "campfireBanEffectiveDate", diff --git a/src/cms/src/api/park-activity/content-types/park-activity/lifecycles.js b/src/cms/src/api/park-activity/content-types/park-activity/lifecycles.js index c1a665f3d..251b00e07 100644 --- a/src/cms/src/api/park-activity/content-types/park-activity/lifecycles.js +++ b/src/cms/src/api/park-activity/content-types/park-activity/lifecycles.js @@ -1,6 +1,7 @@ "use strict"; const { indexPark } = require("../../../../helpers/taskQueue.js"); +const validator = require("../../../../helpers/validator.js"); /** * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) @@ -36,10 +37,12 @@ module.exports = { async beforeCreate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.activityTypeConnectValidator(data.activityType) }, async beforeUpdate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.activityTypeDisconnectValidator(data.activityType) for (const park of event.params.data?.protectedArea?.disconnect || []) { await indexPark(park.id) } diff --git a/src/cms/src/api/park-activity/content-types/park-activity/schema.json b/src/cms/src/api/park-activity/content-types/park-activity/schema.json index 2198ae2d8..b82cf6775 100644 --- a/src/cms/src/api/park-activity/content-types/park-activity/schema.json +++ b/src/cms/src/api/park-activity/content-types/park-activity/schema.json @@ -49,7 +49,8 @@ "activityType": { "type": "relation", "relation": "oneToOne", - "target": "api::activity-type.activity-type" + "target": "api::activity-type.activity-type", + "required": true }, "modifiedBy": { "type": "string" diff --git a/src/cms/src/api/park-camping-type/content-types/park-camping-type/lifecycles.js b/src/cms/src/api/park-camping-type/content-types/park-camping-type/lifecycles.js index 39a1c8040..68657604d 100644 --- a/src/cms/src/api/park-camping-type/content-types/park-camping-type/lifecycles.js +++ b/src/cms/src/api/park-camping-type/content-types/park-camping-type/lifecycles.js @@ -1,6 +1,7 @@ "use strict"; const { indexPark } = require("../../../../helpers/taskQueue.js"); +const validator = require("../../../../helpers/validator.js"); /** * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) @@ -36,10 +37,12 @@ module.exports = { async beforeCreate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.campingTypeConnectValidator(data.campingType) }, async beforeUpdate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.campingTypeDisconnectValidator(data.campingType) for (const park of event.params.data?.protectedArea?.disconnect || []) { await indexPark(park.id) } diff --git a/src/cms/src/api/park-camping-type/content-types/park-camping-type/schema.json b/src/cms/src/api/park-camping-type/content-types/park-camping-type/schema.json index cfdf63094..eca322989 100644 --- a/src/cms/src/api/park-camping-type/content-types/park-camping-type/schema.json +++ b/src/cms/src/api/park-camping-type/content-types/park-camping-type/schema.json @@ -46,7 +46,8 @@ "campingType": { "type": "relation", "relation": "oneToOne", - "target": "api::camping-type.camping-type" + "target": "api::camping-type.camping-type", + "required": true }, "modifiedBy": { "type": "string" diff --git a/src/cms/src/api/park-facility/content-types/park-facility/lifecycles.js b/src/cms/src/api/park-facility/content-types/park-facility/lifecycles.js index 96ba1f4b3..35fc5cca3 100644 --- a/src/cms/src/api/park-facility/content-types/park-facility/lifecycles.js +++ b/src/cms/src/api/park-facility/content-types/park-facility/lifecycles.js @@ -1,6 +1,7 @@ "use strict"; const { indexPark } = require("../../../../helpers/taskQueue.js"); +const validator = require("../../../../helpers/validator.js"); /** * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) @@ -36,10 +37,12 @@ module.exports = { async beforeCreate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.facilityTypeConnectValidator(data.facilityType) }, async beforeUpdate(event) { let { data, where } = event.params; data = await updateName(data, where); + validator.facilityTypeDisconnectValidator(data.facilityType) for (const park of event.params.data?.protectedArea?.disconnect || []) { await indexPark(park.id) } diff --git a/src/cms/src/api/park-facility/content-types/park-facility/schema.json b/src/cms/src/api/park-facility/content-types/park-facility/schema.json index 05c7354b6..7baa665ea 100644 --- a/src/cms/src/api/park-facility/content-types/park-facility/schema.json +++ b/src/cms/src/api/park-facility/content-types/park-facility/schema.json @@ -49,7 +49,8 @@ "facilityType": { "type": "relation", "relation": "oneToOne", - "target": "api::facility-type.facility-type" + "target": "api::facility-type.facility-type", + "required": true }, "modifiedBy": { "type": "string" diff --git a/src/cms/src/api/park-operation-sub-area/content-types/park-operation-sub-area/schema.json b/src/cms/src/api/park-operation-sub-area/content-types/park-operation-sub-area/schema.json index 5235e6e11..9b5498e65 100644 --- a/src/cms/src/api/park-operation-sub-area/content-types/park-operation-sub-area/schema.json +++ b/src/cms/src/api/park-operation-sub-area/content-types/park-operation-sub-area/schema.json @@ -12,12 +12,6 @@ "draftAndPublish": true }, "attributes": { - "parkSubAreaId": { - "type": "integer" - }, - "parkSubAreaTypeId": { - "type": "integer" - }, "parkSubArea": { "type": "string" }, diff --git a/src/cms/src/api/protected-area/content-types/protected-area/schema.json b/src/cms/src/api/protected-area/content-types/protected-area/schema.json index 124c85741..b341d3a62 100644 --- a/src/cms/src/api/protected-area/content-types/protected-area/schema.json +++ b/src/cms/src/api/protected-area/content-types/protected-area/schema.json @@ -197,13 +197,6 @@ }, "customField": "plugin::ckeditor5.CKEditor" }, - "natureAndCulture": { - "type": "customField", - "options": { - "preset": "toolbar" - }, - "customField": "plugin::ckeditor5.CKEditor" - }, "partnerships": { "type": "customField", "options": { diff --git a/src/cms/src/helpers/validator.js b/src/cms/src/helpers/validator.js index df872c327..3565383f6 100644 --- a/src/cms/src/helpers/validator.js +++ b/src/cms/src/helpers/validator.js @@ -14,6 +14,42 @@ module.exports = { throw new ApplicationError('Please add protectedArea relation.'); } }, + // saving without an activityType relation is not allowed + activityTypeConnectValidator: function (activityType) { + if (activityType?.connect?.length === 0) { + throw new ApplicationError('Please add activityType relation.'); + } + }, + // removing an activityType relation is not allowed + activityTypeDisconnectValidator: function (activityType) { + if (activityType?.disconnect?.length > 0 && activityType?.connect?.length === 0) { + throw new ApplicationError('Please add activityType relation.'); + } + }, + // saving without a facilityType relation is not allowed + facilityTypeConnectValidator: function (facilityType) { + if (facilityType?.connect?.length === 0) { + throw new ApplicationError('Please add facilityType relation.'); + } + }, + // removing a facilityType relation is not allowed + facilityTypeDisconnectValidator: function (facilityType) { + if (facilityType?.disconnect?.length > 0 && facilityType?.connect?.length === 0) { + throw new ApplicationError('Please add facilityType relation.'); + } + }, + // saving without a campingType relation is not allowed + campingTypeConnectValidator: function (campingType) { + if (campingType?.connect?.length === 0) { + throw new ApplicationError('Please add campingType relation.'); + } + }, + // removing a campingType relation is not allowed + campingTypeDisconnectValidator: function (campingType) { + if (campingType?.disconnect?.length > 0 && campingType?.connect?.length === 0) { + throw new ApplicationError('Please add campingType relation.'); + } + }, // saving without a documentType relation is not allowed documentTypeConnectValidator: function (documentType) { if (documentType?.connect?.length === 0) { @@ -85,4 +121,4 @@ module.exports = { throw new ApplicationError('Do not add slash in slugs.'); } }, -} \ No newline at end of file +} diff --git a/src/gatsby/src/components/park/about.js b/src/gatsby/src/components/park/about.js index eb1fe17bc..c63e140fe 100644 --- a/src/gatsby/src/components/park/about.js +++ b/src/gatsby/src/components/park/about.js @@ -44,7 +44,7 @@ export const AccordionList = ({ eventKey, data, openAccordions, toggleAccordion } export default function About({ - parkType, natureAndCulture, conservation, culturalHeritage, history, wildlife, biogeoclimaticZones, terrestrialEcosections, marineEcosections + parkType, conservation, culturalHeritage, history, wildlife, biogeoclimaticZones, terrestrialEcosections, marineEcosections }) { const dataList = [ { "title": "Cultural heritage", "code": "cultural-heritage", "description": culturalHeritage }, @@ -164,8 +164,7 @@ export default function About({
)} - {/* display conservation/culturalHeritage/history/wildlife accordion, otherwise display natureAndCulture */} - {dataList.length > 0 ? ( + {dataList.length > 0 && ( // if parkType is ecological reserve, display conservation description without accordion parkType === "ecological reserve" ? (