Alerting: Enable "no-unused-props" rule (#91492)

This commit is contained in:
Tom Ratcliffe 2024-08-05 09:18:38 +01:00 committed by GitHub
parent 647f162fe0
commit e771500487
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 17 additions and 37 deletions

View File

@ -1,5 +1,8 @@
{
"plugins": ["testing-library"],
"rules": {
"react/no-unused-prop-types": "error",
},
"overrides": [
{
"files": ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],

View File

@ -58,7 +58,6 @@ export function GrafanaRuleQueryViewer({ rule, queries, condition, evalDataByQue
rule={rule}
key={index}
refId={refId}
isAlertCondition={condition === refId}
model={model}
relativeTimeRange={relativeTimeRange}
dataSource={dataSource}
@ -72,8 +71,6 @@ export function GrafanaRuleQueryViewer({ rule, queries, condition, evalDataByQue
<div className={styles.maxWidthContainer}>
<Stack gap={1} wrap="wrap" data-testid="expressions-container">
{expressions.map(({ model, refId, datasourceUid }, index) => {
const dataSource = dsByUid[datasourceUid];
return (
isExpressionQuery(model) && (
<ExpressionPreview
@ -81,7 +78,6 @@ export function GrafanaRuleQueryViewer({ rule, queries, condition, evalDataByQue
refId={refId}
isAlertCondition={condition === refId}
model={model}
dataSource={dataSource}
evalData={evalDataByQuery[refId]}
/>
)
@ -95,7 +91,6 @@ export function GrafanaRuleQueryViewer({ rule, queries, condition, evalDataByQue
interface QueryPreviewProps extends Pick<AlertQuery, 'refId' | 'relativeTimeRange' | 'model'> {
rule: CombinedRule;
isAlertCondition: boolean;
dataSource?: DataSourceInstanceSettings;
queryData?: PanelData;
thresholds?: ThresholdDefinition;
@ -209,7 +204,6 @@ const getQueryPreviewStyles = (theme: GrafanaTheme2) => ({
interface ExpressionPreviewProps extends Pick<AlertQuery, 'refId'> {
isAlertCondition: boolean;
model: ExpressionQuery;
dataSource: DataSourceInstanceSettings;
evalData?: PanelData;
}

View File

@ -8,8 +8,8 @@ interface DotStylesProps {
includeState?: boolean;
}
const AlertStateDot = (props: DotStylesProps) => {
const styles = useStyles2(getDotStyles, props);
const AlertStateDot = ({ color, includeState }: DotStylesProps) => {
const styles = useStyles2(getDotStyles, { color, includeState });
return (
<Stack direction="row" gap={0.5}>

View File

@ -138,7 +138,6 @@ export const Expression: FC<ExpressionProps> = ({
queryType={queryType}
onRemoveExpression={() => onRemoveExpression(query.refId)}
onUpdateRefId={(newRefId) => onUpdateRefId(query.refId, newRefId)}
onUpdateExpressionType={(type) => onUpdateExpressionType(query.refId, type)}
onSetCondition={onSetCondition}
query={query}
alertCondition={alertCondition}
@ -286,7 +285,6 @@ interface HeaderProps {
queryType: ExpressionQueryType;
onUpdateRefId: (refId: string) => void;
onRemoveExpression: () => void;
onUpdateExpressionType: (type: ExpressionQueryType) => void;
onSetCondition: (refId: string) => void;
query: ExpressionQuery;
alertCondition: boolean;

View File

@ -165,14 +165,7 @@ export const QueryWrapper = ({
hideHideQueryButton={true}
/>
</div>
{showVizualisation && (
<VizWrapper
data={data}
thresholds={thresholds}
thresholdsType={thresholdsType}
onThresholdsChange={onChangeThreshold ? (thresholds) => onChangeThreshold(thresholds, index) : undefined}
/>
)}
{showVizualisation && <VizWrapper data={data} thresholds={thresholds} thresholdsType={thresholdsType} />}
</Stack>
);
};

View File

@ -15,7 +15,6 @@ interface Props {
data: PanelData;
thresholds?: ThresholdsConfig;
thresholdsType?: GraphThresholdsStyleMode;
onThresholdsChange?: (thresholds: ThresholdsConfig) => void;
}
/** The VizWrapper is just a simple component that renders either a table or a graph based on the type of data we receive from "PanelData" */

View File

@ -29,7 +29,6 @@ interface AlertRuleListItemProps {
isProvisioned?: boolean;
lastEvaluation?: string;
evaluationInterval?: string;
evaluationDuration?: number;
labels?: Labels;
instancesCount?: number;
// used for alert rules that use simplified routing
@ -79,9 +78,7 @@ export const AlertRuleListItem = (props: AlertRuleListItemProps) => {
<EvaluationMetadata
lastEvaluation={lastEvaluation}
evaluationInterval={evaluationInterval}
health={health}
state={state}
error={error}
/>
<MetaText icon="layers-alt">
<TextLink href={href + '?tab=instances'} variant="bodySmall" color="primary" inline={false}>
@ -170,13 +167,11 @@ interface RecordingRuleListItemProps {
href: string;
error?: string;
health?: RuleHealth;
recording?: boolean;
state?: PromAlertingRuleState;
labels?: Labels;
isProvisioned?: boolean;
lastEvaluation?: string;
evaluationInterval?: string;
evaluationDuration?: number;
}
// @TODO split in to smaller re-usable bits
@ -213,9 +208,7 @@ export const RecordingRuleListItem = ({
<EvaluationMetadata
lastEvaluation={lastEvaluation}
evaluationInterval={evaluationInterval}
health={health}
state={state}
error={error}
/>
{!isEmpty(labels) && (
<MetaText icon="tag-alt">
@ -258,8 +251,6 @@ interface EvaluationMetadataProps {
lastEvaluation?: string;
evaluationInterval?: string;
state?: PromAlertingRuleState;
health?: RuleHealth;
error?: string; // if health is "error" this should have error details for us
}
function EvaluationMetadata({ lastEvaluation, evaluationInterval, state }: EvaluationMetadataProps) {

View File

@ -42,7 +42,6 @@ export const EvaluationGroupWithRules = ({ group, rulesSource }: EvaluationGroup
name={rulerRule.alert}
labels={rulerRule.labels}
lastEvaluation={promRule?.lastEvaluation}
evaluationDuration={promRule?.evaluationTime}
evaluationInterval={group.interval}
instancesCount={isAlertingPromRule ? size(promRule.alerts) : undefined}
href={createViewLink(rulesSource, rule)}
@ -59,7 +58,6 @@ export const EvaluationGroupWithRules = ({ group, rulesSource }: EvaluationGroup
health={promRule?.health}
error={promRule?.lastError}
lastEvaluation={promRule?.lastEvaluation}
evaluationDuration={promRule?.evaluationTime}
evaluationInterval={group.interval}
labels={rulerRule.labels}
href={createViewLink(rulesSource, rule)}
@ -80,7 +78,6 @@ export const EvaluationGroupWithRules = ({ group, rulesSource }: EvaluationGroup
labels={rulerRule.labels}
isPaused={rulerRule.grafana_alert.is_paused}
lastEvaluation={promRule?.lastEvaluation}
evaluationDuration={promRule?.evaluationTime}
evaluationInterval={group.interval}
instancesCount={isAlertingPromRule ? size(promRule.alerts) : undefined}
href={createViewLink(rulesSource, rule)}

View File

@ -23,7 +23,6 @@ interface Props {
handleDuplicateRule: (identifier: RuleIdentifier) => void;
onPauseChange?: () => void;
buttonSize?: ComponentSize;
hideLabels?: boolean;
}
/**

View File

@ -74,7 +74,6 @@ const QueryResults = ({ rule }: Props) => {
dataSource={Object.values(config.datasources).find((ds) => ds.uid === query.datasourceUid)}
queryData={data[query.refId]}
relativeTimeRange={query.relativeTimeRange}
isAlertCondition={false}
/>
);
})}

View File

@ -11,7 +11,6 @@ import { RuleListStateSection } from './RuleListStateSection';
interface Props {
namespaces: CombinedRuleNamespace[];
expandAll?: boolean;
}
type GroupedRules = Record<PromAlertingRuleState, CombinedRule[]>;

View File

@ -11,12 +11,15 @@ import { AlertStateTag } from '../AlertStateTag';
import { LogRecord, omitLabels } from './common';
interface LogRecordViewerProps {
type LogRecordViewerProps = {
records: LogRecord[];
commonLabels: Array<[string, string]>;
};
type AdditionalLogRecordViewerProps = {
onRecordsRendered?: (timestampRefs: Map<number, HTMLElement>) => void;
onLabelClick?: (label: string) => void;
}
};
function groupRecordsByTimestamp(records: LogRecord[]) {
// groupBy has been replaced by the reduce to avoid back and forth conversion of timestamp from number to string
@ -35,7 +38,12 @@ function groupRecordsByTimestamp(records: LogRecord[]) {
}
export const LogRecordViewerByTimestamp = memo(
({ records, commonLabels, onLabelClick, onRecordsRendered }: LogRecordViewerProps) => {
({
records,
commonLabels,
onLabelClick,
onRecordsRendered,
}: LogRecordViewerProps & AdditionalLogRecordViewerProps) => {
const styles = useStyles2(getStyles);
const groupedLines = groupRecordsByTimestamp(records);