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

glideapps / glide-data-grid / 7333166280

26 Dec 2023 10:45PM UTC coverage: 90.585% (+4.2%) from 86.42%
7333166280

Pull #810

github

jassmith
5.99.9-charlie1
Pull Request #810: 6.0.0

2594 of 3246 branches covered (0.0%)

3363 of 3831 new or added lines in 62 files covered. (87.78%)

265 existing lines in 12 files now uncovered.

15759 of 17397 relevant lines covered (90.58%)

3076.99 hits per line

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

83.65
/packages/core/src/cells/boolean-cell.tsx
1
import { getSquareWidth, getSquareXPosFromAlign, getSquareBB, pointIsWithinBB } from "../common/utils.js";
1✔
2
import { toggleBoolean } from "../data-editor/data-editor-fns.js";
1✔
3
import {
1✔
4
    GridCellKind,
1✔
5
    type BooleanCell,
1✔
6
    booleanCellIsEditable,
1✔
7
    BooleanEmpty,
1✔
8
    BooleanIndeterminate,
1✔
9
} from "../internal/data-grid/data-grid-types.js";
1✔
10
import { drawCheckbox } from "../internal/data-grid/draw-checkbox.js";
1✔
11
import type { BaseDrawArgs, InternalCellRenderer } from "./cell-types.js";
1✔
12

1✔
13
const defaultCellMaxSize = 20;
1✔
14

1✔
15
export const booleanCellRenderer: InternalCellRenderer<BooleanCell> = {
1✔
16
    getAccessibilityString: c => c.data?.toString() ?? "false",
1✔
17
    kind: GridCellKind.Boolean,
1✔
18
    needsHover: true,
1✔
19
    useLabel: false,
1✔
20
    needsHoverPosition: true,
1✔
21
    measure: () => 50,
1✔
22
    draw: a => drawBoolean(a, a.cell.data, booleanCellIsEditable(a.cell), a.cell.maxSize ?? defaultCellMaxSize),
1✔
23
    onDelete: c => ({
1✔
24
        ...c,
1✔
25
        data: false,
1✔
26
    }),
1✔
27
    onClick: e => {
1✔
28
        const { cell, posX: pointerX, posY: pointerY, bounds, theme } = e;
6✔
29
        const { width, height, x: cellX, y: cellY } = bounds;
6✔
30
        const maxWidth = cell.maxSize ?? defaultCellMaxSize;
6✔
31
        const cellCenterY = Math.floor(bounds.y + height / 2);
6✔
32
        const checkBoxWidth = getSquareWidth(maxWidth, height, theme.cellVerticalPadding);
6✔
33
        const posX = getSquareXPosFromAlign(
6✔
34
            cell.contentAlign ?? "center",
6✔
35
            cellX,
6✔
36
            width,
6✔
37
            theme.cellHorizontalPadding,
6✔
38
            checkBoxWidth
6✔
39
        );
6✔
40
        const bb = getSquareBB(posX, cellCenterY, checkBoxWidth);
6✔
41
        const checkBoxClicked = pointIsWithinBB(cellX + pointerX, cellY + pointerY, bb);
6✔
42

6✔
43
        if (booleanCellIsEditable(cell) && checkBoxClicked) {
6✔
44
            return {
4✔
45
                ...cell,
4✔
46
                data: toggleBoolean(cell.data),
4✔
47
            };
4✔
48
        }
4✔
49
        return undefined;
2✔
50
    },
6✔
51
    onPaste: (toPaste, cell) => {
1✔
52
        let newVal: boolean | BooleanEmpty | BooleanIndeterminate = BooleanEmpty;
×
53
        if (toPaste.toLowerCase() === "true") {
×
54
            newVal = true;
×
55
        } else if (toPaste.toLowerCase() === "false") {
×
56
            newVal = false;
×
57
        } else if (toPaste.toLowerCase() === "indeterminate") {
×
58
            newVal = BooleanIndeterminate;
×
59
        }
×
60
        return newVal === cell.data
×
61
            ? undefined
×
62
            : {
×
63
                  ...cell,
×
64
                  data: newVal,
×
65
              };
×
66
    },
×
67
};
1✔
68

1✔
69
function drawBoolean(
10,591✔
70
    args: BaseDrawArgs,
10,591✔
71
    data: boolean | BooleanEmpty | BooleanIndeterminate,
10,591✔
72
    canEdit: boolean,
10,591✔
73
    maxSize?: number
10,591✔
74
) {
10,591✔
75
    if (!canEdit && data === BooleanEmpty) {
10,591!
NEW
76
        return;
×
NEW
77
    }
×
78
    const {
10,591✔
79
        ctx,
10,591✔
80
        hoverAmount,
10,591✔
81
        theme,
10,591✔
82
        rect,
10,591✔
83
        highlighted,
10,591✔
84
        hoverX,
10,591✔
85
        hoverY,
10,591✔
86
        cell: { contentAlign },
10,591✔
87
    } = args;
10,591✔
88
    const { x, y, width: w, height: h } = rect;
10,591✔
89

10,591✔
90
    const hoverEffect = 0.35;
10,591✔
91

10,591✔
92
    let alpha = canEdit ? 1 - hoverEffect + hoverEffect * hoverAmount : 0.4;
10,591✔
93
    if (data === BooleanEmpty) {
10,591✔
94
        alpha *= hoverAmount;
2,293✔
95
    }
2,293✔
96
    if (alpha === 0) {
10,591✔
97
        return;
2,293✔
98
    }
2,293✔
99
    ctx.globalAlpha = alpha;
8,298✔
100

8,298✔
101
    drawCheckbox(ctx, theme, data, x, y, w, h, highlighted, hoverX, hoverY, maxSize, contentAlign);
8,298✔
102

8,298✔
103
    ctx.globalAlpha = 1;
8,298✔
104
}
8,298✔
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