From a71a8b3ccb3dee30710ace6ccf2d55fbb267a19e Mon Sep 17 00:00:00 2001 From: Ryan Koch <6863534+ryguyk@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:00:56 -0600 Subject: [PATCH] Vacms 15949 cleanup (#243) Co-authored-by: Tanner Heffner --- src/data/queries/alert.ts | 4 +- src/data/queries/audienceTopics.ts | 4 +- src/data/queries/banners.ts | 10 +- src/data/queries/benefitsHub.ts | 4 +- src/data/queries/button.ts | 4 +- src/data/queries/emailContact.ts | 9 +- src/data/queries/expandableText.ts | 4 +- src/data/queries/headerFooter.ts | 2 +- src/data/queries/linkTeaser.ts | 4 +- src/data/queries/mediaImage.ts | 18 +- src/data/queries/newsStory.ts | 4 +- src/data/queries/newsStoryTeaser.ts | 4 +- src/data/queries/personProfile.ts | 9 +- src/data/queries/promoBlock.ts | 2 +- src/data/queries/questionAnswer.ts | 4 +- src/data/queries/staticPathResources.ts | 14 +- src/data/queries/storyListing.ts | 4 +- .../tests/__snapshots__/banners.test.tsx.snap | 2 +- src/data/queries/tests/mediaImage.test.tsx | 4 +- src/data/queries/utils.ts | 6 +- src/data/queries/wysiwyg.ts | 4 +- src/lib/constants/resourceTypes.ts | 3 +- src/lib/drupal/facilitySideNav.ts | 6 +- src/lib/drupal/listingPages.ts | 31 +- src/lib/drupal/lovell/staticPaths.ts | 26 +- src/lib/drupal/lovell/staticProps.ts | 6 +- src/lib/drupal/lovell/tests/mockData.ts | 42 +-- .../drupal/lovell/tests/staticPaths.test.ts | 18 +- src/lib/drupal/lovell/tests/utils.test.ts | 34 +- src/lib/drupal/lovell/utils.ts | 22 +- src/lib/drupal/staticPaths.ts | 24 +- src/lib/drupal/staticProps.ts | 10 +- src/lib/utils/header.test.ts | 2 +- src/lib/utils/header.ts | 2 +- src/lib/utils/headerFooter.test.ts | 2 +- src/lib/utils/headerFooter.ts | 5 +- src/lib/utils/slug.test.ts | 28 +- src/lib/utils/slug.ts | 4 + src/pages/[[...slug]].tsx | 4 +- .../common/benefitsHubLinks/index.test.tsx | 4 +- .../common/benefitsHubLinks/index.tsx | 9 +- src/templates/common/button/index.test.tsx | 4 +- src/templates/common/button/index.tsx | 4 +- src/templates/common/contentFooter/index.tsx | 7 +- .../common/mediaImage/index.test.tsx | 16 +- src/templates/common/mediaImage/index.tsx | 5 +- src/templates/components/alert/index.test.tsx | 4 +- src/templates/components/alert/index.tsx | 4 +- .../components/audienceTopics/index.test.tsx | 10 +- .../components/audienceTopics/index.tsx | 4 +- .../components/emailContact/index.test.tsx | 4 +- .../components/emailContact/index.tsx | 4 +- .../components/expandableText/index.tsx | 4 +- .../components/linkTeaser/index.test.tsx | 8 +- src/templates/components/linkTeaser/index.tsx | 4 +- .../components/lovellSwitcher/index.tsx | 9 +- .../components/newsStoryTeaser/index.test.tsx | 16 +- .../components/newsStoryTeaser/index.tsx | 4 +- .../newsStoryTeaser.stories.tsx | 16 +- .../components/personProfile/index.test.tsx | 25 +- .../components/personProfile/index.tsx | 4 +- .../personProfile/personProfile.stories.tsx | 23 +- .../components/storyListingLink/index.tsx | 4 +- .../components/wysiwyg/index.test.tsx | 4 +- src/templates/components/wysiwyg/index.tsx | 7 +- .../globals/banners/banner/index.tsx | 4 +- .../banners/facilityBanner/index.test.tsx | 11 +- .../globals/banners/facilityBanner/index.tsx | 18 +- .../globals/banners/promoBanner/index.tsx | 4 +- src/templates/globals/wrapper/index.tsx | 15 +- .../layouts/newsStory/index.test.tsx | 16 +- src/templates/layouts/newsStory/index.tsx | 6 +- .../layouts/newsStory/newsStory.stories.tsx | 16 +- .../layouts/questionAnswer/index.test.tsx | 4 +- .../layouts/questionAnswer/index.tsx | 4 +- .../layouts/staffProfile/dataService.tsx | 10 +- src/templates/layouts/staffProfile/index.tsx | 4 +- .../staffProfile/staffProfile.test.tsx | 27 +- .../layouts/storyListing/index.test.tsx | 4 +- src/templates/layouts/storyListing/index.tsx | 12 +- src/types/dataTypes/drupal/block.ts | 4 +- src/types/dataTypes/drupal/media.ts | 4 +- src/types/dataTypes/drupal/node.ts | 10 +- src/types/dataTypes/drupal/paragraph.ts | 4 +- .../dataTypes/formatted/administration.ts | 4 + src/types/dataTypes/formatted/alert.ts | 9 + .../dataTypes/formatted/audienceTopics.ts | 16 + src/types/dataTypes/formatted/banners.ts | 37 ++ src/types/dataTypes/formatted/benefitsHub.ts | 12 + src/types/dataTypes/formatted/button.ts | 5 + src/types/dataTypes/formatted/emailContact.ts | 5 + .../dataTypes/formatted/expandableText.ts | 5 + src/types/dataTypes/formatted/headerFooter.ts | 49 +++ src/types/dataTypes/formatted/html.ts | 3 + src/types/dataTypes/formatted/linkTeaser.ts | 13 + src/types/dataTypes/formatted/media.ts | 24 ++ src/types/dataTypes/formatted/newsStory.ts | 31 ++ .../dataTypes/formatted/personProfile.ts | 28 ++ .../dataTypes/formatted/publishedEntity.ts | 5 + .../dataTypes/formatted/questionAnswer.ts | 15 + src/types/dataTypes/formatted/sideNav.ts | 20 ++ src/types/dataTypes/formatted/staffProfile.ts | 12 + .../dataTypes/formatted/staticPathResource.ts | 6 + src/types/dataTypes/formatted/storyListing.ts | 21 ++ src/types/dataTypes/formatted/wysiwyg.ts | 5 + src/types/index.d.ts | 333 ------------------ 106 files changed, 742 insertions(+), 689 deletions(-) create mode 100644 src/types/dataTypes/formatted/administration.ts create mode 100644 src/types/dataTypes/formatted/alert.ts create mode 100644 src/types/dataTypes/formatted/audienceTopics.ts create mode 100644 src/types/dataTypes/formatted/banners.ts create mode 100644 src/types/dataTypes/formatted/benefitsHub.ts create mode 100644 src/types/dataTypes/formatted/button.ts create mode 100644 src/types/dataTypes/formatted/emailContact.ts create mode 100644 src/types/dataTypes/formatted/expandableText.ts create mode 100644 src/types/dataTypes/formatted/headerFooter.ts create mode 100644 src/types/dataTypes/formatted/html.ts create mode 100644 src/types/dataTypes/formatted/linkTeaser.ts create mode 100644 src/types/dataTypes/formatted/media.ts create mode 100644 src/types/dataTypes/formatted/newsStory.ts create mode 100644 src/types/dataTypes/formatted/personProfile.ts create mode 100644 src/types/dataTypes/formatted/publishedEntity.ts create mode 100644 src/types/dataTypes/formatted/questionAnswer.ts create mode 100644 src/types/dataTypes/formatted/sideNav.ts create mode 100644 src/types/dataTypes/formatted/staffProfile.ts create mode 100644 src/types/dataTypes/formatted/staticPathResource.ts create mode 100644 src/types/dataTypes/formatted/storyListing.ts create mode 100644 src/types/dataTypes/formatted/wysiwyg.ts delete mode 100644 src/types/index.d.ts diff --git a/src/data/queries/alert.ts b/src/data/queries/alert.ts index b793d5a63..f2059f2c6 100644 --- a/src/data/queries/alert.ts +++ b/src/data/queries/alert.ts @@ -1,9 +1,9 @@ // Define the query params for fetching block--alert. import { BlockAlert } from '@/types/dataTypes/drupal/block' import { QueryFormatter } from 'next-drupal-query' -import { AlertType } from '@/types/index' +import { Alert } from '@/types/dataTypes/formatted/alert' -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: BlockAlert ) => { return { diff --git a/src/data/queries/audienceTopics.ts b/src/data/queries/audienceTopics.ts index d0dae2b74..be9fbf455 100644 --- a/src/data/queries/audienceTopics.ts +++ b/src/data/queries/audienceTopics.ts @@ -1,7 +1,7 @@ // Define the query params for fetching node--news_story. import { ParagraphAudienceTopics } from '@/types/dataTypes/drupal/paragraph' import { QueryFormatter } from 'next-drupal-query' -import { AudienceTopicType } from '@/types/index' +import { AudienceTopic } from '@/types/dataTypes/formatted/audienceTopics' const getTagsList = (fieldTags) => { if (!fieldTags) return null @@ -39,7 +39,7 @@ const getTagsList = (fieldTags) => { */ export const formatter: QueryFormatter< ParagraphAudienceTopics, - AudienceTopicType[] + AudienceTopic[] > = (entity: ParagraphAudienceTopics) => { return getTagsList(entity) } diff --git a/src/data/queries/banners.ts b/src/data/queries/banners.ts index 8448a575d..7a1a9a6ca 100644 --- a/src/data/queries/banners.ts +++ b/src/data/queries/banners.ts @@ -1,6 +1,10 @@ import { QueryFormatter } from 'next-drupal-query' import { NodeBanner } from '@/types/dataTypes/drupal/node' -import { BannerType, FacilityBannerType, PromoBannerType } from '@/types/index' +import { + Banner, + FacilityBanner, + PromoBanner, +} from '@/types/dataTypes/formatted/banners' export const BannerDisplayType = { PROMO_BANNER: 'promoBanner', @@ -16,7 +20,7 @@ export const BannerTypeMapping = { export const formatter: QueryFormatter< NodeBanner[], - Array + Array > = (entities: NodeBanner[]) => { return entities?.map((banner) => { switch (banner?.type as string) { @@ -50,7 +54,7 @@ export const formatter: QueryFormatter< operatingStatus: banner.field_alert_operating_status_cta, inheritanceSubpages: banner.field_alert_inheritance_subpages, path: banner.path?.alias, - bannerAlertVacms: banner.field_banner_alert_vamcs, + bannerAlertVamcs: banner.field_banner_alert_vamcs, type: banner.type, } default: diff --git a/src/data/queries/benefitsHub.ts b/src/data/queries/benefitsHub.ts index d331351de..c35211e41 100644 --- a/src/data/queries/benefitsHub.ts +++ b/src/data/queries/benefitsHub.ts @@ -1,10 +1,10 @@ import { QueryFormatter } from 'next-drupal-query' import { NodeLandingPage } from '@/types/dataTypes/drupal/node' -import { BenefitsHubType } from '@/types/index' +import { BenefitsHub } from '@/types/dataTypes/formatted/benefitsHub' // Define the query params for fetching node--landing_page. // This is a "special" case in that these nodes are primarily (only?) used as entity references from other nodes -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: NodeLandingPage ) => { return { diff --git a/src/data/queries/button.ts b/src/data/queries/button.ts index 934f2ef4a..976a2be90 100644 --- a/src/data/queries/button.ts +++ b/src/data/queries/button.ts @@ -1,9 +1,9 @@ // Define the query params for fetching paragraph--button. import { ParagraphButton } from '@/types/dataTypes/drupal/paragraph' import { QueryFormatter } from 'next-drupal-query' -import { ButtonType } from '@/types/index' +import { Button } from '@/types/dataTypes/formatted/button' -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: ParagraphButton ) => { return { diff --git a/src/data/queries/emailContact.ts b/src/data/queries/emailContact.ts index 6ef874fc1..e91294709 100644 --- a/src/data/queries/emailContact.ts +++ b/src/data/queries/emailContact.ts @@ -1,12 +1,11 @@ // Define the query params for fetching paragraph--email_contact. import { ParagraphEmailContact } from '@/types/dataTypes/drupal/paragraph' import { QueryFormatter } from 'next-drupal-query' -import { EmailContactType } from '@/types/index' +import { EmailContact } from '@/types/dataTypes/formatted/emailContact' -export const formatter: QueryFormatter< - ParagraphEmailContact, - EmailContactType -> = (entity: ParagraphEmailContact) => { +export const formatter: QueryFormatter = ( + entity: ParagraphEmailContact +) => { return { id: entity.id, label: entity.field_email_label || null, diff --git a/src/data/queries/expandableText.ts b/src/data/queries/expandableText.ts index 2d3839204..bbc1d5f3e 100644 --- a/src/data/queries/expandableText.ts +++ b/src/data/queries/expandableText.ts @@ -8,7 +8,7 @@ import { } from 'next-drupal-query' import { queries } from '@/data/queries/index' import { drupalClient } from '@/lib/drupal/drupalClient' -import { ExpandableTextType } from '@/types/index' +import { ExpandableText } from '@/types/dataTypes/formatted/expandableText' export const params: QueryParams = () => { return queries.getParams().addPageLimit(10) @@ -32,7 +32,7 @@ export const data: QueryData = async ( export const formatter: QueryFormatter< ParagraphExpandableText[], - ExpandableTextType[] + ExpandableText[] > = (entities: ParagraphExpandableText[]) => { return entities.map((entity) => ({ id: entity.id, diff --git a/src/data/queries/headerFooter.ts b/src/data/queries/headerFooter.ts index 22bfa640b..359ed1c3a 100644 --- a/src/data/queries/headerFooter.ts +++ b/src/data/queries/headerFooter.ts @@ -2,7 +2,7 @@ import { QueryData, QueryFormatter, QueryParams } from 'next-drupal-query' import { queries } from '.' import { drupalClient } from '@/lib/drupal/drupalClient' import { Menu, HeaderMegaMenu } from '@/types/dataTypes/drupal/menu' -import { HeaderFooterData } from '@/types/index' +import { HeaderFooterData } from '@/types/dataTypes/formatted/headerFooter' import { buildHeaderFooterData } from '@/lib/utils/headerFooter' export type RawHeaderFooterData = { diff --git a/src/data/queries/linkTeaser.ts b/src/data/queries/linkTeaser.ts index a4e698b21..3fe8229d4 100644 --- a/src/data/queries/linkTeaser.ts +++ b/src/data/queries/linkTeaser.ts @@ -7,7 +7,7 @@ import { import { queries } from '.' import { ParagraphLinkTeaser } from '@/types/dataTypes/drupal/paragraph' import { drupalClient } from '@/lib/drupal/drupalClient' -import { LinkTeaserType } from '@/types/index' +import { LinkTeaser } from '@/types/dataTypes/formatted/linkTeaser' // Define the query params for fetching node--news_story. export const params: QueryParams = () => { @@ -30,7 +30,7 @@ export const data: QueryData = async ( return entities } -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: ParagraphLinkTeaser ) => { return { diff --git a/src/data/queries/mediaImage.ts b/src/data/queries/mediaImage.ts index ea9c844bc..63cbaeef0 100644 --- a/src/data/queries/mediaImage.ts +++ b/src/data/queries/mediaImage.ts @@ -5,12 +5,12 @@ import { QueryParams, } from 'next-drupal-query' import { queries } from '.' -import { MediaImage } from '@/types/dataTypes/drupal/media' +import { DrupalMediaImage } from '@/types/dataTypes/drupal/media' import { drupalClient } from '@/lib/drupal/drupalClient' -import { MediaImageType } from '@/types/index' +import { MediaImage } from '@/types/dataTypes/formatted/media' -type MediaImageData = { - entity: MediaImage +type DrupalMediaImageData = { + entity: DrupalMediaImage cropType?: string } @@ -25,10 +25,10 @@ type DataOpts = QueryOpts<{ }> // Implement the data loader. -export const data: QueryData = async ( +export const data: QueryData = async ( opts -): Promise => { - const entity = await drupalClient.getResource( +): Promise => { + const entity = await drupalClient.getResource( 'media--image', opts.id, { @@ -39,12 +39,14 @@ export const data: QueryData = async ( return { entity, cropType: opts.cropType || '2_1_large' } } -export const formatter: QueryFormatter = ({ +export const formatter: QueryFormatter = ({ entity, cropType = '2_1_large', }) => { if (!entity) return null // TODO: may need more handling here around crop type + image height / width. TBD. + // TODO: `link` has reference to all image styles whereas `url` narrows down based on + // cropType. Which do we want at this layer? return { id: entity.image.id, type: entity.type, diff --git a/src/data/queries/newsStory.ts b/src/data/queries/newsStory.ts index ba32b72c2..aabdfa40f 100644 --- a/src/data/queries/newsStory.ts +++ b/src/data/queries/newsStory.ts @@ -7,7 +7,7 @@ import { import { drupalClient } from '@/lib/drupal/drupalClient' import { queries } from '.' import { NodeNewsStory } from '@/types/dataTypes/drupal/node' -import { NewsStoryType } from '@/types/index' +import { NewsStory } from '@/types/dataTypes/formatted/newsStory' import { GetServerSidePropsContext } from 'next' // Define the query params for fetching node--news_story. @@ -54,7 +54,7 @@ export const data: QueryData = async ( return entity } -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: NodeNewsStory ) => { return { diff --git a/src/data/queries/newsStoryTeaser.ts b/src/data/queries/newsStoryTeaser.ts index d071a1c23..ac87c4d92 100644 --- a/src/data/queries/newsStoryTeaser.ts +++ b/src/data/queries/newsStoryTeaser.ts @@ -1,7 +1,7 @@ import { QueryFormatter, QueryParams } from 'next-drupal-query' import { queries } from '.' import { NodeNewsStory } from '@/types/dataTypes/drupal/node' -import { NewsStoryTeaserType } from '@/types/index' +import { NewsStoryTeaser } from '@/types/dataTypes/formatted/newsStory' // Define the query params for fetching node--news_story. export const params: QueryParams = () => { @@ -10,7 +10,7 @@ export const params: QueryParams = () => { .addInclude(['field_media', 'field_media.image', 'field_listing']) } -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: NodeNewsStory ) => { return { diff --git a/src/data/queries/personProfile.ts b/src/data/queries/personProfile.ts index e301950b7..9c795f203 100644 --- a/src/data/queries/personProfile.ts +++ b/src/data/queries/personProfile.ts @@ -7,7 +7,7 @@ import { import { queries } from '.' import { NodePersonProfile } from '@/types/dataTypes/drupal/node' import { drupalClient } from '@/lib/drupal/drupalClient' -import { PersonProfileType } from '@/types/index' +import { PersonProfile } from '@/types/dataTypes/formatted/personProfile' // Define the query params for fetching node--news_story. export const params: QueryParams = () => { @@ -35,10 +35,9 @@ export const data: QueryData = async (): Promise< return entities } -export const formatter: QueryFormatter< - NodePersonProfile, - PersonProfileType[] -> = (entities: NodePersonProfile) => { +export const formatter: QueryFormatter = ( + entities: NodePersonProfile +) => { if (!entities) return null return entities.map((entity) => ({ diff --git a/src/data/queries/promoBlock.ts b/src/data/queries/promoBlock.ts index d6ba49ca6..92f23b5af 100644 --- a/src/data/queries/promoBlock.ts +++ b/src/data/queries/promoBlock.ts @@ -7,7 +7,7 @@ import { import { queries } from '.' import { drupalClient } from '@/lib/drupal/drupalClient' import { BlockPromo } from '@/types/dataTypes/drupal/block' -import { MegaMenuPromoColumn } from '@/types/index' +import { MegaMenuPromoColumn } from '@/types/dataTypes/formatted/headerFooter' // Define the query params for fetching block_content--promo. export const params: QueryParams = () => { diff --git a/src/data/queries/questionAnswer.ts b/src/data/queries/questionAnswer.ts index 91999f94a..f7e7f8573 100644 --- a/src/data/queries/questionAnswer.ts +++ b/src/data/queries/questionAnswer.ts @@ -7,7 +7,7 @@ import { import { drupalClient } from '@/lib/drupal/drupalClient' import { queries } from '.' import { NodeQA } from '@/types/dataTypes/drupal/node' -import { QuestionAnswerType } from '@/types/index' +import { QuestionAnswer } from '@/types/dataTypes/formatted/questionAnswer' // Define the query params for fetching node--q_a. export const params: QueryParams = () => { @@ -43,7 +43,7 @@ export const data: QueryData = async ( return entity } -export const formatter: QueryFormatter = ( +export const formatter: QueryFormatter = ( entity: NodeQA ) => { const buttons = entity.field_buttons?.map((button) => { diff --git a/src/data/queries/staticPathResources.ts b/src/data/queries/staticPathResources.ts index 6777766ee..9dbcf26b7 100644 --- a/src/data/queries/staticPathResources.ts +++ b/src/data/queries/staticPathResources.ts @@ -7,9 +7,9 @@ import { import { JsonApiResourceWithPath } from 'next-drupal' import { ADDITIONAL_RESOURCE_TYPES, - ResourceTypeType, + ResourceType, } from '@/lib/constants/resourceTypes' -import { StaticPathResourceType } from '@/types/index' +import { StaticPathResource } from '@/types/dataTypes/formatted/staticPathResource' import { FieldAdministration } from '@/types/dataTypes/drupal/field_type' import { PAGE_SIZES } from '@/lib/constants/pageSizes' import { queries } from '.' @@ -18,8 +18,8 @@ import { fetchAndConcatAllResourceCollectionPages } from './utils' const PAGE_SIZE = PAGE_SIZES[ADDITIONAL_RESOURCE_TYPES.STATIC_PATHS] // Define the query params for fetching static paths. -export const params: QueryParams = ( - resourceType: ResourceTypeType +export const params: QueryParams = ( + resourceType: ResourceType ) => { return ( queries @@ -35,7 +35,7 @@ export const params: QueryParams = ( // Define the option types for the data loader. type DataOpts = QueryOpts<{ - resourceType: ResourceTypeType + resourceType: ResourceType }> type JsonApiResourceWithPathAndFieldAdmin = JsonApiResourceWithPath & { @@ -58,10 +58,10 @@ export const data: QueryData< export const formatter: QueryFormatter< JsonApiResourceWithPathAndFieldAdmin[], - StaticPathResourceType[] + StaticPathResource[] > = (resources: JsonApiResourceWithPathAndFieldAdmin[]) => { return resources.map((resource) => ({ - path: resource.path, + path: resource.path.alias, administration: { id: resource.field_administration?.drupal_internal__tid || null, name: resource.field_administration?.name || null, diff --git a/src/data/queries/storyListing.ts b/src/data/queries/storyListing.ts index 4802cdf5b..f44a8d568 100644 --- a/src/data/queries/storyListing.ts +++ b/src/data/queries/storyListing.ts @@ -3,7 +3,7 @@ import { drupalClient } from '@/lib/drupal/drupalClient' import { queries } from '.' import { NodeStoryListing, NodeNewsStory } from '@/types/dataTypes/drupal/node' import { Menu } from '@/types/dataTypes/drupal/menu' -import { StoryListingType } from '@/types/index' +import { StoryListing } from '@/types/dataTypes/formatted/storyListing' import { DrupalJsonApiParams } from 'drupal-jsonapi-params' import { buildSideNavDataFromMenu } from '@/lib/drupal/facilitySideNav' import { ListingPageDataOpts } from '@/lib/drupal/listingPages' @@ -102,7 +102,7 @@ export const data: QueryData = async ( } } -export const formatter: QueryFormatter = ({ +export const formatter: QueryFormatter = ({ entity, stories, menu, diff --git a/src/data/queries/tests/__snapshots__/banners.test.tsx.snap b/src/data/queries/tests/__snapshots__/banners.test.tsx.snap index f3677589a..964aeaa8e 100644 --- a/src/data/queries/tests/__snapshots__/banners.test.tsx.snap +++ b/src/data/queries/tests/__snapshots__/banners.test.tsx.snap @@ -29,7 +29,7 @@ exports[`Banners return formatted data outputs formatted data 1`] = ` }, { "alertType": "information", - "bannerAlertVacms": [ + "bannerAlertVamcs": [ { "id": "8822bbdd-f5f8-4700-8abb-5566431bd705", "resourceIdObjMeta": { diff --git a/src/data/queries/tests/mediaImage.test.tsx b/src/data/queries/tests/mediaImage.test.tsx index 0ed807c7b..cd1f37078 100644 --- a/src/data/queries/tests/mediaImage.test.tsx +++ b/src/data/queries/tests/mediaImage.test.tsx @@ -1,9 +1,9 @@ -import { MediaImage } from '@/types/dataTypes/drupal/media' +import { DrupalMediaImage } from '@/types/dataTypes/drupal/media' import { queries } from '@/data/queries/' import mockData from '@/mocks/mediaImage.mock.json' //eslint-disable-next-line -const mediaImageMock: MediaImage | any = mockData +const mediaImageMock: DrupalMediaImage | any = mockData describe('Media image returns formatted data', () => { let windowSpy diff --git a/src/data/queries/utils.ts b/src/data/queries/utils.ts index d91456398..7f1fa9a39 100644 --- a/src/data/queries/utils.ts +++ b/src/data/queries/utils.ts @@ -1,6 +1,6 @@ import { DrupalJsonApiParams } from 'drupal-jsonapi-params' import { JsonApiResponse } from 'next-drupal' -import { ResourceTypeType } from '@/lib/constants/resourceTypes' +import { ResourceType } from '@/lib/constants/resourceTypes' import { drupalClient } from '@/lib/drupal/drupalClient' type ResourceCollection = { @@ -21,7 +21,7 @@ function addPagingParams( } export async function fetchSingleResourceCollectionPage( - resourceType: ResourceTypeType, + resourceType: ResourceType, params: DrupalJsonApiParams, pageSize: number, pageNumber: number @@ -46,7 +46,7 @@ export async function fetchSingleResourceCollectionPage( } export async function fetchAndConcatAllResourceCollectionPages( - resourceType: ResourceTypeType, + resourceType: ResourceType, params: DrupalJsonApiParams, pageSize: number ): Promise> { diff --git a/src/data/queries/wysiwyg.ts b/src/data/queries/wysiwyg.ts index 0c5140d61..ff4686577 100644 --- a/src/data/queries/wysiwyg.ts +++ b/src/data/queries/wysiwyg.ts @@ -3,13 +3,13 @@ import { ParagraphRichTextCharLimit1000, } from '@/types/dataTypes/drupal/paragraph' import { QueryFormatter } from 'next-drupal-query' -import { WysiwygType } from '@/types/index' +import { Wysiwyg } from '@/types/dataTypes/formatted/wysiwyg' import { drupalToVaPath, phoneLinks } from '@/lib/utils/helpers' // Define the formatter for returning paragraph--wysiwyg & paragraph--rich_text_char_limit_1000 data. export const formatter: QueryFormatter< ParagraphWysiwyg | ParagraphRichTextCharLimit1000, - WysiwygType + Wysiwyg > = (entity: ParagraphWysiwyg | ParagraphRichTextCharLimit1000) => { const data = [entity.field_wysiwyg?.processed] const filters = [phoneLinks, drupalToVaPath] diff --git a/src/lib/constants/resourceTypes.ts b/src/lib/constants/resourceTypes.ts index 5e0dd2226..4bcbc5147 100644 --- a/src/lib/constants/resourceTypes.ts +++ b/src/lib/constants/resourceTypes.ts @@ -4,8 +4,7 @@ export const RESOURCE_TYPES = { QA: 'node--q_a', } as const -export type ResourceTypeType = - (typeof RESOURCE_TYPES)[keyof typeof RESOURCE_TYPES] +export type ResourceType = (typeof RESOURCE_TYPES)[keyof typeof RESOURCE_TYPES] export const ADDITIONAL_RESOURCE_TYPES = { STATIC_PATHS: 'static-path-resources', diff --git a/src/lib/drupal/facilitySideNav.ts b/src/lib/drupal/facilitySideNav.ts index 7720d1e7e..27a4777df 100644 --- a/src/lib/drupal/facilitySideNav.ts +++ b/src/lib/drupal/facilitySideNav.ts @@ -1,5 +1,9 @@ import { Menu, MenuItem } from '@/types/dataTypes/drupal/menu' -import { SideNavData, SideNavItem, SideNavMenu } from '@/types/index' +import { + SideNavData, + SideNavItem, + SideNavMenu, +} from '@/types/dataTypes/formatted/sideNav' // Recursively fit menu items into sidenav-requested shape const normalizeMenuItem = (item: MenuItem): SideNavItem => { diff --git a/src/lib/drupal/listingPages.ts b/src/lib/drupal/listingPages.ts index 38ceb123c..c33a3d672 100644 --- a/src/lib/drupal/listingPages.ts +++ b/src/lib/drupal/listingPages.ts @@ -1,7 +1,7 @@ import { drupalClient } from '@/lib/drupal/drupalClient' import { QUERIES_MAP, queries } from '@/data/queries' -import { RESOURCE_TYPES, ResourceTypeType } from '@/lib/constants/resourceTypes' -import { StaticPathResourceType } from '@/types/index' +import { RESOURCE_TYPES, ResourceType } from '@/lib/constants/resourceTypes' +import { StaticPathResource } from '@/types/dataTypes/formatted/staticPathResource' import { GetServerSidePropsContext, GetStaticPropsContext } from 'next' import { QueryOpts } from 'next-drupal-query' import { LovellStaticPropsContextProps } from '@/lib/drupal/lovell/types' @@ -12,9 +12,9 @@ import { PAGE_SIZES } from '@/lib/constants/pageSizes' const LISTING_RESOURCE_TYPES = [RESOURCE_TYPES.STORY_LISTING] as const -export type ListingResourceTypeType = (typeof LISTING_RESOURCE_TYPES)[number] +export type ListingResourceType = (typeof LISTING_RESOURCE_TYPES)[number] -export type StaticPathResourceTypeWithPaging = StaticPathResourceType & { +export type StaticPathResourceTypeWithPaging = StaticPathResource & { paging: { totalPages: number } @@ -56,15 +56,15 @@ export const LISTING_RESOURCE_TYPE_URL_SEGMENTS: Readonly<{ [RESOURCE_TYPES.STORY_LISTING]: 'stories', } -export function isListingResourceType(resourceType: ResourceTypeType): boolean { +export function isListingResourceType(resourceType: ResourceType): boolean { return (LISTING_RESOURCE_TYPES as readonly string[]).includes(resourceType) } export async function getListingPageCounts( - listingPageStaticPathResource: StaticPathResourceType, - listingResourceType: ListingResourceTypeType + listingPageStaticPathResource: StaticPathResource, + listingResourceType: ListingResourceType ): Promise { - const resourcePath = listingPageStaticPathResource.path.alias + const resourcePath = listingPageStaticPathResource.path const pathInfo = await drupalClient.translatePath(resourcePath) if (pathInfo?.entity?.uuid) { const resource = await queries.getData(listingResourceType, { @@ -85,8 +85,8 @@ export async function getListingPageCounts( } async function getListingPageStaticPathResourcesWithPagingData( - listingPageStaticPathResources: StaticPathResourceType[], - listingResourceType: ListingResourceTypeType + listingPageStaticPathResources: StaticPathResource[], + listingResourceType: ListingResourceType ): Promise { if (!listingPageStaticPathResources?.length) { return [] @@ -135,7 +135,7 @@ async function getListingPageStaticPathResourcesWithPagingData( function addStaticPathResourcesFromPagingData( listingPageStaticPathResourcesWithPagingData: StaticPathResourceTypeWithPaging[] -): StaticPathResourceType[] { +): StaticPathResource[] { return listingPageStaticPathResourcesWithPagingData.reduce( (acc, firstPageResource) => { // Determine if there are additional pages @@ -146,10 +146,7 @@ function addStaticPathResourcesFromPagingData( length: firstPageResource.paging.totalPages - 1, }).map((_, i) => ({ ...firstPageResource, - path: { - ...firstPageResource.path, - alias: `${firstPageResource.path.alias}/page-${i + 2}`, - }, + path: `${firstPageResource.path}/page-${i + 2}`, })) return [...acc, firstPageResource, ...additionalPageResources] @@ -160,8 +157,8 @@ function addStaticPathResourcesFromPagingData( } export async function getAllPagedListingStaticPathResources( - listingPageStaticPathResources: StaticPathResourceType[], - listingResourceType: ListingResourceTypeType + listingPageStaticPathResources: StaticPathResource[], + listingResourceType: ListingResourceType ) { // Paging step 1: Determine the number of pages for each listing const resourcesWithPagingData = diff --git a/src/lib/drupal/lovell/staticPaths.ts b/src/lib/drupal/lovell/staticPaths.ts index 86194c9ba..3fcf2092d 100644 --- a/src/lib/drupal/lovell/staticPaths.ts +++ b/src/lib/drupal/lovell/staticPaths.ts @@ -1,30 +1,24 @@ import { LovellVariant } from './types' import { LOVELL } from './constants' import { getLovellVariantOfUrl, isLovellFederalResource } from './utils' -import { StaticPathResourceType } from '@/types/index' +import { StaticPathResource } from '@/types/dataTypes/formatted/staticPathResource' /** * Returns a static-path resource adjusted for `variant` */ export function getLovellVariantOfStaticPathResource( - resource: StaticPathResourceType, + resource: StaticPathResource, variant: LovellVariant -): StaticPathResourceType { +): StaticPathResource { return { - path: { - ...resource.path, - alias: getLovellVariantOfUrl( - resource.path.alias, - LOVELL[variant].variant - ), - }, + path: getLovellVariantOfUrl(resource.path, LOVELL[variant].variant), administration: LOVELL[variant].administration, } } export function removeLovellFederalPathResources( - resources: StaticPathResourceType[] -): StaticPathResourceType[] { + resources: StaticPathResource[] +): StaticPathResource[] { return resources.filter((resource) => !isLovellFederalResource(resource)) } @@ -33,8 +27,8 @@ export function removeLovellFederalPathResources( * one for TRICARE and one for VA. */ function bifurcateLovellFederalPathResource( - resource: StaticPathResourceType -): StaticPathResourceType[] { + resource: StaticPathResource +): StaticPathResource[] { const tricareResource = getLovellVariantOfStaticPathResource( resource, LOVELL.tricare.variant @@ -48,8 +42,8 @@ function bifurcateLovellFederalPathResource( return [tricareResource, vaResource] } export function bifurcateLovellFederalPathResources( - resources: StaticPathResourceType[] -): StaticPathResourceType[] { + resources: StaticPathResource[] +): StaticPathResource[] { // Split resources into Lovell Federal and others. // Note: This could be done with two filter calls, // but that would require two passes over the array. diff --git a/src/lib/drupal/lovell/staticProps.ts b/src/lib/drupal/lovell/staticProps.ts index d0e7a449f..af0c1946f 100644 --- a/src/lib/drupal/lovell/staticProps.ts +++ b/src/lib/drupal/lovell/staticProps.ts @@ -7,7 +7,7 @@ import { getDefaultStaticPropsResource, } from '@/lib/drupal/staticProps' import { - ListingResourceTypeType, + ListingResourceType, LISTING_RESOURCE_TYPE_URL_SEGMENTS, } from '@/lib/drupal/listingPages' import { PAGE_SIZES } from '@/lib/constants/pageSizes' @@ -88,7 +88,7 @@ export function getLovellChildVariantOfResource( } async function getLovellListingPageStaticPropsResource( - resourceType: ListingResourceTypeType, + resourceType: ListingResourceType, pathInfo: DrupalTranslatedPath, context: ExpandedStaticPropsContext ): Promise> { @@ -164,7 +164,7 @@ export async function getLovellStaticPropsResource( // Lovell listing pages need Federal items merged if (context.lovell.isLovellVariantPage && context.listing.isListingPage) { const resource = await getLovellListingPageStaticPropsResource( - resourceType as ListingResourceTypeType, + resourceType as ListingResourceType, pathInfo, context ) diff --git a/src/lib/drupal/lovell/tests/mockData.ts b/src/lib/drupal/lovell/tests/mockData.ts index 9b51736ff..d66bcf915 100644 --- a/src/lib/drupal/lovell/tests/mockData.ts +++ b/src/lib/drupal/lovell/tests/mockData.ts @@ -19,38 +19,22 @@ export const lovellVaSlug = [LOVELL.va.pathSegment, 'stories', 'story-1'] export const otherSlug = ['some-other-health-care', 'stories', 'story-1'] export const lovellFederalResource = { - path: { - alias: slugToPath(lovellFederalSlug), - pid: null, - langcode: null, - }, + path: slugToPath(lovellFederalSlug), administration: LOVELL.federal.administration, } export const lovellTricareResource = { - path: { - alias: slugToPath(lovellTricareSlug), - pid: null, - langcode: null, - }, + path: slugToPath(lovellTricareSlug), administration: LOVELL.tricare.administration, } export const lovellVaResource = { - path: { - alias: slugToPath(lovellVaSlug), - pid: null, - langcode: null, - }, + path: slugToPath(lovellVaSlug), administration: LOVELL.va.administration, } export const otherResource = { - path: { - alias: slugToPath(otherSlug), - pid: null, - langcode: null, - }, + path: slugToPath(otherSlug), administration: { id: 123, name: 'Some Other health care', @@ -67,8 +51,23 @@ export const newsStoryPartialResource = { { title: 'News', uri: '/news', options: [] }, ], image: { - src: 'image/src', alt: 'alt-text', + id: 'id', + title: 'title', + url: 'image/src', + width: 100, + height: 100, + link: { + '2_1_large': { + href: 'image/src', + meta: { + linkParams: { + width: 100, + height: 100, + }, + }, + }, + }, }, caption: 'caption', author: { @@ -79,6 +78,7 @@ export const newsStoryPartialResource = { date: '2020-01-01', socialLinks: { title: 'Social Network', + path: 'path/to/social', }, listing: 'listing', entityId: 12345, diff --git a/src/lib/drupal/lovell/tests/staticPaths.test.ts b/src/lib/drupal/lovell/tests/staticPaths.test.ts index 912e37454..162307db4 100644 --- a/src/lib/drupal/lovell/tests/staticPaths.test.ts +++ b/src/lib/drupal/lovell/tests/staticPaths.test.ts @@ -18,11 +18,7 @@ import { describe('getLovellVariantOfStaticPathResource', () => { const resource = { - path: { - alias: `/${LOVELL.va.pathSegment}/stories`, - pid: 68161, - langcode: 'en', - }, + path: `/${LOVELL.va.pathSegment}/stories`, administration: LOVELL.va.administration, } @@ -32,11 +28,7 @@ describe('getLovellVariantOfStaticPathResource', () => { LOVELL.federal.variant ) expect(result).toStrictEqual({ - path: { - alias: `/${LOVELL.federal.pathSegment}/stories`, - pid: resource.path.pid, - langcode: resource.path.langcode, - }, + path: `/${LOVELL.federal.pathSegment}/stories`, administration: LOVELL.federal.administration, }) }) @@ -47,11 +39,7 @@ describe('getLovellVariantOfStaticPathResource', () => { LOVELL.tricare.variant ) expect(result).toStrictEqual({ - path: { - alias: `/${LOVELL.tricare.pathSegment}/stories`, - pid: resource.path.pid, - langcode: resource.path.langcode, - }, + path: `/${LOVELL.tricare.pathSegment}/stories`, administration: LOVELL.tricare.administration, }) }) diff --git a/src/lib/drupal/lovell/tests/utils.test.ts b/src/lib/drupal/lovell/tests/utils.test.ts index f1998201a..824a8b1f3 100644 --- a/src/lib/drupal/lovell/tests/utils.test.ts +++ b/src/lib/drupal/lovell/tests/utils.test.ts @@ -171,51 +171,51 @@ describe('isLovellChildVariantResource', () => { describe('isLovellTricarePath', () => { test('should return true when TRICARE path', () => { - const result = isLovellTricarePath(lovellTricareResource.path.alias) + const result = isLovellTricarePath(lovellTricareResource.path) expect(result).toBe(true) }) test('should return false when VA path', () => { - const result = isLovellTricarePath(lovellVaResource.path.alias) + const result = isLovellTricarePath(lovellVaResource.path) expect(result).toBe(false) }) test('should return false when any other path', () => { - const result = isLovellTricarePath(otherResource.path.alias) + const result = isLovellTricarePath(otherResource.path) expect(result).toBe(false) }) }) describe('isLovellVaPath', () => { test('should return true when VA path', () => { - const result = isLovellVaPath(lovellVaResource.path.alias) + const result = isLovellVaPath(lovellVaResource.path) expect(result).toBe(true) }) test('should return false when TRICARE path', () => { - const result = isLovellVaPath(lovellTricareResource.path.alias) + const result = isLovellVaPath(lovellTricareResource.path) expect(result).toBe(false) }) test('should return false when any other path', () => { - const result = isLovellVaPath(otherResource.path.alias) + const result = isLovellVaPath(otherResource.path) expect(result).toBe(false) }) }) describe('isLovellChildVariantPath', () => { test('should return true when VA path', () => { - const result = isLovellChildVariantPath(lovellVaResource.path.alias) + const result = isLovellChildVariantPath(lovellVaResource.path) expect(result).toBe(true) }) test('should return true when TRICARE path', () => { - const result = isLovellChildVariantPath(lovellTricareResource.path.alias) + const result = isLovellChildVariantPath(lovellTricareResource.path) expect(result).toBe(true) }) test('should return false when any other path', () => { - const result = isLovellChildVariantPath(otherResource.path.alias) + const result = isLovellChildVariantPath(otherResource.path) expect(result).toBe(false) }) }) @@ -285,16 +285,16 @@ describe('getOppositeChildVariant', () => { describe('getLovellVariantOfUrl', () => { test('should properly convert relative url', () => { - const url = lovellFederalResource.path.alias + const url = lovellFederalResource.path const result = getLovellVariantOfUrl(url, LOVELL.tricare.variant) - expect(result).toBe(lovellTricareResource.path.alias) + expect(result).toBe(lovellTricareResource.path) }) test('should properly convert absolute url', () => { const domain = 'https://www.va.gov' - const url = `${domain}${lovellFederalResource.path.alias}` + const url = `${domain}${lovellFederalResource.path}` const result = getLovellVariantOfUrl(url, LOVELL.va.variant) - expect(result).toBe(`${domain}${lovellVaResource.path.alias}`) + expect(result).toBe(`${domain}${lovellVaResource.path}`) }) test('should leave non-Lovell url unchanged', () => { @@ -363,7 +363,7 @@ describe('isLovellBifurcatedResource', () => { test('should return true when Lovell bifurcated', () => { const bifurcatedResource = { ...newsStoryPartialResource, - entityPath: lovellVaResource.path.alias, + entityPath: lovellVaResource.path, administration: LOVELL.federal.administration, } const result = isLovellBifurcatedResource(bifurcatedResource) @@ -373,7 +373,7 @@ describe('isLovellBifurcatedResource', () => { test('should return false when Lovell TRICARE only', () => { const tricareResource = { ...newsStoryPartialResource, - entityPath: lovellTricareResource.path.alias, + entityPath: lovellTricareResource.path, administration: lovellTricareResource.administration, } const result = isLovellBifurcatedResource(tricareResource) @@ -383,7 +383,7 @@ describe('isLovellBifurcatedResource', () => { test('should return false when Lovell VA only', () => { const vaResource = { ...newsStoryPartialResource, - entityPath: lovellVaResource.path.alias, + entityPath: lovellVaResource.path, administration: lovellVaResource.administration, } const result = isLovellBifurcatedResource(vaResource) @@ -393,7 +393,7 @@ describe('isLovellBifurcatedResource', () => { test('should return false when not a Lovell resource', () => { const someOtherResource = { ...newsStoryPartialResource, - entityPath: otherResource.path.alias, + entityPath: otherResource.path, administration: otherResource.administration, } const result = isLovellBifurcatedResource(someOtherResource) diff --git a/src/lib/drupal/lovell/utils.ts b/src/lib/drupal/lovell/utils.ts index cd886b588..012d73d9e 100644 --- a/src/lib/drupal/lovell/utils.ts +++ b/src/lib/drupal/lovell/utils.ts @@ -9,19 +9,19 @@ import { LOVELL_RESOURCE_TYPES, LOVELL_BIFURCATED_RESOURCE_TYPES, } from './constants' -import { StaticPathResourceType } from '@/types/index' +import { StaticPathResource } from '@/types/dataTypes/formatted/staticPathResource' import { FormattedResource } from '@/data/queries' -import { ResourceTypeType } from '@/lib/constants/resourceTypes' +import { ResourceType } from '@/lib/constants/resourceTypes' import { slugToPath } from '@/lib/utils/slug' -import { SideNavItem, SideNavMenu } from '@/types/index' +import { SideNavItem, SideNavMenu } from '@/types/dataTypes/formatted/sideNav' import { BreadcrumbItem } from '@/types/dataTypes/drupal/field_type' -export function isLovellResourceType(resourceType: ResourceTypeType): boolean { +export function isLovellResourceType(resourceType: ResourceType): boolean { return (LOVELL_RESOURCE_TYPES as readonly string[]).includes(resourceType) } export function isLovellBifurcatedResourceType( - resourceType: ResourceTypeType + resourceType: ResourceType ): boolean { return (LOVELL_BIFURCATED_RESOURCE_TYPES as readonly string[]).includes( resourceType @@ -29,7 +29,7 @@ export function isLovellBifurcatedResourceType( } export function isLovellFederalResource( - resource: LovellFormattedResource | StaticPathResourceType + resource: LovellFormattedResource | StaticPathResource ): boolean { return ( 'administration' in resource && @@ -37,7 +37,7 @@ export function isLovellFederalResource( ) } export function isLovellTricareResource( - resource: LovellFormattedResource | StaticPathResourceType + resource: LovellFormattedResource | StaticPathResource ): boolean { return ( 'administration' in resource && @@ -45,7 +45,7 @@ export function isLovellTricareResource( ) } export function isLovellVaResource( - resource: LovellFormattedResource | StaticPathResourceType + resource: LovellFormattedResource | StaticPathResource ): boolean { return ( 'administration' in resource && @@ -53,7 +53,7 @@ export function isLovellVaResource( ) } export function isLovellResource( - resource: LovellFormattedResource | StaticPathResourceType + resource: LovellFormattedResource | StaticPathResource ): boolean { return ( isLovellFederalResource(resource) || @@ -62,7 +62,7 @@ export function isLovellResource( ) } export function isLovellChildVariantResource( - resource: LovellFormattedResource | StaticPathResourceType + resource: LovellFormattedResource | StaticPathResource ): boolean { return isLovellTricareResource(resource) || isLovellVaResource(resource) } @@ -210,7 +210,7 @@ export function isLovellBifurcatedResource( resource: FormattedResource ): boolean { return ( - isLovellBifurcatedResourceType(resource.type as ResourceTypeType) && + isLovellBifurcatedResourceType(resource.type as ResourceType) && isLovellChildVariantPath(resource.entityPath) && isLovellFederalResource(resource as LovellBifurcatedFormattedResource) ) diff --git a/src/lib/drupal/staticPaths.ts b/src/lib/drupal/staticPaths.ts index b17c0dd01..4268e0163 100644 --- a/src/lib/drupal/staticPaths.ts +++ b/src/lib/drupal/staticPaths.ts @@ -1,16 +1,17 @@ import { drupalClient } from '@/lib/drupal/drupalClient' import { - ListingResourceTypeType, + ListingResourceType, getAllPagedListingStaticPathResources, isListingResourceType, } from '@/lib/drupal/listingPages' -import { RESOURCE_TYPES, ResourceTypeType } from '@/lib/constants/resourceTypes' +import { RESOURCE_TYPES, ResourceType } from '@/lib/constants/resourceTypes' import { queries } from '@/data/queries' -import { StaticPathResourceType } from '@/types/index' +import { StaticPathResource } from '@/types/dataTypes/formatted/staticPathResource' import { bifurcateLovellFederalPathResources, removeLovellFederalPathResources, } from '@/lib/drupal/lovell/staticPaths' +import { pathToSlug } from '@/lib/utils/slug' /** * Returns a static-path resource collection that is modified per business logic. @@ -22,9 +23,9 @@ import { * - Lovell Federal listing pages are REMOVED */ async function modifyStaticPathResourcesByResourceType( - resourceType: ResourceTypeType, - resources: StaticPathResourceType[] -): Promise { + resourceType: ResourceType, + resources: StaticPathResource[] +): Promise { if (resourceType === RESOURCE_TYPES.STORY) { return bifurcateLovellFederalPathResources(resources) } @@ -33,7 +34,7 @@ async function modifyStaticPathResourcesByResourceType( const lovellFederalRemoved = removeLovellFederalPathResources(resources) return await getAllPagedListingStaticPathResources( lovellFederalRemoved, - resourceType as ListingResourceTypeType + resourceType as ListingResourceType ) } @@ -41,7 +42,7 @@ async function modifyStaticPathResourcesByResourceType( } export async function getStaticPathsByResourceType( - resourceType: ResourceTypeType + resourceType: ResourceType ): ReturnType { // Get resources from which static paths can be built const resources = await queries.getData('static-path-resources', { @@ -55,6 +56,9 @@ export async function getStaticPathsByResourceType( ) // Convert the resources to static paths - const paths = drupalClient.buildStaticPathsFromResources(modifiedResources) - return paths + return modifiedResources.map((resource) => ({ + params: { + slug: pathToSlug(resource.path), + }, + })) } diff --git a/src/lib/drupal/staticProps.ts b/src/lib/drupal/staticProps.ts index baee68b55..8432ac7bb 100644 --- a/src/lib/drupal/staticProps.ts +++ b/src/lib/drupal/staticProps.ts @@ -18,7 +18,7 @@ import { LovellFormattedResource, } from './lovell/types' import { FormattedResource } from '@/data/queries' -import { RESOURCE_TYPES, ResourceTypeType } from '@/lib/constants/resourceTypes' +import { RESOURCE_TYPES, ResourceType } from '@/lib/constants/resourceTypes' import { ListingPageDataOpts } from '@/lib/drupal/listingPages' import { NewsStoryDataOpts } from '@/data/queries/newsStory' @@ -79,7 +79,7 @@ export function getExpandedStaticPropsContext( * @returns A query options object whose shape is determined by the resource type */ export function getStaticPropsQueryOpts( - resourceType: ResourceTypeType, + resourceType: ResourceType, id: string, context: ExpandedStaticPropsContext ): StaticPropsQueryOpts { @@ -101,7 +101,7 @@ export function getStaticPropsQueryOpts( } export async function fetchSingleStaticPropsResource( - resourceType: ResourceTypeType, + resourceType: ResourceType, pathInfo: DrupalTranslatedPath, queryOpts: StaticPropsQueryOpts ): Promise { @@ -114,7 +114,7 @@ export async function fetchSingleStaticPropsResource( } export async function getDefaultStaticPropsResource( - resourceType: ResourceTypeType, + resourceType: ResourceType, pathInfo: DrupalTranslatedPath, context: ExpandedStaticPropsContext ): Promise { @@ -125,7 +125,7 @@ export async function getDefaultStaticPropsResource( } export async function getStaticPropsResource( - resourceType: ResourceTypeType, + resourceType: ResourceType, pathInfo: DrupalTranslatedPath, context: ExpandedStaticPropsContext ): Promise> { diff --git a/src/lib/utils/header.test.ts b/src/lib/utils/header.test.ts index b824c7178..20fb283e5 100644 --- a/src/lib/utils/header.test.ts +++ b/src/lib/utils/header.test.ts @@ -1,4 +1,4 @@ -import { MegaMenuSection } from '@/types/index' +import { MegaMenuSection } from '@/types/dataTypes/formatted/headerFooter' import { formatHeaderData } from './header' describe('header megamenu', () => { diff --git a/src/lib/utils/header.ts b/src/lib/utils/header.ts index 10cd58ad0..be3a841e2 100644 --- a/src/lib/utils/header.ts +++ b/src/lib/utils/header.ts @@ -6,7 +6,7 @@ import { MegaMenuLink, MegaMenuLinkObject, MegaMenuSection, -} from '@/types/index' +} from '@/types/dataTypes/formatted/headerFooter' /** * Most of this file is to massage the data for the menu links diff --git a/src/lib/utils/headerFooter.test.ts b/src/lib/utils/headerFooter.test.ts index 7587885d7..9419b91b7 100644 --- a/src/lib/utils/headerFooter.test.ts +++ b/src/lib/utils/headerFooter.test.ts @@ -1,5 +1,5 @@ import { buildHeaderFooterData } from './headerFooter' -import { FooterLink } from '@/types/index' +import { FooterLink } from '@/types/dataTypes/formatted/headerFooter' describe('headerFooter', () => { test('should combine footer menus into one array', () => { diff --git a/src/lib/utils/headerFooter.ts b/src/lib/utils/headerFooter.ts index 63aee8128..8fd66e86f 100644 --- a/src/lib/utils/headerFooter.ts +++ b/src/lib/utils/headerFooter.ts @@ -1,7 +1,10 @@ import { convertLinkToAbsolute, formatHeaderData } from '@/lib/utils/header' import { FOOTER_LINKS } from '../constants/footer-links' import { RawHeaderFooterData } from '@/data/queries/headerFooter' -import { FooterLink, HeaderFooterData } from '@/types/index' +import { + FooterLink, + HeaderFooterData, +} from '@/types/dataTypes/formatted/headerFooter' // Helper functions to format footer menu items const formatLink = (link, linkIndex, columnId, hostUrl): FooterLink => { diff --git a/src/lib/utils/slug.test.ts b/src/lib/utils/slug.test.ts index 46445d68c..c2faf9073 100644 --- a/src/lib/utils/slug.test.ts +++ b/src/lib/utils/slug.test.ts @@ -1,4 +1,4 @@ -import { slugToPath } from './slug' +import { slugToPath, pathToSlug } from './slug' describe('slugToPath', () => { test('should properly handle string with leading slash', () => { @@ -19,3 +19,29 @@ describe('slugToPath', () => { expect(result).toBe(`/${slug[0]}/${slug[1]}`) }) }) + +describe('pathToSlug', () => { + test('should properly handle string with leading slash', () => { + const path = '/some/path' + const result = pathToSlug(path) + expect(result).toStrictEqual(['some', 'path']) + }) + + test('should properly handle string with trailing slash', () => { + const path = 'some/path/' + const result = pathToSlug(path) + expect(result).toStrictEqual(['some', 'path']) + }) + + test('should properly handle string with leading and trailing slashes', () => { + const path = '/some/path/' + const result = pathToSlug(path) + expect(result).toStrictEqual(['some', 'path']) + }) + + test('should properly handle string without leading or trailing slash', () => { + const path = 'some/path' + const result = pathToSlug(path) + expect(result).toStrictEqual(['some', 'path']) + }) +}) diff --git a/src/lib/utils/slug.ts b/src/lib/utils/slug.ts index a56390777..4fe01146a 100644 --- a/src/lib/utils/slug.ts +++ b/src/lib/utils/slug.ts @@ -3,3 +3,7 @@ export function slugToPath(slug: string | string[]): string { const leadingSlashPath = path.substring(0, 1) === '/' ? path : `/${path}` return leadingSlashPath } + +export function pathToSlug(path: string): string[] { + return path.split('/').filter((segment) => segment !== '') +} diff --git a/src/pages/[[...slug]].tsx b/src/pages/[[...slug]].tsx index 5a7d85bbf..cc801d26c 100644 --- a/src/pages/[[...slug]].tsx +++ b/src/pages/[[...slug]].tsx @@ -25,7 +25,7 @@ const RESOURCE_TYPES_TO_BUILD = [ RESOURCE_TYPES.STORY, ] as const -export type BuiltResourceTypeType = (typeof RESOURCE_TYPES_TO_BUILD)[number] +export type BuiltResourceType = (typeof RESOURCE_TYPES_TO_BUILD)[number] // [[...slug]] is a catchall route. We build the appropriate layout based on the resource returned for a given path. export default function ResourcePage({ @@ -138,7 +138,7 @@ export async function getStaticProps(context: GetStaticPropsContext) { } // If the requested path isn't a type we're building, 404 - const resourceType = pathInfo.jsonapi.resourceName as BuiltResourceTypeType + const resourceType = pathInfo.jsonapi.resourceName as BuiltResourceType if (!Object.values(RESOURCE_TYPES).includes(resourceType)) { return { notFound: true, diff --git a/src/templates/common/benefitsHubLinks/index.test.tsx b/src/templates/common/benefitsHubLinks/index.test.tsx index 400fa0c12..6b0582b6f 100644 --- a/src/templates/common/benefitsHubLinks/index.test.tsx +++ b/src/templates/common/benefitsHubLinks/index.test.tsx @@ -1,8 +1,8 @@ import { render, screen } from '@testing-library/react' import { BenefitsHubLinks } from './index' -import { BenefitsHubLinksType } from '@/types/index' +import { BenefitsHubLinks as FormattedBenefitsHubLinks } from '@/types/dataTypes/formatted/benefitsHub' -let benefitHubProps: BenefitsHubLinksType = { +let benefitHubProps: FormattedBenefitsHubLinks = { title: 'Deciding how much life insurance to get', relatedBenefitHubs: [ { diff --git a/src/templates/common/benefitsHubLinks/index.tsx b/src/templates/common/benefitsHubLinks/index.tsx index 9ff8df1eb..67cb4128b 100644 --- a/src/templates/common/benefitsHubLinks/index.tsx +++ b/src/templates/common/benefitsHubLinks/index.tsx @@ -1,17 +1,20 @@ import Link from 'next/link' import { isEmpty } from 'lodash' -import { BenefitsHubLinksType, BenefitsHubType } from '@/types/index' +import { + BenefitsHubLinks as FormattedBenefitHubLinks, + BenefitsHub, +} from '@/types/dataTypes/formatted/benefitsHub' // Partial outputting a list of benefits related to a given page. // Typically, used on a resource page. export function BenefitsHubLinks({ title, relatedBenefitHubs, -}: BenefitsHubLinksType) { +}: FormattedBenefitHubLinks) { if (isEmpty(relatedBenefitHubs)) return null const benefitsHubLink = relatedBenefitHubs.map( - ({ id, url, homePageHubLabel, teaserText }: BenefitsHubType) => ( + ({ id, url, homePageHubLabel, teaserText }: BenefitsHub) => (
  • diff --git a/src/templates/common/button/index.test.tsx b/src/templates/common/button/index.test.tsx index 84b0887a1..4071aec70 100644 --- a/src/templates/common/button/index.test.tsx +++ b/src/templates/common/button/index.test.tsx @@ -1,8 +1,8 @@ import { render, screen } from '@testing-library/react' import { Button } from './index' -import { ButtonType } from '@/types/index' +import { Button as FormattedButton } from '@/types/dataTypes/formatted/button' -const buttonProps: ButtonType = { +const buttonProps: FormattedButton = { id: 'f421578b-0add-405c-ac0c-1b1d146a360f', label: 'Sign in now', url: 'https://www.va.gov/?next=sign-in-faq', diff --git a/src/templates/common/button/index.tsx b/src/templates/common/button/index.tsx index cb62cf7d3..e21459f92 100644 --- a/src/templates/common/button/index.tsx +++ b/src/templates/common/button/index.tsx @@ -1,7 +1,7 @@ import Link from 'next/link' -import { ButtonType } from '@/types/index' +import { Button as FormattedButton } from '@/types/dataTypes/formatted/button' -export function Button({ id, label, url }: ButtonType) { +export function Button({ id, label, url }: FormattedButton) { return ( label && url && ( diff --git a/src/templates/common/contentFooter/index.tsx b/src/templates/common/contentFooter/index.tsx index 6505403f4..80ba87738 100644 --- a/src/templates/common/contentFooter/index.tsx +++ b/src/templates/common/contentFooter/index.tsx @@ -1,9 +1,12 @@ import React from 'react' -import { ContentFooterType } from '@/types/index' import { parseDate, getDateParts } from '@/lib/utils/date' import { MedalliaAssets } from '@/templates/globals/medallia' import { getSurveyNumber, showForm } from '@/lib/utils/medallia' +type ContentFooterProps = { + lastUpdated?: string | number +} + function formatDate(date: Date, format: 'display' | 'machine'): string { const dateParts = getDateParts(date) if (format === 'display') { @@ -54,7 +57,7 @@ function FeedbackButton() { ) } -export function ContentFooter({ lastUpdated }: ContentFooterType) { +export function ContentFooter({ lastUpdated }: ContentFooterProps) { let displayDate, machineDate const date = parseDate(lastUpdated) if (date) { diff --git a/src/templates/common/mediaImage/index.test.tsx b/src/templates/common/mediaImage/index.test.tsx index 69b749b57..86a31e6e5 100644 --- a/src/templates/common/mediaImage/index.test.tsx +++ b/src/templates/common/mediaImage/index.test.tsx @@ -1,8 +1,8 @@ import { render, screen, waitFor } from '@testing-library/react' -import { MediaImageType } from '@/types/index' +import { MediaImage as FormattedMediaImage } from '@/types/dataTypes/formatted/media' import { MediaImage } from '@/templates/common/mediaImage' -const mediaImage: MediaImageType = { +const mediaImage: FormattedMediaImage = { id: '3', alt: 'Smiling man in glasses.', title: 'Cats or Dogs?', @@ -10,11 +10,13 @@ const mediaImage: MediaImageType = { height: 1512, url: 'http://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/styles/2_1_large/public/2020-08/Raab.jpg?h=d3381009', link: { - href: 'http://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/styles/2_1_large/public/2020-08/Raab.jpg?h=d3381009', - meta: { - linkParams: { - width: 100, - height: 100, + '2_1_large': { + href: 'http://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/styles/2_1_large/public/2020-08/Raab.jpg?h=d3381009', + meta: { + linkParams: { + width: 100, + height: 100, + }, }, }, }, diff --git a/src/templates/common/mediaImage/index.tsx b/src/templates/common/mediaImage/index.tsx index 3bdc32164..9aed216fd 100644 --- a/src/templates/common/mediaImage/index.tsx +++ b/src/templates/common/mediaImage/index.tsx @@ -1,7 +1,8 @@ import Image from '../image' -import { MediaImageType } from '@/types/index' +import { MediaImage as FormattedMediaImage } from '@/types/dataTypes/formatted/media' -export const MediaImage = (props: MediaImageType) => { +// TODO: Do we need this component? It appears to be an unnecessary wrapper. +export const MediaImage = (props: FormattedMediaImage) => { return ( { - const audienceTopicProps: AudienceTopicsType = { + const audienceTopicProps: FormattedAudienceTopics = { tags: [ { id: '386eb70d-696c-4af3-8986-306ce63d90de', @@ -43,7 +43,7 @@ describe('AudienceTopics with valid data', () => { }) describe('AudienceTopics without Topics', () => { - const audienceTopicProps: AudienceTopicsType = { + const audienceTopicProps: FormattedAudienceTopics = { tags: [ { id: '386eb70d-696c-4af3-8986-306ce63d90de', @@ -64,7 +64,7 @@ describe('AudienceTopics without Topics', () => { }) describe('AudienceTopics without Audience', () => { - const audienceTopicProps: AudienceTopicsType = { + const audienceTopicProps: FormattedAudienceTopics = { tags: [ { id: '8360523e-a4bb-4d36-851f-1c445501c8bf', @@ -85,7 +85,7 @@ describe('AudienceTopics without Audience', () => { }) describe('AudienceTopics without Topics and Audience', () => { - const audienceTopicProps: AudienceTopicsType = { + const audienceTopicProps: FormattedAudienceTopics = { tags: [], } diff --git a/src/templates/components/audienceTopics/index.tsx b/src/templates/components/audienceTopics/index.tsx index 3bac706d0..92b3b901e 100644 --- a/src/templates/components/audienceTopics/index.tsx +++ b/src/templates/components/audienceTopics/index.tsx @@ -1,8 +1,8 @@ import Link from 'next/link' import { isEmpty } from 'lodash' -import { AudienceTopicsType } from '@/types/index' +import { AudienceTopics as FormattedAudienceTopics } from '@/types/dataTypes/formatted/audienceTopics' -export function AudienceTopics({ tags }: AudienceTopicsType) { +export function AudienceTopics({ tags }: FormattedAudienceTopics) { if (isEmpty(tags)) return null const tagsList = tags.map(({ id, href, name }) => (

    diff --git a/src/templates/components/emailContact/index.test.tsx b/src/templates/components/emailContact/index.test.tsx index 9e2005ef4..66c897aee 100644 --- a/src/templates/components/emailContact/index.test.tsx +++ b/src/templates/components/emailContact/index.test.tsx @@ -3,9 +3,9 @@ import { fireEvent, getByRole } from '@testing-library/dom' jest.mock('@/lib/analytics/recordEvent') import * as recordEvent from '@/lib/analytics/recordEvent' import { EmailContact } from '@/templates/components/emailContact' -import { EmailContactType } from '@/types/index' +import { EmailContact as FormattedEmailContact } from '@/types/dataTypes/formatted/emailContact' -const emailContact: EmailContactType = { +const emailContact: FormattedEmailContact = { id: 'f421578b-0add-405c-ac0c-1b1d146a360f', address: 'test.veteran@va.gov', label: 'Minority Veterans Program', diff --git a/src/templates/components/emailContact/index.tsx b/src/templates/components/emailContact/index.tsx index 9aae7cbe5..827b9aebc 100644 --- a/src/templates/components/emailContact/index.tsx +++ b/src/templates/components/emailContact/index.tsx @@ -1,13 +1,13 @@ import Link from 'next/link' import { recordEvent } from '@/lib/analytics/recordEvent' import { isEmpty, isNull } from 'lodash' -import { EmailContactType } from '@/types/index' +import { EmailContact as FormattedEmailContact } from '@/types/dataTypes/formatted/emailContact' function isRequestInValid(email) { return isNull(email.label) || isNull(email.address) } -export function EmailContact(email: EmailContactType) { +export function EmailContact(email: FormattedEmailContact) { if (isEmpty(email) || isRequestInValid(email)) return const analytic = { diff --git a/src/templates/components/expandableText/index.tsx b/src/templates/components/expandableText/index.tsx index b644dd1fb..dba3f516f 100644 --- a/src/templates/components/expandableText/index.tsx +++ b/src/templates/components/expandableText/index.tsx @@ -3,9 +3,9 @@ import { VaAccordionItem, } from '@department-of-veterans-affairs/component-library/dist/react-bindings' import { isEmpty } from 'lodash' -import { ExpandableTextType } from '@/types/index' +import { ExpandableText as FormattedExpandableText } from '@/types/dataTypes/formatted/expandableText' -export function ExpandableText({ id, header, text }: ExpandableTextType) { +export function ExpandableText({ id, header, text }: FormattedExpandableText) { if (isEmpty(header)) return return ( diff --git a/src/templates/components/linkTeaser/index.test.tsx b/src/templates/components/linkTeaser/index.test.tsx index 84422f032..6aa6acef2 100644 --- a/src/templates/components/linkTeaser/index.test.tsx +++ b/src/templates/components/linkTeaser/index.test.tsx @@ -3,10 +3,10 @@ import { fireEvent } from '@testing-library/dom' jest.mock('@/lib/analytics/recordEvent') import * as recordEvent from '@/lib/analytics/recordEvent' import { LinkTeaser } from './index' -import { LinkTeaserType } from '@/types/index' +import { LinkTeaser as FormattedLinkTeaser } from '@/types/dataTypes/formatted/linkTeaser' describe(' component renders without field_spokes', () => { - const LinkTeaserCollectionProps: LinkTeaserType = { + const LinkTeaserCollectionProps: FormattedLinkTeaser = { id: 'cb0c2019-0f48-448f-98ca-205d80c8f6fe', uri: '/health-care/eligibility/', title: 'Health Care Benefits Eligibility', @@ -106,7 +106,7 @@ describe(' component renders without field_spokes', () => { }) describe(' component renders with field_spokes', () => { - const LinkTeaserCollectionProps: LinkTeaserType = { + const LinkTeaserCollectionProps: FormattedLinkTeaser = { id: 'cb0c2019-0f48-448f-98ca-205d80c8f6fe', uri: '/health-care/eligibility/', title: 'Health Care Benefits Eligibility', @@ -216,7 +216,7 @@ describe(' component renders with field_spokes', () => { describe('LinkTeaser with invalid data', () => { test('does render component when uri is not present', () => { - const LinkTeaserCollectionProps: LinkTeaserType = { + const LinkTeaserCollectionProps: FormattedLinkTeaser = { id: 'cb0c2019-0f48-448f-98ca-205d80c8f6fe', uri: '/health-care/eligibility/', title: 'Health Care Benefits Eligibility', diff --git a/src/templates/components/linkTeaser/index.tsx b/src/templates/components/linkTeaser/index.tsx index 2c44480db..0ea3eb857 100644 --- a/src/templates/components/linkTeaser/index.tsx +++ b/src/templates/components/linkTeaser/index.tsx @@ -1,7 +1,7 @@ import Image from '@/templates/common/image' import { get } from 'lodash' import { recordEvent } from '@/lib/analytics/recordEvent' -import { LinkTeaserType } from '@/types/index' +import { LinkTeaser as FormattedLinkTeaser } from '@/types/dataTypes/formatted/linkTeaser' // todo: fix this export const thumbnail = 'https://www.va.gov/img/arrow-right-blue.svg' @@ -14,7 +14,7 @@ export const LinkTeaser = ({ parentField, componentParams, options, -}: LinkTeaserType) => { +}: FormattedLinkTeaser) => { const { boldTitle, sectionHeader } = componentParams const analytic = { diff --git a/src/templates/components/lovellSwitcher/index.tsx b/src/templates/components/lovellSwitcher/index.tsx index 11d01de26..2b43d80fd 100644 --- a/src/templates/components/lovellSwitcher/index.tsx +++ b/src/templates/components/lovellSwitcher/index.tsx @@ -1,11 +1,16 @@ import React from 'react' import { getOppositeChildVariant } from '@/lib/drupal/lovell/utils' -import { LovellSwitcherType } from '@/types/index' +import { LovellChildVariant } from '@/lib/drupal/lovell/types' + +type LovellSwitcherProps = { + currentVariant: LovellChildVariant + switchPath: string +} export function LovellSwitcher({ currentVariant, switchPath, -}: LovellSwitcherType) { +}: LovellSwitcherProps) { if (!switchPath || !currentVariant) { return <> } diff --git a/src/templates/components/newsStoryTeaser/index.test.tsx b/src/templates/components/newsStoryTeaser/index.test.tsx index ab8ed1fad..5d9fb8826 100644 --- a/src/templates/components/newsStoryTeaser/index.test.tsx +++ b/src/templates/components/newsStoryTeaser/index.test.tsx @@ -1,17 +1,19 @@ import { render, screen } from '@testing-library/react' -import { MediaImageType } from '@/types/index' +import { MediaImage } from '@/types/dataTypes/formatted/media' import { NewsStoryTeaser } from '@/templates/components/newsStoryTeaser' // Language: typescript // Path: src/components/media/index.test.tsx -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3d6716b3-fb66-4e63-9b21-bb9c024129d3', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', - meta: { - linkParams: { - width: 318, - height: 159, + '2_1_large': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', + meta: { + linkParams: { + width: 318, + height: 159, + }, }, }, }, diff --git a/src/templates/components/newsStoryTeaser/index.tsx b/src/templates/components/newsStoryTeaser/index.tsx index 60ae7f890..a286407df 100644 --- a/src/templates/components/newsStoryTeaser/index.tsx +++ b/src/templates/components/newsStoryTeaser/index.tsx @@ -1,6 +1,6 @@ import { MediaImage } from '@/templates/common/mediaImage' import { truncateWordsOrChar } from '@/lib/utils/helpers' -import { NewsStoryTeaserType } from '@/types/index' +import { NewsStoryTeaser as FormattedNewsStoryTeaser } from '@/types/dataTypes/formatted/newsStory' /** Teaser news story. */ export const NewsStoryTeaser = ({ @@ -9,7 +9,7 @@ export const NewsStoryTeaser = ({ image, link, introText, -}: NewsStoryTeaserType) => { +}: FormattedNewsStoryTeaser) => { const TitleTag = ({ children, className }) => { const Heading = headingLevel ? headingLevel : 'h2' return {children} diff --git a/src/templates/components/newsStoryTeaser/newsStoryTeaser.stories.tsx b/src/templates/components/newsStoryTeaser/newsStoryTeaser.stories.tsx index 2e14b9cd9..add3f6493 100644 --- a/src/templates/components/newsStoryTeaser/newsStoryTeaser.stories.tsx +++ b/src/templates/components/newsStoryTeaser/newsStoryTeaser.stories.tsx @@ -1,16 +1,18 @@ import { ComponentMeta, ComponentStory } from '@storybook/react' import React from 'react' import { NewsStoryTeaser } from '@/templates/components/newsStoryTeaser' -import { MediaImageType } from '@/types/index' +import { MediaImage } from '@/types/dataTypes/formatted/media' -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3d6716b3-fb66-4e63-9b21-bb9c024129d3', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', - meta: { - linkParams: { - width: 318, - height: 159, + '2_1_large': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', + meta: { + linkParams: { + width: 318, + height: 159, + }, }, }, }, diff --git a/src/templates/components/personProfile/index.test.tsx b/src/templates/components/personProfile/index.test.tsx index a62028a38..c84a658c1 100644 --- a/src/templates/components/personProfile/index.test.tsx +++ b/src/templates/components/personProfile/index.test.tsx @@ -1,35 +1,36 @@ import { render, screen } from 'test-utils' import { PersonProfile } from '@/templates/components/personProfile/index' -import { PersonProfileType, MediaImageType } from '@/types/index' +import { PersonProfile as FormattedPersonProfile } from '@/types/dataTypes/formatted/personProfile' +import { MediaImage } from '@/types/dataTypes/formatted/media' -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3', alt: 'Heather Steele outreach and community engagement specialist', title: 'Heather Steele', width: 151, height: 227, - imageStyle: '1_1_square_medium_thumbnail', + imageStyle: '2_3_medium_thumbnail', url: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', - meta: { - linkParams: { - width: 151, - height: 227, + '2_3_medium_thumbnail': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', + meta: { + linkParams: { + width: 151, + height: 227, + }, }, }, }, } -const personProfileData: PersonProfileType = { +const personProfileData: FormattedPersonProfile = { id: '4406ee13-e60f-43f7-b969-13e2cd693c1b', entityId: 1234, entityPath: 'sample/path/url', type: 'node--person-profile', title: 'Heather Steele', - path: { - alias: '/pittsburgh-health-care/staff-profiles/raab-john', - }, + path: '/pittsburgh-health-care/staff-profiles/raab-john', firstName: 'Heather', lastName: 'Steele', suffix: null, diff --git a/src/templates/components/personProfile/index.tsx b/src/templates/components/personProfile/index.tsx index 4d164972d..278b7a9e4 100644 --- a/src/templates/components/personProfile/index.tsx +++ b/src/templates/components/personProfile/index.tsx @@ -1,5 +1,5 @@ import { MediaImage } from '@/templates/common/mediaImage' -import { PersonProfileType } from '@/types/index' +import { PersonProfile as FormattedPersonProfile } from '@/types/dataTypes/formatted/personProfile' export type PersonProfileTeaserProps = { title: string @@ -21,7 +21,7 @@ export const PersonProfile = ({ vamcOfficalName, media, office, -}: PersonProfileType): JSX.Element => { +}: FormattedPersonProfile): JSX.Element => { return (
    diff --git a/src/templates/components/personProfile/personProfile.stories.tsx b/src/templates/components/personProfile/personProfile.stories.tsx index 62d2abed7..358ceaf5f 100644 --- a/src/templates/components/personProfile/personProfile.stories.tsx +++ b/src/templates/components/personProfile/personProfile.stories.tsx @@ -1,9 +1,10 @@ import { ComponentMeta, ComponentStory } from '@storybook/react' import React from 'react' -import { PersonProfileType, MediaImageType } from '@/types/index' +import { PersonProfile as FormattedPersonProfile } from '@/types/dataTypes/formatted/personProfile' +import { MediaImage } from '@/types/dataTypes/formatted/media' import { PersonProfile } from '@/templates/components/personProfile' -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3', alt: 'Raab Steele outreach and community engagement specialist', title: 'Raab Steele', @@ -12,23 +13,23 @@ const mediaImage: MediaImageType = { imageStyle: '2_3_medium_thumbnail', url: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', - meta: { - linkParams: { - width: 151, - height: 227, + '2_3_medium_thumbnail': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_3_medium_thumbnail/public/2021-04/Zachary_Sage.jpg', + meta: { + linkParams: { + width: 151, + height: 227, + }, }, }, }, } -const personProfileData: PersonProfileType = { +const personProfileData: FormattedPersonProfile = { id: '4406ee13-e60f-43f7-b969-13e2cd693c1b', type: 'node--person-profile', title: 'Zachary M. Sage', - path: { - alias: '/illiana-health-care/staff-profiles/zachary-m-sage/', - }, + path: '/illiana-health-care/staff-profiles/zachary-m-sage/', entityId: 1234, entityPath: 'sample/path', firstName: 'Zachary', diff --git a/src/templates/components/storyListingLink/index.tsx b/src/templates/components/storyListingLink/index.tsx index 04784a854..0182ef382 100644 --- a/src/templates/components/storyListingLink/index.tsx +++ b/src/templates/components/storyListingLink/index.tsx @@ -1,7 +1,7 @@ import { recordEvent } from '@/lib/analytics/recordEvent' -import { StoryListingLinkType } from '@/types/index' +import { StoryListingLink as FormattedStoryListingLink } from '@/types/dataTypes/formatted/storyListing' -export const StoryListingLink = ({ path }: StoryListingLinkType) => { +export const StoryListingLink = ({ path }: FormattedStoryListingLink) => { return ( // @todo can be used here? { +}: FormattedBanner): JSX.Element => { return ( IMPORTANT UPDATES FROM VA PITTSBURGH

    \n\n

    In-person visitation for COVID-negative inpatients at University Drive is limited to two visitors per patient during specified hours. Outpatients can bring a support person to clinic appointments and procedures. We require all entrants to wear a VA-provided procedure mask. For more information, please see VA Pittsburgh Health Care.

    \n\n

    Please contact your local VA medical center if you have questions or concerns.

    ', @@ -10,11 +10,8 @@ const bannerData: FacilityBannerType = { dismiss: true, operatingStatus: true, inheritanceSubpages: null, - path: { - alias: - '/va-pittsburgh-health-care/vamc-banner-alert/2021-01-08/help-limit-the-spread-of-covid-19-and-other', - }, - bannerAlertVacms: [null], + path: '/va-pittsburgh-health-care/vamc-banner-alert/2021-01-08/help-limit-the-spread-of-covid-19-and-other', + bannerAlertVamcs: [null], type: 'node--full_width_banner_alert', } diff --git a/src/templates/globals/banners/facilityBanner/index.tsx b/src/templates/globals/banners/facilityBanner/index.tsx index 2994b65dc..6664a028e 100644 --- a/src/templates/globals/banners/facilityBanner/index.tsx +++ b/src/templates/globals/banners/facilityBanner/index.tsx @@ -3,7 +3,7 @@ import { recordEvent } from '@/lib/analytics/recordEvent' import { regionBaseURL } from '@/lib/utils/helpers' import { VaBanner } from '@department-of-veterans-affairs/component-library/dist/react-bindings' import { NodeMetaInfo } from '@/types/dataTypes/drupal/node' -import { FacilityBannerType } from '@/types/index' +import { FacilityBanner as FormattedFacilityBanner } from '@/types/dataTypes/formatted/banners' export const FacilityBanner = ({ id, @@ -14,9 +14,9 @@ export const FacilityBanner = ({ findFacilities, operatingStatus, inheritanceSubpages, - bannerAlertVacms, + bannerAlertVamcs, dismiss, -}: FacilityBannerType): JSX.Element => { +}: FormattedFacilityBanner): JSX.Element => { const [isClicked, setIsClicked] = useState(false) const [outputStatus, setOutputStatus] = useState(true) const analyticsRef = useRef(null) @@ -31,7 +31,7 @@ export const FacilityBanner = ({ return () => window.removeEventListener('click', handler) }, []) - const findPath = path?.alias + const findPath = path const hideOnSubpages = inheritanceSubpages const alertType = fieldAlertType === 'information' ? 'info' : fieldAlertType @@ -41,10 +41,10 @@ export const FacilityBanner = ({ let content = body const statusUrl = '' - // TODO: Banner AlertVACMS data is a special case. we need to call a relationship which our current banner endpoint does not support. node--vamc_operating_status_and_alerts - // if (bannerAlertVacms) { - // bannerAlertVacms?.map((vamc) => { - // if (region == vamc?.field_office?.path?.alias) { + // TODO: Banner AlertVAMCS data is a special case. we need to call a relationship which our current banner endpoint does not support. node--vamc_operating_status_and_alerts + // if (bannerAlertVamcs) { + // bannerAlertVamcs?.map((vamc) => { + // if (region == vamc?.office?.path) { // setOutputStatus(true) // return outputStatus // } @@ -56,7 +56,7 @@ export const FacilityBanner = ({ // setOutputStatus(false) // return outputStatus // } - // statusUrl = vamc?.path?.alias + // statusUrl = vamc?.path // }) // } diff --git a/src/templates/globals/banners/promoBanner/index.tsx b/src/templates/globals/banners/promoBanner/index.tsx index 2cb2dd3c5..ec14df9cb 100644 --- a/src/templates/globals/banners/promoBanner/index.tsx +++ b/src/templates/globals/banners/promoBanner/index.tsx @@ -1,12 +1,12 @@ import { VaPromoBanner } from '@department-of-veterans-affairs/component-library/dist/react-bindings' -import { PromoBannerType } from '@/types/index' +import { PromoBanner as FormattedPromoBanner } from '@/types/dataTypes/formatted/banners' export const PromoBanner = ({ id, href, title, alertType, -}: PromoBannerType): JSX.Element => { +}: FormattedPromoBanner): JSX.Element => { return ( {title} diff --git a/src/templates/globals/wrapper/index.tsx b/src/templates/globals/wrapper/index.tsx index ee9fbeabd..a2ad4d72b 100644 --- a/src/templates/globals/wrapper/index.tsx +++ b/src/templates/globals/wrapper/index.tsx @@ -4,12 +4,12 @@ import { Banner } from '@/templates/globals/banners/banner' import { PromoBanner } from '@/templates/globals/banners/promoBanner' import { FacilityBanner } from '@/templates/globals/banners/facilityBanner' import { isEmpty } from 'lodash' +import { HeaderFooterData } from '@/types/dataTypes/formatted/headerFooter' import { - BannerType, - FacilityBannerType, - PromoBannerType, - HeaderFooterData, -} from '@/types/index' + Banner as FormattedBanner, + FacilityBanner as FormattedFacilityBanner, + PromoBanner as FormattedPromoBanner, +} from '@/types/dataTypes/formatted/banners' import { NodeBanner } from '@/types/dataTypes/drupal/node' import { BannerDisplayType, BannerTypeMapping } from '@/data/queries/banners' import { Header } from '../header' @@ -27,7 +27,10 @@ declare const window: customWindow export interface LayoutProps { children?: React.ReactNode bannerData?: Array< - NodeBanner | PromoBannerType | BannerType | FacilityBannerType + | NodeBanner + | FormattedPromoBanner + | FormattedBanner + | FormattedFacilityBanner > headerFooterData?: HeaderFooterData } diff --git a/src/templates/layouts/newsStory/index.test.tsx b/src/templates/layouts/newsStory/index.test.tsx index 5b5571e31..3851ae85b 100644 --- a/src/templates/layouts/newsStory/index.test.tsx +++ b/src/templates/layouts/newsStory/index.test.tsx @@ -1,15 +1,17 @@ import { render, screen } from '@testing-library/react' -import { MediaImageType } from '@/types/index' +import { MediaImage } from '@/types/dataTypes/formatted/media' import { NewsStory } from './index' -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', - meta: { - linkParams: { - width: 700, - height: 350, + '2_1_large': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', + meta: { + linkParams: { + width: 700, + height: 350, + }, }, }, }, diff --git a/src/templates/layouts/newsStory/index.tsx b/src/templates/layouts/newsStory/index.tsx index 67a87a59f..da28e17c1 100644 --- a/src/templates/layouts/newsStory/index.tsx +++ b/src/templates/layouts/newsStory/index.tsx @@ -3,10 +3,10 @@ import { StaffNewsProfile } from '@/templates/components/personProfile' import { formatDate } from '@/lib/utils/helpers' import { SocialLinks } from '@/templates/common/socialLinks' import { StoryListingLink } from '@/templates/components/storyListingLink' -import { NewsStoryType } from '@/types/index' +import { NewsStory as FormattedNewsStory } from '@/types/dataTypes/formatted/newsStory' +import { LovellStaticPropsResource } from '@/lib/drupal/lovell/types' import { ContentFooter } from '@/templates/common/contentFooter' import { LovellSwitcher } from '@/templates/components/lovellSwitcher' -import { LovellStaticPropsResource } from '@/lib/drupal/lovell/types' export const NewsStory = ({ title, @@ -20,7 +20,7 @@ export const NewsStory = ({ listing, lovellVariant, lovellSwitchPath, -}: LovellStaticPropsResource) => { +}: LovellStaticPropsResource) => { const imageClassName = caption ? 'vads-u-margin-bottom--1' : 'vads-u-margin-bottom--2p5' diff --git a/src/templates/layouts/newsStory/newsStory.stories.tsx b/src/templates/layouts/newsStory/newsStory.stories.tsx index 1340085c4..8c92e75dd 100644 --- a/src/templates/layouts/newsStory/newsStory.stories.tsx +++ b/src/templates/layouts/newsStory/newsStory.stories.tsx @@ -1,16 +1,18 @@ import React from 'react' import { ComponentMeta, ComponentStory } from '@storybook/react' -import { MediaImageType } from '@/types/index' +import { MediaImage } from '@/types/dataTypes/formatted/media' import { NewsStory } from './index' -const mediaImage: MediaImageType = { +const mediaImage: MediaImage = { id: '3d6716b3-fb66-4e63-9b21-bb9c024129d3', link: { - href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', - meta: { - linkParams: { - width: 700, - height: 350, + '2_1_large': { + href: 'https://s3-us-gov-west-1.amazonaws.com/content.www.va.gov/img/styles/2_1_large/public/2019-05/doctor-year2019-decker-480_0.jpg', + meta: { + linkParams: { + width: 700, + height: 350, + }, }, }, }, diff --git a/src/templates/layouts/questionAnswer/index.test.tsx b/src/templates/layouts/questionAnswer/index.test.tsx index cacdaf51f..873aee8d7 100644 --- a/src/templates/layouts/questionAnswer/index.test.tsx +++ b/src/templates/layouts/questionAnswer/index.test.tsx @@ -1,9 +1,9 @@ import { render, screen } from '@testing-library/react' import { QuestionAnswer } from './index' -import { QuestionAnswerType } from '@/types/index' +import { QuestionAnswer as FormattedQuestionAnswer } from '@/types/dataTypes/formatted/questionAnswer' describe(' component renders with data', () => { - const QuestionAnswerData: QuestionAnswerType = { + const QuestionAnswerData: FormattedQuestionAnswer = { id: 'test-id', type: 'node--q_a', entityId: 1234, diff --git a/src/templates/layouts/questionAnswer/index.tsx b/src/templates/layouts/questionAnswer/index.tsx index 42974cfb1..2b3beca48 100644 --- a/src/templates/layouts/questionAnswer/index.tsx +++ b/src/templates/layouts/questionAnswer/index.tsx @@ -13,7 +13,7 @@ */ import map from 'lodash/map' import { Button } from '@/templates/common/button' -import { QuestionAnswerType } from '@/types/index' +import { QuestionAnswer as FormattedQuestionAnswer } from '@/types/dataTypes/formatted/questionAnswer' import { AudienceTopics } from '@/templates/components/audienceTopics' import { LinkTeaser } from '@/templates/components/linkTeaser' @@ -27,7 +27,7 @@ export const QuestionAnswer = ({ buttons, tags, teasers, -}: QuestionAnswerType) => { +}: FormattedQuestionAnswer) => { const tag = tags ? : null const button = map(buttons, (data) => diff --git a/src/templates/layouts/staffProfile/dataService.tsx b/src/templates/layouts/staffProfile/dataService.tsx index d27c26fd1..c8ea88a6b 100644 --- a/src/templates/layouts/staffProfile/dataService.tsx +++ b/src/templates/layouts/staffProfile/dataService.tsx @@ -1,7 +1,8 @@ // TODO: refactor this file to the @data/queries directory import { ParagraphStaffProfile } from '@/types/dataTypes/drupal/paragraph' -import { StaffProfileType } from '@/types/index' +import { StaffProfile } from '@/types/dataTypes/formatted/staffProfile' import { DrupalJsonApiParams } from 'drupal-jsonapi-params' +import { queries } from '@/data/queries' function isRequestValid(paragraph) { return paragraph.field_staff_profile !== null @@ -10,7 +11,7 @@ function isRequestValid(paragraph) { export const transformStaffProfileData = function ( entity: ParagraphStaffProfile, viewMode?: string -): StaffProfileType { +): StaffProfile { if (!entity || !isRequestValid(entity)) return const name = @@ -23,7 +24,10 @@ export const transformStaffProfileData = function ( return { id: entity.field_staff_profile.id, name: name, - thumbnail: entity.field_staff_profile.field_media, + thumbnail: queries.formatData('media--image', { + entity: entity.field_staff_profile.field_media, + cropType: '2_1_large', // TODO: Which cropType do we want here? + }), linkToBio: entity.field_staff_profile.field_complete_biography_create, path: entity.field_staff_profile.field_entity?.entityUrl.path || null, description: entity.field_staff_profile.field_description, diff --git a/src/templates/layouts/staffProfile/index.tsx b/src/templates/layouts/staffProfile/index.tsx index 6ea19f840..ad4d6f624 100644 --- a/src/templates/layouts/staffProfile/index.tsx +++ b/src/templates/layouts/staffProfile/index.tsx @@ -1,5 +1,5 @@ import { MediaImage } from '@/templates/common/mediaImage' -import { StaffProfileType } from '@/types/index' +import { StaffProfile as FormattedStaffProfile } from '@/types/dataTypes/formatted/staffProfile' export function StaffProfile({ id, @@ -10,7 +10,7 @@ export function StaffProfile({ description, phone, email, -}: StaffProfileType) { +}: FormattedStaffProfile) { return (
    diff --git a/src/templates/layouts/staffProfile/staffProfile.test.tsx b/src/templates/layouts/staffProfile/staffProfile.test.tsx index 88ff118c2..938a5a545 100644 --- a/src/templates/layouts/staffProfile/staffProfile.test.tsx +++ b/src/templates/layouts/staffProfile/staffProfile.test.tsx @@ -1,17 +1,28 @@ import { render, screen } from 'test-utils' import { StaffProfile } from '@/templates/layouts/staffProfile/index' +const thumbnail = { + id: 'some-unique-id', + url: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/2019-08/William_W_Smathers.jpg', + alt: 'William W Smathers Headshot', + title: 'William W Smathers', + width: 110, + height: 136, + styles: {}, + link: { + '2_1_large': { + href: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/styles/1_1_square_medium_thumbnail/public/2019-08/William_W_Smathers.jpg', + meta: { + linkParams: {}, + }, + }, + }, +} + const props = { id: '7783e76f-5aca-4d14-9f5e-fb00cc11e4da', name: 'Mr William Smathers', - thumbnail: { - url: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/sites/default/files/2019-08/William_W_Smathers.jpg', - alt: 'William W Smathers Headshot', - title: 'William W Smathers', - width: 110, - height: 136, - styles: {}, - }, + thumbnail, linkToBio: true, path: 'http:va.gov', description: 'OEF Transition Patient Advocate', diff --git a/src/templates/layouts/storyListing/index.test.tsx b/src/templates/layouts/storyListing/index.test.tsx index 47245e4d6..15b36ab66 100644 --- a/src/templates/layouts/storyListing/index.test.tsx +++ b/src/templates/layouts/storyListing/index.test.tsx @@ -1,8 +1,8 @@ import { render, screen } from '@testing-library/react' import { StoryListing } from '@/templates/layouts/storyListing' -import { StoryListingType } from '@/types/index' +import { StoryListing as FormattedStoryListing } from '@/types/dataTypes/formatted/storyListing' -let storyListingProps: StoryListingType = { +let storyListingProps: FormattedStoryListing = { id: 'f421578b-0add-405c-ac0c-1b1d146a360f', breadcrumbs: [ { title: 'Home', uri: '/', options: [] }, diff --git a/src/templates/layouts/storyListing/index.tsx b/src/templates/layouts/storyListing/index.tsx index 7efd5393f..42eb2679d 100644 --- a/src/templates/layouts/storyListing/index.tsx +++ b/src/templates/layouts/storyListing/index.tsx @@ -10,11 +10,9 @@ */ import { VaPagination } from '@department-of-veterans-affairs/component-library/dist/react-bindings' -import { - NewsStoryTeaserType, - SideNavMenu, - StoryListingType, -} from '@/types/index' +import { SideNavMenu } from '@/types/dataTypes/formatted/sideNav' +import { StoryListing as FormattedStoryListing } from '@/types/dataTypes/formatted/storyListing' +import { NewsStoryTeaser as FormattedNewsStoryTeaser } from '@/types/dataTypes/formatted/newsStory' import { NewsStoryTeaser } from '@/templates/components/newsStoryTeaser' import { ContentFooter } from '@/templates/common/contentFooter' import { useEffect } from 'react' @@ -37,7 +35,7 @@ export function StoryListing({ totalPages, lovellVariant, lovellSwitchPath, -}: LovellStaticPropsResource) { +}: LovellStaticPropsResource) { // Add data to the window object for the sidebar widget useEffect(() => { window.sideNav = menu @@ -45,7 +43,7 @@ export function StoryListing({ const storyTeasers = stories?.length > 0 ? ( - stories?.map((story: NewsStoryTeaserType) => ( + stories?.map((story: FormattedNewsStoryTeaser) => (
  • diff --git a/src/types/dataTypes/drupal/block.ts b/src/types/dataTypes/drupal/block.ts index b94ea8837..89992faad 100644 --- a/src/types/dataTypes/drupal/block.ts +++ b/src/types/dataTypes/drupal/block.ts @@ -1,5 +1,5 @@ import { DrupalBlock } from 'next-drupal' -import { MediaImage } from './media' +import { DrupalMediaImage } from './media' import { ParagraphExpandableText, ParagraphLinkTeaser, @@ -24,7 +24,7 @@ export interface BlockAlert extends DrupalBlock { } export interface BlockPromo extends DrupalBlock { - field_image: MediaImage + field_image: DrupalMediaImage field_promo_link: ParagraphLinkTeaser } diff --git a/src/types/dataTypes/drupal/media.ts b/src/types/dataTypes/drupal/media.ts index 40ca78126..4470253d6 100644 --- a/src/types/dataTypes/drupal/media.ts +++ b/src/types/dataTypes/drupal/media.ts @@ -6,11 +6,11 @@ export const enum MediaResourceType { Document = 'media--document', } -export interface MediaImage extends DrupalMedia { +export interface DrupalMediaImage extends DrupalMedia { field_description: string image: DrupalFile } -export interface MediaDocument extends DrupalMedia { +export interface DrupalMediaDocument extends DrupalMedia { field_document: DrupalFile } diff --git a/src/types/dataTypes/drupal/node.ts b/src/types/dataTypes/drupal/node.ts index 54db83427..331819bd2 100644 --- a/src/types/dataTypes/drupal/node.ts +++ b/src/types/dataTypes/drupal/node.ts @@ -11,7 +11,7 @@ import { FieldTable, FieldAdministration, } from './field_type' -import { MediaImage } from './media' +import { DrupalMediaImage } from './media' import { ParagraphAlert, ParagraphAlertSingle, @@ -135,7 +135,7 @@ export interface NodeHealthCareLocalFacility extends DrupalNode { field_local_health_care_service_: NodeHealthCareLocalHealthService[] field_facility_hours: FieldTable field_office_hours: FieldOfficeHours[] - field_media: MediaImage + field_media: DrupalMediaImage field_location_services: ParagraphHealthCareLocalFacilityService[] field_main_location: boolean field_mental_health_phone: string @@ -161,7 +161,7 @@ export interface NodeHealthCareLocalHealthService extends DrupalNode { export interface NodeHealthCareRegionPage extends DrupalNode { field_appointments_online: boolean - field_media: MediaImage + field_media: DrupalMediaImage field_related_links: ParagraphListOfLinks field_vamc_ehr_system: string field_facebook: FieldLink @@ -212,7 +212,7 @@ export interface NodeNewsStory extends DrupalNode { /** Lede text that is printed larger. */ field_intro_text: string /** An attached image for the story. */ - field_media: MediaImage + field_media: DrupalMediaImage /** Where in the story listing this story should display. */ field_order: number /** Which Story Listing page this story should display on. */ @@ -260,7 +260,7 @@ export interface NodePersonProfile extends DrupalNode { /** Phone number. */ field_phone_number: string /** A photo of the person. */ - field_media: MediaImage + field_media: DrupalMediaImage /** The office or facility which this person is associated with. */ field_office: NodeOffice | NodeHealthCareRegionPage /** Any honorific suffix, i.e. MD, LCSW, PhD, etc. */ diff --git a/src/types/dataTypes/drupal/paragraph.ts b/src/types/dataTypes/drupal/paragraph.ts index 454f32cb7..7e51fe370 100644 --- a/src/types/dataTypes/drupal/paragraph.ts +++ b/src/types/dataTypes/drupal/paragraph.ts @@ -8,7 +8,7 @@ import { FieldOfficeHours, FieldTable, } from './field_type' -import { MediaImage } from './media' +import { DrupalMediaImage } from './media' import { NodeLandingPage, NodePersonProfile, @@ -191,7 +191,7 @@ export interface ParagraphStaffProfile extends DrupalParagraph { export interface ParagraphStep extends DrupalParagraph { field_alert: ParagraphAlertSingle - field_media: MediaImage + field_media: DrupalMediaImage field_wysiwyg: FieldFormattedText } diff --git a/src/types/dataTypes/formatted/administration.ts b/src/types/dataTypes/formatted/administration.ts new file mode 100644 index 000000000..434b9b736 --- /dev/null +++ b/src/types/dataTypes/formatted/administration.ts @@ -0,0 +1,4 @@ +export type Administration = { + id: number + name: string +} diff --git a/src/types/dataTypes/formatted/alert.ts b/src/types/dataTypes/formatted/alert.ts new file mode 100644 index 000000000..c66be8396 --- /dev/null +++ b/src/types/dataTypes/formatted/alert.ts @@ -0,0 +1,9 @@ +export type Alert = { + alertType: string + id: string + title: string + content: { + header?: string + text: string + } +} diff --git a/src/types/dataTypes/formatted/audienceTopics.ts b/src/types/dataTypes/formatted/audienceTopics.ts new file mode 100644 index 000000000..ffcbcf667 --- /dev/null +++ b/src/types/dataTypes/formatted/audienceTopics.ts @@ -0,0 +1,16 @@ +/** + * This is the structure of an individual tag in AudienceTopics. + */ +export type AudienceTopic = { + id: string + href: string + name: string + categoryLabel: string +} + +/** + * This is for a collection of tags. + */ +export type AudienceTopics = { + tags: AudienceTopic[] +} diff --git a/src/types/dataTypes/formatted/banners.ts b/src/types/dataTypes/formatted/banners.ts new file mode 100644 index 000000000..9b7cf8feb --- /dev/null +++ b/src/types/dataTypes/formatted/banners.ts @@ -0,0 +1,37 @@ +export type Banner = { + id: string + title: string + body?: string + alertType?: string + dismiss?: boolean + type?: string +} + +export type PromoBanner = { + id: string + title?: string + href?: string + alertType?: string + dismiss?: boolean + type?: string +} + +export type BannerAlertVamcs = { + id: string + path?: string + office?: { path: string } +} + +export type FacilityBanner = { + id: string + title: string + body?: string + fieldAlertType?: string + dismiss?: boolean + path?: string + type?: string + operatingStatus?: boolean + findFacilities?: string + inheritanceSubpages?: boolean + bannerAlertVamcs?: BannerAlertVamcs[] +} diff --git a/src/types/dataTypes/formatted/benefitsHub.ts b/src/types/dataTypes/formatted/benefitsHub.ts new file mode 100644 index 000000000..927cda596 --- /dev/null +++ b/src/types/dataTypes/formatted/benefitsHub.ts @@ -0,0 +1,12 @@ +export type BenefitsHub = { + id: string + url: string + title: string + homePageHubLabel: string + teaserText: string +} + +export type BenefitsHubLinks = { + title: string + relatedBenefitHubs: BenefitsHub[] +} diff --git a/src/types/dataTypes/formatted/button.ts b/src/types/dataTypes/formatted/button.ts new file mode 100644 index 000000000..ca8a9dc98 --- /dev/null +++ b/src/types/dataTypes/formatted/button.ts @@ -0,0 +1,5 @@ +export type Button = { + id: string + label: string + url: string +} diff --git a/src/types/dataTypes/formatted/emailContact.ts b/src/types/dataTypes/formatted/emailContact.ts new file mode 100644 index 000000000..639f442a8 --- /dev/null +++ b/src/types/dataTypes/formatted/emailContact.ts @@ -0,0 +1,5 @@ +export type EmailContact = { + id: string + label: string + address: string +} diff --git a/src/types/dataTypes/formatted/expandableText.ts b/src/types/dataTypes/formatted/expandableText.ts new file mode 100644 index 000000000..eded5e2f7 --- /dev/null +++ b/src/types/dataTypes/formatted/expandableText.ts @@ -0,0 +1,5 @@ +export type ExpandableText = { + id: string + header: string + text: string +} diff --git a/src/types/dataTypes/formatted/headerFooter.ts b/src/types/dataTypes/formatted/headerFooter.ts new file mode 100644 index 000000000..28a0a6e38 --- /dev/null +++ b/src/types/dataTypes/formatted/headerFooter.ts @@ -0,0 +1,49 @@ +export type FooterLink = { + column: number | string // either # or 'bottom_rail' + href: string + order: number + target?: string + title: string +} + +export type MegaMenuLink = { + text: string + href: string +} + +export type MegaMenuLinkObject = { + mainColumn?: MegaMenuColumn + columnOne?: MegaMenuColumn + columnTwo?: MegaMenuColumn + columnThree?: MegaMenuPromoColumn + columnFour?: MegaMenuColumn + seeAllLink?: MegaMenuLink +} + +export type MegaMenuSection = { + title: string + href?: string + menuSections?: + | (MegaMenuColumn | MegaMenuPromoColumn | MegaMenuLink)[] + | MegaMenuLinkObject +} + +export type MegaMenuColumn = { + title: string + links: MegaMenuLinkObject | MegaMenuLink[] +} + +export type MegaMenuPromoColumn = { + img: { + src: string + alt: string + } + link: MegaMenuLink + description: string +} + +// type expected by window.VetsGov.headerFooter +export type HeaderFooterData = { + footerData?: FooterLink[] + megaMenuData?: MegaMenuSection[] +} diff --git a/src/types/dataTypes/formatted/html.ts b/src/types/dataTypes/formatted/html.ts new file mode 100644 index 000000000..7ba1f6a35 --- /dev/null +++ b/src/types/dataTypes/formatted/html.ts @@ -0,0 +1,3 @@ +export type Html = { + __html: string +} diff --git a/src/types/dataTypes/formatted/linkTeaser.ts b/src/types/dataTypes/formatted/linkTeaser.ts new file mode 100644 index 000000000..b64c2de2b --- /dev/null +++ b/src/types/dataTypes/formatted/linkTeaser.ts @@ -0,0 +1,13 @@ +export type LinkTeaser = { + id: string + title: string + summary: string + uri: string + parentField: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + options: any[] + componentParams: { + boldTitle: boolean + sectionHeader: string + } +} diff --git a/src/types/dataTypes/formatted/media.ts b/src/types/dataTypes/formatted/media.ts new file mode 100644 index 000000000..25fef501e --- /dev/null +++ b/src/types/dataTypes/formatted/media.ts @@ -0,0 +1,24 @@ +export type MediaImageLink = { + [key: string]: { + href: string + meta: { + linkParams: { + width?: number + height?: number + } + } + } +} + +export type MediaImage = { + id: string + alt: string + title: string + url: string + width: number + height: number + link: MediaImageLink + imageStyle?: string + className?: string + style?: string +} diff --git a/src/types/dataTypes/formatted/newsStory.ts b/src/types/dataTypes/formatted/newsStory.ts new file mode 100644 index 000000000..39e96ad01 --- /dev/null +++ b/src/types/dataTypes/formatted/newsStory.ts @@ -0,0 +1,31 @@ +import { ComponentType } from 'react' +import { PersonProfileTeaserProps } from '@/templates/components/personProfile' +import { SocialLinksProps } from '@/templates/common/socialLinks' +import { Administration } from '@/types/dataTypes/formatted/administration' +import { BreadcrumbItem } from '@/types/dataTypes/drupal/field_type' +import { PublishedEntity } from './publishedEntity' +import { MediaImage } from './media' + +export type NewsStoryTeaser = PublishedEntity & { + headingLevel?: ComponentType | keyof JSX.IntrinsicElements + link: string + title: string + image: MediaImage + introText: string +} + +export type NewsStory = PublishedEntity & { + title: string + image: MediaImage + caption: string + author: PersonProfileTeaserProps + introText: string + bodyContent: string + date: string + socialLinks: SocialLinksProps + listing: string + entityId: number + entityPath: string + administration: Administration + breadcrumbs: BreadcrumbItem[] +} diff --git a/src/types/dataTypes/formatted/personProfile.ts b/src/types/dataTypes/formatted/personProfile.ts new file mode 100644 index 000000000..742f1c541 --- /dev/null +++ b/src/types/dataTypes/formatted/personProfile.ts @@ -0,0 +1,28 @@ +import { MediaImage } from './media' +import { + NodeOffice, + NodeHealthCareRegionPage, +} from '@/types/dataTypes/drupal/node' + +export type PersonProfile = { + id: string + type: string + entityId: number + entityPath: string + path: string + title?: string + firstName: string + lastName: string + suffix?: string + emailAddress?: string + phoneNumber?: string + description?: string + introText: string + body: string + media?: MediaImage + completeBiography?: { url: string } + completeBiographyCreate?: boolean + photoAllowHiresDownload?: boolean + vamcOfficalName: string + office: NodeOffice | NodeHealthCareRegionPage //TODO: This should be a formatted office type, not Drupal specific. +} diff --git a/src/types/dataTypes/formatted/publishedEntity.ts b/src/types/dataTypes/formatted/publishedEntity.ts new file mode 100644 index 000000000..5c919a831 --- /dev/null +++ b/src/types/dataTypes/formatted/publishedEntity.ts @@ -0,0 +1,5 @@ +export interface PublishedEntity { + id: string + type: string + published: boolean +} diff --git a/src/types/dataTypes/formatted/questionAnswer.ts b/src/types/dataTypes/formatted/questionAnswer.ts new file mode 100644 index 000000000..13bf52472 --- /dev/null +++ b/src/types/dataTypes/formatted/questionAnswer.ts @@ -0,0 +1,15 @@ +import { PublishedEntity } from './publishedEntity' +import { AudienceTopic } from './audienceTopics' +import { LinkTeaser } from './linkTeaser' +import { Button } from './button' + +export type QuestionAnswer = PublishedEntity & { + title: string + answers: string + buttons: Button[] + tags: AudienceTopic[] + teasers: LinkTeaser[] + className?: string + entityId: number + entityPath: string +} diff --git a/src/types/dataTypes/formatted/sideNav.ts b/src/types/dataTypes/formatted/sideNav.ts new file mode 100644 index 000000000..d852a04c4 --- /dev/null +++ b/src/types/dataTypes/formatted/sideNav.ts @@ -0,0 +1,20 @@ +// These SideNav types are what the vets-website widget expects +export type SideNavItem = { + description: string + expanded: boolean + label: string + links: SideNavItem[] + url: { path: string } + lovellSection?: string +} + +export type SideNavData = { + name: string + description: string + links: SideNavItem[] +} + +export type SideNavMenu = { + rootPath: string + data: SideNavData +} diff --git a/src/types/dataTypes/formatted/staffProfile.ts b/src/types/dataTypes/formatted/staffProfile.ts new file mode 100644 index 000000000..efca870b5 --- /dev/null +++ b/src/types/dataTypes/formatted/staffProfile.ts @@ -0,0 +1,12 @@ +import { MediaImage } from '@/types/dataTypes/formatted/media' + +export type StaffProfile = { + id: string + name: string + thumbnail?: MediaImage + linkToBio?: boolean + path?: string | null + description?: string + phone?: string + email?: string +} diff --git a/src/types/dataTypes/formatted/staticPathResource.ts b/src/types/dataTypes/formatted/staticPathResource.ts new file mode 100644 index 000000000..d7691aa50 --- /dev/null +++ b/src/types/dataTypes/formatted/staticPathResource.ts @@ -0,0 +1,6 @@ +import { Administration } from './administration' + +export type StaticPathResource = { + path: string + administration: Administration +} diff --git a/src/types/dataTypes/formatted/storyListing.ts b/src/types/dataTypes/formatted/storyListing.ts new file mode 100644 index 000000000..e106dbe81 --- /dev/null +++ b/src/types/dataTypes/formatted/storyListing.ts @@ -0,0 +1,21 @@ +import { PublishedEntity } from './publishedEntity' +import { NewsStoryTeaser } from '@/types/dataTypes/formatted/newsStory' +import { SideNavMenu } from '@/types/dataTypes/formatted/sideNav' +import { BreadcrumbItem } from '@/types/dataTypes/drupal/field_type' + +export type StoryListingLink = { + path: string +} + +export type StoryListing = PublishedEntity & { + title: string + introText: string + stories: NewsStoryTeaser[] + menu: SideNavMenu + currentPage: number + totalItems: number + totalPages: number + entityId: number + entityPath: string + breadcrumbs: BreadcrumbItem[] +} diff --git a/src/types/dataTypes/formatted/wysiwyg.ts b/src/types/dataTypes/formatted/wysiwyg.ts new file mode 100644 index 000000000..33cb6951a --- /dev/null +++ b/src/types/dataTypes/formatted/wysiwyg.ts @@ -0,0 +1,5 @@ +export type Wysiwyg = { + id: string + html: string + className?: string +} diff --git a/src/types/index.d.ts b/src/types/index.d.ts deleted file mode 100644 index 884f51580..000000000 --- a/src/types/index.d.ts +++ /dev/null @@ -1,333 +0,0 @@ -import { Menu } from '@/types/dataTypes/drupal/menu' -import { - NodeOffice, - NodeHealthCareRegionPage, -} from '@/types/dataTypes/drupal/node' -import { PathAlias } from 'next-drupal' -import { LovellChildVariant } from '@/lib/drupal/lovell' -import { BreadcrumbItem } from '@/types/dataTypes/drupal/field_type' -export interface PublishedEntity { - id: string - type: string - published: boolean -} - -export type Administration = { - id: number - name: string -} - -export type Path = { - pid?: number - alias?: string - langcode?: string -} - -export type BannerType = { - id: string - title: string - body?: string - alertType?: string - dismiss?: boolean - type?: string -} - -export type PromoBannerType = { - id: string - title?: string - href?: string - alertType?: string - dismiss?: boolean - type?: string -} - -export type BannerAlertVacms = { - id: string - path?: { alias?: string } - field_office?: { path: Path } -} - -export type FacilityBannerType = { - id: string - title: string - body?: string - fieldAlertType?: string - dismiss?: boolean - path?: Path - type?: string - operatingStatus?: boolean - findFacilities?: string - inheritanceSubpages?: boolean - bannerAlertVacms?: BannerAlertVacms[] -} - -export type MediaImageLink = { - href: string - meta: { linkParams: { width: number; height: number } } -} - -export type MediaImageType = { - id: string - alt: string - title: string - url: string - width: number - height: number - link: MediaImageLink - imageStyle?: string - className?: string - style?: string -} - -export type NewsStoryType = PublishedEntity & { - title: string - image: ImageProps - caption: string - author: PersonProfileTeaserProps - introText: string - bodyContent: string - date: string - socialLinks: SocialLinksProps - listing: string - entityId: number - entityPath: string - administration: Administration - breadcrumbs: BreadcrumbItem[] -} - -export type NewsStoryTeaserType = PublishedEntity & { - headingLevel?: ComponentType | keyof JSX.IntrinsicElements - link: string - title: string - image: ImageProps - introText: string -} - -export type PersonProfileType = { - id: string - type: string - entityId: number - entityPath: string - path: Path - title?: string - firstName: string - lastName: string - suffix?: string - emailAddress?: string - phoneNumber?: string - description?: string - introText: string - body: string - media?: MediaImageType - completeBiography?: { url: string } - completeBiographyCreate?: boolean - photoAllowHiresDownload?: boolean - vamcOfficalName: string - office: NodeOffice | NodeHealthCareRegionPage -} - -export type StaffProfileType = { - id: string - name: string - thumbnail?: ImageProps - linkToBio?: boolean - path?: string | null - description?: string - phone?: string - email?: string -} - -export type StoryListingType = PublishedEntity & { - title: string - introText: string - stories: NewsStoryTeaserType[] - menu: SideNavMenu - currentPage: number - totalItems: number - totalPages: number - entityId: number - entityPath: string - breadcrumbs: BreadcrumbItem[] -} - -export type StoryListingLinkType = { - path: string -} - -export type ExpandableTextType = { - id: string - header: string - text: string -} - -export type LinkTeaserType = { - id: string - title: string - summary: string - uri: string - parentField: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options: any[] - componentParams: { - boldTitle: boolean - sectionHeader: string - } -} - -export type ContentFooterType = { - lastUpdated?: string | number -} - -export type LovellSwitcherType = { - currentVariant: LovellChildVariant - switchPath: string -} - -export type StaticPathResourceType = { - path: PathAlias - administration: Administration -} - -// These SideNav types are what the vets-website widget expects -export type SideNavItem = { - description: string - expanded: boolean - label: string - links: SideNavItem[] - url: { path: string } - lovellSection?: string -} - -export type SideNavData = { - name: string - description: string - links: SideNavItem[] -} - -export type SideNavMenu = { - rootPath: string - data: SideNavData -} - -interface ButtonType { - id: string - label: string - url: string -} - -interface AlertType { - alertType: string - id: string - title: string - content: { - header?: string - text: string - } -} - -interface EmailContactType { - id: string - label: string - address: string -} - -interface WysiwygType { - id: string - html: string - className?: string -} - -interface HtmlType { - __html: string -} - -export type QuestionAnswerType = PublishedEntity & { - title: string - answers: string - buttons: ButtonType[] - tags: AudienceTopicType[] - teasers: LinkTeaserType[] - className?: string - entityId: number - entityPath: string -} - -interface BenefitsHubLinksType { - title: string - relatedBenefitHubs: BenefitsHubType[] -} - -interface BenefitsHubType { - id: string - url: string - title: string - homePageHubLabel: string - teaserText: string -} - -/** - * This is the structure of an individual tag in AudienceTopics. - */ -interface AudienceTopicType { - id: string - href: string - name: string - categoryLabel: string -} - -/** - * This is for the paragraph's collection of tags. - */ -interface AudienceTopicsType { - tags: AudienceTopicType[] -} - -// type expected by window.VetsGov.headerFooter -export type HeaderFooterData = { - footerData?: FooterLink[] - megaMenuData?: MegaMenuSection[] -} - -export type FooterLink = { - column: number | string // either # or 'bottom_rail' - href: string - order: number - target?: string - title: string -} - -export type MegaMenuLink = { - text: string - href: string -} - -export type MegaMenuLinkObject = { - mainColumn?: MegaMenuColumn - columnOne?: MegaMenuColumn - columnTwo?: MegaMenuColumn - columnThree?: MegaMenuPromoColumn - columnFour?: MegaMenuColumn - seeAllLink?: MegaMenuLink -} - -export type MegaMenuSection = { - title: string - href?: string - menuSections?: - | (MegaMenuColumn | MegaMenuPromoColumn | MegaMenuLink)[] - | MegaMenuLinkObject -} - -export type MegaMenuColumn = { - title: string - links: MegaMenuLinkObject | MegaMenuLink[] -} - -export type MegaMenuPromoColumn = { - img: { - src: string - alt: string - } - link: MegaMenuLink - description: string -}