-
Notifications
You must be signed in to change notification settings - Fork 0
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
taken lectures api/#35 #36
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2b3b861
remove: delete table root page
gahyuun 45404ad
remove: sample stories
gahyuun 61e8442
refactor: add list row key prop
gahyuun ab4b204
chore: change table type
gahyuun fe690cf
feat: implement taken lecture list query
gahyuun 03877b3
feat: implement taken lecture list mock data
gahyuun 1c42387
style: change table width style
gahyuun 4e1da15
feat: implement taken lecture list component
gahyuun 4005d3f
feat: implement taken lecture title component
gahyuun 26a7685
chore: merge branch main
gahyuun 0a1a557
chore: interface -> type
gahyuun 8a218ab
refactor: change table data type
gahyuun 5aa2967
rename: taken lecture -> lecture
gahyuun 45eae33
feat: implement label container component
gahyuun 5f3b5f6
refactor: change taken lecture label role
gahyuun 6d2461e
chore: fix next link import
gahyuun be454f7
test: implement taken lecture list rendering test code
gahyuun ca6c51d
rename: taken lecture title -> taken lecture label
gahyuun aa0c3aa
chore: modifying type name to Pascal Case
gahyuun 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import TakenLectureList from '@/app/ui/lecture/taken-lecture-list'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
describe('Taken lecture list', () => { | ||
it('๊ธฐ์ด์ ๊ณผ๋ชฉ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋ค.', async () => { | ||
render(await TakenLectureList()); | ||
expect(await screen.findByTestId('table-data')); | ||
}); | ||
}); |
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,20 @@ | ||
import { API_PATH } from '../api-path'; | ||
|
||
type LectureInfo = { | ||
id: number; | ||
year: string; | ||
semester: string; | ||
lectureCode: string; | ||
lectureName: string; | ||
credit: number; | ||
}; | ||
type TakenLectures = { | ||
totalCredit: number; | ||
takenLectures: LectureInfo[]; | ||
}; | ||
|
||
export const fetchTakenLectures = async (): Promise<TakenLectures> => { | ||
const response = await fetch(API_PATH.takenLectures); | ||
const data = await response.json(); | ||
return data; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Link from 'next/link'; | ||
import Button from '../view/atom/button/button'; | ||
import LabelContainer from '../view/atom/label-container/label-container'; | ||
|
||
export default function TakenLectureLabel() { | ||
return ( | ||
<LabelContainer | ||
label="๋ด ๊ธฐ์ด์ ๊ณผ๋ชฉ" | ||
rightElement={ | ||
<div className="flex gap-2"> | ||
<Button label="์ปค์คํ ํ๊ธฐ" variant="secondary" size="md" /> | ||
<Link href="/file-upload"> | ||
<Button label="์ ๋ฐ์ดํธ" variant="secondary" size="md" /> | ||
</Link> | ||
</div> | ||
} | ||
/> | ||
); | ||
} |
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,15 @@ | ||
import { fetchTakenLectures } from '@/app/business/lecture/taken-lecture-list.query'; | ||
import { Table } from '../view/molecule/table'; | ||
import TakenLectureLabel from './taken-lecture-label'; | ||
|
||
const headerInfo = ['์๊ฐ๋ ๋', '์๊ฐํ๊ธฐ', '๊ณผ๋ชฉ์ฝ๋', '๊ณผ๋ชฉ๋ช ', 'ํ์ ']; | ||
|
||
export default async function TakenLectureList() { | ||
const data = await fetchTakenLectures(); | ||
return ( | ||
<div className="w-[800px] flex flex-col gap-2"> | ||
<TakenLectureLabel /> | ||
<Table headerInfo={headerInfo} data={data.takenLectures} /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
app/ui/view/atom/label-container/label-container.stories.tsx
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,40 @@ | ||
import React from 'react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import LabelContainer from './label-container'; | ||
import Button from '../button/button'; | ||
|
||
const meta = { | ||
title: 'ui/view/atom/Button', | ||
component: LabelContainer, | ||
tags: ['autodocs'], | ||
parameters: { | ||
componentSubtitle: 'LabelContainer๋ ๊ธฐ์ด์, ๋ฏธ์ด์ ๊ณผ๋ชฉ์ ๋ํ ์ ๋ณด๋ฅผ ๋ํ๋ผ ๋ ์ฌ์ฉ๋๋ view component์ ๋๋ค.', | ||
docs: { | ||
description: { | ||
component: ` | ||
- label ๊ฐ์ผ๋ก ํ๋ฉด์ ์ถ๋ ฅํ๊ณ ์ถ์ text๋ฅผ ํ ๋นํด์ผํฉ๋๋ค. \n | ||
- right element ๊ฐ์ผ๋ก ์ค๋ฅธ์ชฝ์ ๋ ๋๋ง ๋ ์์๋ฅผ ํ ๋นํด์ผํฉ๋๋ค. \n | ||
`, | ||
}, | ||
}, | ||
}, | ||
} satisfies Meta<typeof LabelContainer>; | ||
|
||
export default meta; | ||
|
||
export const TakenLectureLabel: StoryObj<typeof LabelContainer> = { | ||
args: { | ||
label: '๋ด ๊ธฐ์ด์ ๊ณผ๋ชฉ', | ||
rightElement: ( | ||
<div className="flex gap-2"> | ||
<Button label="์ปค์คํ ํ๊ธฐ" variant="secondary" size="md" /> | ||
<Button label="์ ๋ฐ์ดํธ" variant="secondary" size="md" /> | ||
</div> | ||
), | ||
}, | ||
render: (args) => ( | ||
<div className="w-[800px]"> | ||
<LabelContainer {...args} /> | ||
</div> | ||
), | ||
}; |
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,15 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
type LabelContainerProps = { | ||
label: string; | ||
rightElement: ReactNode; | ||
}; | ||
|
||
export default function LabelContainer({ label, rightElement }: LabelContainerProps) { | ||
return ( | ||
<div className="flex justify-between items-center w-full"> | ||
<div className="rounded-[100px] bg-light-blue-6 p-2.5 text-white text-lg font-bold">{label}</div> | ||
{rightElement} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
type ListRootProps<T> = { | ||
data: T[]; | ||
render: (item: T) => ReactNode; | ||
export type ListRow = { [key: string]: string | number; id: number }; | ||
type ListRootProps = { | ||
data: ListRow[]; | ||
render: (item: ListRow, index: number) => ReactNode; | ||
}; | ||
|
||
export function ListRoot<T>({ data, render }: ListRootProps<T>) { | ||
return <div className="rounded-2xl border-[1px] border-black-2 w-full">{data.map((item) => render(item))}</div>; | ||
export function ListRoot({ data, render }: ListRootProps) { | ||
return ( | ||
<div className="rounded-2xl border-[1px] border-black-2 w-full"> | ||
{data.map((item, index) => render(item, index))} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,43 @@ | ||
import { TableHeader } from './table-header'; | ||
import { TableRoot } from './table-root'; | ||
import { ColType } from '../grid/grid-root'; | ||
import List from '../list'; | ||
import Grid from '../grid'; | ||
import { ListRow } from '../list/list-root'; | ||
|
||
const Table = Object.assign(TableRoot, { | ||
Header: TableHeader, | ||
}); | ||
type TableProps = { | ||
headerInfo: string[]; | ||
data: ListRow[]; | ||
renderActionButton?: (id: number) => JSX.Element; | ||
}; | ||
|
||
export default Table; | ||
function isCol(cols: number): cols is ColType { | ||
if (cols === 3 || cols === 4 || cols === 5 || cols === 6) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export function Table({ data, headerInfo, renderActionButton }: TableProps) { | ||
const cols = renderActionButton ? headerInfo.length + 1 : headerInfo.length; | ||
|
||
const render = (item: ListRow, index: number) => { | ||
return ( | ||
<List.Row key={index}> | ||
<Grid cols={isCol(cols) ? cols : 6}> | ||
{Object.keys(item).map((key, index) => { | ||
if (key === 'id') return null; | ||
return <Grid.Column key={index}>{item[key]}</Grid.Column>; | ||
})} | ||
{renderActionButton ? <Grid.Column>{renderActionButton(item.id)}</Grid.Column> : null} | ||
</Grid> | ||
</List.Row> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-2.5 w-full" data-testid="table-data"> | ||
<TableHeader headerInfo={headerInfo} cols={isCol(cols) ? cols : 6} /> | ||
<List data={data} render={render} /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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.
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.
[comment]
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.
๊ธฐ์ด์ ๊ณผ๋ชฉ ๋ฆฌ์คํธ๊ฐ ๋ฐ์ดํฐ๋ฅผ ํธ์ถํด์ ์ ๋ ๋๋ง ํ๋ ์ง ํ์ธํด์ผ ํ์ต๋๋ค!
๋ค๋ฅธ ํ ์คํธ์ฒ๋ผ findByText ๋ฅผ ์ด์ฉํ๊ธฐ์ ์ด๋ค ๋ฐ์ดํฐ๊ฐ ๋ค์ด์ฌ ์ง ๋ชจ๋ฅด๊ธฐ ๋๋ฌธ์ test id๋ฅผ ์ฌ์ฉํ์ต๋๋ค!
๋ฐ์ดํฐ๊ฐ ๋ฌธ์ ์์ด ํธ์ถ๋๋ฉด table์ด ์ ์์ ์ผ๋ก ๋ ๋๋ง ๋ ๊ฒ์ด๋ผ๊ณ ํ๋จํ๊ธฐ ๋๋ฌธ์ ๋๋ค~!
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.
https://docs.cypress.io/guides/references/best-practices#Selecting-Elements