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

fix: APPS-3065 Refactor TagLabels Parsing Logic #69

Merged
merged 6 commits into from
Nov 14, 2024
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
22 changes: 5 additions & 17 deletions pages/events/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import removeTags from '../utils/removeTags'
import { useContentIndexer } from '~/composables/useContentIndexer'

// UTILS
import { getEventFilterLabels } from '~/utils/getEventFilterLabels'

const { $graphql } = useNuxtApp()

Expand Down Expand Up @@ -128,24 +129,11 @@ const parsedFTVAEventScreeningDetails = computed(() => {
})
})

// Extract tag labels from event filters
const parsedTagLabels = computed(() => {
if (!page.value.ftvaEventTypeFilters && !page.value.ftvaScreeningFormatFilters) {
return []
}

const parsedLabels = []
const typeFilters = page.value.ftvaEventTypeFilters
const formatFilters = page.value.ftvaScreeningFormatFilters

if (typeFilters.length) {
typeFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}

if (formatFilters.length) {
formatFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}

return parsedLabels
const eventObj = page.value
const parsedTagLabels = getEventFilterLabels(eventObj)
return parsedTagLabels
})

useHead({
Expand Down
27 changes: 5 additions & 22 deletions pages/series/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import _get from 'lodash/get'
// GQL
import FTVAEventSeriesDetail from '../gql/queries/FTVAEventSeriesDetail.gql'

// UTIL
import { getEventFilterLabels } from '~/utils/getEventFilterLabels'

// COMPOSABLE
import { useContentIndexer } from '~/composables/useContentIndexer'
import removeTags from '~/utils/removeTags'
Expand Down Expand Up @@ -98,7 +101,7 @@ const parsedUpcomingEvents = computed(() => {

// Transform data
return upcomingEvents.value.map((item, index) => {
const parsedTagLabels = getParsedTagLabels(item)
const parsedTagLabels = getEventFilterLabels(item)

return {
...item,
Expand All @@ -116,7 +119,7 @@ const parsedPastEvents = computed(() => {

// Transform data
return pastEvents.value.map((item, index) => {
const parsedTagLabels = getParsedTagLabels(item)
const parsedTagLabels = getEventFilterLabels(item)

return {
...item,
Expand All @@ -127,26 +130,6 @@ const parsedPastEvents = computed(() => {
})
})

function getParsedTagLabels(obj) {
if (!obj.ftvaEventTypeFilters && !obj.ftvaScreeningFormatFilters) {
return []
}

const parsedLabels = []
const typeFilters = obj.ftvaEventTypeFilters
const formatFilters = obj.ftvaScreeningFormatFilters

if (typeFilters.length) {
typeFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}

if (formatFilters.length) {
formatFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}

return parsedLabels
}

// If no Upcoming Events, set starting tab to Past Events
const parsedInitialTabIndex = computed(() => {
if (parsedUpcomingEvents.value.length === 0) {
Expand Down
28 changes: 28 additions & 0 deletions utils/getEventFilterLabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Extract tag labels from FTVA filters (ftvaScreeningFormatFilters,
ftvaEventTypeFilters) and return as a single array

* @param {Object}
* @returns {Array}
*/

export function getEventFilterLabels(obj) {
if (!obj.ftvaEventTypeFilters && !obj.ftvaScreeningFormatFilters) {
return []
}

const parsedTagLabels = []

const eventTypeFilters = obj.ftvaEventTypeFilters
const screeningFormatFilters = obj.ftvaScreeningFormatFilters

if (eventTypeFilters.length) {
eventTypeFilters.forEach(obj => parsedTagLabels.push({ title: obj.title }))
}

if (screeningFormatFilters.length) {
screeningFormatFilters.forEach(obj => parsedTagLabels.push({ title: obj.title }))
}

return parsedTagLabels
}
Loading