mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: replace calls to defaultProps
(#87310)
* replace calls to defaultProps * make linksGetter optional
This commit is contained in:
parent
0c702d335e
commit
37ef6df3b2
@ -17,11 +17,6 @@ export interface Props extends InputHTMLAttributes<HTMLInputElement> {
|
|||||||
interactive?: boolean;
|
interactive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps = {
|
|
||||||
labelWidth: 6,
|
|
||||||
inputWidth: 12,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default form field including label used in Grafana UI. Default input element is simple <input />. You can also pass
|
* Default form field including label used in Grafana UI. Default input element is simple <input />. You can also pass
|
||||||
* custom inputEl if required in which case inputWidth and inputProps are ignored.
|
* custom inputEl if required in which case inputWidth and inputProps are ignored.
|
||||||
@ -31,8 +26,8 @@ const defaultProps = {
|
|||||||
export const FormField = ({
|
export const FormField = ({
|
||||||
label,
|
label,
|
||||||
tooltip,
|
tooltip,
|
||||||
labelWidth,
|
labelWidth = 6,
|
||||||
inputWidth,
|
inputWidth = 12,
|
||||||
inputEl,
|
inputEl,
|
||||||
className,
|
className,
|
||||||
interactive,
|
interactive,
|
||||||
@ -57,7 +52,6 @@ export const FormField = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
FormField.displayName = 'FormField';
|
FormField.displayName = 'FormField';
|
||||||
FormField.defaultProps = defaultProps;
|
|
||||||
|
|
||||||
const getStyles = () => {
|
const getStyles = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -122,10 +122,6 @@ export const LayerDragDropList = <T extends LayerElement>({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
LayerDragDropList.defaultProps = {
|
|
||||||
isGroup: () => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => ({
|
const getStyles = (theme: GrafanaTheme2) => ({
|
||||||
wrapper: css({
|
wrapper: css({
|
||||||
marginBottom: theme.spacing(2),
|
marginBottom: theme.spacing(2),
|
||||||
|
@ -28,7 +28,7 @@ export default class PageActionBar extends PureComponent<Props> {
|
|||||||
placeholder = 'Search by name or type',
|
placeholder = 'Search by name or type',
|
||||||
sortPicker,
|
sortPicker,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const linkProps: typeof LinkButton.defaultProps = { href: linkButton?.href, disabled: linkButton?.disabled };
|
const linkProps: Parameters<typeof LinkButton>[0] = { href: linkButton?.href, disabled: linkButton?.disabled };
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
linkProps.target = target;
|
linkProps.target = target;
|
||||||
|
@ -94,13 +94,16 @@ export type AccordianKeyValuesProps = {
|
|||||||
interactive?: boolean;
|
interactive?: boolean;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
label: string;
|
label: string;
|
||||||
linksGetter: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
linksGetter?: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
||||||
onToggle?: null | (() => void);
|
onToggle?: null | (() => void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface KeyValuesSummaryProps {
|
||||||
|
data?: TraceKeyValuePair[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
// export for tests
|
// export for tests
|
||||||
export function KeyValuesSummary(props: { data?: TraceKeyValuePair[] }) {
|
export function KeyValuesSummary({ data = null }: KeyValuesSummaryProps) {
|
||||||
const { data } = props;
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
if (!Array.isArray(data) || !data.length) {
|
if (!Array.isArray(data) || !data.length) {
|
||||||
@ -121,12 +124,16 @@ export function KeyValuesSummary(props: { data?: TraceKeyValuePair[] }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyValuesSummary.defaultProps = {
|
export default function AccordianKeyValues({
|
||||||
data: null,
|
className = null,
|
||||||
};
|
data,
|
||||||
|
highContrast = false,
|
||||||
export default function AccordianKeyValues(props: AccordianKeyValuesProps) {
|
interactive = true,
|
||||||
const { className, data, highContrast, interactive, isOpen, label, linksGetter, onToggle } = props;
|
isOpen,
|
||||||
|
label,
|
||||||
|
linksGetter,
|
||||||
|
onToggle = null,
|
||||||
|
}: AccordianKeyValuesProps) {
|
||||||
const isEmpty = !Array.isArray(data) || !data.length;
|
const isEmpty = !Array.isArray(data) || !data.length;
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const iconCls = cx(alignIcon, { [styles.emptyIcon]: isEmpty });
|
const iconCls = cx(alignIcon, { [styles.emptyIcon]: isEmpty });
|
||||||
@ -166,10 +173,3 @@ export default function AccordianKeyValues(props: AccordianKeyValuesProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccordianKeyValues.defaultProps = {
|
|
||||||
className: null,
|
|
||||||
highContrast: false,
|
|
||||||
interactive: true,
|
|
||||||
onToggle: null,
|
|
||||||
};
|
|
||||||
|
@ -65,7 +65,7 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
export type AccordianLogsProps = {
|
export type AccordianLogsProps = {
|
||||||
interactive?: boolean;
|
interactive?: boolean;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
linksGetter: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
linksGetter?: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
||||||
logs: TraceLog[];
|
logs: TraceLog[];
|
||||||
onItemToggle?: (log: TraceLog) => void;
|
onItemToggle?: (log: TraceLog) => void;
|
||||||
onToggle?: () => void;
|
onToggle?: () => void;
|
||||||
@ -73,8 +73,16 @@ export type AccordianLogsProps = {
|
|||||||
timestamp: number;
|
timestamp: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function AccordianLogs(props: AccordianLogsProps) {
|
export default function AccordianLogs({
|
||||||
const { interactive, isOpen, linksGetter, logs, openedItems, onItemToggle, onToggle, timestamp } = props;
|
interactive = true,
|
||||||
|
isOpen,
|
||||||
|
linksGetter,
|
||||||
|
logs,
|
||||||
|
openedItems,
|
||||||
|
onItemToggle,
|
||||||
|
onToggle,
|
||||||
|
timestamp,
|
||||||
|
}: AccordianLogsProps) {
|
||||||
let arrow: React.ReactNode | null = null;
|
let arrow: React.ReactNode | null = null;
|
||||||
let HeaderComponent: 'span' | 'a' = 'span';
|
let HeaderComponent: 'span' | 'a' = 'span';
|
||||||
let headerProps: {} | null = null;
|
let headerProps: {} | null = null;
|
||||||
@ -122,11 +130,3 @@ export default function AccordianLogs(props: AccordianLogsProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccordianLogs.defaultProps = {
|
|
||||||
interactive: true,
|
|
||||||
linksGetter: undefined,
|
|
||||||
onItemToggle: undefined,
|
|
||||||
onToggle: undefined,
|
|
||||||
openedItems: undefined,
|
|
||||||
};
|
|
||||||
|
@ -58,17 +58,17 @@ function DefaultTextComponent({ data }: { data: string[] }) {
|
|||||||
return <TextList data={data} />;
|
return <TextList data={data} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AccordianText(props: AccordianTextProps) {
|
export default function AccordianText({
|
||||||
const {
|
className = null,
|
||||||
className,
|
|
||||||
data,
|
data,
|
||||||
headerClassName,
|
headerClassName,
|
||||||
interactive,
|
highContrast = false,
|
||||||
|
interactive = true,
|
||||||
isOpen,
|
isOpen,
|
||||||
label,
|
label,
|
||||||
onToggle,
|
onToggle = null,
|
||||||
TextComponent = DefaultTextComponent,
|
TextComponent = DefaultTextComponent,
|
||||||
} = props;
|
}: AccordianTextProps) {
|
||||||
const isEmpty = !Array.isArray(data) || !data.length;
|
const isEmpty = !Array.isArray(data) || !data.length;
|
||||||
const accordianKeyValuesStyles = useStyles2(getAccordianKeyValuesStyles);
|
const accordianKeyValuesStyles = useStyles2(getAccordianKeyValuesStyles);
|
||||||
const iconCls = cx(alignIcon, { [accordianKeyValuesStyles.emptyIcon]: isEmpty });
|
const iconCls = cx(alignIcon, { [accordianKeyValuesStyles.emptyIcon]: isEmpty });
|
||||||
@ -97,10 +97,3 @@ export default function AccordianText(props: AccordianTextProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccordianText.defaultProps = {
|
|
||||||
className: null,
|
|
||||||
highContrast: false,
|
|
||||||
interactive: true,
|
|
||||||
onToggle: null,
|
|
||||||
};
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import * as React from 'react';
|
import React, { PropsWithChildren } from 'react';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { Icon, useStyles2 } from '@grafana/ui';
|
import { Icon, useStyles2 } from '@grafana/ui';
|
||||||
@ -92,21 +92,23 @@ function parseIfComplexJson(value: unknown) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LinkValue = (props: { href: string; title?: string; children: React.ReactNode }) => {
|
interface LinkValueProps {
|
||||||
|
href: string;
|
||||||
|
title?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LinkValue = ({ href, title = '', children }: PropsWithChildren<LinkValueProps>) => {
|
||||||
return (
|
return (
|
||||||
<a href={props.href} title={props.title} target="_blank" rel="noopener noreferrer">
|
<a href={href} title={title} target="_blank" rel="noopener noreferrer">
|
||||||
{props.children} <Icon name="external-link-alt" />
|
{children} <Icon name="external-link-alt" />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
LinkValue.defaultProps = {
|
|
||||||
title: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
export type KeyValuesTableProps = {
|
export type KeyValuesTableProps = {
|
||||||
data: TraceKeyValuePair[];
|
data: TraceKeyValuePair[];
|
||||||
linksGetter: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
linksGetter?: ((pairs: TraceKeyValuePair[], index: number) => TraceLink[]) | TNil;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function KeyValuesTable(props: KeyValuesTableProps) {
|
export default function KeyValuesTable(props: KeyValuesTableProps) {
|
||||||
|
@ -60,9 +60,7 @@ type TicksProps = {
|
|||||||
startTime?: number | TNil;
|
startTime?: number | TNil;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Ticks(props: TicksProps) {
|
export default function Ticks({ endTime = null, numTicks, showLabels = null, startTime = null }: TicksProps) {
|
||||||
const { endTime, numTicks, showLabels, startTime } = props;
|
|
||||||
|
|
||||||
let labels: undefined | string[];
|
let labels: undefined | string[];
|
||||||
if (showLabels) {
|
if (showLabels) {
|
||||||
labels = [];
|
labels = [];
|
||||||
@ -95,9 +93,3 @@ export default function Ticks(props: TicksProps) {
|
|||||||
}
|
}
|
||||||
return <div className={styles.Ticks}>{ticks}</div>;
|
return <div className={styles.Ticks}>{ticks}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ticks.defaultProps = {
|
|
||||||
endTime: null,
|
|
||||||
showLabels: null,
|
|
||||||
startTime: null,
|
|
||||||
};
|
|
||||||
|
@ -43,8 +43,7 @@ interface TimelineRowCellProps extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
style?: {};
|
style?: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TimelineRow(props: TTimelineRowProps) {
|
export default function TimelineRow({ children, className = '', ...rest }: TTimelineRowProps) {
|
||||||
const { children, className = '', ...rest } = props;
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
return (
|
return (
|
||||||
<div className={cx(styles.row, className)} {...rest}>
|
<div className={cx(styles.row, className)} {...rest}>
|
||||||
@ -53,12 +52,7 @@ export default function TimelineRow(props: TTimelineRowProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineRow.defaultProps = {
|
export function TimelineRowCell({ children, className = '', width, style = {}, ...rest }: TimelineRowCellProps) {
|
||||||
className: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function TimelineRowCell(props: TimelineRowCellProps) {
|
|
||||||
const { children, className = '', width, style, ...rest } = props;
|
|
||||||
const widthPercent = `${width * 100}%`;
|
const widthPercent = `${width * 100}%`;
|
||||||
const mergedStyle = { ...style, flexBasis: widthPercent, maxWidth: widthPercent };
|
const mergedStyle = { ...style, flexBasis: widthPercent, maxWidth: widthPercent };
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
@ -69,6 +63,4 @@ export function TimelineRowCell(props: TimelineRowCellProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineRowCell.defaultProps = { className: '', style: {} };
|
|
||||||
|
|
||||||
TimelineRow.Cell = TimelineRowCell;
|
TimelineRow.Cell = TimelineRowCell;
|
||||||
|
@ -35,8 +35,7 @@ type Props = {
|
|||||||
wordRegexp?: RegExp;
|
wordRegexp?: RegExp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function BreakableText(props: Props): React.ReactElement | null {
|
export default function BreakableText({ text, className, wordRegexp = WORD_RX }: Props): React.ReactElement | null {
|
||||||
const { className, text, wordRegexp = WORD_RX } = props;
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return null;
|
return null;
|
||||||
@ -55,7 +54,3 @@ export default function BreakableText(props: Props): React.ReactElement | null {
|
|||||||
}
|
}
|
||||||
return <>{spans}</>;
|
return <>{spans}</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
BreakableText.defaultProps = {
|
|
||||||
wordRegexp: WORD_RX,
|
|
||||||
};
|
|
||||||
|
@ -41,24 +41,19 @@ type PropsType = {
|
|||||||
tooltipTitle: string;
|
tooltipTitle: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function CopyIcon(props: PropsType) {
|
export default function CopyIcon({ copyText, icon = 'copy', tooltipTitle }: PropsType) {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
const [hasCopied, setHasCopied] = useState(false);
|
const [hasCopied, setHasCopied] = useState(false);
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
navigator.clipboard.writeText(props.copyText);
|
navigator.clipboard.writeText(copyText);
|
||||||
setHasCopied(true);
|
setHasCopied(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip content={hasCopied ? 'Copied' : props.tooltipTitle}>
|
<Tooltip content={hasCopied ? 'Copied' : tooltipTitle}>
|
||||||
<Button className={cx(styles.CopyIcon)} type="button" icon={props.icon} onClick={handleClick} />
|
<Button className={cx(styles.CopyIcon)} type="button" icon={icon} onClick={handleClick} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyIcon.defaultProps = {
|
|
||||||
icon: 'copy',
|
|
||||||
className: undefined,
|
|
||||||
};
|
|
||||||
|
@ -32,13 +32,8 @@ type Props = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NewWindowIcon(props: Props) {
|
export default function NewWindowIcon({ isLarge = false, className }: Props) {
|
||||||
const { isLarge, className, ...rest } = props;
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const cls = cx({ [styles.NewWindowIconLarge]: isLarge }, className);
|
const cls = cx({ [styles.NewWindowIconLarge]: isLarge }, className);
|
||||||
return <Icon className={cls} name={'anchor'} {...rest} />;
|
return <Icon className={cls} name={'anchor'} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewWindowIcon.defaultProps = {
|
|
||||||
isLarge: false,
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user