Add cells for formulae and JSON
This commit is contained in:
parent
4754be109a
commit
2d6c2fe904
|
@ -0,0 +1,5 @@
|
||||||
|
<script>
|
||||||
|
import TextCell from "./TextCell.svelte"
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<TextCell {...$$props} readonly />
|
|
@ -0,0 +1,36 @@
|
||||||
|
<script>
|
||||||
|
import LongFormCell from "./LongFormCell.svelte"
|
||||||
|
|
||||||
|
export let onChange
|
||||||
|
export let value
|
||||||
|
export let api
|
||||||
|
|
||||||
|
$: stringified = getStringifiedValue(value)
|
||||||
|
|
||||||
|
const getStringifiedValue = value => {
|
||||||
|
if (!value) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return JSON.stringify(value, null, 2)
|
||||||
|
} catch (error) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parse = value => {
|
||||||
|
const trimmed = value?.trim()
|
||||||
|
if (!trimmed) {
|
||||||
|
onChange(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(trimmed)
|
||||||
|
onChange(parsed)
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error parsing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<LongFormCell {...$$props} bind:api value={stringified} onChange={parse} />
|
|
@ -4,4 +4,4 @@
|
||||||
export let api
|
export let api
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TextCell bind:api {...$$props} type="number" />
|
<TextCell {...$$props} bind:api type="number" />
|
||||||
|
|
|
@ -7,6 +7,8 @@ import TextCell from "./cells/TextCell.svelte"
|
||||||
import BlankCell from "./cells/BlankCell.svelte"
|
import BlankCell from "./cells/BlankCell.svelte"
|
||||||
import LongFormCell from "./cells/LongFormCell.svelte"
|
import LongFormCell from "./cells/LongFormCell.svelte"
|
||||||
import BooleanCell from "./cells/BooleanCell.svelte"
|
import BooleanCell from "./cells/BooleanCell.svelte"
|
||||||
|
import FormulaCell from "./cells/FormulaCell.svelte"
|
||||||
|
import JSONCell from "./cells/JSONCell.svelte"
|
||||||
|
|
||||||
const TypeComponentMap = {
|
const TypeComponentMap = {
|
||||||
text: TextCell,
|
text: TextCell,
|
||||||
|
@ -19,8 +21,8 @@ const TypeComponentMap = {
|
||||||
boolean: BooleanCell,
|
boolean: BooleanCell,
|
||||||
attachment: BlankCell,
|
attachment: BlankCell,
|
||||||
link: RelationshipCell,
|
link: RelationshipCell,
|
||||||
formula: BlankCell,
|
formula: FormulaCell,
|
||||||
json: BlankCell,
|
json: JSONCell,
|
||||||
}
|
}
|
||||||
export const getCellRenderer = column => {
|
export const getCellRenderer = column => {
|
||||||
return TypeComponentMap[column?.schema?.type] || TextCell
|
return TypeComponentMap[column?.schema?.type] || TextCell
|
||||||
|
|
Loading…
Reference in New Issue