-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add events query/formatter/layout #264
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf1bb59
WIP debugging
jtmst 73e4981
WIP data
jtmst 43c4b32
types fixed, layout complete
jtmst 126f088
types fixed
jtmst b8b02b6
prettier
jtmst 9247e6c
prettier/storybook
jtmst 56616f8
cleanup
jtmst 92c4c27
Merge branch 'main' into 15908-events
jtmst 8b02e52
typescript
jtmst 236035e
Merge branch '15908-events' of github.com:department-of-veterans-affa…
jtmst 68bddc0
more typescript
jtmst 63a969e
lint
jtmst aba5b7f
jest snapshot
jtmst d4b8238
reord files
jtmst d787381
social links restructure, tests
jtmst 3626830
cleanup
jtmst e25bdda
fixed test
jtmst c57d82c
playwright and PR feedback
jtmst ac653d5
lint
jtmst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ body { | |
margin-top: 0; | ||
padding-top: 1.25rem; | ||
} | ||
|
||
.recurring-event { | ||
max-width: 140px; | ||
} |
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,86 @@ | ||
import { | ||
QueryData, | ||
QueryFormatter, | ||
QueryOpts, | ||
QueryParams, | ||
} from 'next-drupal-query' | ||
import { drupalClient } from '@/lib/drupal/drupalClient' | ||
import { queries } from '.' | ||
import { NodeEvent } from '@/types/dataTypes/drupal/node' | ||
import { Event } from '@/types/dataTypes/formatted/event' | ||
import { GetServerSidePropsContext } from 'next' | ||
import { MediaImage } from '@/types/dataTypes/formatted/media' | ||
|
||
export const params: QueryParams<null> = () => { | ||
return queries | ||
.getParams() | ||
.addInclude([ | ||
'field_media', | ||
'field_media.image', | ||
'field_listing', | ||
'field_administration', | ||
'field_facility_location', | ||
]) | ||
} | ||
|
||
// Define the option types for the data loader. | ||
export type EventDataOpts = QueryOpts<{ | ||
id: string | ||
context?: GetServerSidePropsContext | ||
}> | ||
|
||
export const data: QueryData<EventDataOpts, NodeEvent> = async ( | ||
opts | ||
): Promise<NodeEvent> => { | ||
const entity = opts?.context?.preview | ||
? // need to use getResourceFromContext for unpublished revisions | ||
await drupalClient.getResourceFromContext<NodeEvent>( | ||
'node--event', | ||
opts.context, | ||
{ | ||
params: params().getQueryObject(), | ||
} | ||
) | ||
: // otherwise just lookup by uuid | ||
await drupalClient.getResource<NodeEvent>('node--event', opts.id, { | ||
params: params().getQueryObject(), | ||
}) | ||
return entity | ||
} | ||
|
||
export const formatter: QueryFormatter<NodeEvent, Event> = ( | ||
entity: NodeEvent | ||
) => { | ||
return { | ||
id: entity.id, | ||
entityId: entity.drupal_internal__nid, | ||
entityPath: entity.path.alias, | ||
type: entity.type, | ||
published: entity.status, | ||
title: entity.title, | ||
image: queries.formatData('media--image', { | ||
entity: entity.field_media, | ||
cropType: '2_1_large', | ||
}) as MediaImage, | ||
date: entity.created, | ||
breadcrumbs: entity.breadcrumbs, | ||
socialLinks: { | ||
path: entity.path.alias, | ||
title: entity.title, | ||
}, | ||
metatags: entity.metatag, | ||
listing: entity.field_listing.path.alias, | ||
additionalInfo: entity.field_additional_information_abo, | ||
address: entity.field_address, | ||
locationHumanReadable: entity.field_location_humanreadable, | ||
eventCTA: entity.field_event_cta, | ||
cost: entity.field_event_cost, | ||
datetimeRange: entity.field_datetime_range_timezone, | ||
facilityLocation: entity.field_facility_location, | ||
body: entity.field_body, | ||
locationType: entity.field_location_type, | ||
description: entity.field_description, | ||
link: entity.field_link, | ||
urlOfOnlineEvent: entity.field_url_of_an_online_event, | ||
} | ||
} |
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,91 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`node--event formatData outputs formatted data 1`] = ` | ||
{ | ||
"additionalInfo": null, | ||
"address": { | ||
"address_line1": "9000 Douglas Ave", | ||
"address_line2": "", | ||
"administrative_area": "IA", | ||
"country_code": "US", | ||
"langcode": "en", | ||
"locality": "Urbandale", | ||
}, | ||
"body": { | ||
"format": "rich_text", | ||
"processed": "<p>Pickleball Club</p> | ||
|
||
<p>Meets Thursdays from 9 to 11 a.m. </p> | ||
|
||
<p>Contact Kay Queck (515) 214-4578</p>", | ||
"value": "<p>Pickleball Club</p> | ||
|
||
<p>Meets Thursdays from 9 to 11 a.m. </p> | ||
|
||
<p>Contact Kay Queck (515) 214-4578</p> | ||
", | ||
}, | ||
"breadcrumbs": [ | ||
{ | ||
"options": [], | ||
"title": "Home", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "VA Central Iowa health care", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "Events", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care/events", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "Pickleball Club", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care/events/52265", | ||
}, | ||
], | ||
"cost": "Free", | ||
"date": "2022-12-30T14:49:05+00:00", | ||
"datetimeRange": [ | ||
{ | ||
"duration": 120, | ||
"end_value": "2023-09-07T16:00:00+00:00", | ||
"rrule": 180, | ||
"rrule_index": 1, | ||
"timezone": "America/Chicago", | ||
"value": "2023-09-07T14:00:00+00:00", | ||
}, | ||
{ | ||
"duration": 120, | ||
"end_value": "2023-09-14T16:00:00+00:00", | ||
"rrule": 180, | ||
"rrule_index": 2, | ||
"timezone": "America/Chicago", | ||
"value": "2023-09-14T14:00:00+00:00", | ||
}, | ||
], | ||
"description": "Pickleball ", | ||
"entityId": 52265, | ||
"entityPath": "/central-iowa-health-care/events/52265", | ||
"eventCTA": null, | ||
"facilityLocation": null, | ||
"id": "16349f16-be65-46e3-9660-1d3d598a4a0b", | ||
"image": null, | ||
"link": null, | ||
"listing": "/central-iowa-health-care/events", | ||
"locationHumanReadable": "Walker Johnston Park", | ||
"locationType": "non_facility", | ||
"metatags": null, | ||
"published": true, | ||
"socialLinks": { | ||
"path": "/central-iowa-health-care/events/52265", | ||
"title": "Pickleball Club", | ||
}, | ||
"title": "Pickleball Club", | ||
"type": "node--event", | ||
"urlOfOnlineEvent": null, | ||
} | ||
`; |
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,23 @@ | ||
import { NodeEvent } from '@/types/dataTypes/drupal/node' | ||
import { queries } from '@/data/queries' | ||
import mockData from '@/mocks/event.mock.json' | ||
|
||
const nodeEventMock: NodeEvent = mockData | ||
|
||
describe('node--event formatData', () => { | ||
let windowSpy | ||
|
||
beforeEach(() => { | ||
windowSpy = jest.spyOn(window, 'window', 'get') | ||
}) | ||
|
||
afterEach(() => { | ||
windowSpy.mockRestore() | ||
}) | ||
|
||
test('outputs formatted data', () => { | ||
windowSpy.mockImplementation(() => undefined) | ||
const formattedData = queries.formatData('node--event', nodeEventMock) | ||
expect(formattedData).toMatchSnapshot() | ||
}) | ||
}) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be for EVENT_LISTING instead of EVENT