Skip to content

Commit

Permalink
feat(apps): cms - semesters/undergrad relationship, virtual field for…
Browse files Browse the repository at this point in the history
… internal semester label.
  • Loading branch information
johnnycrich committed Jun 18, 2024
1 parent cc316a3 commit 09a9333
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 19 deletions.
36 changes: 35 additions & 1 deletion apps/cms/admin/schema/elab/lists/semester.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { list } from '@keystone-6/core';
import { graphql, list } from '@keystone-6/core';
import {
checkbox,
multiselect,
relationship,
select,
text,
virtual,
} from '@keystone-6/core/fields';
import { document } from '@keystone-6/fields-document';
import { allowAll } from '@keystone-6/core/access';
Expand Down Expand Up @@ -189,6 +190,15 @@ const Semester: Lists.Semester = list({
many: true,
ui: Conditional('current'),
}),
undergrad: relationship({
ref: 'Undergraduate.featuredSemesters',
many: true,
ui: {
createView: { fieldMode: 'hidden' },
itemView: { fieldMode: 'hidden' },
listView: { fieldMode: 'hidden' },
},
}),

// --- UPCOMING SEMESTER ---
previewThumbnail: cloudinaryImage({
Expand Down Expand Up @@ -229,6 +239,30 @@ const Semester: Lists.Semester = list({
},
ui: Conditional('upcoming'),
}),

// Label for CMS use
internalLabel: virtual({
field: graphql.field({
type: graphql.String,
resolve(item, args, context) {
if (item.initiatives) {
const initiativeKeys = item.initiatives as string[];
if (initiativeKeys.length > 0) {
const initiativeLabels: string[] = [];
initiativeKeys.forEach((key) =>
initiativeLabels.push(key === 'gunviolence' ? 'TNGV' : 'TNEJ')
);
return `${item.name} (${initiativeLabels.join(', ')})`;
} else return `${item.name} (N/A)`;
} else return item.name;
},
}),
ui: {
createView: { fieldMode: 'hidden' },
itemView: { fieldMode: 'hidden' },
listView: { fieldMode: 'hidden' },
},
}),
},

