1 import { HttpTypes } from "@medusajs/types"
2 import { createDataTableColumnHelper } from "@medusajs/ui"
3 import { useMemo } from "react"
4 import { useTranslation } from "react-i18next"
5 import { DataTableStatusCell } from "../../../components/data-table/components/data-table-status-cell/data-table-status-cell"
6 import { PencilSquare } from "@medusajs/icons"
7 import { useNavigate, useSearchParams } from "react-router-dom"
8
9 const columnHelper = createDataTableColumnHelper<HttpTypes.AdminEntityInfo>()
10
11 export const usePropertyLabelsTableColumns = () => {
12 const { t } = useTranslation()
13 const navigate = useNavigate()
14 const [searchParams] = useSearchParams()
15
16 return useMemo(
17 () => [
18 columnHelper.accessor("module", {
19 header: () => t("propertyLabels.fields.module"),
20 enableSorting: true,
21 sortLabel: t("propertyLabels.fields.module"),
22 sortAscLabel: t("filters.sorting.alphabeticallyAsc"),
23 sortDescLabel: t("filters.sorting.alphabeticallyDesc"),
24 }),
25 columnHelper.accessor("name", {
26 header: () => t("propertyLabels.fields.model"),
27 enableSorting: true,
28 sortLabel: t("propertyLabels.fields.model"),
29 sortAscLabel: t("filters.sorting.alphabeticallyAsc"),
30 sortDescLabel: t("filters.sorting.alphabeticallyDesc"),
31 }),
32 columnHelper.accessor("propertyCount", {
33 header: () => t("propertyLabels.fields.propertyCount"),
34 }),
35 columnHelper.accessor("hasOverrides", {
36 header: () => t("propertyLabels.fields.hasOverrides"),
37 cell: ({ getValue }) => {
38 const value = getValue()
39 return (
40 <DataTableStatusCell color={value ? "green" : "grey"}>
41 {value ? t("filters.radio.yes") : t("filters.radio.no")}
42 </DataTableStatusCell>
43 )
44 },
45 }),
46 columnHelper.action({
47 actions: (ctx) => [
48 {
49 label: t("actions.edit"),
50 icon: <PencilSquare />,
51 onClick: () => {
52 const params = searchParams.toString()
53 navigate(
54 `/settings/property-labels/${ctx.row.original.name}/edit`,
55 params ? { state: { restore_params: params } } : undefined
56 )
57 },
58 },
59 ],
60 }),
61 ],
62 [t, navigate, searchParams]
63 )
64 }