Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vacms 15949 cleanup #243

Merged
merged 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/data/queries/alert.ts
Original file line number Diff line number Diff line change
@@ -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<BlockAlert, AlertType> = (
export const formatter: QueryFormatter<BlockAlert, Alert> = (
entity: BlockAlert
) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/audienceTopics.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,7 +39,7 @@ const getTagsList = (fieldTags) => {
*/
export const formatter: QueryFormatter<
ParagraphAudienceTopics,
AudienceTopicType[]
AudienceTopic[]
> = (entity: ParagraphAudienceTopics) => {
return getTagsList(entity)
}
10 changes: 7 additions & 3 deletions src/data/queries/banners.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -16,7 +20,7 @@ export const BannerTypeMapping = {

export const formatter: QueryFormatter<
NodeBanner[],
Array<PromoBannerType | BannerType | FacilityBannerType | NodeBanner>
Array<PromoBanner | Banner | FacilityBanner | NodeBanner>
> = (entities: NodeBanner[]) => {
return entities?.map((banner) => {
switch (banner?.type as string) {
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/benefitsHub.ts
Original file line number Diff line number Diff line change
@@ -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<NodeLandingPage, BenefitsHubType> = (
export const formatter: QueryFormatter<NodeLandingPage, BenefitsHub> = (
entity: NodeLandingPage
) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/button.ts
Original file line number Diff line number Diff line change
@@ -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<ParagraphButton, ButtonType> = (
export const formatter: QueryFormatter<ParagraphButton, Button> = (
entity: ParagraphButton
) => {
return {
Expand Down
9 changes: 4 additions & 5 deletions src/data/queries/emailContact.ts
Original file line number Diff line number Diff line change
@@ -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<ParagraphEmailContact, EmailContact> = (
entity: ParagraphEmailContact
) => {
return {
id: entity.id,
label: entity.field_email_label || null,
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/expandableText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> = () => {
return queries.getParams().addPageLimit(10)
Expand All @@ -32,7 +32,7 @@ export const data: QueryData<DataOpts, ParagraphExpandableText[]> = async (

export const formatter: QueryFormatter<
ParagraphExpandableText[],
ExpandableTextType[]
ExpandableText[]
> = (entities: ParagraphExpandableText[]) => {
return entities.map((entity) => ({
id: entity.id,
Expand Down
2 changes: 1 addition & 1 deletion src/data/queries/headerFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/linkTeaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> = () => {
Expand All @@ -30,7 +30,7 @@ export const data: QueryData<DataOpts, ParagraphLinkTeaser[]> = async (
return entities
}

export const formatter: QueryFormatter<ParagraphLinkTeaser, LinkTeaserType> = (
export const formatter: QueryFormatter<ParagraphLinkTeaser, LinkTeaser> = (
entity: ParagraphLinkTeaser
) => {
return {
Expand Down
18 changes: 10 additions & 8 deletions src/data/queries/mediaImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -25,10 +25,10 @@ type DataOpts = QueryOpts<{
}>

// Implement the data loader.
export const data: QueryData<DataOpts, MediaImageData> = async (
export const data: QueryData<DataOpts, DrupalMediaImageData> = async (
opts
): Promise<MediaImageData> => {
const entity = await drupalClient.getResource<MediaImage>(
): Promise<DrupalMediaImageData> => {
const entity = await drupalClient.getResource<DrupalMediaImage>(
'media--image',
opts.id,
{
Expand All @@ -39,12 +39,14 @@ export const data: QueryData<DataOpts, MediaImageData> = async (
return { entity, cropType: opts.cropType || '2_1_large' }
}

export const formatter: QueryFormatter<MediaImageData, MediaImageType> = ({
export const formatter: QueryFormatter<DrupalMediaImageData, MediaImage> = ({
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,
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/newsStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -54,7 +54,7 @@ export const data: QueryData<NewsStoryDataOpts, NodeNewsStory> = async (
return entity
}

export const formatter: QueryFormatter<NodeNewsStory, NewsStoryType> = (
export const formatter: QueryFormatter<NodeNewsStory, NewsStory> = (
entity: NodeNewsStory
) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/newsStoryTeaser.ts
Original file line number Diff line number Diff line change
@@ -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<null> = () => {
Expand All @@ -10,7 +10,7 @@ export const params: QueryParams<null> = () => {
.addInclude(['field_media', 'field_media.image', 'field_listing'])
}

export const formatter: QueryFormatter<NodeNewsStory, NewsStoryTeaserType> = (
export const formatter: QueryFormatter<NodeNewsStory, NewsStoryTeaser> = (
entity: NodeNewsStory
) => {
return {
Expand Down
9 changes: 4 additions & 5 deletions src/data/queries/personProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> = () => {
Expand Down Expand Up @@ -35,10 +35,9 @@ export const data: QueryData<DataOpts, NodePersonProfile[]> = async (): Promise<
return entities
}

export const formatter: QueryFormatter<
NodePersonProfile,
PersonProfileType[]
> = (entities: NodePersonProfile) => {
export const formatter: QueryFormatter<NodePersonProfile, PersonProfile[]> = (
entities: NodePersonProfile
) => {
if (!entities) return null

return entities.map((entity) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/data/queries/promoBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/questionAnswer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> = () => {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const data: QueryData<DataOpts, NodeQA> = async (
return entity
}

export const formatter: QueryFormatter<NodeQA, QuestionAnswerType> = (
export const formatter: QueryFormatter<NodeQA, QuestionAnswer> = (
entity: NodeQA
) => {
const buttons = entity.field_buttons?.map((button) => {
Expand Down
14 changes: 7 additions & 7 deletions src/data/queries/staticPathResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.'
Expand All @@ -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<ResourceTypeType> = (
resourceType: ResourceTypeType
export const params: QueryParams<ResourceType> = (
resourceType: ResourceType
) => {
return (
queries
Expand All @@ -35,7 +35,7 @@ export const params: QueryParams<ResourceTypeType> = (

// Define the option types for the data loader.
type DataOpts = QueryOpts<{
resourceType: ResourceTypeType
resourceType: ResourceType
}>

type JsonApiResourceWithPathAndFieldAdmin = JsonApiResourceWithPath & {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/storyListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -102,7 +102,7 @@ export const data: QueryData<ListingPageDataOpts, StoryListingData> = async (
}
}

export const formatter: QueryFormatter<StoryListingData, StoryListingType> = ({
export const formatter: QueryFormatter<StoryListingData, StoryListing> = ({
entity,
stories,
menu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports[`Banners return formatted data outputs formatted data 1`] = `
},
{
"alertType": "information",
"bannerAlertVacms": [
"bannerAlertVamcs": [
{
"id": "8822bbdd-f5f8-4700-8abb-5566431bd705",
"resourceIdObjMeta": {
Expand Down
4 changes: 2 additions & 2 deletions src/data/queries/tests/mediaImage.test.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/data/queries/utils.ts
Original file line number Diff line number Diff line change
@@ -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<T> = {
Expand All @@ -21,7 +21,7 @@ function addPagingParams(
}

export async function fetchSingleResourceCollectionPage<T>(
resourceType: ResourceTypeType,
resourceType: ResourceType,
params: DrupalJsonApiParams,
pageSize: number,
pageNumber: number
Expand All @@ -46,7 +46,7 @@ export async function fetchSingleResourceCollectionPage<T>(
}

export async function fetchAndConcatAllResourceCollectionPages<T>(
resourceType: ResourceTypeType,
resourceType: ResourceType,
params: DrupalJsonApiParams,
pageSize: number
): Promise<ResourceCollection<T>> {
Expand Down
Loading
Loading