From fe41979b1e2e637066f09f4610af376064788599 Mon Sep 17 00:00:00 2001 From: Mubashirshariq Date: Tue, 22 Oct 2024 21:22:30 +0530 Subject: [PATCH 1/2] change runbook title to actual markdown file name --- keep-ui/app/runbooks/runbook-table.tsx | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/keep-ui/app/runbooks/runbook-table.tsx b/keep-ui/app/runbooks/runbook-table.tsx index 33c016b9c..8d5c6b8ff 100644 --- a/keep-ui/app/runbooks/runbook-table.tsx +++ b/keep-ui/app/runbooks/runbook-table.tsx @@ -64,33 +64,34 @@ const columnsv2 = [ id: "title", header: "Runbook Title", cell: ({ row }) => { - return
{row.original.title}
; + const fileName = row.original.file_name; + const runbookTitle = row.original.title; + const displayTitle = fileName ? fileName : runbookTitle; + return
{displayTitle}
}, }), columnHelperv2.display({ - id: "contents", - header: "Contents", - cell: ({ row }) => { - const contents = row.original.contents || []; - const isMoreContentAvailable = contents.length > 4; - return ( -
- {contents.slice(0, 4)?.map((content: Content) => ( - - {content.file_name} - - ))} - {isMoreContentAvailable && ( - {`${ - contents.length - 4 - } more...`} - )} -
- ); - }, + id: "content", + header: "File Name", + cell: ({ row }) => ( + + {console.log("from inside row", row)} + { + row.original.file_name} + + ), }), ] as DisplayColumnDef[]; +const flattenRunbookData = (runbooks: RunbookV2[]) => { + return runbooks.flatMap((runbook) => + runbook.contents.map((content) => ({ + ...runbook, + file_name: content.file_name, + content_id: content.id, + })) + ); +}; function SettingsPage({handleRunbookMutation}:{ handleRunbookMutation: () => void}) { const [isModalOpen, setIsModalOpen] = useState(false); @@ -245,7 +246,6 @@ function RunbookIncidentTable() { return fetcher(url, session?.accessToken!); } ); - const handleRunbookMutation = ()=>{ mutate(`${getApiURL()}/runbooks?limit=${limit}&offset=${0}`); } @@ -254,7 +254,7 @@ function RunbookIncidentTable() { total_count: 0, runbooks: [], }; - + const flattenedData = flattenRunbookData(runbooks || []); const handlePaginationChange = (newLimit: number, newOffset: number) => { setLimit(newLimit); setOffset(newOffset); @@ -279,7 +279,7 @@ function RunbookIncidentTable() { {!isLoading && !error && ( - data={runbooks} + data={flattenedData} columns={columnsv2} rowCount={total_count} offset={offset} From 4186d8170cd34f30a0068bb7836efb39eeeff0c4 Mon Sep 17 00:00:00 2001 From: Mubashirshariq Date: Thu, 24 Oct 2024 15:21:43 +0530 Subject: [PATCH 2/2] runbook title progress 1 --- keep-ui/app/runbooks/runbook-table.tsx | 32 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/keep-ui/app/runbooks/runbook-table.tsx b/keep-ui/app/runbooks/runbook-table.tsx index 8d5c6b8ff..03cf9b8af 100644 --- a/keep-ui/app/runbooks/runbook-table.tsx +++ b/keep-ui/app/runbooks/runbook-table.tsx @@ -58,16 +58,40 @@ interface RunbookV2 { } const columnHelperv2 = createColumnHelper(); +const extractMetadataFromMarkdown = (markdown) => { + const charactersBetweenGroupedHyphens = /^---([\s\S]*?)---/; + const metadataMatched = markdown.match(charactersBetweenGroupedHyphens); + const metadata = metadataMatched[1]; + + if (!metadata) { + return {}; + } + + const metadataLines = metadata.split("\n"); + const metadataObject = metadataLines.reduce((accumulator, line) => { + const [key, ...value] = line.split(":").map((part) => part.trim()); + + if (key) + accumulator[key] = value[1] ? value.join(":") : value.join(""); + return accumulator; + }, {}); + + return metadataObject; +}; const columnsv2 = [ columnHelperv2.display({ id: "title", header: "Runbook Title", cell: ({ row }) => { - const fileName = row.original.file_name; - const runbookTitle = row.original.title; - const displayTitle = fileName ? fileName : runbookTitle; - return
{displayTitle}
+ const titles = row.original.contents.map(content => { + let decodedContent = Buffer.from(content.content, "base64").toString("utf-8"); + console.log(decodedContent); + // const decodedContent = content.decode("utf8"); + // const metadata = extractMetadataFromMarkdown(decodedContent); + // return metadata.title || row.original.title; + }); + return
; }, }), columnHelperv2.display({