mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
2 changed files with 36 additions and 29 deletions
@ -0,0 +1,31 @@ |
|||||||
|
import { UITypes } from 'nocodb-sdk' |
||||||
|
|
||||||
|
export default |
||||||
|
function convertCellData(args: { from: UITypes; to: UITypes; value: any }) { |
||||||
|
const { from, to, value } = args |
||||||
|
if (from === to) { |
||||||
|
return value |
||||||
|
} |
||||||
|
|
||||||
|
switch (to) { |
||||||
|
case UITypes.Number: |
||||||
|
return Number(value) |
||||||
|
case UITypes.Checkbox: |
||||||
|
return Boolean(value) |
||||||
|
case UITypes.Date: |
||||||
|
return new Date(value) |
||||||
|
case UITypes.Attachment: |
||||||
|
try { |
||||||
|
return typeof value === 'string' ? JSON.parse(value) : value |
||||||
|
} catch (e) { |
||||||
|
return [] |
||||||
|
} |
||||||
|
case UITypes.LinkToAnotherRecord: |
||||||
|
case UITypes.Lookup: |
||||||
|
case UITypes.Rollup: |
||||||
|
case UITypes.Formula: |
||||||
|
throw new Error(`Unsupported conversion from ${from} to ${to}`) |
||||||
|
default: |
||||||
|
return value |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue