Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
shift+select in table
aashuc0baf07ff207
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsxindex f0826751cf..64222edb92 100644--- a/apps/erp/app/components/Table/Table.tsx+++ b/apps/erp/app/components/Table/Table.tsx@@ -40,7 +40,12 @@ import {getCoreRowModel,useReactTable} from "@tanstack/react-table";-import type { CSSProperties, ReactElement, ReactNode } from "react";+import type {+ CSSProperties,+ MutableRefObject,+ ReactElement,+ ReactNode+} from "react";import {Fragment,useCallback,@@ -283,6 +288,9 @@ const Table = <T extends object>({: internalRowSelection;const setRowSelection = onRowSelectionChange ?? setInternalRowSelection;+ // Anchor row (by id) for shift-click range selection.+ const selectionAnchorRef = useRef<string | null>(null);+/* Clear row selection when data changes. Skip when rows have stable ids(getRowId) or selection is controlled — the selection survives datareshapes like tree expansion in those cases. */@@ -423,7 +431,7 @@ const Table = <T extends object>({);}if (withSelectableRows) {- result.push(...getRowSelectionColumn<T>());+ result.push(...getRowSelectionColumn<T>(selectionAnchorRef));}result.push(...columns);if (renderContextMenu) {@@ -1222,7 +1230,9 @@ const Table = <T extends object>({);};-function getRowSelectionColumn<T>(): ColumnDef<T>[] {+function getRowSelectionColumn<T>(+ anchorRef: MutableRefObject<string | null>+): ColumnDef<T>[] {return [{id: "Select",@@ -1237,16 +1247,45 @@ function getRowSelectionColumn<T>(): ColumnDef<T>[] {{...{checked: table.getIsAllRowsSelected(),indeterminate: table.getIsSomeRowsSelected(),- onChange: table.getToggleAllRowsSelectedHandler()+ onChange: (checked: boolean) => {+ table.toggleAllRowsSelected(checked);+ anchorRef.current = null;+ }}}/>),- cell: ({ row }) => (+ cell: ({ row, table }) => (<IndeterminateCheckbox{...{checked: row.getIsSelected(),indeterminate: row.getIsSomeSelected(),- onChange: row.getToggleSelectedHandler()+ onChange: (checked: boolean, shiftKey: boolean) => {+ const rows = table.getRowModel().rows;+ const clickedIndex = rows.findIndex((r) => r.id === row.id);+ const anchorIndex =+ anchorRef.current == null+ ? -1+ : rows.findIndex((r) => r.id === anchorRef.current);++ if (shiftKey && anchorIndex !== -1 && clickedIndex !== -1) {+ const start = Math.min(anchorIndex, clickedIndex);+ const end = Math.max(anchorIndex, clickedIndex);+ table.setRowSelection((prev) => {+ const next = { ...prev };+ for (let i = start; i <= end; i++) {+ const id = rows[i].id;+ if (checked) next[id] = true;+ else delete next[id];+ }+ return next;+ });+ // Keep the anchor fixed so the range can be re-dragged.+ return;+ }++ row.toggleSelected(checked);+ anchorRef.current = row.id;+ }}}/>)diff --git a/apps/erp/app/components/Table/components/IndeterminateCheckbox.tsx b/apps/erp/app/components/Table/components/IndeterminateCheckbox.tsxindex a7014f98c3..63b4c0344a 100644--- a/apps/erp/app/components/Table/components/IndeterminateCheckbox.tsx+++ b/apps/erp/app/components/Table/components/IndeterminateCheckbox.tsx@@ -1,11 +1,12 @@import { Checkbox } from "@carbon/react";import { Trans } from "@lingui/react/macro";import type { MouseEvent } from "react";+import { useRef } from "react";type IndeterminateCheckboxProps = {checked: boolean;indeterminate: boolean;- onChange: (e: MouseEvent<HTMLInputElement>) => void;+ onChange: (checked: boolean, shiftKey: boolean) => void;[key: string]: any;};@@ -15,10 +16,22 @@ const IndeterminateCheckbox = ({onChange,...rest}: IndeterminateCheckboxProps) => {- const handleChange = (checked: boolean) => {- onChange({- target: { checked }- } as unknown as MouseEvent<HTMLInputElement>);+ // onCheckedChange carries no DOM event, so capture the modifier on click.+ // Radix composes our onClick before firing onCheckedChange.+ const shiftKeyRef = useRef(false);++ const handleMouseDown = (event: MouseEvent<HTMLButtonElement>) => {+ // Prevent the browser from selecting text when shift-clicking a range.+ if (event.shiftKey) event.preventDefault();+ };++ const handleClick = (event: MouseEvent<HTMLButtonElement>) => {+ shiftKeyRef.current = event.shiftKey;+ };++ const handleChange = (nextChecked: boolean) => {+ onChange(nextChecked, shiftKeyRef.current);+ shiftKeyRef.current = false;};return (@@ -26,6 +39,8 @@ const IndeterminateCheckbox = ({isChecked={!!checked || !!indeterminate}isIndeterminate={indeterminate}className="ml-2 left-0 sticky z-[1]"+ onMouseDown={handleMouseDown}+ onClick={handleClick}onCheckedChange={handleChange}{...rest}>