Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
cb82cf11
Unverified
Commit
cb82cf11
authored
Aug 19, 2020
by
Ryan McKinley
Committed by
GitHub
Aug 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overrides: expose byType matcher UI (#27056)
parent
98f8ec7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
1 deletions
+86
-1
packages/grafana-ui/src/components/MatchersUI/FieldTypeMatcherEditor.tsx
+84
-0
packages/grafana-ui/src/components/MatchersUI/fieldMatchersUI.ts
+2
-1
No files found.
packages/grafana-ui/src/components/MatchersUI/FieldTypeMatcherEditor.tsx
0 → 100644
View file @
cb82cf11
import
React
,
{
memo
,
useMemo
,
useCallback
}
from
'react'
;
import
{
MatcherUIProps
,
FieldMatcherUIRegistryItem
}
from
'./types'
;
import
{
FieldMatcherID
,
fieldMatchers
,
SelectableValue
,
FieldType
,
DataFrame
}
from
'@grafana/data'
;
import
{
Select
}
from
'../Select/Select'
;
export
const
FieldTypeMatcherEditor
=
memo
<
MatcherUIProps
<
string
>>
(
props
=>
{
const
{
data
,
options
}
=
props
;
const
counts
=
useFieldCounts
(
data
);
const
selectOptions
=
useSelectOptions
(
counts
,
options
);
const
onChange
=
useCallback
(
(
selection
:
SelectableValue
<
string
>
)
=>
{
return
props
.
onChange
(
selection
.
value
!
);
},
[
counts
,
props
.
onChange
]
);
const
selectedOption
=
selectOptions
.
find
(
v
=>
v
.
value
===
options
);
return
<
Select
value=
{
selectedOption
}
options=
{
selectOptions
}
onChange=
{
onChange
}
/>;
});
const
allTypes
:
Array
<
SelectableValue
<
FieldType
>>
=
[
{
value
:
FieldType
.
number
,
label
:
'Numeric'
},
{
value
:
FieldType
.
string
,
label
:
'String'
},
{
value
:
FieldType
.
time
,
label
:
'Time'
},
{
value
:
FieldType
.
boolean
,
label
:
'Boolean'
},
{
value
:
FieldType
.
trace
,
label
:
'Traces'
},
{
value
:
FieldType
.
other
,
label
:
'Other'
},
];
const
useFieldCounts
=
(
data
:
DataFrame
[]):
Map
<
FieldType
,
number
>
=>
{
return
useMemo
(()
=>
{
const
counts
:
Map
<
FieldType
,
number
>
=
new
Map
();
for
(
const
t
of
allTypes
)
{
counts
.
set
(
t
.
value
!
,
0
);
}
for
(
const
frame
of
data
)
{
for
(
const
field
of
frame
.
fields
)
{
const
key
=
field
.
type
||
FieldType
.
other
;
let
v
=
counts
.
get
(
key
);
if
(
!
v
)
{
v
=
0
;
}
counts
.
set
(
key
,
v
+
1
);
}
}
return
counts
;
},
[
data
]);
};
const
useSelectOptions
=
(
counts
:
Map
<
string
,
number
>
,
opt
?:
string
):
Array
<
SelectableValue
<
string
>>
=>
{
return
useMemo
(()
=>
{
let
found
=
false
;
const
options
:
Array
<
SelectableValue
<
string
>>
=
[];
for
(
const
t
of
allTypes
)
{
const
count
=
counts
.
get
(
t
.
value
!
);
const
match
=
opt
===
t
.
value
;
if
(
count
||
match
)
{
options
.
push
({
...
t
,
label
:
`
${
t
.
label
}
(
${
counts
.
get
(
t
.
value
!
)}
)`
,
});
}
if
(
match
)
{
found
=
true
;
}
}
if
(
opt
&&
!
found
)
{
options
.
push
({
value
:
opt
,
label
:
`
${
opt
}
(No matches)`
,
});
}
return
options
;
},
[
counts
,
opt
]);
};
export
const
fieldTypeMatcherItem
:
FieldMatcherUIRegistryItem
<
string
>
=
{
id
:
FieldMatcherID
.
byType
,
component
:
FieldTypeMatcherEditor
,
matcher
:
fieldMatchers
.
get
(
FieldMatcherID
.
byType
),
name
:
'Filter by type'
,
description
:
'Set properties for fields matching a type'
,
};
packages/grafana-ui/src/components/MatchersUI/fieldMatchersUI.ts
View file @
cb82cf11
import
{
Registry
}
from
'@grafana/data'
;
import
{
fieldNameMatcherItem
}
from
'./FieldNameMatcherEditor'
;
import
{
FieldMatcherUIRegistryItem
}
from
'./types'
;
import
{
fieldTypeMatcherItem
}
from
'./FieldTypeMatcherEditor'
;
export
const
fieldMatchersUI
=
new
Registry
<
FieldMatcherUIRegistryItem
<
any
>>
(()
=>
{
return
[
fieldNameMatcherItem
];
return
[
fieldNameMatcherItem
,
fieldTypeMatcherItem
];
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment