Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(desktop): fix data error when exporting csv file #1213

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/ExportData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export default class ExportData extends Vue {
}
const exportDataToCSV = (jsonContent: ConnectionModel[]) => {
try {
const content: string = CSVConvert(jsonContent)
// Prevent CSV from automatically converting string with trailing zeros after decimal point to number.
// https://stackoverflow.com/questions/165042/stop-excel-from-automatically-converting-certain-text-values-to-dates
const content: string = CSVConvert(jsonContent).replace(/"(\d+\.0+)"/g, '="$1"')
this.exportDiffFormatData(content, 'CSV')
} catch (err) {
this.$message.error(err.toString())
Expand Down
15 changes: 11 additions & 4 deletions src/components/ImportData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,11 @@ export default class ImportData extends Vue {
.fromString(data)
.subscribe((jsonObj) => {
try {
let { messages, subscriptions, will, ...otherProps } = jsonObj
let { messages, subscriptions, properties, will, ...otherProps } = jsonObj
// format object
messages = JSON.parse(messages)
subscriptions = JSON.parse(subscriptions)
properties = JSON.parse(properties)
will = JSON.parse(will)
Object.keys(otherProps).forEach((item) => {
// format boolean
Expand All @@ -330,14 +331,20 @@ export default class ImportData extends Vue {
} else if (otherProps[item] === 'false') {
otherProps[item] = false
} else if (this.stringProps.indexOf(item) === -1 && otherProps[item] !== '') {
// format number
const numValue = Number(otherProps[item])
otherProps[item] = !isNaN(numValue) ? numValue : otherProps[item]
if (/^="(\d+\.0+)"/.test(otherProps[item])) {
// format string number
otherProps[item] = otherProps[item].replace(/^="(\d+\.0+)"/, '$1')
} else {
// format number
const numValue = Number(otherProps[item])
otherProps[item] = !isNaN(numValue) ? numValue : otherProps[item]
}
}
})
const oneRealJSONObj = {
messages,
subscriptions,
properties,
will,
...otherProps,
}
Expand Down
2 changes: 1 addition & 1 deletion src/database/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export default class ConnectionService {

// cascade getAll
public async cascadeGetAll(id?: string) {
const query = await this.connectionRepository.createQueryBuilder('cn')
const query = this.connectionRepository.createQueryBuilder('cn')

id && query.where('cn.id = :id', { id })

Expand Down