Skip to content

Commit

Permalink
Remove redundant params
Browse files Browse the repository at this point in the history
  • Loading branch information
madirey committed Jul 15, 2021
1 parent 3daa823 commit 87aff9c
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export function WorkspacePanelWrapper({
},
[dispatchLens, activeVisualization]
);
const warningMessages: React.ReactNode[] = [];
const warnings: React.ReactNode[] = [];
if (activeVisualization?.getWarningMessages) {
warningMessages.push(
warnings.push(
...(activeVisualization.getWarningMessages(visualizationState, framePublicAPI) || [])
);
}
Object.entries(datasourceStates).forEach(([datasourceId, datasourceState]) => {
const datasource = datasourceMap[datasourceId];
if (!datasourceState.isLoading && datasource.getWarningMessages) {
warningMessages.push(
warnings.push(
...(datasource.getWarningMessages(datasourceState.state, framePublicAPI) || [])
);
}
Expand Down Expand Up @@ -120,9 +120,7 @@ export function WorkspacePanelWrapper({
</EuiFlexItem>
) : null}
<EuiFlexItem grow={false}>
{warningMessages && warningMessages.length ? (
<WarningsPopover>{warningMessages}</WarningsPopover>
) : null}
{warnings && warnings.length ? <WarningsPopover>{warnings}</WarningsPopover> : null}
</EuiFlexItem>
</EuiFlexGroup>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function getStateTimeShiftWarningMessages(
{ activeData }: FramePublicAPI
) {
if (!state) return;
const warningMessages: React.ReactNode[] = [];
const warnings: React.ReactNode[] = [];
Object.entries(state.layers).forEach(([layerId, layer]) => {
const dateHistogramInterval = getDateHistogramInterval(
layer,
Expand Down Expand Up @@ -189,7 +189,7 @@ export function getStateTimeShiftWarningMessages(
if (timeShift === 0) return;
if (timeShift < shiftInterval) {
timeShiftMap[timeShift].forEach((columnId) => {
warningMessages.push(
warnings.push(
<FormattedMessage
key={`small-${columnId}`}
id="xpack.lens.indexPattern.timeShiftSmallWarning"
Expand All @@ -204,7 +204,7 @@ export function getStateTimeShiftWarningMessages(
});
} else if (!Number.isInteger(timeShift / shiftInterval)) {
timeShiftMap[timeShift].forEach((columnId) => {
warningMessages.push(
warnings.push(
<FormattedMessage
key={`multiple-${columnId}`}
id="xpack.lens.indexPattern.timeShiftMultipleWarning"
Expand All @@ -220,7 +220,7 @@ export function getStateTimeShiftWarningMessages(
}
});
});
return warningMessages;
return warnings;
}

export function getColumnTimeShiftWarnings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ describe('xy_visualization', () => {
(frame.datasourceLayers.first.getOperationForColumnId as jest.Mock).mockReturnValue({
label: 'Label B',
});
const warningMessages = xyVisualization.getWarningMessages!(
const warnings = xyVisualization.getWarningMessages!(
{
...exampleState(),
layers: [
Expand All @@ -977,8 +977,8 @@ describe('xy_visualization', () => {
},
frame
);
expect(warningMessages).toHaveLength(1);
expect(warningMessages && warningMessages[0]).toMatchInlineSnapshot(`
expect(warnings).toHaveLength(1);
expect(warnings && warnings[0]).toMatchInlineSnapshot(`
<FormattedMessage
defaultMessage="{label} contains array values. Your visualization may not render as expected."
id="xpack.lens.xyVisualization.arrayValues"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('eql_executor', () => {
wrapHits: jest.fn(),
wrapSequences: jest.fn(),
});
expect(response.warningMessages.length).toEqual(1);
expect(response.warnings.length).toEqual(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ export const eqlExecutor = async ({
const result = createSearchAfterReturnType();
const ruleParams = rule.attributes.params;
if (hasLargeValueItem(exceptionItems)) {
result.warningMessages.push(
result.warnings.push(
'Exceptions that use "is in list" or "is not in list" operators are not applied to EQL rules'
);
result.warning = true;
}
try {
const signalIndexVersion = await getIndexVersion(
Expand Down Expand Up @@ -123,7 +122,6 @@ export const eqlExecutor = async ({
if (newSignals?.length) {
const insertResult = await bulkCreate(newSignals);
result.bulkCreateTimes.push(insertResult.bulkCreateDuration);
result.createdSignalsCount += insertResult.createdItemsCount;
result.createdSignals = insertResult.createdItems;
}
result.success = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('ml_executor', () => {
});
expect(logger.warn).toHaveBeenCalled();
expect(logger.warn.mock.calls[0][0]).toContain('Machine learning job(s) are not started');
expect(response.warningMessages.length).toEqual(1);
expect(response.warnings.length).toEqual(1);
});

it('should record a partial failure if Machine learning job was not started', async () => {
Expand All @@ -122,6 +122,6 @@ describe('ml_executor', () => {
});
expect(logger.warn).toHaveBeenCalled();
expect(logger.warn.mock.calls[0][0]).toContain('Machine learning job(s) are not started');
expect(response.warningMessages.length).toEqual(1);
expect(response.warnings.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ export const mlExecutor = async ({
].join(', ')
)
);
result.warningMessages.push(warningMessage);
result.warnings.push(warningMessage);
logger.warn(warningMessage);
result.warning = true;
}

const anomalyResults = await findMlSignals({
Expand Down Expand Up @@ -107,13 +106,7 @@ export const mlExecutor = async ({
if (anomalyCount) {
logger.info(buildRuleMessage(`Found ${anomalyCount} signals from ML anomalies.`));
}
const {
success,
errors,
bulkCreateDuration,
createdItemsCount,
createdItems,
} = await bulkCreateMlSignals({
const { success, errors, bulkCreateDuration, createdItems } = await bulkCreateMlSignals({
someResult: filteredAnomalyResults,
ruleSO: rule,
services,
Expand All @@ -137,7 +130,6 @@ export const mlExecutor = async ({
createSearchAfterReturnType({
success: success && filteredAnomalyResults._shards.failed === 0,
errors: [...errors, ...searchErrors],
createdSignalsCount: createdItemsCount,
createdSignals: createdItems,
bulkCreateTimes: bulkCreateDuration ? [bulkCreateDuration] : [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('threshold_executor', () => {
})),
wrapHits: jest.fn(),
});
expect(response.warningMessages.length).toEqual(1);
expect(response.warnings.length).toEqual(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ export const thresholdExecutor = async ({
let result = createSearchAfterReturnType();
const ruleParams = rule.attributes.params;
if (hasLargeValueItem(exceptionItems)) {
result.warningMessages.push(
result.warnings.push(
'Exceptions that use "is in list" or "is not in list" operators are not applied to Threshold rules'
);
result.warning = true;
}
const inputIndex = await getInputIndex(services, version, ruleParams.index);

Expand Down Expand Up @@ -117,13 +116,7 @@ export const thresholdExecutor = async ({
buildRuleMessage,
});

const {
success,
bulkCreateDuration,
createdItemsCount,
createdItems,
errors,
} = await bulkCreateThresholdSignals({
const { success, bulkCreateDuration, createdItems, errors } = await bulkCreateThresholdSignals({
someResult: thresholdResults,
ruleSO: rule,
filter: esFilter,
Expand All @@ -147,7 +140,6 @@ export const thresholdExecutor = async ({
createSearchAfterReturnType({
success,
errors: [...errors, ...previousSearchErrors, ...searchErrors],
createdSignalsCount: createdItemsCount,
createdSignals: createdItems,
bulkCreateTimes: bulkCreateDuration ? [bulkCreateDuration] : [],
searchAfterTimes: [thresholdSearchDuration],
Expand Down
Loading

0 comments on commit 87aff9c

Please sign in to comment.