• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

glideapps / glide-data-grid / 7316502082

24 Dec 2023 07:35PM CUT coverage: 90.577%. Remained the same
7316502082

Pull #830

github

jassmith
Allow specifying label and value independently in dropdown cell
Pull Request #830: Allow specifying label and value independently in dropdown cell

2590 of 3242 branches covered (0.0%)

15745 of 17383 relevant lines covered (90.58%)

3079.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.56
/packages/core/src/data-editor/use-cells-for-selection.ts
1
import * as React from "react";
1✔
2
import type { DataGridSearchProps } from "../internal/data-grid-search/data-grid-search.js";
1✔
3
import { type CellArray, type GridCell, GridCellKind } from "../internal/data-grid/data-grid-types.js";
1✔
4
import type { DataEditorProps } from "./data-editor.js";
1✔
5

1✔
6
type CellsForSelectionCallback = NonNullable<DataGridSearchProps["getCellsForSelection"]>;
1✔
7
export function useCellsForSelection(
1✔
8
    getCellsForSelectionIn: CellsForSelectionCallback | true | undefined,
677✔
9
    getCellContent: DataEditorProps["getCellContent"],
677✔
10
    rowMarkerOffset: number,
677✔
11
    abortController: AbortController,
677✔
12
    rows: number
677✔
13
) {
677✔
14
    const getCellsForSelectionDirectWhenValid = React.useCallback<CellsForSelectionCallback>(
677✔
15
        rect => {
677✔
16
            if (getCellsForSelectionIn === true) {
156✔
17
                const result: GridCell[][] = [];
156✔
18

156✔
19
                for (let y = rect.y; y < rect.y + rect.height; y++) {
156✔
20
                    const row: GridCell[] = [];
7,303✔
21
                    for (let x = rect.x; x < rect.x + rect.width; x++) {
7,303✔
22
                        if (x < 0 || y >= rows) {
17,364✔
23
                            row.push({
12✔
24
                                kind: GridCellKind.Loading,
12✔
25
                                allowOverlay: false,
12✔
26
                            });
12✔
27
                        } else {
17,364✔
28
                            row.push(getCellContent([x, y]));
17,352✔
29
                        }
17,352✔
30
                    }
17,364✔
31
                    result.push(row);
7,303✔
32
                }
7,303✔
33

156✔
34
                return result;
156✔
35
            }
156!
36
            return getCellsForSelectionIn?.(rect, abortController.signal) ?? [];
156!
37
        },
156✔
38
        [abortController.signal, getCellContent, getCellsForSelectionIn, rows]
677✔
39
    );
677✔
40
    const getCellsForSelectionDirect =
677✔
41
        getCellsForSelectionIn !== undefined ? getCellsForSelectionDirectWhenValid : undefined;
677!
42
    const getCellsForSelectionMangled = React.useCallback<CellsForSelectionCallback>(
677✔
43
        rect => {
677✔
44
            if (getCellsForSelectionDirect === undefined) return [];
156!
45
            const newRect = {
156✔
46
                ...rect,
156✔
47
                x: rect.x - rowMarkerOffset,
156✔
48
            };
156✔
49
            if (newRect.x < 0) {
156!
50
                newRect.x = 0;
×
51
                newRect.width--;
×
52
                const r = getCellsForSelectionDirect(newRect, abortController.signal);
×
53

×
54
                if (typeof r === "function") {
×
55
                    return async () =>
×
56
                        // eslint-disable-next-line unicorn/no-await-expression-member
×
57
                        (await r()).map<CellArray[0]>(row => [
×
58
                            { kind: GridCellKind.Loading, allowOverlay: false },
×
59
                            ...row,
×
60
                        ]);
×
61
                }
×
62
                return r.map(row => [{ kind: GridCellKind.Loading, allowOverlay: false }, ...row]);
×
63
            }
×
64
            return getCellsForSelectionDirect(newRect, abortController.signal);
156✔
65
        },
156✔
66
        [abortController.signal, getCellsForSelectionDirect, rowMarkerOffset]
677✔
67
    );
677✔
68

677✔
69
    const getCellsForSelection = getCellsForSelectionIn !== undefined ? getCellsForSelectionMangled : undefined;
677!
70

677✔
71
    return [getCellsForSelection, getCellsForSelectionDirect] as const;
677✔
72
}
677✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc