@@ -98,43 +98,57 @@ export function LoggingQueryEditor({ datasource, query, range, onChange, onRunQu
98
98
/**
99
99
* Keep an up-to-date URI that links to the equivalent query in the GCP console
100
100
*/
101
- const gcpConsoleURI = useMemo < string | undefined > ( ( ) => {
101
+ const gcpConsoleURI = useMemo < string | undefined > ( ( ) => {
102
102
if ( ! query . queryText ) {
103
103
return undefined ;
104
104
}
105
105
106
106
let storageScope = "" ;
107
107
if ( query . projectId ) {
108
- storageScope = `;storageScope= storage,projects/${ query . projectId } ` ;
108
+ let scopePath = `storage,projects/${ query . projectId } ` ;
109
109
110
110
if ( query . bucketId ) {
111
- storageScope += `/locations/${ query . bucketId } ` ;
111
+ // Check if bucketId already includes 'locations/' prefix
112
+ if ( query . bucketId . startsWith ( 'locations/' ) ) {
113
+ scopePath += `/${ query . bucketId } ` ;
114
+ } else {
115
+ scopePath += `/locations/${ query . bucketId } ` ;
116
+ }
112
117
} else {
113
- storageScope += `/locations/global/buckets/_Default` ;
118
+ scopePath += `/locations/global/buckets/_Default` ;
114
119
}
115
120
if ( query . viewId ) {
116
- storageScope += `/views/${ query . viewId } ` ;
121
+ scopePath += `/views/${ query . viewId } ` ;
117
122
} else {
118
- storageScope += `/views/_AllLogs` ;
123
+ scopePath += `/views/_AllLogs` ;
119
124
}
125
+
126
+ // URL encode the forward slashes in the storage scope
127
+ storageScope = `;storageScope=${ scopePath . replace ( / \/ / g, '%2F' ) } ` ;
120
128
}
121
129
122
- const encodedText = encodeURIComponent ( `${ query . queryText } ${ storageScope } ` ) . replace ( / [ ! ' ( ) * ] / g, function ( c ) {
130
+ const encodedText = encodeURIComponent ( `${ query . queryText } ` ) . replace ( / [ ! ' ( ) * ] / g, function ( c ) {
123
131
if ( c === '(' || c === ')' ) {
124
132
return '%25' + c . charCodeAt ( 0 ) . toString ( 16 ) ;
125
133
}
126
134
return '%' + c . charCodeAt ( 0 ) . toString ( 16 ) ;
127
135
} ) ;
128
- const queryText = `query=${ encodedText } ` ;
129
- // If range is somehow undefined, don't add timeRange to the URI
130
- const timeRange = range !== undefined ?
131
- `timeRange=${ range ?. from ?. toISOString ( ) } %2F${ range ?. to ?. toISOString ( ) } `
132
- : '' ;
136
+
137
+ // Build query string parameters
138
+ let queryParams = [ `project=${ query . projectId } ` , `query=${ encodedText } ` ] ;
139
+
140
+ // Add storageScope without the semicolon prefix
141
+ if ( storageScope ) {
142
+ queryParams . push ( storageScope . substring ( 1 ) ) ; // Remove the leading semicolon
143
+ }
144
+
145
+ // Add time parameters
146
+ if ( range !== undefined ) {
147
+ queryParams . push ( `startTime=${ range ?. from ?. toISOString ( ) } ` ) ;
148
+ queryParams . push ( `endTime=${ range ?. to ?. toISOString ( ) } ` ) ;
149
+ }
133
150
134
- return `https://console.cloud.google.com/logs/query;` +
135
- queryText +
136
- `;${ timeRange } ` +
137
- `?project=${ query . projectId } ` ;
151
+ return `https://console.cloud.google.com/logs/query?${ queryParams . join ( '&' ) } ` ;
138
152
} , [ query , range ] ) ;
139
153
140
154
return (
0 commit comments