Skip to content

ドキュメント一覧ページを作成する #38

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

Merged
merged 46 commits into from
Apr 8, 2025

Conversation

kazuma-naka
Copy link
Contributor

@kazuma-naka kazuma-naka commented Dec 12, 2024

Issue

1回目の提出

概要

  • docs テーブルの migration ファイルの作成
  • seed.sql に docs テーブルにデータを挿入するSQL構文の追加
  • Docs ページを作成
  • Docs ページにリストとページャーを設置

変更確認方法

  1. ブランチfeature/create-docs-listをローカルに取り込む
  2. npm run devでローカル環境を立ち上げる

変更前

agent_before_modify

変更後

top page

top_page

docs

docs_page

概要

  • docs テーブルの migration ファイルの作成
  • seed.sql に docs テーブルにデータを挿入するSQL構文の追加
  • Docs ページを作成
  • Docs ページにリストとページャーを設置
  • ページャー, ドキュメントリストはコンポネントとして作成
  • useDocs hook の作成

itemsPerPage で表示するドキュメント数を設定できるようにする

 <DocList itemsPerPage={20} />

BootCamp のドキュメント一覧と同じような仕様を心がけました。

  • 20のドキュメントをページごとに表示
  • 1ページ目を選択すると 1~ 5 のボタンが表示される

変更確認方法

  1. ブランチfeature/create-docs-listをローカルに取り込む
  2. npm run devでローカル環境を立ち上げる

変更前

agent_before_modify

変更後

top page

top_page

docs

修正前

after_docs

doc-list-shadcn

コンポネントテストの実装

  • DocList.test.tsx
    モックの Docs が表示されるかテスト
  • Pagination.test.tsx
    最初のページ、最後のページ、現在のページから一つ前、後のページに遷移するボタンが表示されているか、クリックすると遷移するかテストする。

## E2E テストの実装
- doclist.test.ts

Supawright でテスト用の docs データを作成。
created_at 順で新しいものからソートされるようにする。
テストデータにはテスト時の時間を渡すことで一番初めにテストデータが表示されるようにする。
このPRではE2Eテストは実装しない

@kazuma-naka kazuma-naka self-assigned this Dec 12, 2024
Copy link

vercel bot commented Dec 12, 2024

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

Name Status Preview Comments Updated (UTC)
agent ❌ Failed (Inspect) Mar 4, 2025 11:21pm

@kazuma-naka kazuma-naka requested a review from komagata December 12, 2024 17:31
import { useState, useEffect } from "react";
import supabase from "../../lib/supabase";

