mirror of
https://github.com/nathonius/obsidian-github-link.git
synced 2026-07-22 09:20:25 +00:00
Merge pull request #37 from nathonius/feat/28/default-columns
✨ feat: #28 Add default columns for simple queries
This commit is contained in:
commit
89954b11eb
2 changed files with 19 additions and 7 deletions
7
src/query/column/defaults.ts
Normal file
7
src/query/column/defaults.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { QueryType } from "../params";
|
||||
|
||||
export const DEFAULT_COLUMNS = {
|
||||
[QueryType.Issue]: ["number", "title", "author", "created", "status"],
|
||||
[QueryType.PullRequest]: ["number", "title", "author", "created", "status"],
|
||||
[QueryType.Repo]: [],
|
||||
};
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
import { getProp, titleCase } from "src/util";
|
||||
|
||||
import type { BaseParams } from "./params";
|
||||
import { QueryType } from "./params";
|
||||
import { PullRequestColumns } from "./column/pull-request";
|
||||
import { DEFAULT_COLUMNS } from "./column/defaults";
|
||||
import { IssueColumns } from "./column/issue";
|
||||
import { PullRequestColumns } from "./column/pull-request";
|
||||
import { QueryType } from "./params";
|
||||
import { RepoColumns } from "./column/repo";
|
||||
|
||||
const columns = {
|
||||
const ALL_COLUMNS = {
|
||||
[QueryType.PullRequest]: PullRequestColumns,
|
||||
[QueryType.Issue]: IssueColumns,
|
||||
[QueryType.Repo]: RepoColumns,
|
||||
|
|
@ -19,18 +20,22 @@ export async function renderTable<T extends { items: unknown[] } | unknown[]>(
|
|||
) {
|
||||
const table = el.createEl("table", { cls: "github-link-table" });
|
||||
const thead = table.createEl("thead");
|
||||
for (const col of params.columns) {
|
||||
let columns = params.columns;
|
||||
if (!columns || columns.length === 0) {
|
||||
columns = DEFAULT_COLUMNS[params.queryType];
|
||||
}
|
||||
for (const col of columns) {
|
||||
const th = thead.createEl("th");
|
||||
// Get predefined header if available
|
||||
th.setText(columns[params.queryType][col]?.header ?? titleCase(col));
|
||||
th.setText(ALL_COLUMNS[params.queryType][col]?.header ?? titleCase(col));
|
||||
}
|
||||
const tbody = table.createEl("tbody");
|
||||
const items = Array.isArray(result) ? result : result.items;
|
||||
for (const row of items) {
|
||||
const tr = tbody.createEl("tr");
|
||||
for (const col of params.columns) {
|
||||
for (const col of columns) {
|
||||
const cell = tr.createEl("td");
|
||||
const renderer = columns[params.queryType][col];
|
||||
const renderer = ALL_COLUMNS[params.queryType][col];
|
||||
if (renderer) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
renderer.cell(row as any, cell);
|
||||
|
|
|
|||
Loading…
Reference in a new issue