From 7ff94ad4fbf92e1307dad0f9cf9df50499060e5e Mon Sep 17 00:00:00 2001 From: Aayush Srivastava Date: Sun, 12 Jan 2025 16:47:48 +0530 Subject: [PATCH] lint Signed-off-by: Aayush Srivastava --- .../assemble-freight/assemble-freight.tsx | 10 +++++-- .../features/assemble-freight/chart-table.tsx | 7 +++-- .../assemble-freight/commit-table.tsx | 8 ++++-- .../features/assemble-freight/image-table.tsx | 14 ++++++---- ui/src/utils/pagination.test.ts | 28 +++++++++++-------- ui/src/utils/pagination.ts | 22 +++++++++------ 6 files changed, 55 insertions(+), 34 deletions(-) diff --git a/ui/src/features/assemble-freight/assemble-freight.tsx b/ui/src/features/assemble-freight/assemble-freight.tsx index a16be954d..1fbe3af07 100644 --- a/ui/src/features/assemble-freight/assemble-freight.tsx +++ b/ui/src/features/assemble-freight/assemble-freight.tsx @@ -252,14 +252,18 @@ export const AssembleFreight = ({ ); }; -const DiscoveryTable = ({ selected, chosenItems, select }: { - selected?: DiscoveryResult, +const DiscoveryTable = ({ + selected, + chosenItems, + select +}: { + selected?: DiscoveryResult; chosenItems: { [key: string]: { artifact: DiscoveryResult; info: FreightInfo; }; - }, + }; select: (item?: FreightInfo) => void; }) => { if (!selected) { diff --git a/ui/src/features/assemble-freight/chart-table.tsx b/ui/src/features/assemble-freight/chart-table.tsx index 7fca8b4c9..e2cf2e28f 100644 --- a/ui/src/features/assemble-freight/chart-table.tsx +++ b/ui/src/features/assemble-freight/chart-table.tsx @@ -1,7 +1,8 @@ -import { calculatePageForSelectedRow } from '@ui/utils/pagination'; import { Radio, Table } from 'antd'; import { useState } from 'react'; +import { calculatePageForSelectedRow } from '@ui/utils/pagination'; + export const ChartTable = ({ versions, selected, @@ -11,7 +12,9 @@ export const ChartTable = ({ selected: string | undefined; select: (version?: string) => void; }) => { - const [defaultPage] = useState(() => calculatePageForSelectedRow(selected, versions, (version) => version)); + const [defaultPage] = useState(() => + calculatePageForSelectedRow(selected, versions, (version) => version) + ); return ( void; }) => { - const [defaultPage] = useState(() => calculatePageForSelectedRow(selected, commits, (commit) => commit.id)); + const [defaultPage] = useState(() => + calculatePageForSelectedRow(selected, commits, (commit) => commit.id) + ); return ( <> diff --git a/ui/src/features/assemble-freight/image-table.tsx b/ui/src/features/assemble-freight/image-table.tsx index a3e43ac8b..a8766e1d9 100644 --- a/ui/src/features/assemble-freight/image-table.tsx +++ b/ui/src/features/assemble-freight/image-table.tsx @@ -1,13 +1,13 @@ import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Radio, Table } from 'antd'; +import { useState } from 'react'; import { DiscoveredImageReference } from '@ui/gen/v1alpha1/generated_pb'; import { timestampDate } from '@ui/utils/connectrpc-utils'; +import { calculatePageForSelectedRow } from '@ui/utils/pagination'; import { TruncatedCopyable } from './truncated-copyable'; -import { useState } from 'react'; -import { calculatePageForSelectedRow } from '@ui/utils/pagination'; export const ImageTable = ({ references, @@ -18,7 +18,9 @@ export const ImageTable = ({ selected: DiscoveredImageReference | undefined; select: (reference?: DiscoveredImageReference) => void; }) => { - const [defaultPage] = useState(() => calculatePageForSelectedRow(selected, references, (ref) => ref.tag)); + const [defaultPage] = useState(() => + calculatePageForSelectedRow(selected, references, (ref) => ref.tag) + ); return ( <> @@ -37,7 +39,9 @@ export const ImageTable = ({ { title: 'Tag', dataIndex: 'tag' }, { title: 'Digest', - render: (record: DiscoveredImageReference) => + render: (record: DiscoveredImageReference) => ( + + ) }, { title: 'Source Repo', @@ -58,5 +62,5 @@ export const ImageTable = ({ ]} /> - ) + ); }; diff --git a/ui/src/utils/pagination.test.ts b/ui/src/utils/pagination.test.ts index 23082ca2e..6882d3000 100644 --- a/ui/src/utils/pagination.test.ts +++ b/ui/src/utils/pagination.test.ts @@ -1,14 +1,18 @@ -import { describe, expect, test } from "vitest"; -import { calculatePageForSelectedRow } from "./pagination"; +import { describe, expect, test } from 'vitest'; -describe("calculatePageForSelectedRow", () => { - test.each([ - [undefined, ["a", "b", "c"], (option: string) => option, 1], - ["a", ["a", "b", "c"], (option: string) => option, 1], - ["j", ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"], (option: string) => option, 1], - ["k", ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"], (option: string) => option, 2], - ])('selectedOption: %s, options: %s, key: %s, expectedPage: %s', (selectedOption, options, key, expectedPage) => { - const page = calculatePageForSelectedRow(selectedOption, options, key); - expect(page).toBe(expectedPage); - }); +import { calculatePageForSelectedRow } from './pagination'; + +describe('calculatePageForSelectedRow', () => { + test.each([ + [undefined, ['a', 'b', 'c'], (option: string) => option, 1], + ['a', ['a', 'b', 'c'], (option: string) => option, 1], + ['j', ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'], (option: string) => option, 1], + ['k', ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'], (option: string) => option, 2] + ])( + 'selectedOption: %s, options: %s, key: %s, expectedPage: %s', + (selectedOption, options, key, expectedPage) => { + const page = calculatePageForSelectedRow(selectedOption, options, key); + expect(page).toBe(expectedPage); + } + ); }); diff --git a/ui/src/utils/pagination.ts b/ui/src/utils/pagination.ts index a8cd94ea9..f99b20517 100644 --- a/ui/src/utils/pagination.ts +++ b/ui/src/utils/pagination.ts @@ -1,12 +1,16 @@ -export function calculatePageForSelectedRow(selectedOption: T | undefined, options: T[], key: (option: T) => string): number { - const pageSize = 10; +export function calculatePageForSelectedRow( + selectedOption: T | undefined, + options: T[], + key: (option: T) => string +): number { + const pageSize = 10; - if (selectedOption) { - const index = options.findIndex((option) => key(option) === key(selectedOption)); - if (index >= 0) { - const page = Math.floor(index / pageSize) + 1; - return page; - } + if (selectedOption) { + const index = options.findIndex((option) => key(option) === key(selectedOption)); + if (index >= 0) { + const page = Math.floor(index / pageSize) + 1; + return page; } - return 1; + } + return 1; }