Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interaction): support empty data cell & calc count #209

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/s2-core/src/interaction/brush-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ export class BrushSelection extends BaseEvent implements BaseEventImplement {
this.interaction.addIntercepts([InterceptType.BRUSH_SELECTION]);
this.hidePrepareSelectMaskShape();
this.updateSelectedCells();
const tooltipData = getActiveCellsTooltipData(this.spreadsheet);
if (!isEmpty(tooltipData)) {
this.spreadsheet.showTooltipWithInfo(event, tooltipData);
}
this.spreadsheet.showTooltipWithInfo(
event,
getActiveCellsTooltipData(this.spreadsheet),
);
}
this.setBrushSelectionStage(InteractionBrushSelectionStage.UN_DRAGGED);
});
Expand Down Expand Up @@ -203,7 +203,7 @@ export class BrushSelection extends BaseEvent implements BaseEventImplement {
private getBrushRangeDataCells(): DataCell[] {
return this.displayedDataCells.filter((cell) => {
const meta = cell.getMeta();
return meta?.data && this.isInBrushRange(meta);
return this.isInBrushRange(meta);
});
}

Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/src/interaction/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ export class EventController {
this.activeResizeArea(event);
this.spreadsheet.emit(S2Event.GLOBAL_RESIZE_MOUSE_MOVE, event);
return;
} else {
this.resetResizeArea();
}
this.resetResizeArea();

const cell = this.spreadsheet.getCell(event.target);
const cellType = this.spreadsheet.getCellType(event.target);
Expand Down
6 changes: 5 additions & 1 deletion packages/s2-core/src/interaction/root.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { clearState, setState } from '@/utils/interaction/state-controller';
import { isMobile } from '@/utils/is-mobile';
import { ColHeader, RowHeader } from 'src/facet/header';
import { includes, isEmpty, concat, merge, forEach } from 'lodash';
import { includes, isEmpty, concat, merge, forEach, size } from 'lodash';
import { BrushSelection, DataCellMultiSelection, RowColResize } from './';
import {
BaseEvent,
Expand Down Expand Up @@ -108,6 +108,10 @@ export class RootInteraction {
return currentState?.cells || [];
}

public getActiveCellsCount() {
return size(this.getActiveCells());
}

public updateCellStyleByState() {
const cells = this.getActiveCells();
cells.forEach((cell) => {
Expand Down
21 changes: 11 additions & 10 deletions packages/s2-core/src/ui/tooltip/components/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { TooltipSummaryOptions } from '@/common/interface';
import * as React from 'react';
import React from 'react';
import { i18n } from '@/common/i18n';
import { TOOLTIP_PREFIX_CLS } from '@/common/constant/tooltip';

const Summary = (props: { summaries: TooltipSummaryOptions[] }) => {
const { summaries = [] } = props;
interface SummaryProps {
summaries: TooltipSummaryOptions[];
count: number;
}

const renderSelected = () => {
const selectedCount = summaries?.reduce((pre, next) => {
return pre + (next?.selectedData?.length || 0);
}, 0);
const Summary: React.FC<SummaryProps> = React.memo((props) => {
const { summaries = [], count = 0 } = props;

const renderSelected = () => {
return (
<div className={`${TOOLTIP_PREFIX_CLS}-summary-item`}>
<span className={`${TOOLTIP_PREFIX_CLS}-bold`}>
{selectedCount} {i18n('项')}
{count} {i18n('项')}
</span>{' '}
{i18n('已选择')}
</div>
Expand All @@ -24,7 +25,7 @@ const Summary = (props: { summaries: TooltipSummaryOptions[] }) => {
const renderSummary = () => {
return summaries?.map((item) => {
const { name = '', value } = item || {};
if(!name && !value) {
if (!name && !value) {
return;
}

Expand Down Expand Up @@ -52,6 +53,6 @@ const Summary = (props: { summaries: TooltipSummaryOptions[] }) => {
{renderSummary()}
</div>
);
};
});

export default Summary;
7 changes: 6 additions & 1 deletion packages/s2-core/src/ui/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ export class BaseTooltip {
}

protected renderSummary(summaries: TooltipSummaryOptions[]) {
return !isEmpty(summaries) && <TooltipSummary summaries={summaries} />;
const count = this.spreadsheet.interaction.getActiveCellsCount();
return (
!isEmpty(summaries) && (
<TooltipSummary summaries={summaries} count={count} />
)
);
}

protected renderHeadInfo(headInfo: TooltipHeadInfoType) {
Expand Down
2 changes: 0 additions & 2 deletions packages/s2-core/src/utils/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,6 @@ export const mergeCellInfo = (cells: S2CellType[]): TooltipData[] => {
});
};

// TODO: 待确定 是否可以复用 mergeCellInfo

export const getActiveCellsTooltipData = (
spreadsheet: SpreadSheet,
): TooltipData[] => {
Expand Down