Skip to content

Commit

Permalink
feat(sheet): set row properties command params
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Oct 26, 2024
1 parent f7a3130 commit 0cd91b1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 95 deletions.
20 changes: 12 additions & 8 deletions packages/facade/src/apis/sheets/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import type { CustomData, ICellData, IColumnData, IDisposable, IFreeze, IObjectArrayPrimitiveType, IRange, IRowData, IStyleData, Nullable, Workbook, Worksheet } from '@univerjs/core';

import type { ISetColDataMutationParams, ISetRangeValuesMutationParams, ISetRowDataMutationParams, IToggleGridlinesCommandParams } from '@univerjs/sheets';
import type { ISetColDataCommandParams, ISetRangeValuesMutationParams, ISetRowDataCommandParams, ISetWorksheetDefaultStyleMutationParams, IToggleGridlinesCommandParams } from '@univerjs/sheets';
import type { FilterModel } from '@univerjs/sheets-filter';
import type { FWorkbook, IFICanvasFloatDom } from './f-workbook';
import { BooleanNumber, Direction, ICommandService, Inject, Injector, ObjectMatrix, RANGE_TYPE } from '@univerjs/core';
import { DataValidationModel } from '@univerjs/data-validation';
import { deserializeRangeWithSheet } from '@univerjs/engine-formula';
import { copyRangeStyles, InsertColCommand, InsertRowCommand, MoveColsCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, SetColDataCommand, SetColHiddenCommand, SetColWidthCommand, SetFrozenCommand, SetRangeValuesMutation, SetRowDataCommand, SetRowHeightCommand, SetRowHiddenCommand, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetDefaultStyleMutation, SetWorksheetRowIsAutoHeightCommand, SheetsSelectionsService, ToggleGridlinesCommand } from '@univerjs/sheets';
import { copyRangeStyles, InsertColCommand, InsertRowCommand, MoveColsCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, SetColDataCommand, SetColHiddenCommand, SetColWidthCommand, SetFrozenCommand, SetRangeValuesMutation, SetRowDataCommand, SetRowHeightCommand, SetRowHiddenCommand, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetDefaultStyleCommand, SetWorksheetRowIsAutoHeightCommand, SheetsSelectionsService, ToggleGridlinesCommand } from '@univerjs/sheets';
import { type IDataValidationResCache, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
import { SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';
import { SheetsFilterService } from '@univerjs/sheets-filter';
Expand Down Expand Up @@ -127,11 +127,14 @@ export class FWorksheet {
async setDefaultStyle(style: Nullable<IStyleData>): Promise<FWorksheet> {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
await this._commandService.executeCommand(SetWorksheetDefaultStyleMutation.id, {

const params: ISetWorksheetDefaultStyleMutationParams = {
unitId,
subUnitId,
defaultStyle: style,
});
};

await this._commandService.executeCommand(SetWorksheetDefaultStyleCommand.id, params);
return this;
}

Expand All @@ -144,7 +147,7 @@ export class FWorksheet {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();

const params: ISetColDataMutationParams = {
const params: ISetColDataCommandParams = {
unitId,
subUnitId,
columnData: {
Expand All @@ -167,7 +170,7 @@ export class FWorksheet {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();

const params: ISetRowDataMutationParams = {
const params: ISetRowDataCommandParams = {
unitId,
subUnitId,
rowData: {
Expand All @@ -176,6 +179,7 @@ export class FWorksheet {
},
},
};

await this._commandService.executeCommand(SetRowDataCommand.id, params);
return this;
}
Expand Down Expand Up @@ -711,7 +715,7 @@ export class FWorksheet {
};
}

const params: ISetRowDataMutationParams = {
const params: ISetRowDataCommandParams = {
unitId,
subUnitId,
rowData,
Expand Down Expand Up @@ -1028,7 +1032,7 @@ export class FWorksheet {
};
}

const params: ISetColDataMutationParams = {
const params: ISetColDataCommandParams = {
unitId,
subUnitId,
columnData,
Expand Down
2 changes: 2 additions & 0 deletions packages/sheets/src/basics/const/command-listener-const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MoveColsMutation, MoveRowsMutation } from '../../commands/mutations/mov
import { RemoveColMutation, RemoveRowMutation } from '../../commands/mutations/remove-row-col.mutation';
import { RemoveWorksheetMergeMutation } from '../../commands/mutations/remove-worksheet-merge.mutation';
import { ReorderRangeMutation } from '../../commands/mutations/reorder-range.mutation';
import { SetColDataMutation } from '../../commands/mutations/set-col-data.mutation';
import { SetColHiddenMutation, SetColVisibleMutation } from '../../commands/mutations/set-col-visible.mutation';
import { SetRangeValuesMutation } from '../../commands/mutations/set-range-values.mutation';
import { SetRowDataMutation } from '../../commands/mutations/set-row-data.mutation';
Expand Down Expand Up @@ -65,4 +66,5 @@ export const COMMAND_LISTENER_VALUE_CHANGE = [
ReorderRangeMutation.id,
SetWorksheetDefaultStyleMutation.id,
SetRowDataMutation.id,
SetColDataMutation.id,
];
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import type { Injector, IWorkbookData, Univer, Workbook } from '@univerjs/core';
import type { ISetRowDataMutationParams } from '../../mutations/set-row-data.mutation';
import { BooleanNumber, DEFAULT_WORKSHEET_ROW_HEIGHT, ICommandService, IUniverInstanceService, LocaleType, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';
import type { ISetRowDataCommandParams } from '../set-row-data.command';

import { BooleanNumber, DEFAULT_WORKSHEET_ROW_HEIGHT, ICommandService, IUniverInstanceService, LocaleType, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { SetRowDataMutation } from '../../mutations/set-row-data.mutation';
import { SetRowDataCommand } from '../set-row-data.command';
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('test set row data commands', () => {
it('should set properties on rows', async () => {
expect(getRowData(1)).toEqual({ hd: BooleanNumber.FALSE });

const params: ISetRowDataMutationParams = {
const params: ISetRowDataCommandParams = {
unitId: 'test',
subUnitId: 'sheet1',
rowData: {
Expand Down
11 changes: 9 additions & 2 deletions packages/sheets/src/commands/commands/set-col-data.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import type { IAccessor, ICommand } from '@univerjs/core';
import type { IAccessor, IColumnData, ICommand, IObjectArrayPrimitiveType, Nullable } from '@univerjs/core';
import type { ISetColDataMutationParams } from '../mutations/set-col-data.mutation';

import type { ISheetCommandSharedParams } from '../utils/interface';
import {
CommandType,
ICommandService,
Expand All @@ -26,10 +27,16 @@ import {
import { SetColDataMutation, SetColDataMutationFactory } from '../mutations/set-col-data.mutation';
import { getSheetCommandTarget } from './utils/target-util';

export type IColumnProperties = Omit<IColumnData, 'w' | 'hd'>;

export interface ISetColDataCommandParams extends Partial<ISheetCommandSharedParams> {
columnData: IObjectArrayPrimitiveType<Nullable<IColumnProperties>>;
}

export const SetColDataCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.set-col-data',
handler: (accessor: IAccessor, params: ISetColDataMutationParams) => {
handler: (accessor: IAccessor, params: ISetColDataCommandParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
Expand Down
11 changes: 9 additions & 2 deletions packages/sheets/src/commands/commands/set-row-data.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import type { IAccessor, ICommand } from '@univerjs/core';
import type { IAccessor, ICommand, IObjectArrayPrimitiveType, IRowData, Nullable } from '@univerjs/core';
import type { ISetRowDataMutationParams } from '../mutations/set-row-data.mutation';

import type { ISheetCommandSharedParams } from '../utils/interface';
import {
CommandType,
ICommandService,
Expand All @@ -26,10 +27,16 @@ import {
import { SetRowDataMutation, SetRowDataMutationFactory } from '../mutations/set-row-data.mutation';
import { getSheetCommandTarget } from './utils/target-util';

export type IRowProperties = Omit<IRowData, 'h' | 'ia' | 'ah' | 'hd'>;

export interface ISetRowDataCommandParams extends Partial<ISheetCommandSharedParams> {
rowData: IObjectArrayPrimitiveType<Nullable<IRowProperties>>;
}

export const SetRowDataCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.set-row-data',
handler: (accessor: IAccessor, params: ISetRowDataMutationParams) => {
handler: (accessor: IAccessor, params: ISetRowDataCommandParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export class BasicWorksheetController extends Disposable implements IDisposable
ReorderRangeMutation,
EmptyMutation,
SetWorksheetColWidthMutation,
SetWorksheetDefaultStyleMutation,
] as IMutation<object>[]).forEach((mutation) => {
this._commandService.registerCommand(mutation);
this._dataSyncPrimaryController?.registerSyncingMutations(mutation);
Expand Down Expand Up @@ -285,6 +284,7 @@ export class BasicWorksheetController extends Disposable implements IDisposable
SetRangeProtectionMutation,

ToggleCellCheckboxCommand,
SetWorksheetDefaultStyleMutation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}

Expand Down
6 changes: 3 additions & 3 deletions packages/sheets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ export { InsertDefinedNameCommand } from './commands/commands/insert-defined-nam
export { InsertRangeMoveDownCommand, type InsertRangeMoveDownCommandParams } from './commands/commands/insert-range-move-down.command';
export { InsertRangeMoveRightCommand, type InsertRangeMoveRightCommandParams } from './commands/commands/insert-range-move-right.command';
export { type ISetWorksheetDefaultStyleMutationParams, SetWorksheetDefaultStyleMutation, SetWorksheetDefaultStyleMutationFactory } from './commands/mutations/set-worksheet-default-style.mutation';
export { type ISetWorksheetRowColumnStyleMutationParams, SetWorksheetRowColumnStyleMutation, SetWorksheetRowColumnStyleMutationFactory } from './commands/mutations/set-worksheet-row-column-style.mutation';
export { SetWorksheetDefaultStyleCommand } from './commands/commands/set-worksheet-default-style.command';
export { type ISetRowDataMutationParams, SetRowDataMutation, SetRowDataMutationFactory } from './commands/mutations/set-row-data.mutation';
export { SetRowDataCommand } from './commands/commands/set-row-data.command';
export { type ISetRowDataCommandParams, SetRowDataCommand } from './commands/commands/set-row-data.command';
export { type ISetColDataMutationParams, SetColDataMutation, SetColDataMutationFactory } from './commands/mutations/set-col-data.mutation';
export { SetColDataCommand } from './commands/commands/set-col-data.command';
export { type ISetColDataCommandParams, SetColDataCommand } from './commands/commands/set-col-data.command';
export {
type IInsertColCommandParams,
type IInsertRowCommandParams,
Expand Down

0 comments on commit 0cd91b1

Please sign in to comment.