Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
revert: "fix(sheets-conditional-formatting-ui): enable stop-if-true toggles in rule list" (#8119)
白熱df6ceaf69b27
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsxindex 358c98cf3b..456f9de355 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx@@ -20,7 +20,6 @@ import type {IConditionFormattingRule,IDeleteCfCommandParams,IMoveCfCommandParams,- ISetCfCommandParams,} from '@univerjs/sheets-conditional-formatting';import type { ComponentType } from 'react';import {@@ -49,7 +48,6 @@ import {DeleteConditionalRuleMutation,MoveCfCommand,MoveConditionalRuleMutation,- SetCfCommand,SetConditionalRuleMutation,} from '@univerjs/sheets-conditional-formatting';import { useHighlightRange } from '@univerjs/sheets-ui';@@ -169,7 +167,7 @@ export function RuleList(props: IRuleListProps) {if (!unitId || !subUnitId) {throw new Error('No active sheet found');}- return commandService.executeCommand(DeleteCfCommand.id, { unitId, subUnitId, cfId: rule.cfId } as IDeleteCfCommandParams);+ commandService.executeCommand(DeleteCfCommand.id, { unitId, subUnitId, cfId: rule.cfId } as IDeleteCfCommandParams);};const handleDragStart = (_layout: unknown, from: { y: number }) => {@@ -195,7 +193,7 @@ export function RuleList(props: IRuleListProps) {return;}if (cfId !== targetCfId) {- return commandService.executeCommand(MoveCfCommand.id, { unitId, subUnitId, start: { id: cfId, type: 'self' }, end: { id: targetCfId, type: to.y > from.y ? 'after' : 'before' } } as IMoveCfCommandParams);+ commandService.executeCommand(MoveCfCommand.id, { unitId, subUnitId, start: { id: cfId, type: 'self' }, end: { id: targetCfId, type: to.y > from.y ? 'after' : 'before' } } as IMoveCfCommandParams);}};@@ -205,10 +203,12 @@ export function RuleList(props: IRuleListProps) {const handleClear = () => {if (selectValue === '2') {- return commandService.executeCommand(ClearWorksheetCfCommand.id);+ commandService.executeCommand(ClearWorksheetCfCommand.id);} else if (selectValue === '1') {const list = ruleList.map((rule) => ({ unitId, subUnitId, cfId: rule.cfId }));- return Promise.all(list.map((config) => commandService.executeCommand(DeleteCfCommand.id, config)));+ list.forEach((config) => {+ commandService.executeCommand(DeleteCfCommand.id, config);+ });}};const ruleListByPermissionCheck = useMemo(() => {@@ -344,16 +344,12 @@ export function RuleList(props: IRuleListProps) {<ConditionalFormattingRulePreview rule={rule.rule} /></div>{rule.rule.type === CFRuleType.highlightCell && (- <div className="univer-mt-2 univer-w-full" onClick={(event) => event.stopPropagation()}>+ <div className="univer-pointer-events-none univer-mt-2 univer-w-full"><CheckboxclassName="univer-max-w-full"contentClassName="univer-min-w-0"checked={!!rule.stopIfTrue}- onChange={(checked) => commandService.executeCommand<ISetCfCommandParams>(SetCfCommand.id, {- unitId,- subUnitId,- rule: { ...rule, stopIfTrue: !!checked },- })}+ disabled>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.stopIfTrue')}</Checkbox>@@ -371,8 +367,8 @@ export function RuleList(props: IRuleListProps) {})}onClick={(e) => {e.stopPropagation();+ handleDelete(rule);setCurrentRuleRanges([]);- return handleDelete(rule);}}><DeleteIcon />diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsxindex 9d9d66d8dc..a3dcc896e3 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx@@ -17,7 +17,7 @@import type { IRange } from '@univerjs/core';import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';import type { Root } from 'react-dom/client';-import { BooleanNumber, LocaleService, LocaleType, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';+import { BooleanNumber, LocaleService, LocaleType, RANGE_TYPE } from '@univerjs/core';import { SetSelectionsOperation } from '@univerjs/sheets';import {AddCfCommand,@@ -26,7 +26,6 @@ import {CFSubRuleType,DeleteCfCommand,MoveCfCommand,- SetCfCommand,} from '@univerjs/sheets-conditional-formatting';import { IMarkSelectionService } from '@univerjs/sheets-ui';import { RediContext } from '@univerjs/ui';@@ -92,10 +91,29 @@ async function createRuleListTestBed(stopIfTrue = false) {testBed.commandService.registerCommand(AddCfCommand);testBed.commandService.registerCommand(DeleteCfCommand);testBed.commandService.registerCommand(MoveCfCommand);- testBed.commandService.registerCommand(SetCfCommand);testBed.commandService.registerCommand(SetSelectionsOperation);testBed.get(LocaleService).load({[LocaleType.ZH_CN]: {+ sheets: {+ conditional: {+ formatting: {+ ui: {+ panel: {+ managerRuleSelect: 'Show {0}',+ workSheet: 'Worksheet',+ selectedRange: 'Selected range',+ createRule: 'Create rule',+ clear: 'Clear rules',+ },+ preview: {+ describe: {+ greaterThan: 'Greater than {0}',+ },+ },+ },+ },+ },+ },'sheets-conditional-formatting-ui': {panel: {managerRuleSelect: 'Show {0}',@@ -145,7 +163,7 @@ describe('RuleList', () => {currentTestBed = undefined;});- it.each([false, true])('toggles stopIfTrue=%s from the rule list with undo and redo without opening the editor', async (stopIfTrue) => {+ it.each([false, true])('opens the rule from its read-only stopIfTrue=%s display without toggling it', async (stopIfTrue) => {currentTestBed = await createRuleListTestBed(stopIfTrue);container = document.createElement('div');document.body.appendChild(container);@@ -164,31 +182,19 @@ describe('RuleList', () => {const row = container.querySelector('[data-draggable-list-item-id="cf-active"]')!;const label = row.querySelector('[data-u-comp="checkbox"]')!;const checkbox = label.querySelector('input')!;- const originalRule = currentTestBed.ruleModel.getRule(currentTestBed.unitId, currentTestBed.subUnitId, 'cf-active')!;+ expect(checkbox.checked).toBe(stopIfTrue);+ expect(checkbox.disabled).toBe(true);+ // The display's icon and label both belong to the surrounding rule's edit target.const target = stopIfTrue ? label.lastElementChild! : checkbox.parentElement!.lastElementChild!;await act(async () => {target.dispatchEvent(new MouseEvent('click', { bubbles: true }));await Promise.resolve();});- expect(currentTestBed.ruleModel.getRule(currentTestBed.unitId, currentTestBed.subUnitId, 'cf-active'))- .toEqual({ ...originalRule, stopIfTrue: !stopIfTrue });- expect(openedRuleIds).toEqual([]);- expect(checkbox.checked).toBe(!stopIfTrue);-- await act(async () => {- expect(await currentTestBed!.commandService.executeCommand(UndoCommand.id)).toBe(true);- });- expect(currentTestBed.ruleModel.getRule(currentTestBed.unitId, currentTestBed.subUnitId, 'cf-active')).toEqual(originalRule);+ expect(openedRuleIds).toEqual(['cf-active']);expect(checkbox.checked).toBe(stopIfTrue);-- await act(async () => {- expect(await currentTestBed!.commandService.executeCommand(RedoCommand.id)).toBe(true);- });- expect(currentTestBed.ruleModel.getRule(currentTestBed.unitId, currentTestBed.subUnitId, 'cf-active'))- .toEqual({ ...originalRule, stopIfTrue: !stopIfTrue });- expect(checkbox.checked).toBe(!stopIfTrue);+ expect(currentTestBed.ruleModel.getRule(currentTestBed.unitId, currentTestBed.subUnitId, 'cf-active')?.stopIfTrue).toBe(stopIfTrue);});it('shows only conditional formatting rules intersecting the current sheet selection in selected-range mode', async () => {