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

Dojo(admin) Create lessons home page. Part 2: Lessons Page #2023

Merged
merged 21 commits into from
Jul 27, 2022

Conversation

HS-90
Copy link
Collaborator

@HS-90 HS-90 commented Jun 28, 2022

Title: enhancement : Create a lessons homepage with Lesson Card components for Dojo(Admin).

Description:

Related to #1959

Create a lessons homepage with the ability to Add New Lessons, Edit Lessons, view questions from students for each lesson.

In this PR. The Lessons page is created. Please see screenshots below.

Included in the PR is an alteration to the AdminLessonCard component CSS. The description section of the card was assigned a min-height to make each card look more uniform when aligned against eachother in the Lessons page.

EDIT 7/7/22: In conjunction with this PR, a seperate PR for the generated query getFlaggedExercises has been made #2055 . In addition, a custom Lesson type has been included in both AdminLessonCard and the new lessons page. This was done so that the data types are consistent when passing them to each component.

New admin lessons page screenshot:
image

@vercel
Copy link

vercel bot commented Jun 28, 2022

@HS-90 is attempting to deploy a commit to the c0d3-prod Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
c0d3-app ✅ Ready (Inspect) Visit Preview Jul 25, 2022 at 6:26PM (UTC)

@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #2023 (aee1961) into master (43b69fc) will not change coverage.
The diff coverage is 100.00%.

❗ Current head aee1961 differs from pull request most recent head a9f56f9. Consider uploading reports for the commit a9f56f9 to get more accurate results

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2023   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          170       171    +1     
  Lines         2937      2953   +16     
  Branches       780       785    +5     
=========================================
+ Hits          2937      2953   +16     
Impacted Files Coverage Δ
components/admin/lessons/AdminLessonCard.tsx 100.00% <ø> (ø)
graphql/resolvers/exerciseCrud.ts 100.00% <ø> (ø)
pages/admin/lessons/new/index.tsx 100.00% <100.00%> (ø)

import Link from 'next/link'
import styles from '../../../../scss/adminLessonPage.module.scss'

type Lesson = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont we already have a Lesson type? It should be in the graphql/index file

Copy link
Collaborator Author

@HS-90 HS-90 Jul 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Lesson type from graphql doesn't match the lessons object type from the getApp query so it will throw a type-error . It needs to match the type shown here:

c0d3-app/graphql/index.tsx

Lines 695 to 715 in a5ad3d3

export type GetAppQuery = {
__typename?: 'Query'
lessons: Array<{
__typename?: 'Lesson'
id: number
title: string
description: string
docUrl?: string | null
githubUrl?: string | null
videoUrl?: string | null
order: number
slug: string
chatUrl?: string | null
challenges: Array<{
__typename?: 'Challenge'
id: number
title: string
description: string
order: number
}>
}>

,but without the array. So my current solution was to create a Lessons object mirroring what's shown in the link.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks the same to me. The Lesson type in the index file has currentUsers and users as fields, but those are optional fields so that shouldn't throw any errors

export type Lesson = {

So when you use this Lesson type instead of the one you created, you say there is a type error?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when you use the Lesson type from index file , you use it as Lesson[] right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
i use Lesson[] like shown above when when using the Lesson type directly imported from graphql/index.

These are the main errors showing :
Type '{ __typename?: "Challenge" | undefined; id: number; title: string; description: string; order: number; }[]' is not assignable to type 'Challenge[]'.
Property 'lessonId' is missing in type '{ __typename?: "Challenge" | undefined; id: number; title: string; description: string; order: number; }' but required in type 'Challenge'.

It appears the Challenge field from the imported Lesson type is not compatible with the Lesson type defined in the GetAppQuery
image

Copy link
Member

@flacial flacial Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we'll need to add lessonId to getAppQuery.

Copy link
Collaborator

@anthonykhoa anthonykhoa Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much time to think of further proposals, but here are two proposals without needing to rewrite the entire Lesson type in this file:

  1. Do what @flacial suggested and add lessonId to getAppQuery
  2. Try to use typescript utils to delete fields you don't want

Example:

interface Lesson {
  title: string;
  challenges: Challenge[]
}

interface Challenge {
  order: number
  lessonId: string
}

type removedLessonId = Omit<Challenge, "lessonId">;


type LessonType = Omit<Lesson, "challenges"> & { challenges: removedLessonId[] }

const lessons: LessonType = {
  title: "Pick up kids",
  challenges: [{
    order: 4
  }],
};

I'm not super familiar with typescript, so i'm not sure this is how to best use typescript for this situation. There are maybe other ways more appropriate to implement for this situation than my given proposal.

Copy link
Collaborator Author

@HS-90 HS-90 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anthonykhoa I ended up going with this stackoverflow: https://stackoverflow.com/questions/47914536/use-partial-in-nested-property-with-typescript

Basically modify the Lessons type from graphql to be able to accept partial keys in the AdminLessonCard file.
image

That way if the lessonId field from challenges is missing, Typescript will still accept the modified type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants