-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 16290-event-listings
- Loading branch information
Showing
13 changed files
with
293 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { QueryData, QueryFormatter, QueryParams } from 'next-drupal-query' | ||
import { queries } from '.' | ||
import { RESOURCE_TYPES } from '@/lib/constants/resourceTypes' | ||
import { fetchAndConcatAllResourceCollectionPages } from '@/lib/drupal/query' | ||
import { VamcEhr as DrupalVamcEhr } from '@/types/drupal/vamcEhr' | ||
import { VamcEhrGraphQLMimic } from '@/types/formatted/vamcEhr' | ||
import { PAGE_SIZES } from '@/lib/constants/pageSizes' | ||
|
||
const PAGE_SIZE = PAGE_SIZES.MAX | ||
|
||
// Define the query params for fetching node--health_care_local_facility. | ||
export const params: QueryParams<null> = () => { | ||
return queries | ||
.getParams() | ||
.addFields(RESOURCE_TYPES.VAMC_FACILITY, [ | ||
'title', | ||
'field_facility_locator_api_id', | ||
'field_region_page', | ||
]) | ||
.addFilter('field_main_location', '1') | ||
.addInclude(['field_region_page']) | ||
.addFields(RESOURCE_TYPES.VAMC_SYSTEM, ['title', 'field_vamc_ehr_system']) | ||
} | ||
|
||
// Implement the data loader. | ||
export const data: QueryData<null, DrupalVamcEhr[]> = async (): Promise< | ||
DrupalVamcEhr[] | ||
> => { | ||
const { data } = | ||
await fetchAndConcatAllResourceCollectionPages<DrupalVamcEhr>( | ||
RESOURCE_TYPES.VAMC_FACILITY, | ||
params(), | ||
PAGE_SIZE | ||
) | ||
return data | ||
} | ||
|
||
export const formatter: QueryFormatter<DrupalVamcEhr[], VamcEhrGraphQLMimic> = ( | ||
entities: DrupalVamcEhr[] | ||
) => { | ||
// For now, return data formatted as it is in content-build (mimic GraphQL output). | ||
// In future, we should move the formatting from the preProcess in vets-website | ||
// into this formatter and, while it exists, into postProcess in content-build. | ||
// This change will require a coordinated effort so as to not break things with regard | ||
// to what vets-website is expecting and what is present in the generated file. | ||
return { | ||
data: { | ||
nodeQuery: { | ||
count: entities.length, | ||
entities: entities.map((entity) => ({ | ||
title: entity.title, | ||
fieldFacilityLocatorApiId: entity.field_facility_locator_api_id, | ||
fieldRegionPage: { | ||
entity: { | ||
title: entity.field_region_page.title, | ||
fieldVamcEhrSystem: | ||
entity.field_region_page.field_vamc_ehr_system, | ||
}, | ||
}, | ||
})), | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { | ||
RESOURCE_TYPES, | ||
ADDITIONAL_RESOURCE_TYPES, | ||
} from '@/lib/constants/resourceTypes' | ||
import { RESOURCE_TYPES } from '@/lib/constants/resourceTypes' | ||
|
||
export const PAGE_SIZES = { | ||
[RESOURCE_TYPES.STORY_LISTING]: 10, | ||
[RESOURCE_TYPES.EVENT_LISTING]: 50, | ||
[ADDITIONAL_RESOURCE_TYPES.STATIC_PATHS]: 50, //must be <= 50 due to JSON:API limit | ||
MAX: 50, //50 is JSON:API limit. Use this for fetching as many as possible at a time. | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
GetStaticPathsContext, | ||
GetStaticPathsResult, | ||
GetStaticPropsContext, | ||
} from 'next' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { QueryDataOptsMap, queries } from '@/data/queries' | ||
|
||
type StaticJsonFile<T extends keyof QueryDataOptsMap> = { | ||
filename: string | ||
query: T | ||
queryOpts?: QueryDataOptsMap[T] | ||
} | ||
|
||
const STATIC_JSON_FILES: Array<StaticJsonFile<keyof QueryDataOptsMap>> = [ | ||
{ | ||
filename: 'vamc-ehr', | ||
query: 'vamc-ehr', | ||
} as StaticJsonFile<'vamc-ehr'>, | ||
|
||
// Another example: | ||
// { | ||
// filename: 'hypothetical-banner-data-static-json-file', | ||
// query: 'banner-data', //must be defined in QUERIES_MAP in src/data/queries/index.ts | ||
// queryOpts: { | ||
// itemPath: 'path/to/item', | ||
// }, | ||
// } as StaticJsonFile<'banner-data'>, | ||
] | ||
|
||
/* This component never generates a page, but this default export must be present */ | ||
export default function StaticJsonPage() { | ||
return null | ||
} | ||
|
||
export async function getStaticPaths( | ||
context: GetStaticPathsContext | ||
): Promise<GetStaticPathsResult> { | ||
if (process.env.SSG === 'false') { | ||
return { | ||
paths: [], | ||
fallback: 'blocking', | ||
} | ||
} | ||
|
||
return { | ||
paths: STATIC_JSON_FILES.map(({ filename }) => ({ | ||
params: { | ||
filename, | ||
}, | ||
})), | ||
fallback: 'blocking', | ||
} | ||
} | ||
|
||
export async function getStaticProps(context: GetStaticPropsContext) { | ||
const staticJsonFilename = context.params?.filename | ||
const staticJsonFile = STATIC_JSON_FILES.find( | ||
({ filename }) => filename === staticJsonFilename | ||
) | ||
if (staticJsonFile) { | ||
const { filename, query, queryOpts = {} } = staticJsonFile | ||
|
||
// fetch data | ||
const data = await queries.getData(query, queryOpts) | ||
|
||
// Write to /public/data/cms | ||
const filePath = path.resolve(`public/data/cms/${filename}.json`) | ||
const directoryPath = path.dirname(filePath) | ||
if (!fs.existsSync(directoryPath)) { | ||
fs.mkdirSync(directoryPath, { | ||
recursive: true, | ||
}) | ||
} | ||
fs.writeFileSync(filePath, JSON.stringify(data)) | ||
} | ||
return { | ||
notFound: true, | ||
} | ||
} |
Oops, something went wrong.