|
| 1 | +import type { TemplateResult } from 'lit'; |
1 | 2 | import { css, html } from 'lit';
|
2 | 3 | import { customElement, property, query, state } from 'lit/decorators.js';
|
3 | 4 | import type { SearchOperators, SearchOperatorsLongForm, SearchQuery } from '../../../../../constants.search';
|
@@ -389,7 +390,23 @@ export class GlSearchInput extends GlElement {
|
389 | 390 | this.searchHistoryPos = this.searchHistory.length - 1;
|
390 | 391 | }
|
391 | 392 |
|
392 |
| - override render(): unknown { |
| 393 | + private padDate(date: number) { |
| 394 | + let stringDate = date.toString(); |
| 395 | + if (stringDate.length < 2) { |
| 396 | + stringDate = `0${stringDate}`; |
| 397 | + } |
| 398 | + return stringDate; |
| 399 | + } |
| 400 | + |
| 401 | + private handleInsertDateToken(tokenPrefix: string) { |
| 402 | + const currentDate = new Date(); |
| 403 | + const year = currentDate.getFullYear(); |
| 404 | + const month = this.padDate(currentDate.getMonth() + 1); |
| 405 | + const date = this.padDate(currentDate.getDate()); |
| 406 | + this.handleInsertToken(`${tokenPrefix}${year}-${month}-${date}`); |
| 407 | + } |
| 408 | + |
| 409 | + override render(): TemplateResult { |
393 | 410 | return html`<div class="field">
|
394 | 411 | <div class="controls controls__start">
|
395 | 412 | <gl-button
|
@@ -486,6 +503,33 @@ export class GlSearchInput extends GlElement {
|
486 | 503 | Type <small>type:stash or is:stash</small>
|
487 | 504 | </button>
|
488 | 505 | </menu-item>
|
| 506 | + <menu-item role="none"> |
| 507 | + <button |
| 508 | + class="menu-button" |
| 509 | + type="button" |
| 510 | + @click="${() => this.handleInsertDateToken('date:')}" |
| 511 | + > |
| 512 | + Date <small>date:YYYY-MM-dd</small> |
| 513 | + </button> |
| 514 | + </menu-item> |
| 515 | + <menu-item role="none"> |
| 516 | + <button |
| 517 | + class="menu-button" |
| 518 | + type="button" |
| 519 | + @click="${() => this.handleInsertDateToken('after:')}" |
| 520 | + > |
| 521 | + Date from <small>after:YYYY-MM-dd</small> |
| 522 | + </button> |
| 523 | + </menu-item> |
| 524 | + <menu-item role="none"> |
| 525 | + <button |
| 526 | + class="menu-button" |
| 527 | + type="button" |
| 528 | + @click="${() => this.handleInsertDateToken(`before:`)}" |
| 529 | + > |
| 530 | + Date to <small>before:YYYY-MM-dd</small> |
| 531 | + </button> |
| 532 | + </menu-item> |
489 | 533 | </div>
|
490 | 534 | </gl-popover>
|
491 | 535 | </div>
|
|
0 commit comments