@@ -17,6 +17,7 @@ import {
17
17
Menu ,
18
18
Radio ,
19
19
SegmentedControl ,
20
+ Select ,
20
21
Slider ,
21
22
Stack ,
22
23
Switch ,
@@ -44,6 +45,8 @@ import { DBTableSelectControlled } from './DBTableSelect';
44
45
import { InputControlled } from './InputControlled' ;
45
46
import { SQLInlineEditorControlled } from './SQLInlineEditor' ;
46
47
48
+ const DEFAULT_DATABASE = 'default' ;
49
+
47
50
function FormRow ( {
48
51
label,
49
52
children,
@@ -112,7 +115,6 @@ export function LogTableModelForm({
112
115
watch : UseFormWatch < TSource > ;
113
116
setValue : UseFormSetValue < TSource > ;
114
117
} ) {
115
- const DEFAULT_DATABASE = 'default' ;
116
118
const databaseName = watch ( `from.databaseName` , DEFAULT_DATABASE ) ;
117
119
const tableName = watch ( `from.tableName` ) ;
118
120
const connectionId = watch ( `connection` ) ;
@@ -319,7 +321,6 @@ export function TraceTableModelForm({
319
321
watch : UseFormWatch < TSource > ;
320
322
setValue : UseFormSetValue < TSource > ;
321
323
} ) {
322
- const DEFAULT_DATABASE = 'default' ;
323
324
const databaseName = watch ( `from.databaseName` , DEFAULT_DATABASE ) ;
324
325
const tableName = watch ( `from.tableName` ) ;
325
326
const connectionId = watch ( `connection` ) ;
@@ -536,6 +537,242 @@ export function TraceTableModelForm({
536
537
) ;
537
538
}
538
539
540
+ export function MetricTableModelForm ( {
541
+ control,
542
+ watch,
543
+ setValue,
544
+ } : {
545
+ control : Control < TSource > ;
546
+ watch : UseFormWatch < TSource > ;
547
+ setValue : UseFormSetValue < TSource > ;
548
+ } ) {
549
+ const databaseName = watch ( `from.databaseName` , DEFAULT_DATABASE ) ;
550
+ const tableName = watch ( `from.tableName` ) ;
551
+ const connectionId = watch ( `connection` ) ;
552
+
553
+ const [ showOptionalFields , setShowOptionalFields ] = useState ( false ) ;
554
+
555
+ return (
556
+ < >
557
+ < Stack gap = "sm" >
558
+ < FormRow label = { 'Server Connection' } >
559
+ < ConnectionSelectControlled control = { control } name = { `connection` } />
560
+ </ FormRow >
561
+ < FormRow label = { 'Database' } >
562
+ < DatabaseSelectControlled
563
+ connectionId = { connectionId }
564
+ control = { control }
565
+ name = { `from.databaseName` }
566
+ />
567
+ </ FormRow >
568
+ < Divider />
569
+ < FormRow label = { 'Metric Type' } >
570
+ < Select
571
+ data = { [ { value : 'gauge' , label : 'Gauge' } ] }
572
+ defaultValue = "gauge"
573
+ placeholder = "Select metric type"
574
+ allowDeselect = { false }
575
+ />
576
+ </ FormRow >
577
+ < FormRow label = { 'Table' } >
578
+ < DBTableSelectControlled
579
+ connectionId = { connectionId }
580
+ database = { databaseName }
581
+ control = { control }
582
+ name = { `from.tableName` }
583
+ rules = { { required : 'Table is required' } }
584
+ />
585
+ </ FormRow >
586
+ < FormRow label = { 'Timestamp Column' } >
587
+ < SQLInlineEditorControlled
588
+ connectionId = { connectionId }
589
+ database = { databaseName }
590
+ table = { tableName }
591
+ control = { control }
592
+ name = "timestampValueExpression"
593
+ placeholder = "TimeUnix"
594
+ disableKeywordAutocomplete
595
+ />
596
+ </ FormRow >
597
+ < FormRow
598
+ label = { 'Default Select' }
599
+ helpText = "Default columns selected in search results (this can be customized per search later)"
600
+ >
601
+ < SQLInlineEditorControlled
602
+ database = { databaseName }
603
+ table = { tableName }
604
+ control = { control }
605
+ name = "defaultTableSelectExpression"
606
+ placeholder = "TimeUnix, MetricName, Value, ServiceName, Attributes"
607
+ connectionId = { connectionId }
608
+ />
609
+ </ FormRow >
610
+ < FormRow
611
+ label = { 'Metric Name Column' }
612
+ helpText = "Column containing the name of the metric being measured"
613
+ >
614
+ < SQLInlineEditorControlled
615
+ connectionId = { connectionId }
616
+ database = { databaseName }
617
+ table = { tableName }
618
+ control = { control }
619
+ name = "metricNameExpression"
620
+ placeholder = "MetricName"
621
+ />
622
+ </ FormRow >
623
+ < FormRow label = { 'Gauge Value Column' } >
624
+ < SQLInlineEditorControlled
625
+ connectionId = { connectionId }
626
+ database = { databaseName }
627
+ table = { tableName }
628
+ control = { control }
629
+ name = "valueExpression"
630
+ placeholder = "Value"
631
+ />
632
+ </ FormRow >
633
+ < Box >
634
+ { ! showOptionalFields && (
635
+ < Anchor
636
+ underline = "always"
637
+ onClick = { ( ) => setShowOptionalFields ( true ) }
638
+ size = "xs"
639
+ c = "gray.4"
640
+ >
641
+ < Text me = "sm" span >
642
+ < i className = "bi bi-gear" />
643
+ </ Text >
644
+ Configure Optional Fields
645
+ </ Anchor >
646
+ ) }
647
+ { showOptionalFields && (
648
+ < Button
649
+ onClick = { ( ) => setShowOptionalFields ( false ) }
650
+ size = "xs"
651
+ variant = "subtle"
652
+ color = "gray.4"
653
+ >
654
+ Hide Optional Fields
655
+ </ Button >
656
+ ) }
657
+ </ Box >
658
+ </ Stack >
659
+ < Stack
660
+ gap = "sm"
661
+ style = { {
662
+ display : showOptionalFields ? 'flex' : 'none' ,
663
+ } }
664
+ >
665
+ < Divider />
666
+ < FormRow
667
+ label = { 'Service Name Column' }
668
+ helpText = "Column containing the service name associated with the metric"
669
+ >
670
+ < SQLInlineEditorControlled
671
+ connectionId = { connectionId }
672
+ database = { databaseName }
673
+ table = { tableName }
674
+ control = { control }
675
+ name = "serviceNameExpression"
676
+ placeholder = "ServiceName"
677
+ />
678
+ </ FormRow >
679
+ < FormRow
680
+ label = { 'Resource Attributes Column' }
681
+ helpText = "Column containing resource attributes/tags associated with the metric"
682
+ >
683
+ < SQLInlineEditorControlled
684
+ connectionId = { connectionId }
685
+ database = { databaseName }
686
+ table = { tableName }
687
+ control = { control }
688
+ name = "resourceAttributesExpression"
689
+ placeholder = "ResourceAttributes"
690
+ />
691
+ </ FormRow >
692
+ < FormRow
693
+ label = { 'Metric Unit Column' }
694
+ helpText = "Column containing the unit of measurement for the metric"
695
+ >
696
+ < SQLInlineEditorControlled
697
+ connectionId = { connectionId }
698
+ database = { databaseName }
699
+ table = { tableName }
700
+ control = { control }
701
+ name = "metricUnitExpression"
702
+ placeholder = "MetricUnit"
703
+ />
704
+ </ FormRow >
705
+ < FormRow
706
+ label = { 'Metric Flag Column' }
707
+ helpText = "Column containing flags or markers associated with the metric"
708
+ >
709
+ < SQLInlineEditorControlled
710
+ connectionId = { connectionId }
711
+ database = { databaseName }
712
+ table = { tableName }
713
+ control = { control }
714
+ name = "flagsExpression"
715
+ placeholder = "Flags"
716
+ />
717
+ </ FormRow >
718
+ < FormRow
719
+ label = { 'Event Attributes Expression' }
720
+ helpText = "Column containing additional attributes/dimensions for the metric"
721
+ >
722
+ < SQLInlineEditorControlled
723
+ connectionId = { connectionId }
724
+ database = { databaseName }
725
+ table = { tableName }
726
+ control = { control }
727
+ name = "eventAttributesExpression"
728
+ placeholder = "Attributes"
729
+ />
730
+ </ FormRow >
731
+ </ Stack >
732
+ </ >
733
+ ) ;
734
+ }
735
+
736
+ function TableModelForm ( {
737
+ control,
738
+ watch,
739
+ setValue,
740
+ kind,
741
+ } : {
742
+ control : Control < TSource > ;
743
+ watch : UseFormWatch < TSource > ;
744
+ setValue : UseFormSetValue < TSource > ;
745
+ kind : SourceKind ;
746
+ } ) {
747
+ switch ( kind ) {
748
+ case SourceKind . Log :
749
+ case SourceKind . Session :
750
+ return (
751
+ < LogTableModelForm
752
+ control = { control }
753
+ watch = { watch }
754
+ setValue = { setValue }
755
+ />
756
+ ) ;
757
+ case SourceKind . Trace :
758
+ return (
759
+ < TraceTableModelForm
760
+ control = { control }
761
+ watch = { watch }
762
+ setValue = { setValue }
763
+ />
764
+ ) ;
765
+ case SourceKind . Metric :
766
+ return (
767
+ < MetricTableModelForm
768
+ control = { control }
769
+ watch = { watch }
770
+ setValue = { setValue }
771
+ />
772
+ ) ;
773
+ }
774
+ }
775
+
539
776
export function TableSourceForm ( {
540
777
sourceId,
541
778
onSave,
@@ -737,6 +974,7 @@ export function TableSourceForm({
737
974
< Group >
738
975
< Radio value = { SourceKind . Log } label = "Log" />
739
976
< Radio value = { SourceKind . Trace } label = "Trace" />
977
+ < Radio value = { SourceKind . Metric } label = "Metric" />
740
978
{ IS_SESSIONS_ENABLED && (
741
979
< Radio value = { SourceKind . Session } label = "Session" />
742
980
) }
@@ -746,22 +984,12 @@ export function TableSourceForm({
746
984
/>
747
985
</ FormRow >
748
986
</ Stack >
749
- { kind === SourceKind . Trace ? (
750
- < TraceTableModelForm
751
- // @ts -ignore
752
- control = { control }
753
- // @ts -ignore
754
- watch = { watch }
755
- // @ts -ignore
756
- setValue = { setValue }
757
- />
758
- ) : (
759
- < LogTableModelForm
760
- control = { control }
761
- watch = { watch }
762
- setValue = { setValue }
763
- />
764
- ) }
987
+ < TableModelForm
988
+ control = { control }
989
+ watch = { watch }
990
+ setValue = { setValue }
991
+ kind = { kind }
992
+ />
765
993
</ div >
766
994
) ;
767
995
}
0 commit comments