- {typeof children === "function"
- ? children({ value: watchedValue })
- : children}
+
+ {typeof children === 'function' ? children({ value: watchedValue }) : children}
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-keyboard-shortcut-modal.tsx b/src/components/data-grid/components/data-grid-keyboard-shortcut-modal.tsx
index a8b5f123..12dea066 100644
--- a/src/components/data-grid/components/data-grid-keyboard-shortcut-modal.tsx
+++ b/src/components/data-grid/components/data-grid-keyboard-shortcut-modal.tsx
@@ -1,208 +1,208 @@
-import { XMark } from "@medusajs/icons"
-import {
- Button,
- clx,
- Heading,
- IconButton,
- Input,
- Kbd,
- Text,
-} from "@medusajs/ui"
-import { Dialog as RadixDialog } from "radix-ui"
-import { useMemo, useState } from "react"
-import { useTranslation } from "react-i18next"
+import { useMemo, useState } from 'react';
+
+import { XMark } from '@medusajs/icons';
+import { Button, clx, Heading, IconButton, Input, Kbd, Text } from '@medusajs/ui';
+import { Dialog as RadixDialog } from 'radix-ui';
+import { useTranslation } from 'react-i18next';
const useDataGridShortcuts = () => {
- const { t } = useTranslation()
+ const { t } = useTranslation();
- const shortcuts = useMemo(
+ return useMemo(
() => [
{
- label: t("dataGrid.shortcuts.commands.undo"),
+ label: t('dataGrid.shortcuts.commands.undo'),
keys: {
- Mac: ["⌘", "Z"],
- Windows: ["Ctrl", "Z"],
- },
+ Mac: ['⌘', 'Z'],
+ Windows: ['Ctrl', 'Z']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.redo"),
+ label: t('dataGrid.shortcuts.commands.redo'),
keys: {
- Mac: ["⇧", "⌘", "Z"],
- Windows: ["Shift", "Ctrl", "Z"],
- },
+ Mac: ['⇧', '⌘', 'Z'],
+ Windows: ['Shift', 'Ctrl', 'Z']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.copy"),
+ label: t('dataGrid.shortcuts.commands.copy'),
keys: {
- Mac: ["⌘", "C"],
- Windows: ["Ctrl", "C"],
- },
+ Mac: ['⌘', 'C'],
+ Windows: ['Ctrl', 'C']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.paste"),
+ label: t('dataGrid.shortcuts.commands.paste'),
keys: {
- Mac: ["⌘", "V"],
- Windows: ["Ctrl", "V"],
- },
+ Mac: ['⌘', 'V'],
+ Windows: ['Ctrl', 'V']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.edit"),
+ label: t('dataGrid.shortcuts.commands.edit'),
keys: {
- Mac: ["↵"],
- Windows: ["Enter"],
- },
+ Mac: ['↵'],
+ Windows: ['Enter']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.delete"),
+ label: t('dataGrid.shortcuts.commands.delete'),
keys: {
- Mac: ["⌫"],
- Windows: ["Backspace"],
- },
+ Mac: ['⌫'],
+ Windows: ['Backspace']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.clear"),
+ label: t('dataGrid.shortcuts.commands.clear'),
keys: {
- Mac: ["Space"],
- Windows: ["Space"],
- },
+ Mac: ['Space'],
+ Windows: ['Space']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveUp"),
+ label: t('dataGrid.shortcuts.commands.moveUp'),
keys: {
- Mac: ["↑"],
- Windows: ["↑"],
- },
+ Mac: ['↑'],
+ Windows: ['↑']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveDown"),
+ label: t('dataGrid.shortcuts.commands.moveDown'),
keys: {
- Mac: ["↓"],
- Windows: ["↓"],
- },
+ Mac: ['↓'],
+ Windows: ['↓']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveLeft"),
+ label: t('dataGrid.shortcuts.commands.moveLeft'),
keys: {
- Mac: ["←"],
- Windows: ["←"],
- },
+ Mac: ['←'],
+ Windows: ['←']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveRight"),
+ label: t('dataGrid.shortcuts.commands.moveRight'),
keys: {
- Mac: ["→"],
- Windows: ["→"],
- },
+ Mac: ['→'],
+ Windows: ['→']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveTop"),
+ label: t('dataGrid.shortcuts.commands.moveTop'),
keys: {
- Mac: ["⌘", "↑"],
- Windows: ["Ctrl", "↑"],
- },
+ Mac: ['⌘', '↑'],
+ Windows: ['Ctrl', '↑']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.moveBottom"),
+ label: t('dataGrid.shortcuts.commands.moveBottom'),
keys: {
- Mac: ["⌘", "↓"],
- Windows: ["Ctrl", "↓"],
- },
+ Mac: ['⌘', '↓'],
+ Windows: ['Ctrl', '↓']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.selectDown"),
+ label: t('dataGrid.shortcuts.commands.selectDown'),
keys: {
- Mac: ["⇧", "↓"],
- Windows: ["Shift", "↓"],
- },
+ Mac: ['⇧', '↓'],
+ Windows: ['Shift', '↓']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.selectUp"),
+ label: t('dataGrid.shortcuts.commands.selectUp'),
keys: {
- Mac: ["⇧", "↑"],
- Windows: ["Shift", "↑"],
- },
+ Mac: ['⇧', '↑'],
+ Windows: ['Shift', '↑']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.selectColumnDown"),
+ label: t('dataGrid.shortcuts.commands.selectColumnDown'),
keys: {
- Mac: ["⇧", "⌘", "↓"],
- Windows: ["Shift", "Ctrl", "↓"],
- },
+ Mac: ['⇧', '⌘', '↓'],
+ Windows: ['Shift', 'Ctrl', '↓']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.selectColumnUp"),
+ label: t('dataGrid.shortcuts.commands.selectColumnUp'),
keys: {
- Mac: ["⇧", "⌘", "↑"],
- Windows: ["Shift", "Ctrl", "↑"],
- },
+ Mac: ['⇧', '⌘', '↑'],
+ Windows: ['Shift', 'Ctrl', '↑']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.focusToolbar"),
+ label: t('dataGrid.shortcuts.commands.focusToolbar'),
keys: {
- Mac: ["⌃", "⌥", ","],
- Windows: ["Ctrl", "Alt", ","],
- },
+ Mac: ['⌃', '⌥', ','],
+ Windows: ['Ctrl', 'Alt', ',']
+ }
},
{
- label: t("dataGrid.shortcuts.commands.focusCancel"),
+ label: t('dataGrid.shortcuts.commands.focusCancel'),
keys: {
- Mac: ["⌃", "⌥", "."],
- Windows: ["Ctrl", "Alt", "."],
- },
- },
+ Mac: ['⌃', '⌥', '.'],
+ Windows: ['Ctrl', 'Alt', '.']
+ }
+ }
],
[t]
- )
-
- return shortcuts
-}
+ );
+};
type DataGridKeyboardShortcutModalProps = {
- open: boolean
- onOpenChange: (open: boolean) => void
-}
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+};
export const DataGridKeyboardShortcutModal = ({
open,
- onOpenChange,
+ onOpenChange
}: DataGridKeyboardShortcutModalProps) => {
- const { t } = useTranslation()
- const [searchValue, onSearchValueChange] = useState("")
- const shortcuts = useDataGridShortcuts()
+ const { t } = useTranslation();
+ const [searchValue, onSearchValueChange] = useState('');
+ const shortcuts = useDataGridShortcuts();
const searchResults = useMemo(() => {
- return shortcuts.filter((shortcut) =>
+ return shortcuts.filter(shortcut =>
shortcut.label.toLowerCase().includes(searchValue.toLowerCase())
- )
- }, [searchValue, shortcuts])
+ );
+ }, [searchValue, shortcuts]);
return (
-
+
-
-
+
- {t("app.menus.user.shortcuts")}
+ {t('app.menus.user.shortcuts')}
esc
-
+
@@ -213,7 +213,7 @@ export const DataGridKeyboardShortcutModal = ({
type="search"
value={searchValue}
autoFocus
- onChange={(e) => onSearchValueChange(e.target.value)}
+ onChange={e => onSearchValueChange(e.target.value)}
/>
@@ -222,24 +222,27 @@ export const DataGridKeyboardShortcutModal = ({
return (
{shortcut.label}
{shortcut.keys.Mac?.map((key, index) => {
return (
-
- )
+ );
})}
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-number-cell.tsx b/src/components/data-grid/components/data-grid-number-cell.tsx
index 86d1f6ab..41855d8a 100644
--- a/src/components/data-grid/components/data-grid-number-cell.tsx
+++ b/src/components/data-grid/components/data-grid-number-cell.tsx
@@ -1,88 +1,93 @@
-import { clx } from "@medusajs/ui"
-import { useEffect, useState } from "react"
-import { Controller, ControllerRenderProps } from "react-hook-form"
-import { useCombinedRefs } from "../../../hooks/use-combined-refs"
-import { useDataGridCell, useDataGridCellError } from "../hooks"
-import { DataGridCellProps, InputProps } from "../types"
-import { DataGridCellContainer } from "./data-grid-cell-container"
+import { useEffect, useState } from 'react';
+import { useDataGridCell, useDataGridCellError } from '@components/data-grid/hooks';
+import type { DataGridCellProps, InputProps } from '@components/data-grid/types';
+import { useCombinedRefs } from '@hooks/use-combined-refs.tsx';
+import { clx } from '@medusajs/ui';
+import { Controller, type ControllerRenderProps } from 'react-hook-form';
+
+import { DataGridCellContainer } from './data-grid-cell-container';
+
+//@todo fix type
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const DataGridNumberCell =
({
context,
...rest
}: DataGridCellProps & {
- min?: number
- max?: number
- placeholder?: string
+ min?: number;
+ max?: number;
+ placeholder?: string;
}) => {
const { field, control, renderProps } = useDataGridCell({
- context,
- })
- const errorProps = useDataGridCellError({ context })
+ context
+ });
+ const errorProps = useDataGridCellError({ context });
- const { container, input } = renderProps
+ const { container, input } = renderProps;
return (
{
- return (
-
-
-
- )
- }}
+ render={({ field }) => (
+
+
+
+ )}
/>
- )
-}
+ );
+};
const Inner = ({
field,
inputProps,
...props
}: {
- field: ControllerRenderProps
- inputProps: InputProps
- min?: number
- max?: number
- placeholder?: string
+ //@todo fix type
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ field: ControllerRenderProps;
+ inputProps: InputProps;
+ min?: number;
+ max?: number;
+ placeholder?: string;
}) => {
- const { ref, value, onChange: _, onBlur, ...fieldProps } = field
- const {
- ref: inputRef,
- onChange,
- onBlur: onInputBlur,
- onFocus,
- ...attributes
- } = inputProps
+ const { ref, value, onChange: _, onBlur, ...fieldProps } = field;
+ const { ref: inputRef, onChange, onBlur: onInputBlur, onFocus, ...attributes } = inputProps;
- const [localValue, setLocalValue] = useState(value)
+ const [localValue, setLocalValue] = useState(value);
useEffect(() => {
- setLocalValue(value)
- }, [value])
+ setLocalValue(value);
+ }, [value]);
- const combinedRefs = useCombinedRefs(inputRef, ref)
+ const combinedRefs = useCombinedRefs(inputRef, ref);
return (
setLocalValue(e.target.value)}
+ onChange={e => setLocalValue(e.target.value)}
onBlur={() => {
- onBlur()
- onInputBlur()
+ onBlur();
+ onInputBlur();
// We propagate the change to the field only when the input is blurred
- onChange(localValue, value)
+ onChange(localValue, value);
}}
onFocus={onFocus}
type="number"
inputMode="decimal"
className={clx(
- "txt-compact-small size-full bg-transparent outline-none",
- "placeholder:text-ui-fg-muted"
+ 'txt-compact-small size-full bg-transparent outline-none',
+ 'placeholder:text-ui-fg-muted'
)}
tabIndex={-1}
{...props}
@@ -90,5 +95,5 @@ const Inner = ({
{...attributes}
/>
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-readonly-cell.tsx b/src/components/data-grid/components/data-grid-readonly-cell.tsx
index cf842684..b5c004b6 100644
--- a/src/components/data-grid/components/data-grid-readonly-cell.tsx
+++ b/src/components/data-grid/components/data-grid-readonly-cell.tsx
@@ -1,33 +1,38 @@
-import { PropsWithChildren } from "react"
+import type { PropsWithChildren } from 'react';
-import { clx } from "@medusajs/ui"
-import { useDataGridCellError } from "../hooks"
-import { DataGridCellProps } from "../types"
-import { DataGridRowErrorIndicator } from "./data-grid-row-error-indicator"
+import { useDataGridCellError } from '@components/data-grid/hooks';
+import type { DataGridCellProps } from '@components/data-grid/types';
+import { clx } from '@medusajs/ui';
+import { DataGridRowErrorIndicator } from './data-grid-row-error-indicator';
+
+//@todo fix type
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
type DataGridReadonlyCellProps = PropsWithChildren<
DataGridCellProps
> & {
- color?: "muted" | "normal"
-}
+ color?: 'muted' | 'normal';
+};
+//@todo fix type
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const DataGridReadonlyCell = ({
context,
- color = "muted",
- children,
+ color = 'muted',
+ children
}: DataGridReadonlyCellProps) => {
- const { rowErrors } = useDataGridCellError({ context })
+ const { rowErrors } = useDataGridCellError({ context });
return (
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-root.tsx b/src/components/data-grid/components/data-grid-root.tsx
index e1c23e11..002797c7 100644
--- a/src/components/data-grid/components/data-grid-root.tsx
+++ b/src/components/data-grid/components/data-grid-root.tsx
@@ -1,32 +1,32 @@
import React, {
- CSSProperties,
- ReactNode,
useCallback,
useEffect,
useMemo,
useRef,
- useState
+ useState,
+ type CSSProperties,
+ type ReactNode
} from 'react';
+import { useCommandHistory } from '@hooks/use-command-history';
+import { useDocumentDirection } from '@hooks/use-document-direction';
import { Adjustments, AdjustmentsDone, ExclamationCircle } from '@medusajs/icons';
import { Button, clx, DropdownMenu } from '@medusajs/ui';
import {
- Cell,
- CellContext,
- Column,
- ColumnDef,
flexRender,
getCoreRowModel,
- Row,
useReactTable,
- VisibilityState
+ type Cell,
+ type CellContext,
+ type Column,
+ type ColumnDef,
+ type Row,
+ type VisibilityState
} from '@tanstack/react-table';
-import { useVirtualizer, VirtualItem } from '@tanstack/react-virtual';
-import { FieldValues, UseFormReturn } from 'react-hook-form';
+import { useVirtualizer, type VirtualItem } from '@tanstack/react-virtual';
+import type { FieldValues, UseFormReturn } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
-import { useCommandHistory } from '../../../hooks/use-command-history';
-import { useDocumentDirection } from '../../../hooks/use-document-direction';
import { ConditionalTooltip } from '../../common/conditional-tooltip';
import { DataGridContext, useDataGridContext } from '../context';
import {
@@ -43,7 +43,7 @@ import {
useDataGridQueryTool
} from '../hooks';
import { DataGridMatrix } from '../models';
-import { DataGridCoordinates, GridColumnOption } from '../types';
+import type { DataGridCoordinates, GridColumnOption } from '../types';
import { isCellMatch, isSpecialFocusKey } from '../utils';
import { DataGridKeyboardShortcutModal } from './data-grid-keyboard-shortcut-modal';
@@ -403,6 +403,7 @@ export const DataGridRoot = {
if (isSpecialFocusKey(e)) {
handleSpecialFocusKeys(e);
+
return;
}
};
@@ -676,6 +677,7 @@ const DataGridHeader = ({
onHeaderInteractionChange(value);
setColumnsOpen(value);
};
+
return (
diff --git a/src/components/data-grid/components/data-grid-row-error-indicator.tsx b/src/components/data-grid/components/data-grid-row-error-indicator.tsx
index 05315110..b756f28a 100644
--- a/src/components/data-grid/components/data-grid-row-error-indicator.tsx
+++ b/src/components/data-grid/components/data-grid-row-error-indicator.tsx
@@ -1,18 +1,16 @@
-import { Badge, Tooltip } from "@medusajs/ui"
-import { useTranslation } from "react-i18next"
-import { DataGridRowError } from "../types"
+import type { DataGridRowError } from '@components/data-grid/types';
+import { Badge, Tooltip } from '@medusajs/ui';
+import { useTranslation } from 'react-i18next';
type DataGridRowErrorIndicatorProps = {
- rowErrors: DataGridRowError[]
-}
+ rowErrors: DataGridRowError[];
+};
-export const DataGridRowErrorIndicator = ({
- rowErrors,
-}: DataGridRowErrorIndicatorProps) => {
- const rowErrorCount = rowErrors ? rowErrors.length : 0
+export const DataGridRowErrorIndicator = ({ rowErrors }: DataGridRowErrorIndicatorProps) => {
+ const rowErrorCount = rowErrors ? rowErrors.length : 0;
if (!rowErrors || rowErrorCount <= 0) {
- return null
+ return null;
}
return (
@@ -20,25 +18,28 @@ export const DataGridRowErrorIndicator = ({
content={
{rowErrors.map((error, index) => (
-
+
))}
}
delayDuration={0}
>
-
+
{rowErrorCount}
- )
-}
+ );
+};
-const DataGridRowErrorLine = ({
- error,
-}: {
- error: { message: string; to: () => void }
-}) => {
- const { t } = useTranslation()
+const DataGridRowErrorLine = ({ error }: { error: { message: string; to: () => void } }) => {
+ const { t } = useTranslation();
return (
@@ -46,10 +47,10 @@ const DataGridRowErrorLine = ({
- {t("dataGrid.errors.fixError")}
+ {t('dataGrid.errors.fixError')}
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-skeleton.tsx b/src/components/data-grid/components/data-grid-skeleton.tsx
index a54f203c..771303ba 100644
--- a/src/components/data-grid/components/data-grid-skeleton.tsx
+++ b/src/components/data-grid/components/data-grid-skeleton.tsx
@@ -1,41 +1,39 @@
-import { ColumnDef } from "@tanstack/react-table"
-import { Skeleton } from "../../common/skeleton"
+import { Skeleton } from '@components/common/skeleton';
+import type { ColumnDef } from '@tanstack/react-table';
type DataGridSkeletonProps = {
- columns: ColumnDef[]
- rows?: number
-}
+ columns: ColumnDef[];
+ rows?: number;
+};
export const DataGridSkeleton = ({
columns,
- rows: rowCount = 10,
+ rows: rowCount = 10
}: DataGridSkeletonProps) => {
- const rows = Array.from({ length: rowCount }, (_, i) => i)
+ const rows = Array.from({ length: rowCount }, (_, i) => i);
- const colCount = columns.length
+ const colCount = columns.length;
return (
-
-
-
+
+
-
+
- {columns.map((_col, i) => {
- return (
-
-
-
- )
- })}
+ {columns.map((_col, i) => (
+
+
+
+ ))}
{rows.map((_, j) => (
@@ -44,20 +42,18 @@ export const DataGridSkeleton =
({
style={{ gridTemplateColumns: `repeat(${colCount}, 1fr)` }}
key={j}
>
- {columns.map((_col, k) => {
- return (
-
-
-
- )
- })}
+ {columns.map((_col, k) => (
+
+
+
+ ))}
))}
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-text-cell.tsx b/src/components/data-grid/components/data-grid-text-cell.tsx
index 3b1fb279..d535f6e5 100644
--- a/src/components/data-grid/components/data-grid-text-cell.tsx
+++ b/src/components/data-grid/components/data-grid-text-cell.tsx
@@ -1,75 +1,83 @@
-import { clx } from "@medusajs/ui"
-import { useEffect, useState } from "react"
-import { Controller, ControllerRenderProps } from "react-hook-form"
+import { useEffect, useState } from 'react';
-import { useCombinedRefs } from "../../../hooks/use-combined-refs"
-import { useDataGridCell, useDataGridCellError } from "../hooks"
-import { DataGridCellProps, InputProps } from "../types"
-import { DataGridCellContainer } from "./data-grid-cell-container"
+import { useDataGridCell, useDataGridCellError } from '@components/data-grid/hooks';
+import type { DataGridCellProps, InputProps } from '@components/data-grid/types';
+import { useCombinedRefs } from '@hooks/use-combined-refs.tsx';
+import { clx } from '@medusajs/ui';
+import { Controller, type ControllerRenderProps } from 'react-hook-form';
-export const DataGridTextCell =
({
- context,
+import { DataGridCellContainer } from './data-grid-cell-container';
+
+export const DataGridTextCell = ({
+ context
}: DataGridCellProps) => {
const { field, control, renderProps } = useDataGridCell({
- context,
- })
- const errorProps = useDataGridCellError({ context })
+ context
+ });
+ const errorProps = useDataGridCellError({ context });
- const { container, input } = renderProps
+ const { container, input } = renderProps;
return (
{
- return (
-
-
-
- )
- }}
+ render={({ field }) => (
+
+
+
+ )}
/>
- )
-}
+ );
+};
const Inner = ({
field,
- inputProps,
+ inputProps
}: {
- field: ControllerRenderProps
- inputProps: InputProps
+ //@todo fix type
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ field: ControllerRenderProps;
+ inputProps: InputProps;
}) => {
- const { onChange: _, onBlur, ref, value, ...rest } = field
- const { ref: inputRef, onBlur: onInputBlur, onChange, ...input } = inputProps
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const { onChange: _, onBlur, ref, value, ...rest } = field;
+ const { ref: inputRef, onBlur: onInputBlur, onChange, ...input } = inputProps;
- const [localValue, setLocalValue] = useState(value)
+ const [localValue, setLocalValue] = useState(value);
useEffect(() => {
- setLocalValue(value)
- }, [value])
+ setLocalValue(value);
+ }, [value]);
- const combinedRefs = useCombinedRefs(inputRef, ref)
+ const combinedRefs = useCombinedRefs(inputRef, ref);
return (
setLocalValue(e.target.value)}
+ onChange={e => setLocalValue(e.target.value)}
ref={combinedRefs}
onBlur={() => {
- onBlur()
- onInputBlur()
+ onBlur();
+ onInputBlur();
// We propagate the change to the field only when the input is blurred
- onChange(localValue, value)
+ onChange(localValue, value);
}}
{...input}
{...rest}
/>
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/data-grid-toggleable-number-cell.tsx b/src/components/data-grid/components/data-grid-toggleable-number-cell.tsx
index aac12fa3..c9930abf 100644
--- a/src/components/data-grid/components/data-grid-toggleable-number-cell.tsx
+++ b/src/components/data-grid/components/data-grid-toggleable-number-cell.tsx
@@ -1,103 +1,112 @@
-import { Switch } from "@medusajs/ui"
-import { useEffect, useRef, useState } from "react"
-import CurrencyInput, { CurrencyInputProps } from "react-currency-input-field"
-import { Controller, ControllerRenderProps } from "react-hook-form"
-import { useCombinedRefs } from "../../../hooks/use-combined-refs"
-import { ConditionalTooltip } from "../../common/conditional-tooltip"
-import { useDataGridCell, useDataGridCellError } from "../hooks"
-import { DataGridCellProps, InputProps } from "../types"
-import { DataGridCellContainer } from "./data-grid-cell-container"
+import { useEffect, useRef, useState } from 'react';
+import { ConditionalTooltip } from '@components/common/conditional-tooltip';
+import { useDataGridCell, useDataGridCellError } from '@components/data-grid/hooks';
+import type { DataGridCellProps, InputProps } from '@components/data-grid/types';
+import { useCombinedRefs } from '@hooks/use-combined-refs.tsx';
+import { Switch } from '@medusajs/ui';
+import CurrencyInput, { type CurrencyInputProps } from 'react-currency-input-field';
+import { Controller, type ControllerRenderProps } from 'react-hook-form';
+
+import { DataGridCellContainer } from './data-grid-cell-container';
+
+//@todo fix type
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const DataGridTogglableNumberCell = ({
context,
disabledToggleTooltip,
...rest
}: DataGridCellProps & {
- min?: number
- max?: number
- placeholder?: string
- disabledToggleTooltip?: string
+ min?: number;
+ max?: number;
+ placeholder?: string;
+ disabledToggleTooltip?: string;
}) => {
const { field, control, renderProps } = useDataGridCell({
- context,
- })
- const errorProps = useDataGridCellError({ context })
+ context
+ });
+ const errorProps = useDataGridCellError({ context });
- const { container, input } = renderProps
+ const { container, input } = renderProps;
return (
{
- return (
-
- }
- >
-
-
- )
- }}
+ render={({ field }) => (
+
+ }
+ >
+
+
+ )}
/>
- )
-}
+ );
+};
const OuterComponent = ({
field,
inputProps,
isAnchor,
- tooltip,
+ tooltip
}: {
- field: ControllerRenderProps
- inputProps: InputProps
- isAnchor: boolean
- tooltip?: string
+ //@todo fix type
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ field: ControllerRenderProps;
+ inputProps: InputProps;
+ isAnchor: boolean;
+ tooltip?: string;
}) => {
- const buttonRef = useRef(null)
- const { value } = field
- const { onChange } = inputProps
+ const buttonRef = useRef(null);
+ const { value } = field;
+ const { onChange } = inputProps;
- const [localValue, setLocalValue] = useState(value)
+ const [localValue, setLocalValue] = useState(value);
useEffect(() => {
- setLocalValue(value)
- }, [value])
+ setLocalValue(value);
+ }, [value]);
const handleCheckedChange = (update: boolean) => {
- const newValue = { ...localValue, checked: update }
+ const newValue = { ...localValue, checked: update };
if (!update && !newValue.disabledToggle) {
- newValue.quantity = ""
+ newValue.quantity = '';
}
- if (update && newValue.quantity === "") {
- newValue.quantity = 0
+ if (update && newValue.quantity === '') {
+ newValue.quantity = 0;
}
- setLocalValue(newValue)
- onChange(newValue, value)
- }
+ setLocalValue(newValue);
+ onChange(newValue, value);
+ };
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
- if (isAnchor && e.key.toLowerCase() === "x") {
- e.preventDefault()
- buttonRef.current?.click()
+ if (isAnchor && e.key.toLowerCase() === 'x') {
+ e.preventDefault();
+ buttonRef.current?.click();
}
- }
+ };
+
+ document.addEventListener('keydown', handleKeyDown);
- document.addEventListener("keydown", handleKeyDown)
- return () => document.removeEventListener("keydown", handleKeyDown)
- }, [isAnchor])
+ return () => document.removeEventListener('keydown', handleKeyDown);
+ }, [isAnchor]);
return (
- )
-}
+ );
+};
const Inner = ({
field,
@@ -125,36 +134,29 @@ const Inner = ({
placeholder,
...props
}: {
- field: ControllerRenderProps
- inputProps: InputProps
- min?: number
- max?: number
- placeholder?: string
+ //@todo fix type
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ field: ControllerRenderProps;
+ inputProps: InputProps;
+ min?: number;
+ max?: number;
+ placeholder?: string;
}) => {
- const { ref, value, onChange: _, onBlur, ...fieldProps } = field
- const {
- ref: inputRef,
- onChange,
- onBlur: onInputBlur,
- onFocus,
- ...attributes
- } = inputProps
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const { ref, value, onChange: _, onBlur, ...fieldProps } = field;
+ const { ref: inputRef, onChange, onBlur: onInputBlur, onFocus, ...attributes } = inputProps;
- const [localValue, setLocalValue] = useState(value)
+ const [localValue, setLocalValue] = useState(value);
useEffect(() => {
- setLocalValue(value)
- }, [value])
+ setLocalValue(value);
+ }, [value]);
- const combinedRefs = useCombinedRefs(inputRef, ref)
+ const combinedRefs = useCombinedRefs(inputRef, ref);
- const handleInputChange: CurrencyInputProps["onValueChange"] = (
- updatedValue,
- _name,
- _values
- ) => {
- const ensuredValue = updatedValue !== undefined ? updatedValue : ""
- const newValue = { ...localValue, quantity: ensuredValue }
+ const handleInputChange: CurrencyInputProps['onValueChange'] = updatedValue => {
+ const ensuredValue = updatedValue !== undefined ? updatedValue : '';
+ const newValue = { ...localValue, quantity: ensuredValue };
/**
* If the value is not empty, then the location should be enabled.
@@ -162,22 +164,24 @@ const Inner = ({
* Else, if the value is empty and the location is enabled, then the
* location should be disabled, unless toggling the location is disabled.
*/
- if (ensuredValue !== "") {
- newValue.checked = true
+ if (ensuredValue !== '') {
+ newValue.checked = true;
} else if (newValue.checked && newValue.disabledToggle === false) {
- newValue.checked = false
+ newValue.checked = false;
}
- setLocalValue(newValue)
- }
+ setLocalValue(newValue);
+ };
const handleOnChange = () => {
- if (localValue.disabledToggle && localValue.quantity === "") {
- localValue.quantity = 0
+ if (localValue.disabledToggle && localValue.quantity === '') {
+ //@todo fix type
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any,react-hooks/immutability
+ localValue.quantity = 0;
}
- onChange(localValue, value)
- }
+ onChange(localValue, value);
+ };
return (
@@ -191,9 +195,9 @@ const Inner = ({
onValueChange={handleInputChange}
formatValueOnBlur
onBlur={() => {
- onBlur()
- onInputBlur()
- handleOnChange()
+ onBlur();
+ onInputBlur();
+ handleOnChange();
}}
onFocus={onFocus}
decimalsLimit={0}
@@ -202,5 +206,5 @@ const Inner = ({
placeholder={!localValue.checked ? placeholder : undefined}
/>
- )
-}
+ );
+};
diff --git a/src/components/data-grid/components/index.ts b/src/components/data-grid/components/index.ts
index 3968df05..b520901e 100644
--- a/src/components/data-grid/components/index.ts
+++ b/src/components/data-grid/components/index.ts
@@ -1,7 +1,8 @@
-export { DataGridBooleanCell } from "./data-grid-boolean-cell"
-export { DataGridCurrencyCell } from "./data-grid-currency-cell"
-export { DataGridNumberCell } from "./data-grid-number-cell"
-export { DataGridReadonlyCell as DataGridReadOnlyCell } from "./data-grid-readonly-cell"
-export { DataGridRoot, type DataGridRootProps } from "./data-grid-root"
-export { DataGridSkeleton } from "./data-grid-skeleton"
-export { DataGridTextCell } from "./data-grid-text-cell"
+export { DataGridBooleanCell } from './data-grid-boolean-cell';
+export { DataGridCurrencyCell } from './data-grid-currency-cell';
+export { DataGridNumberCell } from './data-grid-number-cell';
+export { DataGridReadonlyCell as DataGridReadOnlyCell } from './data-grid-readonly-cell';
+export { DataGridRoot, type DataGridRootProps } from './data-grid-root';
+export { DataGridSkeleton } from './data-grid-skeleton';
+export { DataGridTextCell } from './data-grid-text-cell';
+export { DataGridReadonlyCell } from './data-grid-readonly-cell';
diff --git a/src/components/data-grid/context/data-grid-context.tsx b/src/components/data-grid/context/data-grid-context.tsx
index bdfc4192..da2b0575 100644
--- a/src/components/data-grid/context/data-grid-context.tsx
+++ b/src/components/data-grid/context/data-grid-context.tsx
@@ -1,46 +1,41 @@
-import { FocusEvent, MouseEvent, createContext } from "react"
-import {
- Control,
- FieldErrors,
- FieldValues,
- Path,
- UseFormRegister,
-} from "react-hook-form"
-import { CellErrorMetadata, CellMetadata, DataGridCoordinates } from "../types"
+import { createContext, type FocusEvent, type MouseEvent } from 'react';
+
+import type {
+ CellErrorMetadata,
+ CellMetadata,
+ DataGridCoordinates
+} from '@components/data-grid/types.ts';
+import type { Control, FieldErrors, FieldValues, Path, UseFormRegister } from 'react-hook-form';
type DataGridContextType = {
// Grid state
- anchor: DataGridCoordinates | null
- trapActive: boolean
- setTrapActive: (value: boolean) => void
- errors: FieldErrors
+ anchor: DataGridCoordinates | null;
+ trapActive: boolean;
+ setTrapActive: (value: boolean) => void;
+ errors: FieldErrors;
// Cell handlers
- getIsCellSelected: (coords: DataGridCoordinates) => boolean
- getIsCellDragSelected: (coords: DataGridCoordinates) => boolean
+ getIsCellSelected: (coords: DataGridCoordinates) => boolean;
+ getIsCellDragSelected: (coords: DataGridCoordinates) => boolean;
// Grid handlers
- setIsEditing: (value: boolean) => void
- setIsSelecting: (value: boolean) => void
- setRangeEnd: (coords: DataGridCoordinates) => void
- setSingleRange: (coords: DataGridCoordinates) => void
+ setIsEditing: (value: boolean) => void;
+ setIsSelecting: (value: boolean) => void;
+ setRangeEnd: (coords: DataGridCoordinates) => void;
+ setSingleRange: (coords: DataGridCoordinates) => void;
// Form state and handlers
- register: UseFormRegister
- control: Control
- getInputChangeHandler: (
- field: Path
- ) => (next: any, prev: any) => void
+ register: UseFormRegister;
+ control: Control;
+ getInputChangeHandler: (field: Path) => (next: any, prev: any) => void;
// Wrapper handlers
getWrapperFocusHandler: (
coordinates: DataGridCoordinates
- ) => (e: FocusEvent) => void
+ ) => (e: FocusEvent) => void;
getWrapperMouseOverHandler: (
coordinates: DataGridCoordinates
- ) => ((e: MouseEvent) => void) | undefined
- getCellMetadata: (coords: DataGridCoordinates) => CellMetadata
- getCellErrorMetadata: (coords: DataGridCoordinates) => CellErrorMetadata
- navigateToField: (field: string) => void
- dataTestId?: string
-}
+ ) => ((e: MouseEvent) => void) | undefined;
+ getCellMetadata: (coords: DataGridCoordinates) => CellMetadata;
+ getCellErrorMetadata: (coords: DataGridCoordinates) => CellErrorMetadata;
+ navigateToField: (field: string) => void;
+ dataTestId?: string;
+};
-export const DataGridContext = createContext | null>(
- null
-)
+export const DataGridContext = createContext | null>(null);
diff --git a/src/components/data-grid/context/index.ts b/src/components/data-grid/context/index.ts
index dda988e4..2d09d9f2 100644
--- a/src/components/data-grid/context/index.ts
+++ b/src/components/data-grid/context/index.ts
@@ -1,2 +1,2 @@
-export * from "./data-grid-context"
-export * from "./use-data-grid-context"
+export * from './data-grid-context';
+export * from './use-data-grid-context';
diff --git a/src/components/data-grid/context/use-data-grid-context.tsx b/src/components/data-grid/context/use-data-grid-context.tsx
index 3a0f8bfa..061fc383 100644
--- a/src/components/data-grid/context/use-data-grid-context.tsx
+++ b/src/components/data-grid/context/use-data-grid-context.tsx
@@ -1,14 +1,13 @@
-import { useContext } from "react"
-import { DataGridContext } from "./data-grid-context"
+import { useContext } from 'react';
+
+import { DataGridContext } from './data-grid-context';
export const useDataGridContext = () => {
- const context = useContext(DataGridContext)
+ const context = useContext(DataGridContext);
if (!context) {
- throw new Error(
- "useDataGridContext must be used within a DataGridContextProvider"
- )
+ throw new Error('useDataGridContext must be used within a DataGridContextProvider');
}
- return context
-}
+ return context;
+};
diff --git a/src/components/data-grid/data-grid.tsx b/src/components/data-grid/data-grid.tsx
index 74a08383..aee6d165 100644
--- a/src/components/data-grid/data-grid.tsx
+++ b/src/components/data-grid/data-grid.tsx
@@ -1,5 +1,3 @@
-import { FieldValues } from "react-hook-form"
-
import {
DataGridBooleanCell,
DataGridCurrencyCell,
@@ -8,34 +6,32 @@ import {
DataGridRoot,
DataGridSkeleton,
DataGridTextCell,
- type DataGridRootProps,
-} from "./components"
+ type DataGridRootProps
+} from '@components/data-grid/components';
+import type { FieldValues } from 'react-hook-form';
interface DataGridProps
extends DataGridRootProps {
- isLoading?: boolean
+ isLoading?: boolean;
}
const _DataGrid = ({
isLoading,
...props
-}: DataGridProps) => {
- return isLoading ? (
+}: DataGridProps) =>
+ isLoading ? (
0 ? props.data.length : 10
- }
+ rows={props.data?.length && props.data.length > 0 ? props.data.length : 10}
/>
) : (
- )
-}
+ );
export const DataGrid = Object.assign(_DataGrid, {
BooleanCell: DataGridBooleanCell,
TextCell: DataGridTextCell,
NumberCell: DataGridNumberCell,
CurrencyCell: DataGridCurrencyCell,
- ReadonlyCell: DataGridReadOnlyCell,
-})
+ ReadonlyCell: DataGridReadOnlyCell
+});
diff --git a/src/components/data-grid/helpers/create-data-grid-column-helper.ts b/src/components/data-grid/helpers/create-data-grid-column-helper.ts
index c47b9e80..1683c42c 100644
--- a/src/components/data-grid/helpers/create-data-grid-column-helper.ts
+++ b/src/components/data-grid/helpers/create-data-grid-column-helper.ts
@@ -1,54 +1,50 @@
+import type { DataGridColumnType, FieldFunction } from '@components/data-grid/types';
import {
- CellContext,
- ColumnDefTemplate,
createColumnHelper,
- HeaderContext,
-} from "@tanstack/react-table"
-import { FieldValues } from "react-hook-form"
-
-import { DataGridColumnType, FieldFunction } from "../types"
+ type CellContext,
+ type ColumnDefTemplate,
+ type HeaderContext
+} from '@tanstack/react-table';
+import type { FieldValues } from 'react-hook-form';
type DataGridHelperColumnsProps = {
/**
* The id of the column.
*/
- id: string
+ id: string;
/**
* The name of the column, shown in the column visibility menu.
*/
- name?: string
+ name?: string;
/**
* The header template for the column.
*/
- header: ColumnDefTemplate> | undefined
+ header: ColumnDefTemplate> | undefined;
/**
* The cell template for the column.
*/
- cell: ColumnDefTemplate> | undefined
+ cell: ColumnDefTemplate> | undefined;
/**
* Callback to set the field path for each cell in the column.
* If a callback is not provided, or returns null, the cell will not be editable.
*/
- field?: FieldFunction
+ field?: FieldFunction;
/**
* Whether the column cannot be hidden by the user.
*
* @default false
*/
- disableHiding?: boolean
+ disableHiding?: boolean;
} & (
| {
- field: FieldFunction
- type: DataGridColumnType
+ field: FieldFunction;
+ type: DataGridColumnType;
}
| { field?: null | undefined; type?: never }
-)
+);
-export function createDataGridHelper<
- TData,
- TFieldValues extends FieldValues
->() {
- const columnHelper = createColumnHelper()
+export function createDataGridHelper() {
+ const columnHelper = createColumnHelper();
return {
column: ({
@@ -58,7 +54,7 @@ export function createDataGridHelper<
cell,
disableHiding = false,
field,
- type,
+ type
}: DataGridHelperColumnsProps) =>
columnHelper.display({
id,
@@ -68,8 +64,8 @@ export function createDataGridHelper<
meta: {
name,
field,
- type,
- },
- }),
- }
+ type
+ }
+ })
+ };
}
diff --git a/src/components/data-grid/helpers/create-data-grid-price-columns.tsx b/src/components/data-grid/helpers/create-data-grid-price-columns.tsx
index 0c1fff4e..57b15a74 100644
--- a/src/components/data-grid/helpers/create-data-grid-price-columns.tsx
+++ b/src/components/data-grid/helpers/create-data-grid-price-columns.tsx
@@ -1,126 +1,124 @@
-import { HttpTypes } from "@medusajs/types"
-import { ColumnDef } from "@tanstack/react-table"
-import { TFunction } from "i18next"
-import { FieldPath, FieldValues } from "react-hook-form"
-import { IncludesTaxTooltip } from "../../common/tax-badge/tax-badge"
-import { DataGridCurrencyCell } from "../components/data-grid-currency-cell"
-import { DataGridReadonlyCell } from "../components/data-grid-readonly-cell"
-import { FieldContext } from "../types"
-import { createDataGridHelper } from "./create-data-grid-column-helper"
+import { IncludesTaxTooltip } from '@components/common/tax-badge';
+import { createDataGridHelper } from '@components/data-grid';
+import { DataGridCurrencyCell, DataGridReadonlyCell } from '@components/data-grid/components';
+import type { FieldContext } from '@components/data-grid/types';
+import type { HttpTypes } from '@medusajs/types';
+import type { ColumnDef } from '@tanstack/react-table';
+import type { TFunction } from 'i18next';
+import type { FieldPath, FieldValues } from 'react-hook-form';
-type CreateDataGridPriceColumnsProps<
- TData,
- TFieldValues extends FieldValues
-> = {
- currencies?: string[]
- regions?: HttpTypes.AdminRegion[]
- pricePreferences?: HttpTypes.AdminPricePreference[]
- isReadyOnly?: (context: FieldContext) => boolean
- getFieldName: (
- context: FieldContext,
- value: string
- ) => FieldPath | null
- t: TFunction
-}
+type CreateDataGridPriceColumnsProps = {
+ currencies?: string[];
+ regions?: HttpTypes.AdminRegion[];
+ pricePreferences?: HttpTypes.AdminPricePreference[];
+ isReadyOnly?: (context: FieldContext) => boolean;
+ getFieldName: (context: FieldContext, value: string) => FieldPath | null;
+ t: TFunction;
+};
-export const createDataGridPriceColumns = <
- TData,
- TFieldValues extends FieldValues
->({
+export const createDataGridPriceColumns = ({
currencies,
regions,
pricePreferences,
isReadyOnly,
getFieldName,
- t,
-}: CreateDataGridPriceColumnsProps): ColumnDef<
- TData,
- unknown
->[] => {
- const columnHelper = createDataGridHelper()
+ t
+}: CreateDataGridPriceColumnsProps): ColumnDef[] => {
+ const columnHelper = createDataGridHelper();
return [
- ...(currencies?.map((currency) => {
+ ...(currencies?.map(currency => {
const preference = pricePreferences?.find(
- (p) => p.attribute === "currency_code" && p.value === currency
- )
+ p => p.attribute === 'currency_code' && p.value === currency
+ );
- const translatedCurrencyName = t("fields.priceTemplate", {
- regionOrCurrency: currency.toUpperCase(),
- })
+ const translatedCurrencyName = t('fields.priceTemplate', {
+ regionOrCurrency: currency.toUpperCase()
+ });
return columnHelper.column({
id: `currency_prices.${currency}`,
- name: t("fields.priceTemplate", {
- regionOrCurrency: currency.toUpperCase(),
+ name: t('fields.priceTemplate', {
+ regionOrCurrency: currency.toUpperCase()
}),
- field: (context) => {
- const isReadyOnlyValue = isReadyOnly?.(context)
+ field: context => {
+ const isReadyOnlyValue = isReadyOnly?.(context);
if (isReadyOnlyValue) {
- return null
+ return null;
}
- return getFieldName(context, currency)
+ return getFieldName(context, currency);
},
- type: "number",
+ type: 'number',
header: () => (
-
+
{translatedCurrencyName}
),
- cell: (context) => {
+ cell: context => {
if (isReadyOnly?.(context)) {
- return
+ return ;
}
- return
- },
- })
+ return (
+
+ );
+ }
+ });
}) ?? []),
- ...(regions?.map((region) => {
+ ...(regions?.map(region => {
const preference = pricePreferences?.find(
- (p) => p.attribute === "region_id" && p.value === region.id
- )
+ p => p.attribute === 'region_id' && p.value === region.id
+ );
- const translatedRegionName = t("fields.priceTemplate", {
- regionOrCurrency: region.name,
- })
+ const translatedRegionName = t('fields.priceTemplate', {
+ regionOrCurrency: region.name
+ });
return columnHelper.column({
id: `region_prices.${region.id}`,
- name: t("fields.priceTemplate", {
- regionOrCurrency: region.name,
+ name: t('fields.priceTemplate', {
+ regionOrCurrency: region.name
}),
- field: (context) => {
- const isReadyOnlyValue = isReadyOnly?.(context)
+ field: context => {
+ const isReadyOnlyValue = isReadyOnly?.(context);
if (isReadyOnlyValue) {
- return null
+ return null;
}
- return getFieldName(context, region.id)
+ return getFieldName(context, region.id);
},
- type: "number",
+ type: 'number',
header: () => (
-
+
{translatedRegionName}
),
- cell: (context) => {
+ cell: context => {
if (isReadyOnly?.(context)) {
- return
+ return ;
}
- const currency = currencies?.find((c) => c === region.currency_code)
+ const currency = currencies?.find(c => c === region.currency_code);
if (!currency) {
- return null
+ return null;
}
return (
@@ -128,9 +126,9 @@ export const createDataGridPriceColumns = <
code={region.currency_code}
context={context}
/>
- )
- },
- })
- }) ?? []),
- ]
-}
+ );
+ }
+ });
+ }) ?? [])
+ ];
+};
diff --git a/src/components/data-grid/helpers/index.ts b/src/components/data-grid/helpers/index.ts
index 5a490604..c7b349c0 100644
--- a/src/components/data-grid/helpers/index.ts
+++ b/src/components/data-grid/helpers/index.ts
@@ -1,2 +1,2 @@
-export * from "./create-data-grid-column-helper"
-export * from "./create-data-grid-price-columns"
+export * from './create-data-grid-column-helper';
+export * from './create-data-grid-price-columns';
diff --git a/src/components/data-grid/hooks/index.ts b/src/components/data-grid/hooks/index.ts
index 2307c30c..54299b4c 100644
--- a/src/components/data-grid/hooks/index.ts
+++ b/src/components/data-grid/hooks/index.ts
@@ -1,14 +1,14 @@
-export * from "./use-data-grid-cell"
-export * from "./use-data-grid-cell-error"
-export * from "./use-data-grid-cell-handlers"
-export * from "./use-data-grid-cell-metadata"
-export * from "./use-data-grid-cell-snapshot"
-export * from "./use-data-grid-clipboard-events"
-export * from "./use-data-grid-column-visibility"
-export * from "./use-data-grid-duplicate-cell"
-export * from "./use-data-grid-error-highlighting"
-export * from "./use-data-grid-form-handlers"
-export * from "./use-data-grid-keydown-event"
-export * from "./use-data-grid-mouse-up-event"
-export * from "./use-data-grid-navigation"
-export * from "./use-data-grid-query-tool"
+export * from './use-data-grid-cell';
+export * from './use-data-grid-cell-error';
+export * from './use-data-grid-cell-handlers';
+export * from './use-data-grid-cell-metadata';
+export * from './use-data-grid-cell-snapshot';
+export * from './use-data-grid-clipboard-events';
+export * from './use-data-grid-column-visibility';
+export * from './use-data-grid-duplicate-cell';
+export * from './use-data-grid-error-highlighting';
+export * from './use-data-grid-form-handlers';
+export * from './use-data-grid-keydown-event';
+export * from './use-data-grid-mouse-up-event';
+export * from './use-data-grid-navigation';
+export * from './use-data-grid-query-tool';
diff --git a/src/components/data-grid/hooks/use-data-grid-cell-error.tsx b/src/components/data-grid/hooks/use-data-grid-cell-error.tsx
index b54e3125..c0c3b4b2 100644
--- a/src/components/data-grid/hooks/use-data-grid-cell-error.tsx
+++ b/src/components/data-grid/hooks/use-data-grid-cell-error.tsx
@@ -1,78 +1,70 @@
-import { CellContext } from "@tanstack/react-table"
-import { useMemo } from "react"
-import { FieldError, FieldErrors, get } from "react-hook-form"
+import { useMemo } from 'react';
-import { useDataGridContext } from "../context"
-import { DataGridCellContext, DataGridRowError } from "../types"
+import { useDataGridContext } from '@components/data-grid/context';
+import type { DataGridCellContext, DataGridRowError } from '@components/data-grid/types';
+import type { CellContext } from '@tanstack/react-table';
+import { get, type FieldError, type FieldErrors } from 'react-hook-form';
type UseDataGridCellErrorOptions = {
- context: CellContext
-}
+ context: CellContext;
+};
export const useDataGridCellError = ({
- context,
+ context
}: UseDataGridCellErrorOptions) => {
- const { errors, getCellErrorMetadata, navigateToField } = useDataGridContext()
+ const { errors, getCellErrorMetadata, navigateToField } = useDataGridContext();
- const { rowIndex, columnIndex } = context as DataGridCellContext<
- TextData,
- TValue
- >
+ const { rowIndex, columnIndex } = context as DataGridCellContext;
const { accessor, field } = useMemo(() => {
- return getCellErrorMetadata({ row: rowIndex, col: columnIndex })
- }, [rowIndex, columnIndex, getCellErrorMetadata])
+ return getCellErrorMetadata({ row: rowIndex, col: columnIndex });
+ }, [rowIndex, columnIndex, getCellErrorMetadata]);
const rowErrorsObject: FieldErrors | undefined =
- accessor && columnIndex === 0 ? get(errors, accessor) : undefined
+ accessor && columnIndex === 0 ? get(errors, accessor) : undefined;
- const rowErrors: DataGridRowError[] = []
+ const rowErrors: DataGridRowError[] = [];
- function collectErrors(
- errorObject: FieldErrors | FieldError | undefined,
- baseAccessor: string
- ) {
+ function collectErrors(errorObject: FieldErrors | FieldError | undefined, baseAccessor: string) {
if (!errorObject) {
- return
+ return;
}
if (isFieldError(errorObject)) {
// Handle a single FieldError directly
- const message = errorObject.message
+ const message = errorObject.message;
- const to = () => navigateToField(baseAccessor)
+ const to = () => navigateToField(baseAccessor);
if (message) {
- rowErrors.push({ message, to })
+ rowErrors.push({ message, to });
}
} else {
// Traverse nested objects
- Object.keys(errorObject).forEach((key) => {
- const nestedError = errorObject[key]
- const fieldAccessor = `${baseAccessor}.${key}`
+ Object.keys(errorObject).forEach(key => {
+ const nestedError = errorObject[key];
+ const fieldAccessor = `${baseAccessor}.${key}`;
- if (nestedError && typeof nestedError === "object") {
- collectErrors(nestedError, fieldAccessor)
+ if (nestedError && typeof nestedError === 'object') {
+ collectErrors(nestedError, fieldAccessor);
}
- })
+ });
}
}
if (rowErrorsObject && accessor) {
- collectErrors(rowErrorsObject, accessor)
+ collectErrors(rowErrorsObject, accessor);
}
- const cellError: FieldError | undefined = field
- ? get(errors, field)
- : undefined
+ const cellError: FieldError | undefined = field ? get(errors, field) : undefined;
return {
errors,
rowErrors,
- cellError,
- }
-}
+ cellError
+ };
+};
function isFieldError(errors: FieldErrors | FieldError): errors is FieldError {
- return typeof errors === "object" && "message" in errors && "type" in errors
+ return typeof errors === 'object' && 'message' in errors && 'type' in errors;
}
diff --git a/src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx b/src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx
index 1aee1dc2..f0c416af 100644
--- a/src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx
+++ b/src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx
@@ -1,29 +1,27 @@
-import { FocusEvent, MouseEvent, useCallback } from "react"
-import { FieldValues, UseFormSetValue } from "react-hook-form"
-import { DataGridMatrix, DataGridUpdateCommand } from "../models"
-import { DataGridCoordinates } from "../types"
+import { useCallback, type FocusEvent, type MouseEvent } from 'react';
+
+import { DataGridUpdateCommand, type DataGridMatrix } from '@components/data-grid/models';
+import type { DataGridCoordinates } from '@components/data-grid/types';
+import type { FieldValues, UseFormSetValue } from 'react-hook-form';
type UseDataGridCellHandlersOptions = {
- matrix: DataGridMatrix
- anchor: DataGridCoordinates | null
- rangeEnd: DataGridCoordinates | null
- setRangeEnd: (coords: DataGridCoordinates | null) => void
- isSelecting: boolean
- setIsSelecting: (isSelecting: boolean) => void
- isDragging: boolean
- setIsDragging: (isDragging: boolean) => void
- setSingleRange: (coords: DataGridCoordinates) => void
- dragEnd: DataGridCoordinates | null
- setDragEnd: (coords: DataGridCoordinates | null) => void
- setValue: UseFormSetValue
- execute: (command: DataGridUpdateCommand) => void
- multiColumnSelection?: boolean
-}
-
-export const useDataGridCellHandlers = <
- TData,
- TFieldValues extends FieldValues
->({
+ matrix: DataGridMatrix;
+ anchor: DataGridCoordinates | null;
+ rangeEnd: DataGridCoordinates | null;
+ setRangeEnd: (coords: DataGridCoordinates | null) => void;
+ isSelecting: boolean;
+ setIsSelecting: (isSelecting: boolean) => void;
+ isDragging: boolean;
+ setIsDragging: (isDragging: boolean) => void;
+ setSingleRange: (coords: DataGridCoordinates) => void;
+ dragEnd: DataGridCoordinates | null;
+ setDragEnd: (coords: DataGridCoordinates | null) => void;
+ setValue: UseFormSetValue;
+ execute: (command: DataGridUpdateCommand) => void;
+ multiColumnSelection?: boolean;
+};
+
+export const useDataGridCellHandlers = ({
matrix,
anchor,
rangeEnd,
@@ -37,40 +35,37 @@ export const useDataGridCellHandlers = <
setDragEnd,
setValue,
execute,
- multiColumnSelection,
+ multiColumnSelection
}: UseDataGridCellHandlersOptions