Skip to content

Commit

Permalink
Merge pull request #2731 from centerofci/fix_regressions
Browse files Browse the repository at this point in the history
Reverts #2213 Column reorder from 0.1.1
  • Loading branch information
seancolsen authored Mar 21, 2023
2 parents 422691b + 9aa81b1 commit ef06744
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 384 deletions.
1 change: 0 additions & 1 deletion mathesar_ui/src/api/types/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface TableSettings {
customized: boolean;
template: string;
};
column_order: number[];
}

/**
Expand Down
1 change: 0 additions & 1 deletion mathesar_ui/src/components/sheet/SheetCellResizer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<div
class="column-resizer"
class:is-resizing={isResizing}
on:dragstart
on:mousedown={startColumnResize}
on:touchstart|nonpassive={startColumnResize}
on:dblclick={() => api.resetColumnWidth(columnIdentifierKey)}
Expand Down
71 changes: 25 additions & 46 deletions mathesar_ui/src/components/sheet/SheetSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { get, writable, type Unsubscriber, type Writable } from 'svelte/store';

interface SelectionColumn {
id: number | string;
columnIndex: number;
}

interface SelectionRow {
Expand Down Expand Up @@ -132,8 +133,8 @@ export function scrollBasedOnSelection(): void {
type SelectionBounds = {
startRowIndex: number;
endRowIndex: number;
startColumnId: string | number;
endColumnId: string | number;
startColumnIndex: number;
endColumnIndex: number;
};

type Cell<Row extends SelectionRow, Column extends SelectionColumn> = [
Expand Down Expand Up @@ -194,8 +195,6 @@ export default class SheetSelection<
> {
private getColumns: () => Column[];

private getColumnOrder: () => number[];

private getRows: () => Row[];

// max index is inclusive
Expand All @@ -222,22 +221,17 @@ export default class SheetSelection<

freezeSelection: boolean;

selectionInProgress: Writable<boolean>;

constructor(args: {
getColumns: () => Column[];
getColumnOrder: () => number[];
getRows: () => Row[];
getMaxSelectionRowIndex: () => number;
}) {
this.selectedCells = new WritableSet<string>();
this.columnsSelectedWhenTheTableIsEmpty = new WritableSet<Column['id']>();
this.getColumns = args.getColumns;
this.getColumnOrder = args.getColumnOrder;
this.getRows = args.getRows;
this.getMaxSelectionRowIndex = args.getMaxSelectionRowIndex;
this.freezeSelection = false;
this.selectionInProgress = writable<boolean>(false);
this.activeCell = writable<ActiveCell | undefined>(undefined);

/**
Expand Down Expand Up @@ -287,12 +281,10 @@ export default class SheetSelection<
if (this.freezeSelection) {
return;
}

this.selectionInProgress.set(true);
// Initialize the bounds of the selection
this.selectionBounds = {
startColumnId: column.id,
endColumnId: column.id,
startColumnIndex: column.columnIndex,
endColumnIndex: column.columnIndex,
startRowIndex: row.rowIndex,
endRowIndex: row.rowIndex,
};
Expand All @@ -306,7 +298,7 @@ export default class SheetSelection<
column: SelectionColumn,
): void {
const { rowIndex } = row;
const { id } = column;
const { columnIndex } = column;

// If there is no selection start cell,
// this means the selection was never initiated
Expand All @@ -315,7 +307,7 @@ export default class SheetSelection<
}

this.selectionBounds.endRowIndex = rowIndex;
this.selectionBounds.endColumnId = id;
this.selectionBounds.endColumnIndex = columnIndex;

const cells = this.getIncludedCells(this.selectionBounds);
this.selectMultipleCells(cells);
Expand All @@ -327,7 +319,6 @@ export default class SheetSelection<
this.selectMultipleCells(cells);
this.selectionBounds = undefined;
}
this.selectionInProgress.set(false);
}

selectAndActivateFirstCellIfExists(): void {
Expand All @@ -340,32 +331,22 @@ export default class SheetSelection<
}

getIncludedCells(selectionBounds: SelectionBounds): Cell<Row, Column>[] {
const { startRowIndex, endRowIndex, startColumnId, endColumnId } =
const { startRowIndex, endRowIndex, startColumnIndex, endColumnIndex } =
selectionBounds;
const minRowIndex = Math.min(startRowIndex, endRowIndex);
const maxRowIndex = Math.max(startRowIndex, endRowIndex);

const columnOrder = this.getColumnOrder();

const startOrderIndex = columnOrder.indexOf(Number(startColumnId));
const endOrderIndex = columnOrder.indexOf(Number(endColumnId));

const minColumnPosition = Math.min(startOrderIndex, endOrderIndex);
const maxColumnPosition = Math.max(startOrderIndex, endOrderIndex);
const columnOrderSelected = columnOrder.slice(
minColumnPosition,
maxColumnPosition + 1,
);

const columns = this.getColumns();
const minColumnIndex = Math.min(startColumnIndex, endColumnIndex);
const maxColumnIndex = Math.max(startColumnIndex, endColumnIndex);

const cells: Cell<Row, Column>[] = [];
this.getRows().forEach((row) => {
const { rowIndex } = row;
if (rowIndex >= minRowIndex && rowIndex <= maxRowIndex) {
columnOrderSelected.forEach((columnId) => {
const column = columns.find((c) => c.id === columnId);
if (column) {
this.getColumns().forEach((column) => {
if (
column.columnIndex >= minColumnIndex &&
column.columnIndex <= maxColumnIndex
) {
cells.push([row, column]);
}
});
Expand All @@ -387,7 +368,7 @@ export default class SheetSelection<
this.selectedCells.clear();
}

isCompleteColumnSelected(column: Pick<Column, 'id'>): boolean {
private isCompleteColumnSelected(column: Pick<Column, 'id'>): boolean {
if (this.getRows().length) {
return (
this.columnsSelectedWhenTheTableIsEmpty.getHas(column.id) ||
Expand Down Expand Up @@ -528,19 +509,17 @@ export default class SheetSelection<
}

onColumnSelectionStart(column: Column): boolean {
if (!this.isCompleteColumnSelected(column)) {
this.activateCell({ rowIndex: 0 }, { id: column.id });
const rows = this.getRows();

if (rows.length === 0) {
this.resetSelection();
this.columnsSelectedWhenTheTableIsEmpty.add(column.id);
return true;
}
this.activateCell({ rowIndex: 0 }, { id: column.id });
const rows = this.getRows();

this.onStartSelection(rows[0], column);
this.onMouseEnterCellWhileSelection(rows[rows.length - 1], column);
if (rows.length === 0) {
this.resetSelection();
this.columnsSelectedWhenTheTableIsEmpty.add(column.id);
return true;
}

this.onStartSelection(rows[0], column);
this.onMouseEnterCellWhileSelection(rows[rows.length - 1], column);
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions mathesar_ui/src/pages/record/TableWidget.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
});
export let recordPk: string;
export let table: TableEntry;
export let table: Pick<TableEntry, 'id' | 'name'>;
export let fkColumn: Pick<Column, 'id' | 'name'>;
$: abstractTypesMap = $currentDbAbstractTypes.data;
Expand All @@ -31,7 +31,6 @@
abstractTypesMap,
meta,
contextualFilters: new Map([[fkColumn.id, recordPk]]),
table,
});
$: tabularDataStore.set(tabularData);
</script>
Expand All @@ -43,7 +42,7 @@
</div>

<div class="results">
<TableView context="widget" {table} />
<TableView context="widget" />
</div>
</div>

Expand Down
5 changes: 1 addition & 4 deletions mathesar_ui/src/pages/record/Widgets.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<script lang="ts">
import type { TableEntry } from '@mathesar/api/types/tables';
import type { JoinableTablesResult } from '@mathesar/api/types/tables/joinable_tables';
import { Help } from '@mathesar-component-library';
import NameWithIcon from '@mathesar/components/NameWithIcon.svelte';
import { iconRecord } from '@mathesar/icons';
import { currentTable } from '@mathesar/stores/tables';
import TableWidget from './TableWidget.svelte';
export let recordPk: string;
export let recordSummary: string;
export let joinableTablesResult: JoinableTablesResult;
$: currTable = $currentTable as TableEntry;
$: tableNameMap = new Map(
Object.entries(joinableTablesResult.tables).map(([tableId, table]) => [
parseInt(tableId, 10),
Expand Down Expand Up @@ -56,7 +53,7 @@
<div class="widgets">
{#each tableWidgetInputs as { table, fkColumn } (`${table.id}-${fkColumn.id}`)}
<section class="table-widget-positioner">
<TableWidget {recordPk} table={currTable} {fkColumn} />
<TableWidget {table} {fkColumn} {recordPk} />
</section>
{/each}
</div>
Expand Down
3 changes: 1 addition & 2 deletions mathesar_ui/src/pages/table/TablePage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
id: table.id,
abstractTypesMap,
meta,
table,
});
$: tabularDataStore.set(tabularData);
Expand All @@ -46,7 +45,7 @@
<LayoutWithHeader fitViewport restrictWidth={false}>
<div class="table-page">
<ActionsPane {table} />
<TableView {table} />
<TableView />
</div>
</LayoutWithHeader>

Expand Down
9 changes: 0 additions & 9 deletions mathesar_ui/src/stores/table-data/tabularData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {
type Writable,
} from 'svelte/store';
import type { DBObjectEntry } from '@mathesar/AppTypes';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { AbstractTypesMap } from '@mathesar/stores/abstract-types/types';
import { States } from '@mathesar/api/utils/requestUtils';
import type { Column } from '@mathesar/api/types/tables/columns';
import { SheetSelection } from '@mathesar/components/sheet';
import { getColumnOrder } from '@mathesar/utils/tables';
import { Meta } from './meta';
import { ColumnsDataStore } from './columns';
import type { RecordRow, TableRecordsData } from './records';
Expand All @@ -29,7 +27,6 @@ import { processColumn } from './processedColumns';
export interface TabularDataProps {
id: DBObjectEntry['id'];
abstractTypesMap: AbstractTypesMap;
table: TableEntry;
meta?: Meta;
/**
* Keys are columns ids. Values are cell values.
Expand Down Expand Up @@ -65,8 +62,6 @@ export class TabularData {

selection: TabularDataSelection;

table: TableEntry;

constructor(props: TabularDataProps) {
const contextualFilters =
props.contextualFilters ?? new Map<number, string | number>();
Expand Down Expand Up @@ -107,12 +102,8 @@ export class TabularData {
),
);

this.table = props.table;

this.selection = new SheetSelection({
getColumns: () => [...get(this.processedColumns).values()],
getColumnOrder: () =>
getColumnOrder([...get(this.processedColumns).values()], this.table),
getRows: () => this.recordsData.getRecordRows(),
getMaxSelectionRowIndex: () => {
const totalCount = get(this.recordsData.totalCount) ?? 0;
Expand Down
10 changes: 0 additions & 10 deletions mathesar_ui/src/stores/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,3 @@ export function saveRecordSummaryTemplate(
preview_settings: customized ? previewSettings : { customized },
});
}

export function saveColumnOrder(
table: Pick<TableEntry, 'id' | 'settings' | 'schema'>,
columnOrder: TableSettings['column_order'],
): Promise<void> {
return saveTableSettings(table, {
// Using the Set constructor to remove potential duplicates
column_order: [...new Set(columnOrder)],
});
}
1 change: 0 additions & 1 deletion mathesar_ui/src/systems/data-explorer/QueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default class QueryRunner<
void this.run();
this.selection = new SheetSelection({
getColumns: () => [...get(this.processedColumns).values()],
getColumnOrder: () => [], // Empty array to default to the columnIndex order
getRows: () => get(this.rowsData).rows,
getMaxSelectionRowIndex: () => {
const rowLength = get(this.rowsData).rows.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { getTableName } from '@mathesar/stores/tables';
import { getArticleForWord } from '@mathesar/utils/languageUtils';
import Pagination from '@mathesar/utils/Pagination';
import { tables } from '@mathesar/stores/tables';
import RecordSelectorContent from './RecordSelectorContent.svelte';
import { RecordSelectorController } from './RecordSelectorController';
import type { RecordSelectorPurpose } from './recordSelectorUtils';
Expand All @@ -33,17 +32,14 @@
nestingLevel: controller.nestingLevel + 1,
});
$: ({ tableId, purpose } = controller);
$: table = $tableId && $tables.data.get($tableId);
$: tabularData =
$tableId && table
? new TabularData({
id: $tableId,
abstractTypesMap: $currentDbAbstractTypes.data,
meta: new Meta({ pagination: new Pagination({ size: 10 }) }),
hasEnhancedPrimaryKeyCell: false,
table,
})
: undefined;
$: tabularData = $tableId
? new TabularData({
id: $tableId,
abstractTypesMap: $currentDbAbstractTypes.data,
meta: new Meta({ pagination: new Pagination({ size: 10 }) }),
hasEnhancedPrimaryKeyCell: false,
})
: undefined;
$: tableName = $tableId ? getTableName($tableId) : undefined;
$: verb = verbMap.get($purpose) ?? '';
$: nestedSelectorIsOpen = nestedController.isOpen;
Expand Down
Loading

0 comments on commit ef06744

Please sign in to comment.