Skip to content

Commit 002b625

Browse files
authored
Fixed bug that readOnly of Action is always readOnly when updated with function. (#269)
1 parent 99881ea commit 002b625

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

packages/cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "0.22.6",
3+
"version": "0.22.7",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/columns/action.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
EditorOption,
77
InlineInputEditorOption,
88
InlineMenuEditorOption,
9+
RecordBoolean,
910
SmallDialogInputEditorOption,
1011
} from "../ts-types";
1112
import { Action } from "./action/Action";
@@ -20,28 +21,28 @@ import { SmallDialogInputEditor } from "./action/SmallDialogInputEditor";
2021

2122
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2223
class ImmutableCheckEditor extends CheckEditor<any> {
23-
get disabled(): boolean {
24+
get disabled(): RecordBoolean {
2425
return this._disabled;
2526
}
26-
get readOnly(): boolean {
27+
get readOnly(): RecordBoolean {
2728
return this._readOnly;
2829
}
2930
}
3031
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3132
class ImmutableRadioEditor extends RadioEditor<any> {
32-
get disabled(): boolean {
33+
get disabled(): RecordBoolean {
3334
return this._disabled;
3435
}
35-
get readOnly(): boolean {
36+
get readOnly(): RecordBoolean {
3637
return this._readOnly;
3738
}
3839
}
3940
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4041
class ImmutableInputEditor extends SmallDialogInputEditor<any> {
41-
get disabled(): boolean {
42+
get disabled(): RecordBoolean {
4243
return this._disabled;
4344
}
44-
get readOnly(): boolean {
45+
get readOnly(): RecordBoolean {
4546
return this._readOnly;
4647
}
4748
}

packages/cheetah-grid/src/js/columns/action/BaseAction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import type {
44
EventListenerId,
55
LayoutObjectId,
66
ListGridAPI,
7+
RecordBoolean,
78
} from "../../ts-types";
89

910
export abstract class BaseAction<T> {
10-
protected _disabled: boolean;
11+
protected _disabled: RecordBoolean;
1112
constructor(option: BaseActionOption = {}) {
1213
this._disabled = option.disabled || false;
1314
}
1415
abstract get editable(): boolean;
15-
get disabled(): boolean {
16+
get disabled(): RecordBoolean {
1617
return this._disabled;
1718
}
18-
set disabled(disabled: boolean) {
19+
set disabled(disabled: RecordBoolean) {
1920
this._disabled = disabled;
2021
this.onChangeDisabledInternal();
2122
}

packages/cheetah-grid/src/js/columns/action/Editor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import type { EditorOption, RecordBoolean } from "../../ts-types";
12
import { BaseAction } from "./BaseAction";
2-
import type { EditorOption } from "../../ts-types";
33
export abstract class Editor<T> extends BaseAction<T> {
4-
protected _readOnly: boolean;
4+
protected _readOnly: RecordBoolean;
55
constructor(option: EditorOption = {}) {
66
super(option);
77
this._readOnly = option.readOnly || false;
88
}
99
get editable(): boolean {
1010
return true;
1111
}
12-
get readOnly(): boolean {
12+
get readOnly(): RecordBoolean {
1313
return this._readOnly;
1414
}
15-
set readOnly(readOnly: boolean) {
16-
this._readOnly = !!readOnly;
15+
set readOnly(readOnly: RecordBoolean) {
16+
this._readOnly = readOnly;
1717
this.onChangeReadOnlyInternal();
1818
}
1919
onChangeReadOnlyInternal(): void {

packages/cheetah-grid/src/js/columns/action/action-utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { ListGridAPI } from "../../ts-types";
1+
import type { ListGridAPI, RecordBoolean } from "../../ts-types";
22
import { isPromise } from "../../internal/utils";
33

44
export function isDisabledRecord<T>(
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
option: boolean | ((record: any) => boolean),
5+
option: RecordBoolean,
76
grid: ListGridAPI<T>,
87
row: number
98
): boolean {
@@ -13,8 +12,7 @@ export function isDisabledRecord<T>(
1312
return getBooleanOptionOfRecord(option, grid, row);
1413
}
1514
export function isReadOnlyRecord<T>(
16-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17-
option: boolean | ((record: any) => boolean),
15+
option: RecordBoolean,
1816
grid: ListGridAPI<T>,
1917
row: number
2018
): boolean {
@@ -55,8 +53,7 @@ export function toggleValue(
5553
}
5654

5755
function getBooleanOptionOfRecord<T>(
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59-
option: boolean | ((record: any) => boolean),
56+
option: RecordBoolean,
6057
grid: ListGridAPI<T>,
6158
row: number
6259
): boolean {

packages/cheetah-grid/src/js/header/action/BaseAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
export class BaseAction<T> {
99
protected _disabled: boolean;
1010
constructor(option: BaseActionOption = {}) {
11-
this._disabled = option.disabled || false;
11+
this._disabled = !!option.disabled || false;
1212
}
1313
get disabled(): boolean {
1414
return this._disabled;

packages/cheetah-grid/src/js/ts-types/column/action.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import type { ColumnMenuItemOptions } from "../define";
33
import type { ListGridAPI } from "../grid-engine";
44
import type { MaybePromise } from "../base";
55

6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7+
export type RecordBoolean<T = any> = boolean | ((record: T) => boolean);
8+
69
export interface BaseActionOption {
7-
disabled?: boolean;
10+
disabled?: RecordBoolean;
811
}
912

1013
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -13,7 +16,7 @@ export interface ActionOption extends BaseActionOption {
1316
action?: ActionListener;
1417
}
1518
export interface EditorOption extends BaseActionOption {
16-
readOnly?: boolean;
19+
readOnly?: RecordBoolean;
1720
}
1821
export type ButtonActionOption = ActionOption;
1922

0 commit comments

Comments
 (0)