Skip to content

Commit 979264a

Browse files
gurinder39Spikatrix
authored andcommitted
typing error fix and modifications (#101)
* typing error fix and modifications * react-use module installed * Fix type error and adhoc filter alignment * Fix one more type error --------- Co-authored-by: Spikatrix <[email protected]>
1 parent 10a214e commit 979264a

File tree

39 files changed

+530
-1233
lines changed

39 files changed

+530
-1233
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryResultMeta } from '../types/data';
1+
import { QueryResultMeta } from '../types';
22
import { Field, FieldType, DataFrame, TIME_SERIES_VALUE_FIELD_NAME } from '../types/dataFrame';
33

44
import { guessFieldTypeForField } from './processDataFrame';
@@ -16,18 +16,16 @@ export class ArrayDataFrame<T = any> implements DataFrame {
1616
meta?: QueryResultMeta;
1717

1818
constructor(source: T[], names?: string[]) {
19-
return arrayToDataFrame(source, names); // returns a standard DataFrame
19+
return arrayToDataFrame(source, names) as ArrayDataFrame<T>; // returns a standard DataFrame
2020
}
2121
}
2222

2323
/**
24-
* arrayToDataFrame will convert any array into a DataFrame.
25-
* @param source - can be an array of objects or an array of simple values.
26-
* @param names - will be used for ordering of fields. Source needs to be array of objects if names are provided.
24+
* arrayToDataFrame will convert any array into a DataFrame
2725
*
2826
* @public
2927
*/
30-
export function arrayToDataFrame(source: Array<Record<string, unknown>> | unknown[], names?: string[]): DataFrame {
28+
export function arrayToDataFrame(source: any[], names?: string[]): DataFrame {
3129
const df: DataFrame = {
3230
fields: [],
3331
length: source.length,
@@ -36,46 +34,30 @@ export function arrayToDataFrame(source: Array<Record<string, unknown>> | unknow
3634
return df;
3735
}
3836

39-
// If names are provided then we assume the source is an array of objects with the names as keys (field names). This
40-
// makes ordering of the fields predictable.
4137
if (names) {
42-
if (!isObjectArray(source)) {
43-
throw new Error('source is not an array of objects');
44-
}
45-
4638
for (const name of names) {
4739
df.fields.push(
4840
makeFieldFromValues(
4941
name,
50-
source.map((v) => (v ? v[name] : v))
42+
source.map((v) => v[name])
5143
)
5244
);
5345
}
5446
return df;
5547
}
5648

57-
const firstDefined = source.find((v) => v); // first not null|undefined
58-
// This means if the source is lots of null/undefined values we throw that away and return empty dataFrame. This is
59-
// different to how we preserve null/undefined values if there is some defined rows. Not sure this inconsistency
60-
// is by design or not.
61-
if (firstDefined === null) {
62-
return df;
63-
}
64-
65-
// If is an array of objects we use the keys as field names.
66-
if (isObjectArray(source)) {
67-
// We need to do this to please TS. We know source is array of objects and that there is some object in there but
68-
// TS still thinks it can all be undefined|nulls.
69-
const first = source.find((v) => v);
70-
df.fields = Object.keys(first || {}).map((name) => {
71-
return makeFieldFromValues(
72-
name,
73-
source.map((v) => (v ? v[name] : v))
74-
);
75-
});
76-
} else {
77-
// Otherwise source should be an array of simple values, so we create single field data frame.
78-
df.fields.push(makeFieldFromValues(TIME_SERIES_VALUE_FIELD_NAME, source));
49+
const first = source.find((v) => v != null); // first not null|undefined
50+
if (first != null) {
51+
if (typeof first === 'object') {
52+
df.fields = Object.keys(first).map((name) => {
53+
return makeFieldFromValues(
54+
name,
55+
source.map((v) => v[name])
56+
);
57+
});
58+
} else {
59+
df.fields.push(makeFieldFromValues(TIME_SERIES_VALUE_FIELD_NAME, source));
60+
}
7961
}
8062
return df;
8163
}
@@ -85,8 +67,3 @@ function makeFieldFromValues(name: string, values: unknown[]): Field {
8567
f.type = guessFieldTypeForField(f) ?? FieldType.other;
8668
return f;
8769
}
88-
89-
function isObjectArray(arr: unknown[]): arr is Array<Record<string, unknown> | null | undefined> {
90-
const first = arr.find((v) => v); // first not null|undefined
91-
return arr.length > 0 && typeof first === 'object';
92-
}

packages/grafana-data/src/themes/fnCreateColors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class FnDarkColors implements ThemeColorsBase<Partial<ThemeRichColor>> {
7575
disabledText: this.text.disabled,
7676
disabledBackground: `rgba(${this.whiteBase}, 0.04)`,
7777
disabledOpacity: 0.38,
78+
selectedBorder: palette.orangeDarkMain,
7879
};
7980

8081
gradients = {
@@ -155,6 +156,7 @@ class FnLightColors implements ThemeColorsBase<Partial<ThemeRichColor>> {
155156
disabledBackground: `rgba(${this.blackBase}, 0.04)`,
156157
disabledText: this.text.disabled,
157158
disabledOpacity: 0.38,
159+
selectedBorder: palette.orangeLightMain,
158160
};
159161

160162
gradients = {

packages/grafana-data/src/types/featureToggles.gen.ts

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export interface FeatureToggles {
4747
mysqlAnsiQuotes?: boolean;
4848
accessControlOnCall?: boolean;
4949
nestedFolders?: boolean;
50+
nestedFolderPicker?: boolean;
51+
accessTokenExpirationCheck?: boolean;
52+
emptyDashboardPage?: boolean;
53+
disablePrometheusExemplarSampling?: boolean;
54+
datasourceOnboarding?: boolean;
5055
alertingBacktesting?: boolean;
5156
editPanelCSVDragAndDrop?: boolean;
5257
alertingNoNormalState?: boolean;
@@ -60,6 +65,7 @@ export interface FeatureToggles {
6065
influxdbRunQueriesInParallel?: boolean;
6166
prometheusRunQueriesInParallel?: boolean;
6267
lokiMetricDataplane?: boolean;
68+
newTraceView?: boolean;
6369
lokiLogsDataplane?: boolean;
6470
dataplaneFrontendFallback?: boolean;
6571
disableSSEDataplane?: boolean;

packages/grafana-o11y-ds-frontend/src/TraceToMetrics/TraceToMetricsSettings.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function TraceToMetricsSettings({ options, onOptionsChange }: Props) {
8080
<InlineFieldRow>
8181
<IntervalInput
8282
label={getTimeShiftLabel('start')}
83-
tooltip={getTimeShiftTooltip('start', '-2m')}
83+
tooltip={getTimeShiftTooltip('start', '')}
8484
value={options.jsonData.tracesToMetrics?.spanStartTimeShift || ''}
8585
onChange={(val) => {
8686
updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'tracesToMetrics', {
@@ -96,7 +96,7 @@ export function TraceToMetricsSettings({ options, onOptionsChange }: Props) {
9696
<InlineFieldRow>
9797
<IntervalInput
9898
label={getTimeShiftLabel('end')}
99-
tooltip={getTimeShiftTooltip('end', '2m')}
99+
tooltip={getTimeShiftTooltip('end', '')}
100100
value={options.jsonData.tracesToMetrics?.spanEndTimeShift || ''}
101101
onChange={(val) => {
102102
updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'tracesToMetrics', {

packages/grafana-ui/src/components/Dropdown/Dropdown.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export const Dropdown = React.memo(({ children, overlay, placement, offset, onVi
8585

8686
return (
8787
<>
88-
{React.cloneElement(children, {
89-
ref: refs.setReference,
90-
...getReferenceProps(),
88+
{/* @ts-ignore */}
89+
{React.cloneElement(typeof children === 'function' ? children(visible) : children, {
90+
ref: setTriggerRef,
9191
})}
9292
{show && (
9393
<Portal>
@@ -105,7 +105,8 @@ export const Dropdown = React.memo(({ children, overlay, placement, offset, onVi
105105
timeout={{ appear: animationDuration, exit: 0, enter: 0 }}
106106
classNames={animationStyles}
107107
>
108-
<div ref={transitionRef}>{ReactUtils.renderOrCallToRender(overlay, { ...getFloatingProps() })}</div>
108+
{/* @ts-ignore */}
109+
<div ref={transitionRef}>{ReactUtils.renderOrCallToRender(overlay, {})}</div>
109110
</CSSTransition>
110111
</div>
111112
</FloatingFocusManager>

packages/grafana-ui/src/components/Icon/Icon.tsx

+23-19
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ const getIconStyles = (theme: GrafanaTheme2) => {
4242
};
4343
};
4444

45-
export const Icon = React.forwardRef<SVGElement, IconProps>(
46-
({ size = 'md', type = 'default', name, className, style, title = '', ...rest }, ref) => {
45+
export const Icon = React.forwardRef<HTMLDivElement, IconProps>(
46+
({ size = 'md', type = 'default', name, className, style, title = '', ...divElementProps }, ref): JSX.Element => {
4747
const styles = useStyles2(getIconStyles);
4848

49+
/* Temporary solution to display also font awesome icons */
50+
if (name?.startsWith('fa fa-')) {
51+
/* @ts-ignore */
52+
return <i className={getFontAwesomeIconStyles(name, className)} {...divElementProps} style={style} />;
53+
}
54+
55+
if (!cacheInitialized) {
56+
initIconCache();
57+
}
58+
4959
if (!isIconName(name)) {
5060
console.warn('Icon component passed an invalid icon name', name);
5161
}
@@ -70,23 +80,17 @@ export const Icon = React.forwardRef<SVGElement, IconProps>(
7080
);
7181

7282
return (
73-
<SVG
74-
aria-hidden={
75-
rest.tabIndex === undefined &&
76-
!title &&
77-
!rest['aria-label'] &&
78-
!rest['aria-labelledby'] &&
79-
!rest['aria-describedby']
80-
}
81-
innerRef={ref}
82-
src={svgPath}
83-
width={svgWid}
84-
height={svgHgt}
85-
title={title}
86-
className={composedClassName}
87-
style={style}
88-
{...rest}
89-
/>
83+
<div className={styles.container} {...divElementProps} ref={ref}>
84+
{/* @ts-ignore */}
85+
<SVG
86+
src={svgPath}
87+
width={svgWid}
88+
height={svgHgt}
89+
title={title}
90+
className={cx(styles.icon, className, type === 'mono' ? { [styles.orange]: name === 'favorite' } : '')}
91+
style={style}
92+
/>
93+
</div>
9094
);
9195
}
9296
);

0 commit comments

Comments
 (0)