feat(grid): open cell http urls from hover overlay
This commit is contained in:
13 files changed
+92
-13
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
ArrowDown,
|
||||
ArrowUpDown,
|
||||
ArrowUpRight,
|
||||
ExternalLink,
|
||||
Download,
|
||||
FileUp,
|
||||
Trash2,
|
||||
@@ -135,6 +136,7 @@ import {
|
||||
} from "@/lib/dataGrid/dataGridTranspose";
|
||||
import { canApplyGridSelectionValue, canDeleteGridRowItem, canEditGridCellDetail, matchesRowStatusFilter, shouldShowQuickEntryDraftRow, type RowStatus, type RowStatusFilter } from "@/lib/dataGrid/gridRowStatus";
|
||||
import { displayCellValue, firstLineCellDisplayValue, limitDataGridCellDisplay, SQLSERVER_DATA_GRID_CELL_DISPLAY_MAX_LENGTH, type CellValue } from "@/lib/dataGrid/cellValue";
|
||||
import { cellExternalUrl } from "@/lib/dataGrid/cellExternalUrl";
|
||||
import { getApplicablePreviewActions, type PreviewAction } from "@/lib/dataGrid/resultPreviewRegistry";
|
||||
import "@/lib/dataGrid/geometryMapPreview";
|
||||
import {
|
||||
@@ -7889,8 +7891,9 @@ const canvasDetailButtonCell = computed(() => {
|
||||
const visibleRight = viewportWidth > 0 ? Math.min(viewportWidth, rect.left + rect.width) : rect.left + rect.width;
|
||||
const canQuickDownload = canQuickDownloadCellValue(target.rowIndex, target.col);
|
||||
const foreignKey = canvasCellForeignKey(target.rowIndex, target.col);
|
||||
if (!cellDetailButtonEnabled.value && !canQuickDownload && !foreignKey) return null;
|
||||
const minWidth = canvasDataGridActionOverlayWidth(canQuickDownload, !!foreignKey, cellDetailButtonEnabled.value) + 2;
|
||||
const externalUrl = cellExternalUrl(displayItemAt(target.rowIndex)?.data[target.col]);
|
||||
if (!cellDetailButtonEnabled.value && !canQuickDownload && !foreignKey && !externalUrl) return null;
|
||||
const minWidth = canvasDataGridActionOverlayWidth(canQuickDownload, !!foreignKey, cellDetailButtonEnabled.value, !!externalUrl) + 2;
|
||||
if (rect.top < 0 || rect.top > viewportHeight - 1 || visibleRight - visibleLeft < minWidth) return null;
|
||||
return {
|
||||
rowIndex: target.rowIndex,
|
||||
@@ -7899,13 +7902,14 @@ const canvasDetailButtonCell = computed(() => {
|
||||
rect,
|
||||
canQuickDownload,
|
||||
foreignKey,
|
||||
externalUrl,
|
||||
};
|
||||
});
|
||||
|
||||
const canvasDetailButtonStyle = computed(() => {
|
||||
const cell = canvasDetailButtonCell.value;
|
||||
if (!cell) return {};
|
||||
const actionWidth = canvasDataGridActionOverlayWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value);
|
||||
const actionWidth = canvasDataGridActionOverlayWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value, !!cell.externalUrl);
|
||||
const edgeGap = 6;
|
||||
return {
|
||||
left: `${Math.max(rowNumberWidth.value, cell.rect.left + cell.rect.width - actionWidth - edgeGap)}px`,
|
||||
@@ -7919,7 +7923,7 @@ const canvasRightAlignedActionCell = computed(() => {
|
||||
return {
|
||||
rowIndex: cell.rowIndex,
|
||||
visibleColIdx: cell.visibleColIdx,
|
||||
reservedWidth: canvasDataGridActionReservedWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value),
|
||||
reservedWidth: canvasDataGridActionReservedWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value, !!cell.externalUrl),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -9854,6 +9858,25 @@ function canQuickDownloadCellValue(rowIndex: number, columnIndex: number): boole
|
||||
return canDownloadDetailBinaryValue(cellDetailFor(rowIndex, columnIndex));
|
||||
}
|
||||
|
||||
function cellExternalUrlFor(rowIndex: number, columnIndex: number): string | null {
|
||||
return cellExternalUrl(displayItemAt(rowIndex)?.data[columnIndex]);
|
||||
}
|
||||
|
||||
function canOpenCellExternalUrl(rowIndex: number, columnIndex: number): boolean {
|
||||
return cellExternalUrlFor(rowIndex, columnIndex) !== null;
|
||||
}
|
||||
|
||||
async function openCellExternalUrl(rowIndex: number, columnIndex: number) {
|
||||
const url = cellExternalUrlFor(rowIndex, columnIndex);
|
||||
if (!url) return;
|
||||
try {
|
||||
const { open } = await import("@tauri-apps/plugin-shell");
|
||||
await open(url);
|
||||
} catch {
|
||||
window.open(url, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
}
|
||||
|
||||
function downloadCellBinaryValue(rowIndex: number, columnIndex: number, mode: BinaryCellDownloadMode) {
|
||||
void downloadDetailBinaryValue(cellDetailFor(rowIndex, columnIndex), mode);
|
||||
}
|
||||
@@ -13033,6 +13056,16 @@ function openGridSnapshot() {
|
||||
</button>
|
||||
</template>
|
||||
</LightDropdownMenu>
|
||||
<button
|
||||
v-if="canOpenCellExternalUrl(cell.recordIndex, cell.valueIndex)"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
:title="t('grid.openUrl')"
|
||||
:aria-label="t('grid.openUrl')"
|
||||
@mousedown.stop
|
||||
@click.stop="openCellExternalUrl(cell.recordIndex, cell.valueIndex)"
|
||||
>
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="cellDetailButtonEnabled"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
@@ -13773,6 +13806,16 @@ function openGridSnapshot() {
|
||||
</button>
|
||||
</template>
|
||||
</LightDropdownMenu>
|
||||
<button
|
||||
v-if="canvasDetailButtonCell.externalUrl"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
:title="t('grid.openUrl')"
|
||||
:aria-label="t('grid.openUrl')"
|
||||
@mousedown.stop
|
||||
@click.stop="openCellExternalUrl(canvasDetailButtonCell.rowIndex, canvasDetailButtonCell.actualColIdx)"
|
||||
>
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="canvasDetailButtonCell.foreignKey"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
@@ -14005,6 +14048,16 @@ function openGridSnapshot() {
|
||||
</button>
|
||||
</template>
|
||||
</LightDropdownMenu>
|
||||
<button
|
||||
v-if="canOpenCellExternalUrl(item.displayIndex, col.actualColIdx)"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
:title="t('grid.openUrl')"
|
||||
:aria-label="t('grid.openUrl')"
|
||||
@mousedown.stop
|
||||
@click.stop="openCellExternalUrl(item.displayIndex, col.actualColIdx)"
|
||||
>
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="cellDetailButtonEnabled"
|
||||
class="flex h-5 w-5 items-center justify-center rounded bg-background/90 text-muted-foreground shadow-sm ring-1 ring-border hover:text-foreground"
|
||||
|
||||
+4
-4
@@ -27,10 +27,10 @@ describe("DataGrid cell detail selection", () => {
|
||||
});
|
||||
|
||||
it("removes the Canvas action overlay and reservation only when no action remains", () => {
|
||||
expect(dataGridSource).toContain("if (!cellDetailButtonEnabled.value && !canQuickDownload && !foreignKey) return null;");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionOverlayWidth(canQuickDownload, !!foreignKey, cellDetailButtonEnabled.value)");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionOverlayWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value)");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionReservedWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value)");
|
||||
expect(dataGridSource).toContain("if (!cellDetailButtonEnabled.value && !canQuickDownload && !foreignKey && !externalUrl) return null;");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionOverlayWidth(canQuickDownload, !!foreignKey, cellDetailButtonEnabled.value, !!externalUrl)");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionOverlayWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value, !!cell.externalUrl)");
|
||||
expect(dataGridSource).toContain("canvasDataGridActionReservedWidth(cell.canQuickDownload, !!cell.foreignKey, cellDetailButtonEnabled.value, !!cell.externalUrl)");
|
||||
expect(dataGridSource).toMatch(/watch\([\s\S]*?cellDetailButtonEnabled,[\s\S]*?scheduleCanvasDraw/);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user