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.

feat: hide statistic opt (#4694)

lumix95410d001ebb
diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.ts
index d34e95b03b..05dcfd2104 100644
--- a/packages/sheets-ui/src/controllers/config.schema.ts
+++ b/packages/sheets-ui/src/controllers/config.schema.ts
@@ -21,6 +21,7 @@ export const SHEETS_UI_PLUGIN_CONFIG_KEY = 'sheets-ui.config';
export const configSymbol = Symbol(SHEETS_UI_PLUGIN_CONFIG_KEY);
+export const HIDE_STATUS_BAR_STATISTIC = Symbol('HIDE_STATUS_BAR_STATISTIC');
export interface IUniverSheetsUIConfig {
menu?: MenuConfig;
disableAutoFocus?: true;
@@ -35,6 +36,8 @@ export interface IUniverSheetsUIConfig {
clipboardConfig?: {
hidePasteOptions?: boolean;
};
+
+ hideStatusBarStatistic?: boolean;
}
export const defaultPluginConfig: IUniverSheetsUIConfig = {
diff --git a/packages/sheets-ui/src/plugin.ts b/packages/sheets-ui/src/plugin.ts
index 37ded7647a..db428a7b03 100644
--- a/packages/sheets-ui/src/plugin.ts
+++ b/packages/sheets-ui/src/plugin.ts
@@ -30,7 +30,7 @@ import { CellAlertRenderController } from './controllers/cell-alert.controller';
import { CellCustomRenderController } from './controllers/cell-custom-render.controller';
import { SheetCheckboxController } from './controllers/checkbox.controller';
import { SheetClipboardController } from './controllers/clipboard/clipboard.controller';
-import { defaultPluginConfig, SHEETS_UI_PLUGIN_CONFIG_KEY } from './controllers/config.schema';
+import { defaultPluginConfig, HIDE_STATUS_BAR_STATISTIC, SHEETS_UI_PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { SheetsDefinedNameController } from './controllers/defined-name/defined-name.controller';
import { DragRenderController } from './controllers/drag-render.controller';
import { EditorDataSyncController } from './controllers/editor/data-sync.controller';
@@ -116,6 +116,10 @@ export class UniverSheetsUIPlugin extends Plugin {
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
+
+ if (this._config?.hideStatusBarStatistic) {
+ this._configService.setConfig(HIDE_STATUS_BAR_STATISTIC, true);
+ }
this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, rest);
}
diff --git a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
index 184edb52ec..cb4f647e00 100644
--- a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
+++ b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
@@ -15,11 +15,12 @@
*/
import type { IStatisticItem } from './CopyableStatisticItem';
-import { debounce } from '@univerjs/core';
+import { debounce, IConfigService } from '@univerjs/core';
import { useDependency } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
+import { HIDE_STATUS_BAR_STATISTIC } from '../../controllers/config.schema';
import { IStatusBarService } from '../../services/status-bar.service';
import { CopyableStatisticItem } from './CopyableStatisticItem';
import styles from './index.module.less';
@@ -28,6 +29,9 @@ const SINGLE_MODE_WIDTH = 800;
const ROW_COUNT_THRESHOLD = 3;
export const StatusBar = () => {
+ const configService = useDependency(IConfigService);
+ const hideStatistic = configService.getConfig(HIDE_STATUS_BAR_STATISTIC);
+
const [isSingle, setIsSingle] = useState(window.innerWidth < SINGLE_MODE_WIDTH);
const [show, setShow] = useState(true);
@@ -44,6 +48,7 @@ export const StatusBar = () => {
const showList = isSingle && firstItem ? [firstItem] : statistics.filter((item) => item.show && !item.disable);
useEffect(() => {
+ if (hideStatistic) return;
const subscription = statusBarService.state$.subscribe((state) => {
const item = state?.values;
if (!item || item.length === 0) {
@@ -67,7 +72,7 @@ export const StatusBar = () => {
return () => {
subscription.unsubscribe();
};
- }, [statusBarService]);
+ }, [statusBarService, hideStatistic, statistics]);
const handleResize = debounce(() => {
const newSingleState = window.innerWidth < SINGLE_MODE_WIDTH;
@@ -84,35 +89,64 @@ export const StatusBar = () => {
};
}, [isSingle]);
- let renderContent = null;
- if (showList.length > ROW_COUNT_THRESHOLD) {
- const doubleLineList: IStatisticItem[][] = [];
- showList.forEach((_, index) => {
- if (index % 2 === 0) {
- doubleLineList.push(showList.slice(index, index + 2));
+ const useStatisticLayout = (
+ showList: IStatisticItem[],
+ rowCountThreshold: number,
+ CopyableStatisticItem: React.ComponentType<IStatisticItem>
+ ) => {
+ if (hideStatistic) return null;
+ const renderContent = React.useMemo(() => {
+ if (showList.length > rowCountThreshold) {
+ const doubleLineList = showList.reduce<IStatisticItem[][]>((acc, _, index) => {
+ if (index % 2 === 0) {
+ acc.push(showList.slice(index, index + 2));
+ }
+ return acc;
+ }, []);
+
+ return (
+ <>
+ {doubleLineList.map((item, index) => (
+ <div
+ key={`stat-col-${index}`}
+ className={styles.statisticListColumn}
+ >
+ {item[0] && (
+ <CopyableStatisticItem
+ key={item[0].name}
+ {...item[0]}
+ />
+ )}
+ {item[1] && (
+ <CopyableStatisticItem
+ key={item[1].name}
+ {...item[1]}
+ />
+ )}
+ </div>
+ ))}
+ </>
+ );
}
- });
- renderContent = (
- <>
- {' '}
- {doubleLineList!.map((item: IStatisticItem[], index: number) => (
- <div key={`stat-col-${index}`} className={styles.statisticListColumn}>
- {item?.[0] && <CopyableStatisticItem key={item?.[0].name} {...item?.[0]} />}
- {item?.[1] && <CopyableStatisticItem key={item?.[1].name} {...item?.[1]} />}
- </div>
- ))}
- {' '}
- </>
- );
- } else {
- renderContent = (
- <>
- {showList.map((item) => (
- <CopyableStatisticItem key={item.name} {...item} />
- ))}
- </>
- );
- }
+
+ return (
+ <>
+ {showList.map((item) => (
+ <CopyableStatisticItem
+ key={item.name}
+ {...item}
+ />
+ ))}
+ </>
+ );
+ }, [showList, rowCountThreshold, CopyableStatisticItem]);
+
+ return renderContent;
+ };
+
+ const renderContent = useStatisticLayout(showList,
+ ROW_COUNT_THRESHOLD,
+ CopyableStatisticItem);
return (
show && (