|
3 | 3 | import React, { useState, useEffect, useRef } from 'react'; |
4 | 4 | import PropTypes from 'prop-types'; |
5 | 5 | import { API, Logger } from 'aws-amplify'; |
6 | | -import { FormField, Input, Button, Grid, Box, SpaceBetween, ButtonDropdown } from '@awsui/components-react'; |
| 6 | +import { FormField, Textarea, Button, Grid, Box, SpaceBetween, ButtonDropdown } from '@awsui/components-react'; |
7 | 7 | import listAnalyticsJobs from '../../graphql/queries/listAnalyticsJobs'; |
8 | 8 | import deleteAnalyticsJob from '../../graphql/queries/deleteAnalyticsJob'; |
9 | 9 |
|
| 10 | +// Custom styles for expandable textarea |
| 11 | +const textareaStyles = ` |
| 12 | + .expandable-textarea { |
| 13 | + max-height: 250px; |
| 14 | + overflow-y: auto !important; |
| 15 | + resize: vertical; |
| 16 | + } |
| 17 | +`; |
| 18 | + |
10 | 19 | const logger = new Logger('AnalyticsQueryInput'); |
11 | 20 |
|
12 | 21 | const AnalyticsQueryInput = ({ onSubmit, isSubmitting, selectedResult }) => { |
@@ -272,45 +281,50 @@ const AnalyticsQueryInput = ({ onSubmit, isSubmitting, selectedResult }) => { |
272 | 281 | }; |
273 | 282 |
|
274 | 283 | return ( |
275 | | - <form onSubmit={handleSubmit}> |
276 | | - <SpaceBetween size="s"> |
277 | | - <Grid gridDefinition={[{ colspan: { default: 12, xxs: 9 } }, { colspan: { default: 12, xxs: 3 } }]}> |
278 | | - <FormField label="Enter your analytics query"> |
279 | | - <Input |
280 | | - placeholder="How has the number of documents processed per day trended over the past three weeks?" |
281 | | - value={query} |
282 | | - onChange={({ detail }) => setQuery(detail.value)} |
| 284 | + <> |
| 285 | + <style>{textareaStyles}</style> |
| 286 | + <form onSubmit={handleSubmit}> |
| 287 | + <SpaceBetween size="s"> |
| 288 | + <Grid gridDefinition={[{ colspan: { default: 12, xxs: 9 } }, { colspan: { default: 12, xxs: 3 } }]}> |
| 289 | + <FormField label="Enter your analytics query"> |
| 290 | + <Textarea |
| 291 | + placeholder="How has the number of documents processed per day trended over the past three weeks?" |
| 292 | + value={query} |
| 293 | + onChange={({ detail }) => setQuery(detail.value)} |
| 294 | + disabled={isSubmitting} |
| 295 | + rows={2} |
| 296 | + className="expandable-textarea" |
| 297 | + /> |
| 298 | + </FormField> |
| 299 | + <Box padding={{ top: 'xl' }}> |
| 300 | + {' '} |
| 301 | + {/* Add top padding to align with input box */} |
| 302 | + <Button variant="primary" type="submit" disabled={!query.trim() || isSubmitting} fullWidth> |
| 303 | + {isSubmitting ? 'Submitting...' : 'Submit query'} |
| 304 | + </Button> |
| 305 | + </Box> |
| 306 | + </Grid> |
| 307 | + |
| 308 | + <FormField label="Previous queries"> |
| 309 | + <ButtonDropdown |
| 310 | + items={createDropdownItems()} |
| 311 | + onItemClick={handleDropdownItemClick} |
| 312 | + onFocus={() => fetchQueryHistory()} |
| 313 | + loading={isLoadingHistory} |
283 | 314 | disabled={isSubmitting} |
284 | | - /> |
| 315 | + > |
| 316 | + {(() => { |
| 317 | + if (!selectedOption) return 'Select a previous query'; |
| 318 | + if (selectedOption.label?.length > 40) { |
| 319 | + return `${selectedOption.label.substring(0, 40)}...`; |
| 320 | + } |
| 321 | + return selectedOption.label || 'Selected query'; |
| 322 | + })()} |
| 323 | + </ButtonDropdown> |
285 | 324 | </FormField> |
286 | | - <Box padding={{ top: 'xl' }}> |
287 | | - {' '} |
288 | | - {/* Add top padding to align with input box */} |
289 | | - <Button variant="primary" type="submit" disabled={!query.trim() || isSubmitting} fullWidth> |
290 | | - {isSubmitting ? 'Submitting...' : 'Submit query'} |
291 | | - </Button> |
292 | | - </Box> |
293 | | - </Grid> |
294 | | - |
295 | | - <FormField label="Previous queries"> |
296 | | - <ButtonDropdown |
297 | | - items={createDropdownItems()} |
298 | | - onItemClick={handleDropdownItemClick} |
299 | | - onFocus={() => fetchQueryHistory()} |
300 | | - loading={isLoadingHistory} |
301 | | - disabled={isSubmitting} |
302 | | - > |
303 | | - {(() => { |
304 | | - if (!selectedOption) return 'Select a previous query'; |
305 | | - if (selectedOption.label?.length > 40) { |
306 | | - return `${selectedOption.label.substring(0, 40)}...`; |
307 | | - } |
308 | | - return selectedOption.label || 'Selected query'; |
309 | | - })()} |
310 | | - </ButtonDropdown> |
311 | | - </FormField> |
312 | | - </SpaceBetween> |
313 | | - </form> |
| 325 | + </SpaceBetween> |
| 326 | + </form> |
| 327 | + </> |
314 | 328 | ); |
315 | 329 | }; |
316 | 330 |
|
|
0 commit comments