ui: {
Expand Down
9 changes: 9 additions & 0 deletions apps/cms/admin/schema/elab/lists/undergraduate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import { group, list } from '@keystone-6/core';
import { relationship, text } from '@keystone-6/core/fields';
import { document } from '@keystone-6/fields-document';
Expand Down Expand Up @@ -73,6 +74,14 @@ const Undergraduate: Lists.Undergraduate = list({
many: true,
ui: { hideCreate: true },
}),

featuredSemesters: relationship({
ref: 'Semester.undergrad',
many: true,
ui: {
labelField: 'internalLabel',
},
}),
...group(Social()),
studioPreviews: StudioPreviews,
},
Expand Down
47 changes: 29 additions & 18 deletions apps/cms/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1828,12 +1828,15 @@ type Semester {
studioStudentsCount(where: PersonWhereInput! = {}): Int
studioStaff(where: PersonWhereInput! = {}, orderBy: [PersonOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: PersonWhereUniqueInput): [Person!]
studioStaffCount(where: PersonWhereInput! = {}): Int
undergrad(where: UndergraduateWhereInput! = {}, orderBy: [UndergraduateOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: UndergraduateWhereUniqueInput): [Undergraduate!]
undergradCount(where: UndergraduateWhereInput! = {}): Int
previewThumbnail: CloudinaryImage_File
previewThumbAltText: String
previewSummary: Semester_previewSummary_Document
previewVideo: VideoFieldOutput
captions: AzureStorageFileFieldOutput
previewVideoThumbnail: CloudinaryImage_File
internalLabel: String
}

enum SemesterStatusType {
Expand Down Expand Up @@ -1903,6 +1906,7 @@ input SemesterWhereInput {
learningPartners: PersonManyRelationFilter
studioStudents: PersonManyRelationFilter
studioStaff: PersonManyRelationFilter
undergrad: UndergraduateManyRelationFilter
previewThumbAltText: StringFilter
}

Expand All @@ -1920,6 +1924,12 @@ input SemesterTypeTypeNullableFilter {
not: SemesterTypeTypeNullableFilter
}

input UndergraduateManyRelationFilter {
every: UndergraduateWhereInput
some: UndergraduateWhereInput
none: UndergraduateWhereInput
}

input SemesterOrderByInput {
id: OrderDirection
name: OrderDirection
Expand Down Expand Up @@ -1953,6 +1963,7 @@ input SemesterUpdateInput {
learningPartners: PersonRelateToManyForUpdateInput
studioStudents: PersonRelateToManyForUpdateInput
studioStaff: PersonRelateToManyForUpdateInput
undergrad: UndergraduateRelateToManyForUpdateInput
previewThumbnail: Upload
previewThumbAltText: String
previewSummary: JSON
Expand All @@ -1973,6 +1984,13 @@ input SlideshowRelateToOneForUpdateInput {
disconnect: Boolean
}

input UndergraduateRelateToManyForUpdateInput {
disconnect: [UndergraduateWhereUniqueInput!]
set: [UndergraduateWhereUniqueInput!]
create: [UndergraduateCreateInput!]
connect: [UndergraduateWhereUniqueInput!]
}

input SemesterUpdateArgs {
where: SemesterWhereUniqueInput!
data: SemesterUpdateInput!
Expand All @@ -1998,6 +2016,7 @@ input SemesterCreateInput {
learningPartners: PersonRelateToManyForCreateInput
studioStudents: PersonRelateToManyForCreateInput
studioStaff: PersonRelateToManyForCreateInput
undergrad: UndergraduateRelateToManyForCreateInput
previewThumbnail: Upload
previewThumbAltText: String
previewSummary: JSON
Expand All @@ -2016,6 +2035,11 @@ input SlideshowRelateToOneForCreateInput {
connect: SlideshowWhereUniqueInput
}

input UndergraduateRelateToManyForCreateInput {
create: [UndergraduateCreateInput!]
connect: [UndergraduateWhereUniqueInput!]
}

type Slide {
id: ID!
slideshowSlides(where: SlideshowWhereInput! = {}, orderBy: [SlideshowOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: SlideshowWhereUniqueInput): [Slideshow!]
Expand Down Expand Up @@ -2434,12 +2458,6 @@ input FilterManyRelationFilter {
none: FilterWhereInput
}

input UndergraduateManyRelationFilter {
every: UndergraduateWhereInput
some: UndergraduateWhereInput
none: UndergraduateWhereInput
}

input StudioProjectOrderByInput {
id: OrderDirection
name: OrderDirection
Expand Down Expand Up @@ -2503,13 +2521,6 @@ input FilterRelateToManyForUpdateInput {
connect: [FilterWhereUniqueInput!]
}

input UndergraduateRelateToManyForUpdateInput {
disconnect: [UndergraduateWhereUniqueInput!]
set: [UndergraduateWhereUniqueInput!]
create: [UndergraduateCreateInput!]
connect: [UndergraduateWhereUniqueInput!]
}

input StudioProjectUpdateArgs {
where: StudioProjectWhereUniqueInput!
data: StudioProjectUpdateInput!
Expand Down Expand Up @@ -2558,11 +2569,6 @@ input FilterRelateToManyForCreateInput {
connect: [FilterWhereUniqueInput!]
}

input UndergraduateRelateToManyForCreateInput {
create: [UndergraduateCreateInput!]
connect: [UndergraduateWhereUniqueInput!]
}

type Undergraduate {
id: ID!
name: String
Expand All @@ -2573,6 +2579,8 @@ type Undergraduate {
socialImpactDesign: Undergraduate_socialImpactDesign_Document
projectSpotlight(where: StudioProjectWhereInput! = {}, orderBy: [StudioProjectOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: StudioProjectWhereUniqueInput): [StudioProject!]
projectSpotlightCount(where: StudioProjectWhereInput! = {}): Int
featuredSemesters(where: SemesterWhereInput! = {}, orderBy: [SemesterOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: SemesterWhereUniqueInput): [Semester!]
featuredSemestersCount(where: SemesterWhereInput! = {}): Int
ogImage: CloudinaryImage_File
helper: HelperFieldOutput
ogDescription: String
Expand Down Expand Up @@ -2601,6 +2609,7 @@ input UndergraduateWhereInput {
introImageAltText: StringFilter
introImageCaption: StringFilter
projectSpotlight: StudioProjectManyRelationFilter
featuredSemesters: SemesterManyRelationFilter
ogDescription: StringFilter
}

Expand All @@ -2620,6 +2629,7 @@ input UndergraduateUpdateInput {
introImageCaption: String
socialImpactDesign: JSON
projectSpotlight: StudioProjectRelateToManyForUpdateInput
featuredSemesters: SemesterRelateToManyForUpdateInput
ogImage: Upload
helper: HelperFieldInput
ogDescription: String
Expand All @@ -2638,6 +2648,7 @@ input UndergraduateCreateInput {
introImageCaption: String
socialImpactDesign: JSON
projectSpotlight: StudioProjectRelateToManyForCreateInput
featuredSemesters: SemesterRelateToManyForCreateInput
ogImage: Upload
helper: HelperFieldInput
ogDescription: String
Expand Down
2 changes: 2 additions & 0 deletions apps/cms/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ model Semester {
learningPartners Person[] @relation("Person_learningPartners")
studioStudents Person[] @relation("Person_studioStudents")
studioStaff Person[] @relation("Person_studioStaff")
undergrad Undergraduate[] @relation("Semester_undergrad")
previewThumbnail Json?
previewThumbAltText String @default("")
previewSummary Json @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
Expand Down Expand Up @@ -408,6 +409,7 @@ model Undergraduate {
introImageCaption String @default("")
socialImpactDesign Json @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
projectSpotlight StudioProject[] @relation("StudioProject_undergrad")
featuredSemesters Semester[] @relation("Semester_undergrad")
ogImage Json?
helper_html String @default("<p>Need HTML!</p>")
helper_iconType icon @default(help)
Expand Down

0 comments on commit 09a9333

Please sign in to comment.