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
feat: disable number stastics when num count is 0 (#761)
YuHong59b8f1db0a28
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.tsindex 32c5f836e4..c62ca273a1 100644--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts@@ -92,7 +92,7 @@ export class StatusBarController extends Disposable {columnCount: sheetConfig.columnCount,};});- if (selections?.length && (selections?.length > 1 || !this._isSingleCell(selections[0]))) {+ if (selections?.length) {const refs = selections.map((s) => new RangeReferenceObject(s, sheetId, unitId));refs.forEach((ref) => {ref.setUnitData({@@ -104,7 +104,7 @@ export class StatusBarController extends Disposable {const functions = this._statusBarService.getFunctions();const calcResult = functions.map((f) => {- const executor = this._functionService.getExecutor(f);+ const executor = this._functionService.getExecutor(f.func);if (!executor) {return undefined;}@@ -113,7 +113,7 @@ export class StatusBarController extends Disposable {return undefined;}return {- func: f,+ func: f.func,value: (executor?.calculate(...refs) as BaseValueObject).getValue(),};});diff --git a/packages/sheets-ui/src/services/status-bar.service.ts b/packages/sheets-ui/src/services/status-bar.service.tsindex 3d8bbea591..af556fb081 100644--- a/packages/sheets-ui/src/services/status-bar.service.ts+++ b/packages/sheets-ui/src/services/status-bar.service.ts@@ -27,7 +27,7 @@ export interface IStatusBarService {dispose(): void;setState(param: IStatusBarServiceStatus | null): void;getState(): Readonly<Nullable<IStatusBarServiceStatus>>;- getFunctions(): Readonly<IFunctionNames[]>;+ getFunctions(): Readonly<IStatusBarFunction[]>;}export type IStatusBarServiceStatus = Array<{@@ -35,14 +35,48 @@ export type IStatusBarServiceStatus = Array<{value: number;}>;+export interface IStatusBarFunction {+ func: IFunctionNames;+ filter?: (status: IStatusBarServiceStatus) => boolean;+}+export class StatusBarService implements IStatusBarService, IDisposable {- private readonly _functions = [- FUNCTION_NAMES_MATH.SUM,- FUNCTION_NAMES_STATISTICAL.MAX,- FUNCTION_NAMES_STATISTICAL.MIN,- FUNCTION_NAMES_STATISTICAL.AVERAGE,- FUNCTION_NAMES_STATISTICAL.COUNT,- FUNCTION_NAMES_STATISTICAL.COUNTA,+ private readonly _functions: IStatusBarFunction[] = [+ {+ func: FUNCTION_NAMES_MATH.SUM,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ },+ {+ func: FUNCTION_NAMES_STATISTICAL.MAX,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ },+ {+ func: FUNCTION_NAMES_STATISTICAL.MIN,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ },+ {+ func: FUNCTION_NAMES_STATISTICAL.AVERAGE,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ },+ {+ func: FUNCTION_NAMES_STATISTICAL.COUNT,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ },+ {+ func: FUNCTION_NAMES_STATISTICAL.COUNTA,+ filter: (status: IStatusBarServiceStatus) =>+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1,+ },];private readonly _state$ = new BehaviorSubject<Nullable<IStatusBarServiceStatus>>(null);readonly state$ = this._state$.asObservable();@@ -52,16 +86,28 @@ export class StatusBarService implements IStatusBarService, IDisposable {}setState(param: IStatusBarServiceStatus | null) {- this._state$.next(param);+ const newState: IStatusBarServiceStatus = [];+ // handle the filter.+ param?.forEach((item) => {+ const func = this._functions.find((func) => func.func === item.func);+ if (func && (func.filter === undefined || func.filter(param))) {+ newState.push(item);+ }+ });+ this._state$.next(newState);}getState(): Readonly<Nullable<IStatusBarServiceStatus>> {return this._state$.getValue();}- getFunctions(): Readonly<IFunctionNames[]> {+ getFunctions(): Readonly<IStatusBarFunction[]> {return this._functions;}++ addFunctions(functions: IStatusBarFunction[]) {+ this._functions.push(...functions);+ }}export const IStatusBarService = createIdentifier<StatusBarService>('univer.sheet-status-bar.service');diff --git a/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx b/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsxindex d34182f791..97b51a94fe 100644--- a/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx+++ b/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx@@ -32,6 +32,7 @@ export interface IStatisticItem {name: IFunctionNames;value: number;show: boolean;+ disable: boolean;}export const functionDisplayNames: FunctionNameMap = {diff --git a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx b/packages/sheets-ui/src/views/status-bar/StatusBar.tsxindex 814ae46e0a..a1b3cc12b1 100644--- a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx+++ b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx@@ -35,12 +35,14 @@ export const StatusBar = () => {const localeService = useDependency(LocaleService);const statusBarService = useDependency(IStatusBarService);const items = statusBarService.getFunctions().map((item, index) => ({- name: item,+ name: item.func,value: 0,show: isSingle ? index < 1 : index < 3,+ disable: false,}));const [statistics, setStatistics] = useState<IStatisticItem[]>(items);- const showList = statistics.filter((item) => item.show);+ const enabledList = statistics.filter((item) => !item.disable);+ const showList = statistics.filter((item) => item.show && !item.disable);const onChange = (item: IStatisticItem) => {const newStatistics = statistics.map((stat) => {@@ -56,13 +58,18 @@ export const StatusBar = () => {useEffect(() => {const subscription = statusBarService.state$.subscribe((item) => {- if (!item) {+ if (!item || item.length === 0) {setShow(false);} else {setShow(true);const newStatistics = statistics.map((stat) => {const target = item.find((i) => i.func === stat.name);- stat.value = target?.value ?? stat.value;+ if (target) {+ stat.value = target.value;+ stat.disable = false;+ } else {+ stat.disable = true;+ }return stat;});setStatistics(newStatistics);@@ -134,7 +141,7 @@ export const StatusBar = () => {placement="topRight"overlay={<div className={styles.statisticPicker}>- {statistics?.map((item) => (+ {enabledList?.map((item) => (<a key={item.name} className={styles.statisticPickerItem}><Checkboxvalue={item.name}