Skip to content

Commit f47621a

Browse files
authored
chore(dashboard): fix type and lint errors (2/n) (#15210)
1 parent a0a5953 commit f47621a

28 files changed

Lines changed: 659 additions & 464 deletions

packages/admin/dashboard/src/dashboard-app/__tests__/sort-menu-items-by-rank.spec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { describe, expect, it } from "vitest"
22
import { sortMenuItemsByRank } from "../utils/sort-menu-items-by-rank"
33
import { INavItem } from "../../components/layout/nav-item"
44

5+
type RankedNavItem = INavItem & {
6+
rank?: number
7+
items?: (INavItem & { rank?: number })[]
8+
}
9+
510
describe("sortMenuItemsByRank", () => {
611
it("should sort items by rank in ascending order", () => {
7-
const items: INavItem[] = [
12+
const items: RankedNavItem[] = [
813
{ label: "Third", to: "/third", rank: 3 },
914
{ label: "First", to: "/first", rank: 1 },
1015
{ label: "Second", to: "/second", rank: 2 },
@@ -18,7 +23,7 @@ describe("sortMenuItemsByRank", () => {
1823
})
1924

2025
it("should place items with rank before items without rank", () => {
21-
const items: INavItem[] = [
26+
const items: RankedNavItem[] = [
2227
{ label: "No Rank", to: "/no-rank" },
2328
{ label: "Ranked 2", to: "/ranked-2", rank: 2 },
2429
{ label: "Ranked 1", to: "/ranked-1", rank: 1 },
@@ -34,7 +39,7 @@ describe("sortMenuItemsByRank", () => {
3439
})
3540

3641
it("should handle items with rank 0", () => {
37-
const items: INavItem[] = [
42+
const items: RankedNavItem[] = [
3843
{ label: "Rank 2", to: "/rank-2", rank: 2 },
3944
{ label: "Rank 0", to: "/rank-0", rank: 0 },
4045
{ label: "Rank 1", to: "/rank-1", rank: 1 },
@@ -48,7 +53,7 @@ describe("sortMenuItemsByRank", () => {
4853
})
4954

5055
it("should handle negative ranks", () => {
51-
const items: INavItem[] = [
56+
const items: RankedNavItem[] = [
5257
{ label: "Rank 1", to: "/rank-1", rank: 1 },
5358
{ label: "Rank -1", to: "/rank-minus-1", rank: -1 },
5459
{ label: "Rank 0", to: "/rank-0", rank: 0 },
@@ -62,7 +67,7 @@ describe("sortMenuItemsByRank", () => {
6267
})
6368

6469
it("should sort nested items independently", () => {
65-
const items: INavItem[] = [
70+
const items: RankedNavItem[] = [
6671
{
6772
label: "Parent 2",
6873
to: "/parent-2",
@@ -101,7 +106,7 @@ describe("sortMenuItemsByRank", () => {
101106
})
102107

103108
it("should handle nested items with mixed ranked and unranked", () => {
104-
const items: INavItem[] = [
109+
const items: RankedNavItem[] = [
105110
{
106111
label: "Parent",
107112
to: "/parent",
@@ -122,15 +127,17 @@ describe("sortMenuItemsByRank", () => {
122127
})
123128

124129
it("should handle empty items array", () => {
125-
const items: INavItem[] = []
130+
const items: RankedNavItem[] = []
126131

127132
const sorted = sortMenuItemsByRank(items)
128133

129134
expect(sorted).toEqual([])
130135
})
131136

132137
it("should handle single item", () => {
133-
const items: INavItem[] = [{ label: "Only Item", to: "/only", rank: 1 }]
138+
const items: RankedNavItem[] = [
139+
{ label: "Only Item", to: "/only", rank: 1 },
140+
]
134141

135142
const sorted = sortMenuItemsByRank(items)
136143

@@ -139,7 +146,7 @@ describe("sortMenuItemsByRank", () => {
139146
})
140147

141148
it("should preserve items without nested arrays", () => {
142-
const items: INavItem[] = [
149+
const items: RankedNavItem[] = [
143150
{ label: "Item 1", to: "/item-1", rank: 2 },
144151
{ label: "Item 2", to: "/item-2", rank: 1 },
145152
]
@@ -151,13 +158,13 @@ describe("sortMenuItemsByRank", () => {
151158
})
152159

153160
it("should handle duplicate rank values", () => {
154-
const items: INavItem[] = [
161+
const items: RankedNavItem[] = [
155162
{ label: "Item C", to: "/item-c", rank: 1 },
156163
{ label: "Item A", to: "/item-a", rank: 1 },
157164
{ label: "Item B", to: "/item-b", rank: 1 },
158165
]
159166

160-
const sorted = sortMenuItemsByRank(items)
167+
const sorted = sortMenuItemsByRank(items) as RankedNavItem[]
161168

162169
// All should have rank 1, order should be stable
163170
expect(sorted[0].rank).toBe(1)
@@ -166,4 +173,3 @@ describe("sortMenuItemsByRank", () => {
166173
expect(sorted).toHaveLength(3)
167174
})
168175
})
169-

packages/admin/dashboard/src/dashboard-app/dashboard-app.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type DashboardAppProps = {
4848
* Example: /path/to/:id?
4949
* Such paths can be added to the menu items without the optional segment.
5050
*/
51-
const OPTIONAL_LAST_SEGMENT_MATCH = /\/([^\/])+\?$/
51+
const OPTIONAL_LAST_SEGMENT_MATCH = /\/([^/])+\?$/
5252

5353
export class DashboardApp {
5454
private widgets: WidgetMap
@@ -400,9 +400,7 @@ export class DashboardApp {
400400
return displays
401401
}
402402

403-
private populateI18n(
404-
plugins: DashboardPlugin[]
405-
): I18nExtension {
403+
private populateI18n(plugins: DashboardPlugin[]): I18nExtension {
406404
let resources: I18nExtension = { ...coreTranslations }
407405

408406
for (const plugin of plugins) {

packages/admin/dashboard/src/dashboard-app/utils/sort-menu-items-by-rank.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ export function sortMenuItemsByRank(
4040

4141
return sortedItems
4242
}
43-

packages/admin/dashboard/src/hooks/table/columns/use-configurable-table-columns.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ import React, { useMemo } from "react"
22
import { createDataTableColumnHelper } from "@medusajs/ui"
33
import { HttpTypes } from "@medusajs/types"
44
import { useTranslation } from "react-i18next"
5-
import { getCellRenderer, getColumnValue } from "../../../lib/table/cell-renderers"
5+
import {
6+
getCellRenderer,
7+
getColumnValue,
8+
} from "../../../lib/table/cell-renderers"
69

710
export interface ColumnAdapter<TData> {
8-
getColumnAlignment?: (column: HttpTypes.AdminColumn) => "left" | "center" | "right"
11+
getColumnAlignment?: (
12+
column: HttpTypes.AdminColumn
13+
) => "left" | "center" | "right"
914
getCustomAccessor?: (field: string, column: HttpTypes.AdminColumn) => any
10-
transformCellValue?: (value: any, row: TData, column: HttpTypes.AdminColumn) => React.ReactNode
15+
transformCellValue?: (
16+
value: any,
17+
row: TData,
18+
column: HttpTypes.AdminColumn
19+
) => React.ReactNode
1120
}
1221

1322
export function useConfigurableTableColumns<TData = any>(
@@ -23,25 +32,22 @@ export function useConfigurableTableColumns<TData = any>(
2332
return []
2433
}
2534

26-
return apiColumns.map(apiColumn => {
35+
return apiColumns.map((apiColumn) => {
2736
let renderType = apiColumn.computed?.type
2837

2938
if (!renderType) {
30-
if (apiColumn.semantic_type === 'timestamp') {
31-
renderType = 'timestamp'
32-
} else if (apiColumn.field === 'display_id') {
33-
renderType = 'display_id'
34-
} else if (apiColumn.field === 'total') {
35-
renderType = 'total'
36-
} else if (apiColumn.semantic_type === 'currency') {
37-
renderType = 'currency'
39+
if (apiColumn.semantic_type === "timestamp") {
40+
renderType = "timestamp"
41+
} else if (apiColumn.field === "display_id") {
42+
renderType = "display_id"
43+
} else if (apiColumn.field === "total") {
44+
renderType = "total"
45+
} else if (apiColumn.semantic_type === "currency") {
46+
renderType = "currency"
3847
}
3948
}
4049

41-
const renderer = getCellRenderer(
42-
renderType,
43-
apiColumn.data_type
44-
)
50+
const renderer = getCellRenderer(renderType, apiColumn.data_type)
4551

4652
const headerAlign = adapter?.getColumnAlignment
4753
? adapter.getColumnAlignment(apiColumn)
@@ -52,11 +58,15 @@ export function useConfigurableTableColumns<TData = any>(
5258
return columnHelper.accessor(accessor, {
5359
id: apiColumn.field,
5460
header: () => apiColumn.name,
55-
cell: ({ getValue, row }: { getValue: any, row: any }) => {
61+
cell: ({ getValue, row }: { getValue: any; row: any }) => {
5662
const value = getValue()
5763

5864
if (adapter?.transformCellValue) {
59-
const transformed = adapter.transformCellValue(value, row.original, apiColumn)
65+
const transformed = adapter.transformCellValue(
66+
value,
67+
row.original,
68+
apiColumn
69+
)
6070
if (transformed !== null) {
6171
return transformed
6272
}
@@ -76,7 +86,9 @@ export function useConfigurableTableColumns<TData = any>(
7686
}, [entity, apiColumns, adapter, t])
7787
}
7888

79-
function getDefaultColumnAlignment(column: HttpTypes.AdminColumn): "left" | "center" | "right" {
89+
function getDefaultColumnAlignment(
90+
column: HttpTypes.AdminColumn
91+
): "left" | "center" | "right" {
8092
if (column.semantic_type === "currency" || column.data_type === "currency") {
8193
return "right"
8294
}
@@ -99,9 +111,11 @@ function getDefaultColumnAlignment(column: HttpTypes.AdminColumn): "left" | "cen
99111
return "center"
100112
}
101113

102-
if (column.computed?.type === "country_code" ||
114+
if (
115+
column.computed?.type === "country_code" ||
103116
column.field === "country" ||
104-
column.field.includes("country_code")) {
117+
column.field.includes("country_code")
118+
) {
105119
return "center"
106120
}
107121

packages/admin/dashboard/src/hooks/table/columns/use-order-data-table-columns.tsx

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ import {
3232
TotalCell,
3333
TotalHeader,
3434
} from "../../../components/table/table-cells/order/total-cell"
35-
import { TextCell, TextHeader } from "../../../components/table/table-cells/common/text-cell"
35+
import {
36+
TextCell,
37+
TextHeader,
38+
} from "../../../components/table/table-cells/common/text-cell"
3639

3740
const columnHelper = createColumnHelper<HttpTypes.AdminOrder>()
3841

3942
/**
4043
* Hook to build columns dynamically based on API columns response
4144
*/
4245
export const useOrderDataTableColumns = (
43-
apiColumns: HttpTypes.AdminOrderColumn[] | undefined,
46+
apiColumns: HttpTypes.AdminColumn[] | undefined,
4447
visibleColumns: string[]
4548
) => {
4649
const { t } = useTranslation()
@@ -128,7 +131,7 @@ export const useOrderDataTableColumns = (
128131
return <DisplayIdCell displayId={id!} />
129132
},
130133
})
131-
134+
132135
case "created_at":
133136
case "updated_at":
134137
return columnHelper.accessor(col.field as any, {
@@ -138,7 +141,7 @@ export const useOrderDataTableColumns = (
138141
return date ? <DateCell date={date} /> : null
139142
},
140143
})
141-
144+
142145
case "email":
143146
return columnHelper.accessor("email", {
144147
header: () => <TextHeader text={col.name} />,
@@ -147,7 +150,7 @@ export const useOrderDataTableColumns = (
147150
return <TextCell text={email || ""} />
148151
},
149152
})
150-
153+
151154
case "customer_display":
152155
return columnHelper.accessor("customer", {
153156
header: () => <CustomerHeader />,
@@ -156,7 +159,7 @@ export const useOrderDataTableColumns = (
156159
return <CustomerCell customer={customer} />
157160
},
158161
})
159-
162+
160163
case "sales_channel.name":
161164
return columnHelper.accessor("sales_channel", {
162165
header: () => <SalesChannelHeader />,
@@ -165,7 +168,7 @@ export const useOrderDataTableColumns = (
165168
return <SalesChannelCell channel={channel} />
166169
},
167170
})
168-
171+
169172
case "payment_status":
170173
return columnHelper.accessor("payment_status", {
171174
header: () => <PaymentStatusHeader />,
@@ -174,7 +177,7 @@ export const useOrderDataTableColumns = (
174177
return <PaymentStatusCell status={status} />
175178
},
176179
})
177-
180+
178181
case "fulfillment_status":
179182
return columnHelper.accessor("fulfillment_status", {
180183
header: () => <FulfillmentStatusHeader />,
@@ -183,7 +186,7 @@ export const useOrderDataTableColumns = (
183186
return <FulfillmentStatusCell status={status} />
184187
},
185188
})
186-
189+
187190
case "total":
188191
return columnHelper.accessor("total", {
189192
header: () => <TotalHeader />,
@@ -193,7 +196,7 @@ export const useOrderDataTableColumns = (
193196
return <TotalCell currencyCode={currencyCode} total={total} />
194197
},
195198
})
196-
199+
197200
case "country":
198201
return columnHelper.display({
199202
id: "country",
@@ -202,24 +205,27 @@ export const useOrderDataTableColumns = (
202205
return <CountryCell country={country} />
203206
},
204207
})
205-
208+
206209
default:
207210
// Handle relationship fields (e.g., customer.email)
208211
if (col.field.includes(".")) {
209212
const [relation, field] = col.field.split(".")
210-
return columnHelper.accessor((row: any) => {
211-
const relationData = row[relation]
212-
return relationData?.[field] || ""
213-
}, {
214-
id: col.id,
215-
header: () => <TextHeader text={col.name} />,
216-
cell: ({ getValue }) => {
217-
const value = getValue()
218-
return <TextCell text={value || ""} />
213+
return columnHelper.accessor(
214+
(row: any) => {
215+
const relationData = row[relation]
216+
return relationData?.[field] || ""
219217
},
220-
})
218+
{
219+
id: col.id,
220+
header: () => <TextHeader text={col.name} />,
221+
cell: ({ getValue }) => {
222+
const value = getValue()
223+
return <TextCell text={value || ""} />
224+
},
225+
}
226+
)
221227
}
222-
228+
223229
// Default text column
224230
return columnHelper.accessor(col.field as any, {
225231
header: () => <TextHeader text={col.name} />,
@@ -231,4 +237,4 @@ export const useOrderDataTableColumns = (
231237
}
232238
})
233239
}, [apiColumns, visibleColumns, t])
234-
}
240+
}

0 commit comments

Comments
 (0)