Skip to content

Add sortable Age (Days) column to GitLab branches export - #6

Merged
pingkunga merged 11 commits into
feature/add_buildRequest2026from
copilot/add-age-days-column
Jun 5, 2026
Merged

Add sortable Age (Days) column to GitLab branches export#6
pingkunga merged 11 commits into
feature/add_buildRequest2026from
copilot/add-age-days-column

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Adds a numeric branch age column to the GitLab Branches admin table so branch age can be sorted directly in the UI and included in Excel exports. The change derives age from created_at and keeps export layout aligned with the new field.

  • Table updates

    • Added getAgeDays() to compute whole-day branch age from created_at
    • Added a new Age (Days) column to the branches table
    • Enabled sorting on the new column using the computed numeric accessor value
  • Export updates

    • Included AgeDays in the Excel row mapping
    • Adjusted worksheet column widths to account for the added export column
  • Edge-case handling

    • Returns 0 for missing, invalid, or future timestamps to avoid NaN/negative values in the table and export
const getAgeDays = (dateString: string | undefined) => {
  if (!dateString) return 0;

  const dayInMilliseconds = 1000 * 60 * 60 * 24;
  const date = new Date(dateString);
  if (Number.isNaN(date.getTime())) return 0;

  const diffInMilliseconds = Math.max(0, now.getTime() - date.getTime());
  return Math.floor(diffInMilliseconds / dayInMilliseconds);
};
Original prompt

Add a new "Age (Days)" column to the GitLab Branches table that:

  1. Calculates the number of days since branch creation
  2. Supports sorting by clicking the column header
  3. Includes the new column in Excel exports

Changes needed:

  • Add getAgeDays() function to calculate days from created_at date
  • Add new column definition with enableSorting: true to columns array
  • Update Excel export to include the Age (Days) value
  • Update worksheet column widths to accommodate the new column

File to modify: app/pages/admin/branches/index.vue

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: @pingkunga/simple-redmine-client/files/app/pages/admin/branches/index.vue จากไฟลฺ์นี้

ถ้าเราอยากเพิ่ม Column Age (Days) แล้วให้มัน Sort ได้ไหม

Assistant: ใช่ได้! สามารถเพิ่ม Column Age (Days) ที่ sortable ได้ ต้องสร้าง computed value สำหรับจำนวนวันที่ผ่านไป แล้วเพิ่มเป็น column ใหม่

ให้ฉันสร้าง solution สำหรับคุณ:

Assistant: ได้ไหม ลองเพิ่ม Column Age (Days) ที่สามารถ Sort ได้ต่อไปเลย

เพิ่ม 2 อย่าง:

  1. ฟังก์ชัน getAgeDays() - คำนวณจำนวนวันจาก created_at
  2. Column ใหม่ Age (Days) - แสดงจำนวนวันและเซ็ต enableSorting: true เพื่อให้ Sort ได้
// เพิ่มฟังก์ชันนี้หลัง formatDate และ getRelativeAge
const getAgeDays = (dateString: string | undefined): number => {
  if (!dateString) return 0;
  const date = new Date(dateString);
  const now = new Date();
  const diffInMilliseconds = now.getTime() - date.getTime();
  return Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24));
};

จากนั้นเพิ่ม Column ใหม่ในอาร์เรย์ columns หลังจาก "Created At (Age)" column:

{ 
  accessorKey: 'ageDays', 
  header: 'Age (Days)',
  enableSorting: true,
  sortingFn: 'auto',
  cell: ({ row }: any) => {
    const branch = row.original as GitLabBranch
    const days = getAgeDays(branch.created_at)
    return h('span', { class: 'font-medium' }, days.toString())
  }
}

และอัปเดต getExportBranches() ให้ export Column นี้ด้วย:

const rows = exportBranches.map((b: any) => ({
  Name: b.name,
  Creator: b.creator_name || '',
  CreatedAt: formatDate(b.created_at),
  Age: getRelativeAge(b.created_at),
  AgeDays: getAgeDays(b.created_at),  // ← เพิ่มบรรทัดนี้
  CommitTitle: b.commit?.title || '',
  ...
}))

// และอัปเดต worksheet['!cols'] 
worksheet['!cols'] = [
  { wch: 30 }, // Name
  { wch: 20 }, // Creator
  { wch: 14 }, // CreatedAt
  { wch: 12 }, // Age
  { wch: 10 }, // AgeDays ← เพิ่ม
  { wch: 50 }, // CommitTitle
  ...
]

เพียงเท่านี้ Column Age (Days) ก็จะสามารถ Sort ได้โดยคลิกที่ Header ของ Column นั้น! 📊

User: ถ้าจะให้แก้เลย ทำได้ไหม

Assistant: รอการยืนยันจากคุณเพื่อให้ฉันสร้าง Pull Request ด้วยการแก้ไขเพิ่ม Age (Days) column ได้

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Add age (days) column to GitLab Branches table Add sortable Age (Days) column to GitLab branches export Jun 5, 2026
Copilot AI requested a review from pingkunga June 5, 2026 10:10
Copilot stopped work on behalf of pingkunga due to an error June 5, 2026 10:11
@pingkunga
pingkunga marked this pull request as ready for review June 5, 2026 14:41
@pingkunga
pingkunga merged commit b54dc5e into feature/add_buildRequest2026 Jun 5, 2026
3 of 4 checks passed
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.

2 participants