Skip to content

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.

refactor(sheets-conditional-formatting-ui): extract conditional formatting preview utilities (#7831)

白熱2d7bedefb20a
diff --git a/packages/sheets-conditional-formatting-ui/src/index.ts b/packages/sheets-conditional-formatting-ui/src/index.ts
index c16f588b5f..87e2db093f 100644
--- a/packages/sheets-conditional-formatting-ui/src/index.ts
+++ b/packages/sheets-conditional-formatting-ui/src/index.ts
@@ -33,4 +33,7 @@ export { ConditionalFormattingClearController } from './controllers/cf.clear.con
export { menuSchema as SheetsConditionalFormattingUIMenuSchema } from './menu/schema';
export { UniverSheetsConditionalFormattingMobileUIPlugin } from './mobile-plugin';
export { UniverSheetsConditionalFormattingUIPlugin } from './plugin';
+export { getRuleDescribe } from './utils/get-rule-describe';
+export type { IConditionalFormattingRulePreviewProps } from './views/ConditionalFormattingRulePreview';
+export { ConditionalFormattingRulePreview } from './views/ConditionalFormattingRulePreview';
export type { IConditionFormattingPanelProps } from './views/ConditionFormattingPanel';
diff --git a/packages/sheets-conditional-formatting-ui/src/utils/__tests__/get-rule-describe.spec.ts b/packages/sheets-conditional-formatting-ui/src/utils/__tests__/get-rule-describe.spec.ts
new file mode 100644
index 0000000000..541cb63eaa
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/utils/__tests__/get-rule-describe.spec.ts
@@ -0,0 +1,206 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IConditionalFormattingRuleConfig, IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
+import { Injector, LocaleService, LocaleType } from '@univerjs/core';
+import {
+ CFNumberOperator,
+ CFRuleType,
+ CFSubRuleType,
+ CFTextOperator,
+ CFTimePeriodOperator,
+ CFValueType,
+ IIconSetType,
+} from '@univerjs/sheets-conditional-formatting';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import enUS from '../../locale/en-US';
+import zhCN from '../../locale/zh-CN';
+import { getRuleDescribe } from '../get-rule-describe';
+
+describe('getRuleDescribe', () => {
+ let injector: Injector;
+
+ beforeEach(() => {
+ injector = new Injector([[LocaleService]]);
+ });
+
+ afterEach(() => {
+ injector.dispose();
+ });
+
+ it('preserves zero and translates using the current locale on each call', () => {
+ const localeService = injector.get(LocaleService);
+ localeService.load({ [LocaleType.EN_US]: enUS, [LocaleType.ZH_CN]: zhCN });
+ localeService.setLocale(LocaleType.EN_US);
+ localeService.setDirection('ltr');
+ const rule: IConditionFormattingRule = {
+ cfId: 'zero-rule',
+ ranges: [],
+ stopIfTrue: false,
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.number,
+ operator: CFNumberOperator.greaterThan,
+ value: 0,
+ style: {},
+ },
+ };
+
+ const englishDescription = getRuleDescribe(rule, localeService);
+ localeService.setLocale(LocaleType.ZH_CN);
+
+ expect([englishDescription, getRuleDescribe(rule, localeService)]).toEqual(['Greater than 0', '大于0']);
+ });
+
+ it.each<{ rule: IConditionalFormattingRuleConfig; expected: string }>([
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.number,
+ operator: CFNumberOperator.between,
+ value: [-10, 0],
+ style: {},
+ },
+ expected: 'Between -10 and 0',
+ },
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.number,
+ operator: CFNumberOperator.notBetween,
+ value: [0, 10],
+ style: {},
+ },
+ expected: 'Not between 0 and 10',
+ },
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.text,
+ operator: CFTextOperator.containsText,
+ value: 'North & South',
+ style: {},
+ },
+ expected: 'Text contains North & South',
+ },
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.average,
+ operator: CFNumberOperator.greaterThanOrEqual,
+ style: {},
+ },
+ expected: 'Greater than or equal to Average',
+ },
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.timePeriod,
+ operator: CFTimePeriodOperator.thisWeek,
+ style: {},
+ },
+ expected: 'This Week',
+ },
+ {
+ rule: { type: CFRuleType.highlightCell, subType: CFSubRuleType.uniqueValues, style: {} },
+ expected: 'Unique Values',
+ },
+ {
+ rule: { type: CFRuleType.highlightCell, subType: CFSubRuleType.duplicateValues, style: {} },
+ expected: 'Duplicate Values',
+ },
+ {
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.formula,
+ value: '=A1>0',
+ style: {},
+ },
+ expected: 'Custom Formula',
+ },
+ {
+ rule: {
+ type: CFRuleType.dataBar,
+ isShowValue: true,
+ config: {
+ min: { type: CFValueType.min },
+ max: { type: CFValueType.max },
+ isGradient: false,
+ positiveColor: '#00ff00',
+ nativeColor: '#ff0000',
+ },
+ },
+ expected: 'Data Bar',
+ },
+ {
+ rule: {
+ type: CFRuleType.colorScale,
+ config: [
+ { index: 0, color: '#000000', value: { type: CFValueType.min } },
+ { index: 1, color: '#ffffff', value: { type: CFValueType.max } },
+ ],
+ },
+ expected: 'Color Scale',
+ },
+ {
+ rule: {
+ type: CFRuleType.iconSet,
+ isShowValue: true,
+ config: [{
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.num, value: 0 },
+ iconType: IIconSetType.threeArrows,
+ iconId: '0',
+ }],
+ },
+ expected: 'Icon Set',
+ },
+ ])('describes a rule as "$expected"', ({ rule, expected }) => {
+ const localeService = injector.get(LocaleService);
+ localeService.load({ [LocaleType.EN_US]: enUS });
+ localeService.setLocale(LocaleType.EN_US);
+ localeService.setDirection('ltr');
+
+ expect(getRuleDescribe({ cfId: 'rule', ranges: [], stopIfTrue: false, rule }, localeService)).toBe(expected);
+ });
+
+ it.each([
+ { isBottom: false, isPercent: false, expected: 'Top 10' },
+ { isBottom: true, isPercent: false, expected: 'Bottom 10' },
+ { isBottom: false, isPercent: true, expected: 'Top 10%' },
+ { isBottom: true, isPercent: true, expected: 'Bottom 10%' },
+ ])('distinguishes the ranking rule "$expected"', ({ isBottom, isPercent, expected }) => {
+ const localeService = injector.get(LocaleService);
+ localeService.load({ [LocaleType.EN_US]: enUS });
+ localeService.setLocale(LocaleType.EN_US);
+ localeService.setDirection('ltr');
+ const rule: IConditionFormattingRule = {
+ cfId: 'rank-rule',
+ ranges: [],
+ stopIfTrue: false,
+ rule: {
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.rank,
+ isBottom,
+ isPercent,
+ value: 10,
+ style: {},
+ },
+ };
+
+ expect(getRuleDescribe(rule, localeService)).toBe(expected);
+ });
+});
diff --git a/packages/sheets-conditional-formatting-ui/src/utils/get-rule-describe.ts b/packages/sheets-conditional-formatting-ui/src/utils/get-rule-describe.ts
new file mode 100644
index 0000000000..b44e0501cb
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/utils/get-rule-describe.ts
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { LocaleService } from '@univerjs/core';
+import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../locale/types';
+import { CFRuleType, CFSubRuleType } from '@univerjs/sheets-conditional-formatting';
+
+/** Returns the localized description used by the built-in conditional formatting rule list. */
+export function getRuleDescribe(rule: IConditionFormattingRule, localeService: LocaleService): string {
+ const ruleConfig = rule.rule;
+ switch (ruleConfig.type) {
+ case CFRuleType.colorScale: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.colorScale');
+ }
+ case CFRuleType.dataBar: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.dataBar');
+ }
+ case CFRuleType.iconSet: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.iconSet');
+ }
+ case CFRuleType.highlightCell: {
+ switch (ruleConfig.subType) {
+ case CFSubRuleType.average: {
+ const operator = ruleConfig.operator;
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.average'));
+ }
+ case CFSubRuleType.duplicateValues: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.duplicateValues');
+ }
+ case CFSubRuleType.uniqueValues: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.uniqueValues');
+ }
+ case CFSubRuleType.number: {
+ const operator = ruleConfig.operator;
+ const values = Array.isArray(ruleConfig.value)
+ ? ruleConfig.value.map((value) => String(value))
+ : [String(ruleConfig.value ?? '')];
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...values);
+ }
+ case CFSubRuleType.text: {
+ const operator = ruleConfig.operator;
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ruleConfig.value || '');
+ }
+
+ case CFSubRuleType.timePeriod: {
+ const operator = ruleConfig.operator;
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`);
+ }
+ case CFSubRuleType.rank: {
+ if (ruleConfig.isPercent) {
+ return localeService.t<LocaleKey>(ruleConfig.isBottom
+ ? 'sheets-conditional-formatting-ui.preview.describe.bottomNPercent'
+ : 'sheets-conditional-formatting-ui.preview.describe.topNPercent', String(ruleConfig.value));
+ }
+ return localeService.t<LocaleKey>(ruleConfig.isBottom
+ ? 'sheets-conditional-formatting-ui.preview.describe.bottomN'
+ : 'sheets-conditional-formatting-ui.preview.describe.topN', String(ruleConfig.value));
+ }
+ case CFSubRuleType.formula: {
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.formula');
+ }
+ }
+ }
+ }
+}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/Preview.tsx b/packages/sheets-conditional-formatting-ui/src/views/ConditionalFormattingRulePreview.tsx
similarity index 94%
rename from packages/sheets-conditional-formatting-ui/src/views/Preview.tsx
rename to packages/sheets-conditional-formatting-ui/src/views/ConditionalFormattingRulePreview.tsx
index af60194e51..4f5140f658 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/Preview.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/ConditionalFormattingRulePreview.tsx
@@ -29,7 +29,12 @@ import {
} from '@univerjs/sheets-conditional-formatting';
import { useMemo } from 'react';
-export function Preview(props: { rule?: IConditionalFormattingRuleConfig }) {
+export interface IConditionalFormattingRulePreviewProps {
+ rule?: IConditionalFormattingRuleConfig;
+}
+
+/** Shows a rule's configured appearance without evaluating worksheet values. */
+export function ConditionalFormattingRulePreview(props: IConditionalFormattingRulePreviewProps) {
const { rule } = props;
const colorList = useMemo(() => {
@@ -51,7 +56,9 @@ export function Preview(props: { rule?: IConditionalFormattingRuleConfig }) {
}
}, [rule]);
- if (!rule) return null;
+ if (!rule) {
+ return null;
+ }
const previewClassName = 'univer-pointer-events-none univer-flex univer-h-5 univer-min-w-[72px] univer-items-center univer-justify-center univer-text-xs';
diff --git a/packages/sheets-conditional-formatting-ui/src/views/__tests__/ConditionalFormattingRulePreview.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/__tests__/ConditionalFormattingRulePreview.spec.tsx
new file mode 100644
index 0000000000..3d5f2d9551
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/views/__tests__/ConditionalFormattingRulePreview.spec.tsx
@@ -0,0 +1,131 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BooleanNumber } from '@univerjs/core';
+import {
+ CFNumberOperator,
+ CFRuleType,
+ CFSubRuleType,
+ CFValueType,
+ iconMap,
+ IIconSetType,
+} from '@univerjs/sheets-conditional-formatting';
+import { renderToStaticMarkup } from 'react-dom/server';
+import { describe, expect, it } from 'vitest';
+import { ConditionalFormattingRulePreview } from '../ConditionalFormattingRulePreview';
+
+describe('ConditionalFormattingRulePreview', () => {
+ it('previews the configured highlight colors and text decoration', () => {
+ const container = document.createElement('div');
+ container.innerHTML = renderToStaticMarkup(
+ <ConditionalFormattingRulePreview
+ rule={{
+ type: CFRuleType.highlightCell,
+ subType: CFSubRuleType.number,
+ operator: CFNumberOperator.greaterThan,
+ value: 0,
+ style: {
+ bg: { rgb: '#ff0000' },
+ cl: { rgb: '#0000ff' },
+ ul: { s: BooleanNumber.TRUE },
+ st: { s: BooleanNumber.TRUE },
+ },
+ }}
+ />
+ );
+
+ const preview = container.firstElementChild as HTMLElement;
+ expect(preview.style.backgroundColor).toBe('#ff0000');
+ expect(preview.style.color).toBe('#0000ff');
+ expect(preview.style.textDecoration).toBe('underline line-through');
+ });
+
+ it('previews both negative and positive data bar colors', () => {
+ const container = document.createElement('div');
+ container.innerHTML = renderToStaticMarkup(
+ <ConditionalFormattingRulePreview
+ rule={{
+ type: CFRuleType.dataBar,
+ isShowValue: true,
+ config: {
+ min: { type: CFValueType.min },
+ max: { type: CFValueType.max },
+ isGradient: false,
+ nativeColor: '#ff0000',
+ positiveColor: '#00ff00',
+ },
+ }}
+ />
+ );
+
+ const bars = Array.from(container.firstElementChild!.children) as HTMLElement[];
+ expect(bars.map((bar) => bar.style.background)).toEqual(['#ff0000', '#00ff00']);
+ });
+
+ it('previews the configured color scale endpoints', () => {
+ const container = document.createElement('div');
+ container.innerHTML = renderToStaticMarkup(
+ <ConditionalFormattingRulePreview
+ rule={{
+ type: CFRuleType.colorScale,
+ config: [
+ { index: 0, color: '#000000', value: { type: CFValueType.min } },
+ { index: 1, color: '#ffffff', value: { type: CFValueType.max } },
+ ],
+ }}
+ />
+ );
+
+ const firstColor = container.firstElementChild!.firstElementChild as HTMLElement;
+ const lastColor = container.firstElementChild!.lastElementChild as HTMLElement;
+ expect([firstColor.style.background, lastColor.style.background]).toEqual(['rgb(0, 0, 0)', 'rgb(255, 255, 255)']);
+ });
+
+ it('previews the chosen icons in rule order', () => {
+ const container = document.createElement('div');
+ container.innerHTML = renderToStaticMarkup(
+ <ConditionalFormattingRulePreview
+ rule={{
+ type: CFRuleType.iconSet,
+ isShowValue: true,
+ config: [
+ {
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.num, value: 10 },
+ iconType: IIconSetType.threeArrows,
+ iconId: '2',
+ },
+ {
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.num, value: 0 },
+ iconType: IIconSetType.threeArrowsGray,
+ iconId: '0',
+ },
+ ],
+ }}
+ />
+ );
+
+ expect(Array.from(container.querySelectorAll('img'), (image) => image.getAttribute('src'))).toEqual([
+ iconMap[IIconSetType.threeArrows][2],
+ iconMap[IIconSetType.threeArrowsGray][0],
+ ]);
+ });
+
+ it('renders nothing while no rule is selected', () => {
+ expect(renderToStaticMarkup(<ConditionalFormattingRulePreview />)).toBe('');
+ });
+});
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
index 682b6c51ac..0631285a94 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
@@ -42,8 +42,6 @@ import {
} from '@univerjs/sheets';
import {
AddConditionalRuleMutation,
- CFRuleType,
- CFSubRuleType,
ClearWorksheetCfCommand,
ConditionalFormattingRuleModel,
DeleteCfCommand,
@@ -57,72 +55,14 @@ import { useDependency, useObservable } from '@univerjs/ui';
import { useMemo, useState } from 'react';
import { debounceTime, filter, map, merge, Observable, share, startWith } from 'rxjs';
import { ConditionalFormattingI18nController } from '../../controllers/cf.i18n.controller';
-import { Preview } from '../Preview';
+import { getRuleDescribe } from '../../utils/get-rule-describe';
+import { ConditionalFormattingRulePreview } from '../ConditionalFormattingRulePreview';
export interface IRuleListProps {
onClick: (rule: IConditionFormattingRule) => void;
onCreate: () => void;
SelectComponent?: ComponentType<ISelectProps>;
};
-const getRuleDescribe = (rule: IConditionFormattingRule, localeService: LocaleService) => {
- const ruleConfig = rule.rule;
- switch (ruleConfig.type) {
- case CFRuleType.colorScale: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.colorScale');
- }
- case CFRuleType.dataBar: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.dataBar');
- }
- case CFRuleType.iconSet: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.iconSet');
- }
- case CFRuleType.highlightCell: {
- switch (ruleConfig.subType) {
- case CFSubRuleType.average: {
- const operator = ruleConfig.operator;
- return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.average'));
- }
- case CFSubRuleType.duplicateValues: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.duplicateValues');
- }
- case CFSubRuleType.uniqueValues: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.uniqueValues');
- }
- case CFSubRuleType.number: {
- const operator = ruleConfig.operator;
- return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...Array.isArray(ruleConfig.value) ? (ruleConfig.value.map((e) => String(e))) : [String(ruleConfig.value || '')]);
- }
- case CFSubRuleType.text: {
- const operator = ruleConfig.operator;
- return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ruleConfig.value || '');
- }
-
- case CFSubRuleType.timePeriod: {
- const operator = ruleConfig.operator;
- return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`);
- }
- case CFSubRuleType.rank: {
- if (ruleConfig.isPercent) {
- if (ruleConfig.isBottom) {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.bottomNPercent', String(ruleConfig.value));
- } else {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.topNPercent', String(ruleConfig.value));
- }
- } else {
- if (ruleConfig.isBottom) {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.bottomN', String(ruleConfig.value));
- } else {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.topN', String(ruleConfig.value));
- }
- }
- }
- case CFSubRuleType.formula: {
- return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.formula');
- }
- }
- }
- }
-};
export function RuleList(props: IRuleListProps) {
const { SelectComponent = Select } = props;
@@ -400,7 +340,7 @@ export function RuleList(props: IRuleListProps) {
</div>
</div>
<div>
- <Preview rule={rule.rule} />
+ <ConditionalFormattingRulePreview rule={rule.rule} />
</div>
<div
className={clsx(`
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/ColorScale.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/ColorScale.tsx
index d443166870..7bdf352f36 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/ColorScale.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/ColorScale.tsx
@@ -26,7 +26,7 @@ import { FormulaEditor } from '@univerjs/sheets-formula-ui';
import { useDependency, useSidebarClick } from '@univerjs/ui';
import { useEffect, useMemo, useRef, useState } from 'react';
import { ColorPicker } from '../../ColorPicker';
-import { Preview } from '../../Preview';
+import { ConditionalFormattingRulePreview } from '../../ConditionalFormattingRulePreview';
import { previewClassName } from './styles';
const createOptionItem = (text: CFValueType | 'none'): { label: LocaleKey; value: CFValueType | 'none' } => ({
@@ -249,7 +249,7 @@ export const ColorScaleStyleEditor = (props: IStyleEditorProps) => {
{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}
</div>
<div className={previewClassName}>
- <Preview
+ <ConditionalFormattingRulePreview
rule={getResult({
minType,
medianType,
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
index 5acc4f4d41..2e8829c9bc 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
@@ -32,7 +32,7 @@ import { FormulaEditor } from '@univerjs/sheets-formula-ui';
import { useDependency, useSidebarClick } from '@univerjs/ui';
import { useEffect, useMemo, useRef, useState } from 'react';
import { ColorPicker } from '../../ColorPicker';
-import { Preview } from '../../Preview';
+import { ConditionalFormattingRulePreview } from '../../ConditionalFormattingRulePreview';
import { previewClassName } from './styles';
const createOptionItem = (text: CFValueType): { label: LocaleKey; value: CFValueType } => ({
@@ -287,7 +287,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}
</div>
<div className={previewClassName}>
- <Preview
+ <ConditionalFormattingRulePreview
rule={getResult({
isGradient,
minValue,
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
index daf182a44d..cada34726e 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
@@ -29,8 +29,8 @@ import { CFRuleType, CFSubRuleType } from '@univerjs/sheets-conditional-formatti
import { FormulaEditor } from '@univerjs/sheets-formula-ui';
import { useDependency, useSidebarClick } from '@univerjs/ui';
import { useEffect, useRef, useState } from 'react';
+import { ConditionalFormattingRulePreview } from '../../ConditionalFormattingRulePreview';
import { ConditionalStyleEditor } from '../../ConditionalStyleEditor';
-import { Preview } from '../../Preview';
import { previewClassName } from './styles';
export const FormulaStyleEditor = (props: IStyleEditorProps) => {
@@ -153,7 +153,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
</div>
<div className={previewClassName}>
- <Preview
+ <ConditionalFormattingRulePreview
rule={getResult({
style,
formula,
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/HighlightCell.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/HighlightCell.tsx
index f7c975325c..4d818b1e08 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/HighlightCell.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/HighlightCell.tsx
@@ -36,8 +36,8 @@ import {
} from '@univerjs/sheets-conditional-formatting';
import { useDependency } from '@univerjs/ui';
import { useEffect, useMemo, useState } from 'react';
+import { ConditionalFormattingRulePreview } from '../../ConditionalFormattingRulePreview';
import { ConditionalStyleEditor } from '../../ConditionalStyleEditor';
-import { Preview } from '../../Preview';
import { WrapperError } from '../../wrapper-error/WrapperError';
import { previewClassName } from './styles';
@@ -439,7 +439,7 @@ export const HighlightCellStyleEditor = (props: IStyleEditorProps<any, IEditable
onChange={onInputChange}
/>
<div className={previewClassName}>
- <Preview rule={getResult({})} />
+ <ConditionalFormattingRulePreview rule={getResult({})} />
</div>
<ConditionalStyleEditor
ColorPickerComponent={ColorPickerComponent}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
index 59b3fdb963..0eed6723c7 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
@@ -26,8 +26,8 @@ import { Checkbox, InputNumber, Select } from '@univerjs/design';
import { CFNumberOperator, CFRuleType, CFSubRuleType } from '@univerjs/sheets-conditional-formatting';
import { useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
+import { ConditionalFormattingRulePreview } from '../../ConditionalFormattingRulePreview';
import { ConditionalStyleEditor } from '../../ConditionalStyleEditor';
-import { Preview } from '../../Preview';
import { previewClassName } from './styles';
type IRankRuleType = 'isNotBottom' | 'isBottom' | 'greaterThanAverage' | 'lessThanAverage';
@@ -196,7 +196,7 @@ export const RankStyleEditor = (props: IStyleEditorProps) => {
</div>
)}
<div className={previewClassName}>
- <Preview
+ <ConditionalFormattingRulePreview
rule={getResult({
type,
isPercent,