Skip to content

Commit

Permalink
Add filter tags to generic list items
Browse files Browse the repository at this point in the history
  • Loading branch information
RunarVestmann committed Jun 11, 2024
1 parent 619c1ca commit b20e9f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libs/cms/src/lib/generated/contentfulTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,9 @@ export interface IGenericListFields {

/** Item Type */
itemType?: 'Non-clickable' | 'Clickable' | undefined

/** Filter Tags */
filterTags?: IGenericTag[] | undefined
}

/** A list of items which can be embedded into rich text */
Expand Down Expand Up @@ -1585,11 +1588,14 @@ export interface IGenericListItemFields {
/** Card Intro */
cardIntro?: Document | undefined

/** Slug */
slug?: string | undefined

/** Content */
content?: Document | undefined

/** Slug */
slug?: string | undefined
/** Filter Tags */
filterTags?: IGenericTag[] | undefined
}

/** An item that belongs to a generic list */
Expand Down
5 changes: 5 additions & 0 deletions libs/cms/src/lib/models/genericList.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CacheField } from '@island.is/nest/graphql'
import { IGenericList, IGenericListFields } from '../generated/contentfulTypes'
import { GenericListItemResponse } from './genericListItemResponse.model'
import { GetGenericListItemsInput } from '../dto/getGenericListItems.input'
import { GenericTag, mapGenericTag } from './genericTag.model'

enum GenericListItemType {
NonClickable = 'NonClickable',
Expand All @@ -28,6 +29,9 @@ export class GenericList {

@CacheField(() => GenericListItemType, { nullable: true })
itemType?: GenericListItemType

@CacheField(() => [GenericTag], { nullable: true })
filterTags?: GenericTag[]
}

const mapItemType = (itemType?: IGenericListFields['itemType']) =>
Expand All @@ -49,4 +53,5 @@ export const mapGenericList = ({
},
searchInputPlaceholder: fields.searchInputPlaceholder,
itemType: mapItemType(fields.itemType),
filterTags: fields.filterTags ? fields.filterTags.map(mapGenericTag) : [],
})
5 changes: 5 additions & 0 deletions libs/cms/src/lib/models/genericListItem.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Field, ID, ObjectType } from '@nestjs/graphql'
import { SliceUnion, mapDocument } from '../unions/slice.union'
import { GenericList, mapGenericList } from './genericList.model'
import { IGenericListItem } from '../generated/contentfulTypes'
import { GenericTag, mapGenericTag } from './genericTag.model'

@ObjectType()
export class GenericListItem {
Expand All @@ -26,6 +27,9 @@ export class GenericListItem {

@Field(() => String, { nullable: true })
slug?: string

@CacheField(() => [GenericTag], { nullable: true })
filterTags?: GenericTag[]
}

export const mapGenericListItem = ({
Expand All @@ -45,4 +49,5 @@ export const mapGenericListItem = ({
? mapDocument(fields.content, `${sys.id}:content`)
: [],
slug: fields.slug,
filterTags: fields.filterTags ? fields.filterTags.map(mapGenericTag) : [],
})
6 changes: 5 additions & 1 deletion libs/cms/src/lib/search/importers/genericListItem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export class GenericListItemSyncService
2,
)

const tags: MappedData['tags'] = []
const tags: MappedData['tags'] =
mapped.filterTags?.map((tag) => ({
type: 'genericTag',
key: tag.id,
})) ?? []

if (mapped.genericList) {
tags.push({
Expand Down

0 comments on commit b20e9f7

Please sign in to comment.