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

feat(sheets-data-validation): support hide edit button on dropdown #3574

Merged
merged 2 commits into from
Sep 25, 2024
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
4 changes: 3 additions & 1 deletion examples/src/sheets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ setTimeout(() => {

// mock lazy load data validation
setTimeout(() => {
univer.registerPlugin(UniverSheetsDataValidationPlugin);
univer.registerPlugin(UniverSheetsDataValidationPlugin, {
// showEditOnDropdown: false,
});
}, 500);

// sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);

export interface IUniverSheetsDataValidationConfig {
menu?: MenuConfig;

showEditOnDropdown?: boolean;
}

export const defaultPluginConfig: IUniverSheetsDataValidationConfig = {};
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
border: 1px solid rgb(var(--border-color));
background: rgba(var(--color-white));
box-shadow: var(--box-shadow-base);
// display: flex;
// flex-direction: column;
// max-width: 200px;
box-sizing: border-box;
padding-bottom: var(--padding-xs);

&-title {
padding: var(--padding-sm) 14px;
Expand Down Expand Up @@ -75,7 +73,7 @@
}

&-edit {
padding: 0 var(--padding-xs) var(--padding-xs) var(--padding-xs);
padding: 0 var(--padding-xs);
flex-shrink: 0;
flex-grow: 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@
* limitations under the License.
*/

import { BuildTextUtils, DataValidationRenderMode, DataValidationType, ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
import { BuildTextUtils, DataValidationRenderMode, DataValidationType, ICommandService, IConfigService, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
import { DataValidationModel } from '@univerjs/data-validation';
import { RectPopup, Scrollbar } from '@univerjs/design';
import { RichTextEditingMutation } from '@univerjs/docs';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle } from '@univerjs/icons';
import { SetRangeValuesCommand } from '@univerjs/sheets';
import { IEditorBridgeService } from '@univerjs/sheets-ui';
import { RangeProtectionPermissionEditPoint, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
import { IEditorBridgeService, SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
import { KeyCode, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
import { debounceTime } from 'rxjs';
import type { DocumentDataModel } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { ISetRangeValuesCommandParams } from '@univerjs/sheets';
import type { ISetRangeValuesCommandParams, ISheetLocation } from '@univerjs/sheets';
import { OpenValidationPanelOperation } from '../../commands/operations/data-validation.operation';
import { DROP_DOWN_DEFAULT_COLOR } from '../../common/const';
import { PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';
import { deserializeListOptions, getDataValidationCellValue, serializeListOptions } from '../../validators/util';
import styles from './index.module.less';
import type { IUniverSheetsDataValidationConfig } from '../../controllers/config.schema';
import type { IDropdownComponentProps } from '../../services/dropdown-manager.service';
import type { ListMultipleValidator } from '../../validators/list-multiple-validator';

Expand All @@ -44,13 +46,28 @@ interface ISelectListProps {
onEdit?: () => void;
style?: React.CSSProperties;
filter?: string;
location: ISheetLocation;
}

const SelectList = (props: ISelectListProps) => {
const { value, onChange, multiple, options, title, onEdit, style, filter } = props;
const { value, onChange, multiple, options, title, onEdit, style, filter, location } = props;
const localeService = useDependency(LocaleService);
const configService = useDependency(IConfigService);
const lowerFilter = filter?.toLowerCase();
const { row, col, unitId, subUnitId } = location;
const filteredOptions = options.filter((item) => lowerFilter ? item.label.toLowerCase().includes(lowerFilter) : true);
const showEditOnDropdown = configService.getConfig<IUniverSheetsDataValidationConfig>(PLUGIN_CONFIG_KEY)?.showEditOnDropdown ?? true;
const sheetPermissionInterceptorBaseController = useDependency(SheetPermissionInterceptorBaseController);
const hasPermission = useMemo(() => sheetPermissionInterceptorBaseController.permissionCheckWithRanges(
{
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
worksheetTypes: [WorksheetEditPermission],
},
[{ startColumn: col, startRow: row, endColumn: col, endRow: row }],
unitId,
subUnitId
), [sheetPermissionInterceptorBaseController, col, row, unitId, subUnitId]);

return (
<div className={styles.dvListDropdown} style={style}>
Expand Down Expand Up @@ -102,10 +119,16 @@ const SelectList = (props: ISelectListProps) => {
</div>
</Scrollbar>
</div>
<div className={styles.dvListDropdownSplit} />
<div className={styles.dvListDropdownEdit}>
<a onClick={onEdit}>{localeService.t('dataValidation.list.edit')}</a>
</div>
{showEditOnDropdown && hasPermission
? (
<>
<div className={styles.dvListDropdownSplit} />
<div className={styles.dvListDropdownEdit}>
<a onClick={onEdit}>{localeService.t('dataValidation.list.edit')}</a>
</div>
</>
)
: null}
</div>
);
};
Expand Down Expand Up @@ -218,6 +241,7 @@ export function ListDropDown(props: IDropdownComponentProps) {
options={options}
onEdit={handleEdit}
filter={editingText}
location={location}
/>
);
}
Loading