Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create return reason #8516

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- "@sradevski"
- "@edast"
- "@thetutlage"
- "@christiananese"
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export interface DataTableRootProps<TData> {
* Whether the table is empty due to no results from the active query
*/
noResults?: boolean
/**
* Whether to display the tables header
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I'm not a big fan of "negative" naming for props, but wanted to stay consistent with other props in this component

*/
noHeader?: boolean
/**
* The layout of the table
*/
Expand Down Expand Up @@ -80,6 +84,7 @@ export const DataTableRoot = <TData,>({
commands,
count = 0,
noResults = false,
noHeader = false,
layout = "fit",
}: DataTableRootProps<TData>) => {
const { t } = useTranslation()
Expand Down Expand Up @@ -133,64 +138,66 @@ export const DataTableRoot = <TData,>({
>
{!noResults ? (
<Table className="relative w-full">
<Table.Header className="border-t-0">
{table.getHeaderGroups().map((headerGroup) => {
return (
<Table.Row
key={headerGroup.id}
className={clx({
"relative border-b-0 [&_th:last-of-type]:w-[1%] [&_th:last-of-type]:whitespace-nowrap":
hasActions,
"[&_th:first-of-type]:w-[1%] [&_th:first-of-type]:whitespace-nowrap":
hasSelect,
})}
>
{headerGroup.headers.map((header, index) => {
const isActionHeader = header.id === "actions"
const isSelectHeader = header.id === "select"
const isSpecialHeader = isActionHeader || isSelectHeader
{!noHeader && (
<Table.Header className="border-t-0">
{table.getHeaderGroups().map((headerGroup) => {
return (
<Table.Row
key={headerGroup.id}
className={clx({
"relative border-b-0 [&_th:last-of-type]:w-[1%] [&_th:last-of-type]:whitespace-nowrap":
hasActions,
"[&_th:first-of-type]:w-[1%] [&_th:first-of-type]:whitespace-nowrap":
hasSelect,
})}
>
{headerGroup.headers.map((header, index) => {
const isActionHeader = header.id === "actions"
const isSelectHeader = header.id === "select"
const isSpecialHeader = isActionHeader || isSelectHeader

const firstHeader = headerGroup.headers.findIndex(
(h) => h.id !== "select"
)
const isFirstHeader =
firstHeader !== -1
? header.id === headerGroup.headers[firstHeader].id
: index === 0
const firstHeader = headerGroup.headers.findIndex(
(h) => h.id !== "select"
)
const isFirstHeader =
firstHeader !== -1
? header.id === headerGroup.headers[firstHeader].id
: index === 0

const isStickyHeader = isSelectHeader || isFirstHeader
const isStickyHeader = isSelectHeader || isFirstHeader

return (
<Table.HeaderCell
data-table-header-id={header.id}
key={header.id}
style={{
width: !isSpecialHeader
? `${colWidth}%`
: undefined,
}}
className={clx({
"bg-ui-bg-base sticky left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']":
isStickyHeader,
"left-[68px]":
isStickyHeader && hasSelect && !isSelectHeader,
"after:bg-ui-border-base":
showStickyBorder &&
isStickyHeader &&
!isSpecialHeader,
})}
>
{flexRender(
header.column.columnDef.header,
header.getContext()
)}
</Table.HeaderCell>
)
})}
</Table.Row>
)
})}
</Table.Header>
return (
<Table.HeaderCell
data-table-header-id={header.id}
key={header.id}
style={{
width: !isSpecialHeader
? `${colWidth}%`
: undefined,
}}
className={clx({
"bg-ui-bg-base sticky left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']":
isStickyHeader,
"left-[68px]":
isStickyHeader && hasSelect && !isSelectHeader,
"after:bg-ui-border-base":
showStickyBorder &&
isStickyHeader &&
!isSpecialHeader,
})}
>
{flexRender(
header.column.columnDef.header,
header.getContext()
)}
</Table.HeaderCell>
)
})}
</Table.Row>
)
})}
</Table.Header>
)}
<Table.Body className="border-b-0">
{table.getRowModel().rows.map((row) => {
const to = navigateTo ? navigateTo(row) : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const DataTable = <TData,>({
queryObject = {},
pageSize,
isLoading = false,
noHeader = false,
layout = "fit",
noRecords: noRecordsProps = {},
}: DataTableProps<TData>) => {
Expand Down Expand Up @@ -84,6 +85,7 @@ export const DataTable = <TData,>({
navigateTo={navigateTo}
commands={commands}
noResults={noResults}
noHeader={noHeader}
layout={layout}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import { HttpTypes } from "@medusajs/types"
import { Badge } from "@medusajs/ui"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import { TextCell } from "../../../components/table/table-cells/common/text-cell"

const columnHelper = createColumnHelper<HttpTypes.AdminReturnReason>()

export const useReturnReasonTableColumns = () => {
const { t } = useTranslation()

return useMemo(
() => [
columnHelper.accessor("value", {
header: () => t("fields.value"),
cell: ({ getValue }) => <TextCell text={getValue()} />,
cell: ({ getValue }) => <Badge size="2xsmall">{getValue()}</Badge>,
}),
columnHelper.accessor("label", {
header: () => t("fields.createdAt"),
cell: ({ getValue }) => <TextCell text={getValue()} />,
cell: ({ row }) => {
const { label, description } = row.original
return (
<div className="flex h-full w-full flex-col justify-center py-4">
<span className="truncate font-medium">{label}</span>
<span className="truncate">
{description ? description : "-"}
</span>
</div>
)
},
}),
],
[t]
[]
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
"goToPublishableApiKeys": "Publishable API Keys",
"goToSecretApiKeys": "Secret API Keys",
"goToWorkflows": "Workflows",
"goToProfile": "Profile"
"goToProfile": "Profile",
"goToReturnReasons": "Return reasons"
}
},
"menus": {
Expand Down Expand Up @@ -2101,6 +2102,7 @@
},
"returnReasons": {
"domain": "Return Reasons",
"subtitle": "Manage reasons for returned items.",
"calloutHint": "Manage the reasons to categorize returns.",
"editReason": "Edit Return Reason",
"create": {
Expand All @@ -2110,6 +2112,8 @@
"successToast": "Return reason {{label}} was successfully created."
},
"edit": {
"header": "Edit Return Reason",
"subtitle": "Edit the value of the return reason.",
"successToast": "Return reason {{label}} was successfully updated."
},
"delete": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ export const useGlobalShortcuts = () => {
type: "settingShortcut",
to: "/settings/locations",
},
{
keys: {
Mac: ["G", ",", "M"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Would this be more fitting? Typically, the keyboard shortcut is coupled with the resource name

Suggested change
Mac: ["G", ",", "M"],
Mac: ["G", ",", "R"],

},
label: t("app.keyboardShortcuts.settings.goToReturnReasons"),
type: "settingShortcut",
to: "/settings/return-reasons",
},
{
keys: {
Mac: ["G", ",", "J"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,28 @@ export const RouteMap: RouteObject[] = [
path: "",
lazy: () =>
import("../../routes/return-reasons/return-reason-list"),
children: [
{
path: "create",
lazy: () =>
import(
"../../routes/return-reasons/return-reason-create"
),
},

{
path: ":id",
children: [
{
path: "edit",
lazy: () =>
import(
"../../routes/return-reasons/return-reason-edit"
),
},
],
},
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./return-reason-create-form"
Loading
Loading