Skip to content

[UX] Admin UI: Accept full S3 URL / s3:// URI in the prefix input and auto-extract the prefix #5

@ogawsh

Description

@ogawsh

[UX] Admin UI の S3 Prefix 入力欄で、S3 console の URL / s3:// URI を貼ると自動で prefix 部分だけ抽出してほしい

背景

Admin UI の「既存 S3 パス指定」モードで CSV を指定するとき、プレースホルダ通りに testdata/ といったプレフィックスだけを貼ろうとすると、普段 S3 コンソールや aws s3 cp で扱っているのは下記のような完全な URL / URI であることが多く、毎回手で先頭を削るのが面倒。

  • S3 コンソール "Copy URL" で得られる HTTPS URL:
    https://20260422-sample-text2sql-agent-databucket.s3.ap-northeast-1.amazonaws.com/testcase/C01-manufacturing-decimal-overflow/
    
  • s3:// URI 形式:
    s3://20260422-sample-text2sql-agent-databucket/testcase/C01-manufacturing-decimal-overflow/
    

現状、この文字列をそのまま貼ると list-csv API に "https://..." が渡って失敗するので、利用者がエラーを見てから手で testcase/C01-manufacturing-decimal-overflow/ だけに削る必要がある。

提案

frontend/admin/src/components/UploadAndBuild.tsxs3Prefix state の書き込み経路(L253 の setS3Prefix コールバック、または handleListCsv 直前)で、入力文字列から prefix 部分だけを抽出する正規化関数を通す。

function normalizeS3Prefix(input: string): string {
  let s = input.trim();
  // s3://bucket/prefix → prefix
  s = s.replace(/^s3:\/\/[^\/]+\//, '');
  // https://bucket.s3.region.amazonaws.com/prefix → prefix (virtual-hosted style)
  s = s.replace(/^https?:\/\/[^\/]+\.s3[.-][^\/]+\.amazonaws\.com\//, '');
  // https://s3.region.amazonaws.com/bucket/prefix → prefix (path style)
  s = s.replace(/^https?:\/\/s3[.-][^\/]+\.amazonaws\.com\/[^\/]+\//, '');
  // S3 console URL (https://ap-northeast-1.console.aws.amazon.com/s3/buckets/<bucket>?...&prefix=<encoded>&...) の prefix クエリ
  const m = s.match(/[?&]prefix=([^&]+)/);
  if (m) {
    try { s = decodeURIComponent(m[1]); } catch { /* noop */ }
  }
  // 先頭スラッシュを除去
  s = s.replace(/^\/+/, '');
  return s;
}
  • onChange の段階でリアルタイムに置換すると「貼り付け直後に先頭が勝手に消える」UX になるので、onPasteonBlur、または handleListCsv の冒頭で呼ぶのがおすすめ
  • helper text に「s3://... や https://...amazonaws.com/... をそのまま貼っても OK です」の文言追加

期待する挙動

  • S3 console の "Copy URL" で得られる HTTPS URL をそのまま貼れる
  • s3://bucket/prefix/ 形式もそのまま貼れる
  • バケット名が対象バケット 20260422-sample-text2sql-agent-databucket と違う場合は警告を出す(任意)

参考情報

  • 関連ファイル: frontend/admin/src/components/UploadAndBuild.tsx L252 以降

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions