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

CB-6063 feat: add ability to import data without PK #3188

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export const CellRenderer = observer<CellRendererProps<IResultSetRowKey, unknown
);

function isEditable(column: CalculatedColumn<IResultSetRowKey>): boolean {
if (!cellContext.cell) {
if (
!cellContext.cell ||
(!dataGridContext.model.hasRowIdentifier(tableDataContext.view.resultIndex) && cellContext.editionState !== DatabaseEditChangeType.add)
) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,32 @@ export class DataGridContextMenuCellEditingService {
const isComplex = format.isBinary(key) || format.isGeometry(key);
const isTruncated = content.isTextTruncated(key);
const selectedElements = select?.getSelectedElements() || [];
const hasRowIdentifier = model.hasRowIdentifier(resultIndex);
// we can't edit table cells if table doesn't have row identifier, but we can edit new created rows before insert (CB-6063)
const canEdit = hasRowIdentifier || (!hasRowIdentifier && editor.getElementState(key) === DatabaseEditChangeType.add);
Wroud marked this conversation as resolved.
Show resolved Hide resolved

if (action === ACTION_EDIT) {
if (!column || cellValue === undefined || format.isReadOnly(key) || isComplex || isTruncated) {
if (!column || cellValue === undefined || format.isReadOnly(key) || isComplex || isTruncated || !canEdit) {
return false;
}

return !isBooleanValuePresentationAvailable(cellValue, column);
}

if (action === ACTION_DATA_GRID_EDITING_SET_TO_NULL) {
return cellValue !== undefined && !format.isReadOnly(key) && !view.getColumn(key.column)?.required && !format.isNull(key);
return cellValue !== undefined && !format.isReadOnly(key) && !view.getColumn(key.column)?.required && !format.isNull(key) && canEdit;
}

if (action === ACTION_DATA_GRID_EDITING_ADD_ROW || action === ACTION_DATA_GRID_EDITING_DUPLICATE_ROW) {
return editor.hasFeature('add');
}

if (action === ACTION_DATA_GRID_EDITING_DELETE_ROW) {
return !format.isReadOnly(key) && editor.getElementState(key) !== DatabaseEditChangeType.delete;
return !format.isReadOnly(key) && canEdit && editor.getElementState(key) !== DatabaseEditChangeType.delete;
}

if (action === ACTION_DATA_GRID_EDITING_DELETE_SELECTED_ROW) {
if (model.isReadonly(resultIndex) || !editor.hasFeature('delete')) {
if (model.isReadonly(resultIndex) || !canEdit || !editor.hasFeature('delete')) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,16 @@ export const DataGridTable = observer<IDataPresentationProps>(function DataGridT

function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
gridSelectedCellCopy.onKeydownHandler(event);
const cell = selectionAction.getFocusedElement();
// we can't edit table cells if table doesn't have row identifier, but we can edit new created rows before insert (CB-6063)
const canEdit =
model.hasRowIdentifier(resultIndex) ||
!!(!model.hasRowIdentifier(resultIndex) && cell && tableData.editor.getElementState(cell) === DatabaseEditChangeType.add);

if (EventContext.has(event, EventStopPropagationFlag) || tableData.isReadOnly() || model.isReadonly(resultIndex)) {
if (EventContext.has(event, EventStopPropagationFlag) || !canEdit || tableData.isReadOnly() || model.isReadonly(resultIndex)) {
return;
}

const cell = selectionAction.getFocusedElement();
const activeElements = selectionAction.getActiveElements();
const activeRows = selectionAction.getActiveRows();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class DatabaseDataModel<TSource extends IDatabaseDataSource<any, any> = I
return this.source.isReadonly(resultIndex);
}

hasRowIdentifier(resultIndex: number): boolean {
return this.source.hasRowIdentifier(resultIndex);
}

isDataAvailable(offset: number, count: number): boolean {
return this.source.isDataAvailable(offset, count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export abstract class DatabaseDataSource<TOptions, TResult extends IDatabaseData
return !this.isLoading() && !this.disabled;
}

hasRowIdentifier(resultIndex: number): boolean {
return this.getResult(resultIndex)?.data?.hasRowIdentifier === true;
}
Wroud marked this conversation as resolved.
Show resolved Hide resolved

isReadonly(resultIndex: number): boolean {
return this.access === DatabaseDataAccessMode.Readonly || this.results.length > 1 || this.disabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IDatabaseDataModel<TSource extends IDatabaseDataSource<any, any

setName: (name: string | null) => this;
isReadonly: (resultIndex: number) => boolean;
hasRowIdentifier: (resultIndex: number) => boolean;
isDisabled: (resultIndex?: number) => boolean;
isLoading: () => boolean;
isDataAvailable: (offset: number, count: number) => boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface IDatabaseDataSource<TOptions = unknown, TResult extends IDataba
isOutdated: () => boolean;
isLoadable: () => boolean;
isReadonly: (resultIndex: number) => boolean;
hasRowIdentifier: (resultIndex: number) => boolean;
isDataAvailable: (offset: number, count: number) => boolean;
isLoading: () => boolean;
isDisabled: (resultIndex?: number) => boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class ResultSetDataSource<TOptions = IDatabaseDataOptions> exten
}

override isReadonly(resultIndex: number): boolean {
return super.isReadonly(resultIndex) || !this.executionContext?.context || this.getResult(resultIndex)?.data?.hasRowIdentifier === false;
return super.isReadonly(resultIndex) || !this.executionContext?.context;
}

override async cancel(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ export class TableFooterMenuService {
}
case ACTION_DELETE: {
const editor = model.source.getActionImplementation(resultIndex, DatabaseEditAction);
const selectedElements = getActiveElements(model, resultIndex);

if (!editor) {
// we can't edit table cells if table doesn't have row identifier, but we can edit new created rows before insert (CB-6063)
const canEdit =
model.hasRowIdentifier(resultIndex) ||
(!model.hasRowIdentifier(resultIndex) && selectedElements.every(key => editor?.getElementState(key) === DatabaseEditChangeType.add));

if (!editor || !canEdit) {
return true;
}

const selectedElements = getActiveElements(model, resultIndex);

return selectedElements.length === 0 || !selectedElements.some(key => editor.getElementState(key) !== DatabaseEditChangeType.delete);
}
case ACTION_REVERT: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const BooleanValuePresentation: TabContainerPanelComponent<IDataValuePane

const column = viewAction.getColumn(firstSelectedCell.column);
const nullable = column?.required === false;
const readonly = model.isReadonly(resultIndex) || model.isDisabled(resultIndex) || formatAction.isReadOnly(firstSelectedCell);
const readonly =
model.isReadonly(resultIndex) ||
!model.hasRowIdentifier(resultIndex) ||
model.isDisabled(resultIndex) ||
formatAction.isReadOnly(firstSelectedCell);

return (
<div className={classes['container']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function isTextValueReadonly({ contentAction, formatAction, model, result
formatAction.isGeometry(cell) ||
contentAction.isTextTruncated(cell) ||
model.isReadonly(resultIndex) ||
model.isDisabled(resultIndex)
model.isDisabled(resultIndex) ||
!model.hasRowIdentifier(resultIndex)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GeneratorMenuBootstrap extends Bootstrap {
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);
return (
!model.isReadonly(resultIndex) &&
model.hasRowIdentifier(resultIndex) &&
model.source.getResult(resultIndex)?.dataFormat === ResultDataFormat.Resultset &&
!presentation?.readonly &&
(!presentation || presentation.type === DataViewerPresentationType.Data)
Expand Down
Loading