55 */
66
77import ms from 'ms' ;
8+ import { useState } from 'react' ;
89import { AppState , QueryData , FilePath } from '../types' ;
10+ import { sendFeedback } from './utils' ;
911
1012const jsonminify = require ( "jsonminify" )
1113const path = require ( 'path' ) ;
@@ -16,8 +18,8 @@ const electron = require('electron');
1618/**
1719 * create identifiew from label and database name
1820 */
19- export const keyFromData = ( label : string , db : string ) =>
20- `label:${ label } db:${ db } ` ;
21+ export const keyFromData = ( label : string , db : string , group : string ) =>
22+ `label:${ label } db:${ db } group: ${ group } ` ;
2123
2224/**
2325 * create identifiew from query object
@@ -53,7 +55,7 @@ export const deleteQuery = (
5355// Finds proper data path for saving based on operating system
5456type GetAppDataPath = ( ) => string ;
5557
56- //used to determine default filepath for saving query information locally
58+ // used to determine default filepath for saving query information locally
5759export const getAppDataPath : GetAppDataPath = ( ) => {
5860 switch ( process . platform ) {
5961 case "darwin" : {
@@ -76,17 +78,20 @@ export const getAppDataPath: GetAppDataPath = () => {
7678type SaveQuery = ( query : QueryData , filepath : string ) => void
7779
7880export const saveQuery :SaveQuery = ( query : QueryData , filePath : string ) => {
79- //Open electron prompt and async writes to file
81+ // Open electron prompt and async writes to file
8082 fs . access ( filePath , ( err : unknown ) => {
8183 if ( err ) {
82- console . log ( 'File not found, writing file' ) ;
8384 try {
8485 const label : string = `label:${ query . label } db:${ query . db } group:${ query . group } `
8586 const data : object = { } ;
8687 data [ label ] = query ;
8788 fs . writeFileSync ( filePath , JSON . stringify ( data ) ) ;
88- console . log ( 'File saved successfully' ) ;
89- } catch ( err : unknown ) {
89+ sendFeedback ( {
90+ type : 'info' ,
91+ message : `File saved at location ${ filePath } ` ,
92+ } ) ;
93+ }
94+ catch ( err : unknown ) {
9095 console . log ( err ) ;
9196 } ;
9297 } else {
@@ -95,7 +100,10 @@ export const saveQuery:SaveQuery = ( query: QueryData, filePath: string) => {
95100 const label : string = `label:${ query . label } db:${ query . db } group:${ query . group } `
96101 data [ label ] = query ;
97102 fs . writeFileSync ( filePath , JSON . stringify ( data ) ) ;
98- console . log ( 'File saved successfully' ) ;
103+ sendFeedback ( {
104+ type : 'info' ,
105+ message : `File saved at location ${ filePath } ` ,
106+ } ) ;
99107 } ;
100108 } )
101109} ;
@@ -106,17 +114,26 @@ export const saveQuery:SaveQuery = ( query: QueryData, filePath: string) => {
106114 */
107115export const setCompare = (
108116 comparedQueries : AppState [ 'comparedQueries' ] ,
117+ queries : Record < string , QueryData > ,
109118 query : QueryData ,
110119 isCompared : boolean
111120) => {
112- const tempQueries = { ...comparedQueries } ;
121+ const tempQueries : any = JSON . parse ( JSON . stringify ( comparedQueries ) ) ;
122+ const queriess :any = { ...queries }
123+ const qKey = key ( query ) ;
113124
114125 if ( ! isCompared ) {
115- delete tempQueries [ key ( query ) ] ;
126+ tempQueries [ qKey ] . executionPlan [ 'Execution Time' ] = 0 ;
127+ tempQueries [ qKey ] . executionPlan [ 'Planning Time' ] = 0 ;
116128 return tempQueries ;
117129 }
118130
119- tempQueries [ key ( query ) ] = query ;
131+ if ( tempQueries . hasOwnProperty ( qKey ) ) {
132+ tempQueries [ qKey ] . executionPlan [ 'Execution Time' ] = queriess [ qKey ] . executionPlan [ 'Execution Time' ] ;
133+ tempQueries [ qKey ] . executionPlan [ 'Planning Time' ] = queriess [ qKey ] . executionPlan [ 'Planning Time' ] ;
134+ } else {
135+ tempQueries [ qKey ] = query ;
136+ }
120137 return tempQueries ;
121138} ;
122139
0 commit comments