interface Doc {
Copy link
Member

Choose a reason for hiding this comment

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

DBにあるテーブルの型はsupabaseの機能で生成したものを使ってください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

型を supabase の機能で生成したものに変更しました🖊

const [totalPages, setTotalPages] = useState(0);
const [loading, setLoading] = useState(true);

const fetchDocs = async (page: number) => {
Copy link
Member

Choose a reason for hiding this comment

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

テストしやすいようにページにはコンポーネントを置くだけの感じでお願いします〜。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

docs/page.tsx にコンポネントを置くだけに変更しました🖊

@@ -0,0 +1,9 @@
import SingleLayout from "@/components/layouts/SingleLayout";

export default function DashboardLayout({
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export default function DashboardLayout({
export default function DocsLayout({

の方がいいかも?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DocsLayout に修正しました🖊

<li>
<Link href="/dashboard">ダッシュボード</Link>
</li>
{links.map((link, index) => (
Copy link
Member

Choose a reason for hiding this comment

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

👍

import supabase from "../lib/supabase";
import Pagination from "./Pagination";

interface Doc {
Copy link
Member

Choose a reason for hiding this comment

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

これって自分で手書き定義しているからsupabaseの機能で生成した型を使っていることにならないかな〜と思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type Doc = Tables<"docs">;

に変更しました🖊

https://supabase.com/docs/guides/api/rest/generating-types#type-shorthands

updated_at TIMESTAMP DEFAULT NOW(),
user_id INT NOT NULL,
last_updated_user_id INT NOT NULL
);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

最終行に改行を挿入しました🖊
またエディタの設定で最後に改行されるようにしました⚙

@kazuma-naka
Copy link
Contributor Author

@komagata さん、
こちらも修正が終わりましたので確認よろしくおねがいします。

@komagata
Copy link
Member

komagata commented Jan 8, 2025

これに対するcomponent test, e2e testの作成をお願いします。

@komagata
Copy link
Member

komagata commented Feb 9, 2025

@kazuma-naka こちら、最後のコメントが僕になっているので、該当箇所が修正完了して、再度レビューが必要という状態になったらメンションで連絡お願いします。

今の状態はどういう状態ですか?(どちらがやり取りのボールを持っているのか)

@kazuma-naka
Copy link
Contributor Author

@kazuma-naka こちら、最後のコメントが僕になっているので、該当箇所が修正完了して、再度レビューが必要という状態になったらメンションで連絡お願いします。

今の状態はどういう状態ですか?(どちらがやり取りのボールを持っているのか)

お疲れ様です。
現在 Jyouma さんにレビューを依頼しており、Jyouma さんから LGTM をいただいてから駒形さんにレビュー依頼を再度する予定です。
ですのでやり取りのボールはわたしは持っていないと思います。

@@ -0,0 +1,53 @@
"use client";
Copy link
Member

Choose a reason for hiding this comment

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

@m0nch1 @firewood next.jsのデフォルトがサーバーなのでそっちがいいかなと思うのですが何が一般的ですかね?

Choose a reason for hiding this comment

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

App Routerとしては、できるだけ (client側の) hooksに依存せずに、サーバーで処理するのが基本なのかなと思います。
webで見つかるサンプルはclientのほうが多いようですね。

Copy link

Choose a reason for hiding this comment

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

ページネーションが hooks なので、そこを切り出して use client にするのがいいかも 🤔

Copy link
Member

Choose a reason for hiding this comment

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

@firewood @m0nch1

お二人は逆の意見ってことですかね。
う〜ん、どっちに刷るのがいいですかね〜

Copy link

Choose a reason for hiding this comment

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

@komagata cc: @kazuma-naka

逆ではなく、できるところは server で処理した方が良いかなという意見でした!
ページネーションの state とかは use client じゃないとできない気がするのでその部分は client component になると思うんですが、他のところは server にできると良いのかな〜という気持ちです!

Copy link
Member

Choose a reason for hiding this comment

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

@m0nch1

ページネーションの state とかは use client じゃないとできない気がするので

すみません、こちら意味が理解できなかったのですが、もう少しご説明いただければありがたいです〜。

Choose a reason for hiding this comment

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

ページネーションですが、

  • server側でページネーションし、指定されたページを返す
  • server側で全部返しておいて、clientでページネーションする
    の後者の意味かなと思います。
    普通にserverで実装すると前者になりそうですが、ページの行き来や、フィルタ条件を動的に変えるなら後者になるのかなと思います。

Copy link
Member

Choose a reason for hiding this comment

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

@firewood なるほどです、回答ありがとうございます。
@m0nch1 上記いかがでしょうか?

Copy link

Choose a reason for hiding this comment

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

hotpepsi さんの記載の通りです!!
返信遅れました 🙏

Copy link
Member

Choose a reason for hiding this comment

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

@m0nch1 @firewood なるほどです。回答ありがとうございます。

Copy link
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

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

僕も確認させて頂きました。OKです〜🙆‍♂️

@komagata komagata removed the request for review from Jyoumama April 8, 2025 06:39
@komagata komagata merged commit 296bbe1 into main Apr 8, 2025
4 of 6 checks passed
@komagata komagata deleted the feature/create-docs-list branch April 8, 2025 06:39
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.

4 participants