mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
761 B
31 lines
761 B
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 |
|
} |
|
}
|
|
|