PR comments.
This commit is contained in:
parent
cf440cc39d
commit
582ed1d75b
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import DataCell from "../cells/DataCell.svelte"
|
import DataCell from "../cells/DataCell.svelte"
|
||||||
import { combineRowId } from "../lib/utils"
|
import { getCellID } from "../lib/utils"
|
||||||
|
|
||||||
export let row
|
export let row
|
||||||
export let top = false
|
export let top = false
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
on:click={() => dispatch("rowclick", rows.actions.cleanRow(row))}
|
on:click={() => dispatch("rowclick", rows.actions.cleanRow(row))}
|
||||||
>
|
>
|
||||||
{#each $visibleColumns as column, columnIdx}
|
{#each $visibleColumns as column, columnIdx}
|
||||||
{@const cellId = combineRowId(row._id, column.name)}
|
{@const cellId = getCellID(row._id, column.name)}
|
||||||
<DataCell
|
<DataCell
|
||||||
{cellId}
|
{cellId}
|
||||||
{column}
|
{column}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import { GutterWidth, NewRowID } from "../lib/constants"
|
import { GutterWidth, NewRowID } from "../lib/constants"
|
||||||
import GutterCell from "../cells/GutterCell.svelte"
|
import GutterCell from "../cells/GutterCell.svelte"
|
||||||
import KeyboardShortcut from "./KeyboardShortcut.svelte"
|
import KeyboardShortcut from "./KeyboardShortcut.svelte"
|
||||||
import { combineRowId } from "../lib/utils"
|
import { getCellID } from "../lib/utils"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
// Select the first cell if possible
|
// Select the first cell if possible
|
||||||
if (firstColumn) {
|
if (firstColumn) {
|
||||||
$focusedCellId = combineRowId(savedRow._id, firstColumn.name)
|
$focusedCellId = getCellID(savedRow._id, firstColumn.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isAdding = false
|
isAdding = false
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
visible = true
|
visible = true
|
||||||
$hoveredRowId = NewRowID
|
$hoveredRowId = NewRowID
|
||||||
if (firstColumn) {
|
if (firstColumn) {
|
||||||
$focusedCellId = combineRowId(NewRowID, firstColumn.name)
|
$focusedCellId = getCellID(NewRowID, firstColumn.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach key listener
|
// Attach key listener
|
||||||
|
@ -195,7 +195,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
</GutterCell>
|
</GutterCell>
|
||||||
{#if $stickyColumn}
|
{#if $stickyColumn}
|
||||||
{@const cellId = combineRowId(NewRowID, $stickyColumn.name)}
|
{@const cellId = getCellID(NewRowID, $stickyColumn.name)}
|
||||||
<DataCell
|
<DataCell
|
||||||
{cellId}
|
{cellId}
|
||||||
rowFocused
|
rowFocused
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import { GutterWidth, BlankRowID } from "../lib/constants"
|
import { GutterWidth, BlankRowID } from "../lib/constants"
|
||||||
import GutterCell from "../cells/GutterCell.svelte"
|
import GutterCell from "../cells/GutterCell.svelte"
|
||||||
import KeyboardShortcut from "./KeyboardShortcut.svelte"
|
import KeyboardShortcut from "./KeyboardShortcut.svelte"
|
||||||
import { combineRowId } from "../lib/utils"
|
import { getCellID } from "../lib/utils"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
rows,
|
rows,
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
{@const rowSelected = !!$selectedRows[row._id]}
|
{@const rowSelected = !!$selectedRows[row._id]}
|
||||||
{@const rowHovered = $hoveredRowId === row._id}
|
{@const rowHovered = $hoveredRowId === row._id}
|
||||||
{@const rowFocused = $focusedRow?._id === row._id}
|
{@const rowFocused = $focusedRow?._id === row._id}
|
||||||
{@const cellId = combineRowId(row._id, $stickyColumn?.name)}
|
{@const cellId = getCellID(row._id, $stickyColumn?.name)}
|
||||||
<div
|
<div
|
||||||
class="row"
|
class="row"
|
||||||
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = row._id)}
|
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = row._id)}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { TypeIconMap } from "../../../constants"
|
||||||
// using something very unusual to avoid this problem
|
// using something very unusual to avoid this problem
|
||||||
const JOINING_CHARACTER = "‽‽"
|
const JOINING_CHARACTER = "‽‽"
|
||||||
|
|
||||||
export const splitRowId = rowId => {
|
export const parseCellID = rowId => {
|
||||||
if (!rowId) {
|
if (!rowId) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export const splitRowId = rowId => {
|
||||||
return { id: parts.join(JOINING_CHARACTER), field }
|
return { id: parts.join(JOINING_CHARACTER), field }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const combineRowId = (rowId, fieldName) => {
|
export const getCellID = (rowId, fieldName) => {
|
||||||
return `${rowId}${JOINING_CHARACTER}${fieldName}`
|
return `${rowId}${JOINING_CHARACTER}${fieldName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { getContext, onMount } from "svelte"
|
import { getContext, onMount } from "svelte"
|
||||||
import { debounce } from "../../../utils/utils"
|
import { debounce } from "../../../utils/utils"
|
||||||
import { NewRowID } from "../lib/constants"
|
import { NewRowID } from "../lib/constants"
|
||||||
import { combineRowId, splitRowId } from "../lib/utils"
|
import { getCellID, parseCellID } from "../lib/utils"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
rows,
|
rows,
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
if (!firstColumn) {
|
if (!firstColumn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
focusedCellId.set(combineRowId(firstRow._id, firstColumn.name))
|
focusedCellId.set(getCellID(firstRow._id, firstColumn.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes the focused cell by moving it left or right to a different column
|
// Changes the focused cell by moving it left or right to a different column
|
||||||
|
@ -164,7 +164,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const cols = $visibleColumns
|
const cols = $visibleColumns
|
||||||
const { id, field: columnName } = splitRowId($focusedCellId)
|
const { id, field: columnName } = parseCellID($focusedCellId)
|
||||||
let newColumnName
|
let newColumnName
|
||||||
if (columnName === $stickyColumn?.name) {
|
if (columnName === $stickyColumn?.name) {
|
||||||
const index = delta - 1
|
const index = delta - 1
|
||||||
|
@ -178,7 +178,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newColumnName) {
|
if (newColumnName) {
|
||||||
$focusedCellId = combineRowId(id, newColumnName)
|
$focusedCellId = getCellID(id, newColumnName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +189,8 @@
|
||||||
}
|
}
|
||||||
const newRow = $rows[$focusedRow.__idx + delta]
|
const newRow = $rows[$focusedRow.__idx + delta]
|
||||||
if (newRow) {
|
if (newRow) {
|
||||||
const { field } = splitRowId($focusedCellId)
|
const { field } = parseCellID($focusedCellId)
|
||||||
$focusedCellId = combineRowId(newRow._id, field)
|
$focusedCellId = getCellID(newRow._id, field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { NewRowID } from "../lib/constants"
|
import { NewRowID } from "../lib/constants"
|
||||||
import GridPopover from "./GridPopover.svelte"
|
import GridPopover from "./GridPopover.svelte"
|
||||||
import { combineRowId } from "../lib/utils"
|
import { getCellID } from "../lib/utils"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
focusedRow,
|
focusedRow,
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
const newRow = await rows.actions.duplicateRow($focusedRow)
|
const newRow = await rows.actions.duplicateRow($focusedRow)
|
||||||
if (newRow) {
|
if (newRow) {
|
||||||
const column = $stickyColumn?.name || $columns[0].name
|
const column = $stickyColumn?.name || $columns[0].name
|
||||||
$focusedCellId = combineRowId(newRow._id, column)
|
$focusedCellId = getCellID(newRow._id, column)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { writable, derived, get } from "svelte/store"
|
import { writable, derived, get } from "svelte/store"
|
||||||
import { fetchData } from "../../../fetch"
|
import { fetchData } from "../../../fetch"
|
||||||
import { NewRowID, RowPageSize } from "../lib/constants"
|
import { NewRowID, RowPageSize } from "../lib/constants"
|
||||||
import { combineRowId, splitRowId } from "../lib/utils"
|
import { getCellID, parseCellID } from "../lib/utils"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ export const createActions = context => {
|
||||||
// If the server doesn't reply with a valid error, assume that the source
|
// If the server doesn't reply with a valid error, assume that the source
|
||||||
// of the error is the focused cell's column
|
// of the error is the focused cell's column
|
||||||
if (!error?.json?.validationErrors && errorString) {
|
if (!error?.json?.validationErrors && errorString) {
|
||||||
const { field: focusedColumn } = splitRowId(get(focusedCellId))
|
const { field: focusedColumn } = parseCellID(get(focusedCellId))
|
||||||
if (focusedColumn) {
|
if (focusedColumn) {
|
||||||
error = {
|
error = {
|
||||||
json: {
|
json: {
|
||||||
|
@ -246,7 +246,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
// Set error against the cell
|
// Set error against the cell
|
||||||
validation.actions.setError(
|
validation.actions.setError(
|
||||||
combineRowId(rowId, column),
|
getCellID(rowId, column),
|
||||||
Helpers.capitalise(err)
|
Helpers.capitalise(err)
|
||||||
)
|
)
|
||||||
// Ensure the column is visible
|
// Ensure the column is visible
|
||||||
|
@ -266,7 +266,7 @@ export const createActions = context => {
|
||||||
|
|
||||||
// Focus the first cell with an error
|
// Focus the first cell with an error
|
||||||
if (erroredColumns.length) {
|
if (erroredColumns.length) {
|
||||||
focusedCellId.set(combineRowId(rowId, erroredColumns[0]))
|
focusedCellId.set(getCellID(rowId, erroredColumns[0]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
get(notifications).error(errorString || "An unknown error occurred")
|
get(notifications).error(errorString || "An unknown error occurred")
|
||||||
|
@ -572,10 +572,10 @@ export const initialise = context => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Stop if we changed row
|
// Stop if we changed row
|
||||||
const split = splitRowId(id)
|
const split = parseCellID(id)
|
||||||
const oldRowId = split.id
|
const oldRowId = split.id
|
||||||
const oldColumn = split.field
|
const oldColumn = split.field
|
||||||
const { id: newRowId } = splitRowId(get(focusedCellId))
|
const { id: newRowId } = parseCellID(get(focusedCellId))
|
||||||
if (oldRowId !== newRowId) {
|
if (oldRowId !== newRowId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { writable, derived, get } from "svelte/store"
|
import { writable, derived, get } from "svelte/store"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import { Padding, GutterWidth, FocusedCellMinOffset } from "../lib/constants"
|
import { Padding, GutterWidth, FocusedCellMinOffset } from "../lib/constants"
|
||||||
import { splitRowId } from "../lib/utils"
|
import { parseCellID } from "../lib/utils"
|
||||||
|
|
||||||
export const createStores = () => {
|
export const createStores = () => {
|
||||||
const scroll = writable({
|
const scroll = writable({
|
||||||
|
@ -177,7 +177,7 @@ export const initialise = context => {
|
||||||
// Ensure horizontal position is viewable
|
// Ensure horizontal position is viewable
|
||||||
// Check horizontal position of columns next
|
// Check horizontal position of columns next
|
||||||
const $visibleColumns = get(visibleColumns)
|
const $visibleColumns = get(visibleColumns)
|
||||||
const { field: columnName } = splitRowId($focusedCellId)
|
const { field: columnName } = parseCellID($focusedCellId)
|
||||||
const column = $visibleColumns.find(col => col.name === columnName)
|
const column = $visibleColumns.find(col => col.name === columnName)
|
||||||
if (!column) {
|
if (!column) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
MediumRowHeight,
|
MediumRowHeight,
|
||||||
NewRowID,
|
NewRowID,
|
||||||
} from "../lib/constants"
|
} from "../lib/constants"
|
||||||
import { splitRowId } from "../lib/utils"
|
import { parseCellID } from "../lib/utils"
|
||||||
|
|
||||||
export const createStores = context => {
|
export const createStores = context => {
|
||||||
const { props } = context
|
const { props } = context
|
||||||
|
@ -26,7 +26,7 @@ export const createStores = context => {
|
||||||
const focusedRowId = derived(
|
const focusedRowId = derived(
|
||||||
focusedCellId,
|
focusedCellId,
|
||||||
$focusedCellId => {
|
$focusedCellId => {
|
||||||
return splitRowId($focusedCellId)?.id
|
return parseCellID($focusedCellId)?.id
|
||||||
},
|
},
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
@ -73,7 +73,7 @@ export const deriveStores = context => {
|
||||||
const focusedRow = derived(
|
const focusedRow = derived(
|
||||||
[focusedCellId, rowLookupMap, rows],
|
[focusedCellId, rowLookupMap, rows],
|
||||||
([$focusedCellId, $rowLookupMap, $rows]) => {
|
([$focusedCellId, $rowLookupMap, $rows]) => {
|
||||||
const rowId = splitRowId($focusedCellId)?.id
|
const rowId = parseCellID($focusedCellId)?.id
|
||||||
|
|
||||||
// Edge case for new rows
|
// Edge case for new rows
|
||||||
if (rowId === NewRowID) {
|
if (rowId === NewRowID) {
|
||||||
|
@ -153,7 +153,7 @@ export const initialise = context => {
|
||||||
const hasRow = rows.actions.hasRow
|
const hasRow = rows.actions.hasRow
|
||||||
|
|
||||||
// Check selected cell
|
// Check selected cell
|
||||||
const selectedRowId = splitRowId($focusedCellId)?.id
|
const selectedRowId = parseCellID($focusedCellId)?.id
|
||||||
if (selectedRowId && !hasRow(selectedRowId)) {
|
if (selectedRowId && !hasRow(selectedRowId)) {
|
||||||
focusedCellId.set(null)
|
focusedCellId.set(null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { writable, get, derived } from "svelte/store"
|
import { writable, get, derived } from "svelte/store"
|
||||||
import { combineRowId, splitRowId } from "../lib/utils"
|
import { getCellID, parseCellID } from "../lib/utils"
|
||||||
|
|
||||||
// Normally we would break out actions into the explicit "createActions"
|
// Normally we would break out actions into the explicit "createActions"
|
||||||
// function, but for validation all these actions are pure so can go into
|
// function, but for validation all these actions are pure so can go into
|
||||||
|
@ -13,7 +13,7 @@ export const createStores = () => {
|
||||||
Object.entries($validation).forEach(([key, error]) => {
|
Object.entries($validation).forEach(([key, error]) => {
|
||||||
// Extract row ID from all errored cell IDs
|
// Extract row ID from all errored cell IDs
|
||||||
if (error) {
|
if (error) {
|
||||||
map[splitRowId(key).id] = true
|
map[parseCellID(key).id] = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return map
|
return map
|
||||||
|
@ -54,10 +54,10 @@ export const initialise = context => {
|
||||||
const $stickyColumn = get(stickyColumn)
|
const $stickyColumn = get(stickyColumn)
|
||||||
validation.update(state => {
|
validation.update(state => {
|
||||||
$columns.forEach(column => {
|
$columns.forEach(column => {
|
||||||
state[combineRowId(id, column.name)] = null
|
state[getCellID(id, column.name)] = null
|
||||||
})
|
})
|
||||||
if ($stickyColumn) {
|
if ($stickyColumn) {
|
||||||
state[combineRowId(id, stickyColumn.name)] = null
|
state[getCellID(id, stickyColumn.name)] = null
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue