Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename isAutoHeight to ia and change its TS type #1210

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: rename isAutoHeight to ia and change it TS type to BooleanN…
…umber
  • Loading branch information
Jocs committed Jan 22, 2024
commit 6abc026120d041451db12ef760d682c6bd69409f
4 changes: 2 additions & 2 deletions packages/core/src/sheets/row-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class RowManager {
hd: BooleanNumber.FALSE,
h: config.defaultRowHeight,
};
const { isAutoHeight, ah, h = config.defaultRowHeight } = row;
const { ia, ah, h = config.defaultRowHeight } = row;

height += (isAutoHeight == null || !!isAutoHeight) && typeof ah === 'number' ? ah : h;
height += (ia == null || ia === BooleanNumber.TRUE) && typeof ah === 'number' ? ah : h;
}

return height;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/interfaces/i-row-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IRowData {
/**
* is current row self-adaptive to its content, use `ah` to set row height when true, else use `h`.
*/
isAutoHeight?: boolean;
ia?: BooleanNumber; // pre name `isAutoHeight`
/**
* auto height
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}

// The row sets isAutoHeight to false, and there is no need to calculate the automatic row height for the row.
if (rowObjectArray[rowIndex]?.isAutoHeight === false) {
// The row sets ia to false, and there is no need to calculate the automatic row height for the row.
if (rowObjectArray[rowIndex]?.ia === BooleanNumber.FALSE) {
continue;
}

Expand Down Expand Up @@ -1330,8 +1330,8 @@ export class SpreadsheetSkeleton extends Skeleton {
if (!rowDataItem) {
continue;
}
const { h = defaultRowHeight, ah, isAutoHeight } = rowDataItem;
if ((isAutoHeight == null || !!isAutoHeight) && typeof ah === 'number') {
const { h = defaultRowHeight, ah, ia } = rowDataItem;
if ((ia == null || ia === BooleanNumber.TRUE) && typeof ah === 'number') {
rowHeight = ah;
} else {
rowHeight = h;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
*/

import type { IWorkbookData, Workbook } from '@univerjs/core';
import { ILogService, IUniverInstanceService, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
import {
BooleanNumber,
ILogService,
IUniverInstanceService,
LogLevel,
Plugin,
PluginType,
Univer,
} from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';

Expand Down Expand Up @@ -54,7 +62,7 @@ const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({
'3': {
hd: 0,
h: 96.328125,
isAutoHeight: false,
ia: BooleanNumber.FALSE,
},
},
columnData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
*/

import type { Nullable, Univer } from '@univerjs/core';
import { ICommandService, IUniverInstanceService, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';
import {
BooleanNumber,
ICommandService,
IUniverInstanceService,
RANGE_TYPE,
RedoCommand,
UndoCommand,
} from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -44,12 +51,12 @@ describe('Test set row height commands', () => {
return worksheet.getRowHeight(row);
}

function getRowIsAutoHeight(row: number): Nullable<boolean> {
function getRowIsAutoHeight(row: number): Nullable<BooleanNumber> {
const worksheet = get(IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet();
const rowManager = worksheet.getRowManager();
const rowInfo = rowManager.getRow(row);

return rowInfo?.isAutoHeight;
return rowInfo?.ia;
}

beforeEach(() => {
Expand Down Expand Up @@ -111,11 +118,11 @@ describe('Test set row height commands', () => {
anchorRow: 5,
});
expect(getRowHeight(1)).toBe(14);
expect(getRowIsAutoHeight(1)).toBe(false);
expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(2)).toBe(14);
expect(getRowIsAutoHeight(2)).toBe(false);
expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(5)).toBe(14);
expect(getRowIsAutoHeight(5)).toBe(false);
expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.FALSE);

await commandService.executeCommand(UndoCommand.id);
expect(getRowHeight(1)).toBe(19);
Expand Down Expand Up @@ -150,11 +157,11 @@ describe('Test set row height commands', () => {
value: 77,
});
expect(getRowHeight(1)).toBe(77);
expect(getRowIsAutoHeight(1)).toBe(false);
expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(2)).toBe(77);
expect(getRowIsAutoHeight(2)).toBe(false);
expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowHeight(5)).toBe(77);
expect(getRowIsAutoHeight(5)).toBe(false);
expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.FALSE);

await commandService.executeCommand(UndoCommand.id);
expect(getRowHeight(1)).toBe(14);
Expand All @@ -168,21 +175,21 @@ describe('Test set row height commands', () => {
});

describe('Set fit content in ranges', () => {
it('Should change all rows isAutoHeight to true in selections', async () => {
it('Should change all rows ia to true in selections', async () => {
await commandService.executeCommand(SetWorksheetRowIsAutoHeightCommand.id);
expect(getRowIsAutoHeight(1)).toBe(true);
expect(getRowIsAutoHeight(2)).toBe(true);
expect(getRowIsAutoHeight(5)).toBe(true);
expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.TRUE);
expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.TRUE);
expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.TRUE);

await commandService.executeCommand(UndoCommand.id);
expect(getRowIsAutoHeight(1)).toBe(undefined);
expect(getRowIsAutoHeight(2)).toBe(false);
expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.FALSE);
expect(getRowIsAutoHeight(5)).toBe(undefined);

await commandService.executeCommand(RedoCommand.id);
expect(getRowIsAutoHeight(1)).toBe(true);
expect(getRowIsAutoHeight(2)).toBe(true);
expect(getRowIsAutoHeight(5)).toBe(true);
expect(getRowIsAutoHeight(1)).toBe(BooleanNumber.TRUE);
expect(getRowIsAutoHeight(2)).toBe(BooleanNumber.TRUE);
expect(getRowIsAutoHeight(5)).toBe(BooleanNumber.TRUE);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import type { ICommand, IRange } from '@univerjs/core';
import {
BooleanNumber,
CommandType,
ICommandService,
IUndoRedoService,
Expand Down Expand Up @@ -123,7 +124,7 @@ export const DeltaRowHeightCommand: ICommand = {
unitId,
subUnitId,
ranges: redoMutationParams.ranges,
autoHeightInfo: false,
autoHeightInfo: BooleanNumber.FALSE,
};

const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =
Expand All @@ -132,7 +133,7 @@ export const DeltaRowHeightCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);

const result = await sequenceExecute(
const result = sequenceExecute(
[
{
id: SetWorksheetRowHeightMutation.id,
Expand Down Expand Up @@ -214,7 +215,7 @@ export const SetRowHeightCommand: ICommand = {
unitId,
subUnitId,
ranges: redoMutationParams.ranges,
autoHeightInfo: false,
autoHeightInfo: BooleanNumber.FALSE,
};

const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =
Expand Down Expand Up @@ -303,7 +304,7 @@ export const SetWorksheetRowIsAutoHeightCommand: ICommand = {
unitId,
subUnitId,
ranges,
autoHeightInfo: true, // Hard code first, maybe it will change by the menu item in the future.
autoHeightInfo: BooleanNumber.TRUE, // Hard code first, maybe it will change by the menu item in the future.
};

const undoMutationParams: ISetWorksheetRowIsAutoHeightMutationParams =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
*/

import type { IWorkbookData, Workbook } from '@univerjs/core';
import { ILogService, IUniverInstanceService, LogLevel, Plugin, PluginType, Univer } from '@univerjs/core';
import {
BooleanNumber,
ILogService,
IUniverInstanceService,
LogLevel,
Plugin,
PluginType,
Univer,
} from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';

Expand Down Expand Up @@ -54,7 +62,7 @@ const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({
'3': {
hd: 0,
h: 96.328125,
isAutoHeight: false,
ia: BooleanNumber.FALSE,
},
},
columnData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ICommandService, IUniverInstanceService } from '@univerjs/core';
import { BooleanNumber, ICommandService, IUniverInstanceService } from '@univerjs/core';
import type { Injector } from '@wendellhu/redi';
import { beforeEach, describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('Test moving rows & cols', () => {
expect(undoDeleteParams).toEqual({
...getId(),
range: { endColumn: 19, endRow: 3, rangeType: 1, startColumn: 0, startRow: 3 },
rowInfo: { 0: { h: 96.328125, hd: 0, isAutoHeight: false } },
rowInfo: { 0: { h: 96.328125, hd: 0, ia: BooleanNumber.FALSE } },
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';
import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import type { IRowAutoHeightInfo } from '@univerjs/engine-render';
import type { IAccessor } from '@wendellhu/redi';
Expand All @@ -32,7 +32,7 @@ export interface ISetWorksheetRowIsAutoHeightMutationParams {
unitId: string;
subUnitId: string;
ranges: IRange[];
autoHeightInfo: boolean | IObjectArrayPrimitiveType<Nullable<boolean>>;
autoHeightInfo: BooleanNumber | IObjectArrayPrimitiveType<Nullable<BooleanNumber>>;
}

export interface ISetWorksheetRowAutoHeightMutationParams {
Expand Down Expand Up @@ -82,14 +82,14 @@ export const SetWorksheetRowIsAutoHeightMutationFactory = (
const workbook = univerInstanceService.getUniverSheetInstance(unitId)!;
const worksheet = workbook.getSheetBySheetId(subUnitId)!;

const autoHeightHash: IObjectArrayPrimitiveType<Nullable<boolean>> = {};
const autoHeightHash: IObjectArrayPrimitiveType<Nullable<BooleanNumber>> = {};
const manager = worksheet.getRowManager();

for (const { startRow, endRow } of ranges) {
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
const row = manager.getRowOrCreate(rowIndex);

autoHeightHash[rowIndex] = row.isAutoHeight;
autoHeightHash[rowIndex] = row.ia;
}
}

Expand Down Expand Up @@ -184,10 +184,10 @@ export const SetWorksheetRowIsAutoHeightMutation: IMutation<ISetWorksheetRowIsAu
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
const row = manager.getRowOrCreate(rowIndex);

if (typeof autoHeightInfo === 'boolean') {
row.isAutoHeight = autoHeightInfo;
if (typeof autoHeightInfo === 'number') {
row.ia = autoHeightInfo;
} else {
row.isAutoHeight = autoHeightInfo[rowIndex - startRow] ?? defaultRowIsAutoHeight;
row.ia = autoHeightInfo[rowIndex - startRow] ?? defaultRowIsAutoHeight;
}
}
}
Expand Down
Loading