@spinnaker/kayenta 0.0.0-2025.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintrc.js +1 -0
- package/.huskyrc +5 -0
- package/.lintstagedrc.json +4 -0
- package/.prettierignore +4 -0
- package/.prettierrc.js +1 -0
- package/LICENSE.txt +203 -0
- package/README.md +81 -0
- package/__mocks__/styleMock.js +1 -0
- package/__mocks__/version.json +4 -0
- package/babel.config.js +3 -0
- package/build.gradle +67 -0
- package/build_scripts/checkLicenses.js +79 -0
- package/gradle.properties +0 -0
- package/jest.config.js +204 -0
- package/jest.setup.js +5 -0
- package/package.json +166 -0
- package/rollup-plugin-angularjs-template-loader.js +82 -0
- package/rollup.config.js +30 -0
- package/src/index.ts +2 -0
- package/src/kayenta/actions/creators.ts +163 -0
- package/src/kayenta/actions/index.ts +98 -0
- package/src/kayenta/canary.dataSource.bridge.ts +53 -0
- package/src/kayenta/canary.dataSource.stub.ts +64 -0
- package/src/kayenta/canary.help.ts +136 -0
- package/src/kayenta/canary.less +168 -0
- package/src/kayenta/canary.settings.ts +26 -0
- package/src/kayenta/canary.tsx +67 -0
- package/src/kayenta/components/canaryScore.component.less +77 -0
- package/src/kayenta/components/canaryScore.component.ts +12 -0
- package/src/kayenta/components/canaryScore.tsx +63 -0
- package/src/kayenta/components/canaryScores.component.ts +20 -0
- package/src/kayenta/components/canaryScores.less +22 -0
- package/src/kayenta/components/canaryScores.tsx +163 -0
- package/src/kayenta/components/loadStates.tsx +52 -0
- package/src/kayenta/domain/ICanaryConfig.ts +57 -0
- package/src/kayenta/domain/ICanaryConfigSummary.ts +7 -0
- package/src/kayenta/domain/ICanaryConfigUpdateResponse.ts +3 -0
- package/src/kayenta/domain/ICanaryExecutionStatusResult.ts +72 -0
- package/src/kayenta/domain/ICanaryJudgeResult.ts +51 -0
- package/src/kayenta/domain/ICanaryJudgeResultSummary.ts +5 -0
- package/src/kayenta/domain/ICanaryScoreThresholds.ts +4 -0
- package/src/kayenta/domain/IJudge.ts +5 -0
- package/src/kayenta/domain/IKayentaAccount.ts +14 -0
- package/src/kayenta/domain/IKayentaStageConfig.ts +58 -0
- package/src/kayenta/domain/IMetricSetPair.ts +17 -0
- package/src/kayenta/domain/IMetricsServiceMetadata.ts +2 -0
- package/src/kayenta/domain/ISetupCanaryStage.ts +11 -0
- package/src/kayenta/domain/MetricClassificationLabel.ts +8 -0
- package/src/kayenta/domain/ScoreClassificationLabel.ts +7 -0
- package/src/kayenta/domain/index.ts +15 -0
- package/src/kayenta/edit/changeMetricGroupModal.tsx +107 -0
- package/src/kayenta/edit/configDetail.tsx +31 -0
- package/src/kayenta/edit/configDetailActionButtons.tsx +24 -0
- package/src/kayenta/edit/configDetailHeader.tsx +104 -0
- package/src/kayenta/edit/configDetailLoadStates.tsx +36 -0
- package/src/kayenta/edit/configDetailLoader.tsx +60 -0
- package/src/kayenta/edit/configJson.less +42 -0
- package/src/kayenta/edit/configJsonModal.tsx +158 -0
- package/src/kayenta/edit/configList.less +7 -0
- package/src/kayenta/edit/configList.tsx +57 -0
- package/src/kayenta/edit/copyConfigButton.tsx +34 -0
- package/src/kayenta/edit/createConfigButton.tsx +34 -0
- package/src/kayenta/edit/deleteModal.tsx +87 -0
- package/src/kayenta/edit/edit.tsx +24 -0
- package/src/kayenta/edit/editMetricEffectSizes.tsx +186 -0
- package/src/kayenta/edit/editMetricModal.less +9 -0
- package/src/kayenta/edit/editMetricModal.spec.tsx +129 -0
- package/src/kayenta/edit/editMetricModal.tsx +294 -0
- package/src/kayenta/edit/editMetricValidation.spec.ts +63 -0
- package/src/kayenta/edit/editMetricValidation.ts +50 -0
- package/src/kayenta/edit/filterTemplateSelector.less +15 -0
- package/src/kayenta/edit/filterTemplateSelector.spec.tsx +106 -0
- package/src/kayenta/edit/filterTemplateSelector.tsx +194 -0
- package/src/kayenta/edit/filterTemplatesValidation.spec.ts +108 -0
- package/src/kayenta/edit/filterTemplatesValidation.ts +95 -0
- package/src/kayenta/edit/footer.less +30 -0
- package/src/kayenta/edit/footer.tsx +12 -0
- package/src/kayenta/edit/groupName.tsx +80 -0
- package/src/kayenta/edit/groupTabs.tsx +106 -0
- package/src/kayenta/edit/groupWeight.tsx +80 -0
- package/src/kayenta/edit/groupWeights.tsx +38 -0
- package/src/kayenta/edit/inlineTemplateEditor.spec.tsx +42 -0
- package/src/kayenta/edit/inlineTemplateEditor.tsx +61 -0
- package/src/kayenta/edit/judgeSelect.tsx +82 -0
- package/src/kayenta/edit/metricConfigurerDelegator.tsx +30 -0
- package/src/kayenta/edit/metricList.less +21 -0
- package/src/kayenta/edit/metricList.tsx +215 -0
- package/src/kayenta/edit/metricStoreSelector.tsx +66 -0
- package/src/kayenta/edit/nameAndDescription.tsx +90 -0
- package/src/kayenta/edit/openConfigJsonModalButton.tsx +33 -0
- package/src/kayenta/edit/openDeleteModalButton.tsx +50 -0
- package/src/kayenta/edit/ownedBy.tsx +34 -0
- package/src/kayenta/edit/save.tsx +19 -0
- package/src/kayenta/edit/saveConfigButton.tsx +65 -0
- package/src/kayenta/edit/saveConfigError.tsx +59 -0
- package/src/kayenta/edit/scoring.tsx +35 -0
- package/src/kayenta/edit/selectConfig.tsx +10 -0
- package/src/kayenta/edit/validationErrors.tsx +39 -0
- package/src/kayenta/index.ts +6 -0
- package/src/kayenta/layout/addNewButton.tsx +20 -0
- package/src/kayenta/layout/centeredDetail.tsx +13 -0
- package/src/kayenta/layout/deleteButton.tsx +11 -0
- package/src/kayenta/layout/disableable.tsx +87 -0
- package/src/kayenta/layout/formList.tsx +26 -0
- package/src/kayenta/layout/formRow.tsx +36 -0
- package/src/kayenta/layout/formattedDate.tsx +14 -0
- package/src/kayenta/layout/index.ts +2 -0
- package/src/kayenta/layout/keyValueList.less +20 -0
- package/src/kayenta/layout/keyValueList.tsx +114 -0
- package/src/kayenta/layout/list.less +9 -0
- package/src/kayenta/layout/list.spec.tsx +83 -0
- package/src/kayenta/layout/list.tsx +73 -0
- package/src/kayenta/layout/listDetail.tsx +33 -0
- package/src/kayenta/layout/radioChoice.tsx +29 -0
- package/src/kayenta/layout/styleguide.tsx +16 -0
- package/src/kayenta/layout/table/index.ts +5 -0
- package/src/kayenta/layout/table/nativeTable.tsx +51 -0
- package/src/kayenta/layout/table/nativeTableHeader.tsx +26 -0
- package/src/kayenta/layout/table/table.tsx +56 -0
- package/src/kayenta/layout/table/tableColumn.ts +7 -0
- package/src/kayenta/layout/table/tableHeader.tsx +23 -0
- package/src/kayenta/layout/tabs.tsx +26 -0
- package/src/kayenta/layout/titledSection.less +16 -0
- package/src/kayenta/layout/titledSection.tsx +20 -0
- package/src/kayenta/layout/titledSubsection.less +11 -0
- package/src/kayenta/layout/titledSubsection.tsx +22 -0
- package/src/kayenta/manualAnalysis/ManualAnalysisModal.tsx +716 -0
- package/src/kayenta/metricStore/atlas/atlasMetricConfigurer.tsx +130 -0
- package/src/kayenta/metricStore/atlas/index.ts +8 -0
- package/src/kayenta/metricStore/datadog/domain/IDatadogMetricDescriptor.ts +5 -0
- package/src/kayenta/metricStore/datadog/index.ts +9 -0
- package/src/kayenta/metricStore/datadog/metricConfigurer.tsx +90 -0
- package/src/kayenta/metricStore/datadog/metricTypeSelector.spec.tsx +59 -0
- package/src/kayenta/metricStore/datadog/metricTypeSelector.tsx +73 -0
- package/src/kayenta/metricStore/graphite/domain/IGraphiteMetricDescriptor.ts +5 -0
- package/src/kayenta/metricStore/graphite/index.ts +8 -0
- package/src/kayenta/metricStore/graphite/metricConfigurer.tsx +54 -0
- package/src/kayenta/metricStore/graphite/metricTypeSelector.tsx +80 -0
- package/src/kayenta/metricStore/graphite/typeahead.less +3 -0
- package/src/kayenta/metricStore/index.ts +8 -0
- package/src/kayenta/metricStore/metricStoreConfig.service.ts +12 -0
- package/src/kayenta/metricStore/newrelic/domain/INewRelicMetricDescriptor.ts +5 -0
- package/src/kayenta/metricStore/newrelic/index.ts +8 -0
- package/src/kayenta/metricStore/newrelic/metricConfigurer.tsx +58 -0
- package/src/kayenta/metricStore/prometheus/domain/IPrometheusCanaryMetricSetQueryConfig.ts +14 -0
- package/src/kayenta/metricStore/prometheus/domain/IPrometheusMetricDescriptor.ts +5 -0
- package/src/kayenta/metricStore/prometheus/index.ts +12 -0
- package/src/kayenta/metricStore/prometheus/metricConfigurer.tsx +157 -0
- package/src/kayenta/metricStore/prometheus/metricTypeSelector.less +5 -0
- package/src/kayenta/metricStore/prometheus/metricTypeSelector.spec.tsx +62 -0
- package/src/kayenta/metricStore/prometheus/metricTypeSelector.tsx +144 -0
- package/src/kayenta/metricStore/prometheus/queryTypeSelectors.spec.ts +61 -0
- package/src/kayenta/metricStore/prometheus/queryTypeSelectors.ts +38 -0
- package/src/kayenta/metricStore/signalfx/domain/ISignalFxCanaryMetricSetQueryConfig.ts +7 -0
- package/src/kayenta/metricStore/signalfx/index.ts +8 -0
- package/src/kayenta/metricStore/signalfx/metricConfigurer.less +10 -0
- package/src/kayenta/metricStore/signalfx/metricConfigurer.tsx +187 -0
- package/src/kayenta/metricStore/stackdriver/domain/IStackdriverCanaryMetricSetQueryConfig.ts +9 -0
- package/src/kayenta/metricStore/stackdriver/domain/IStackdriverMetricDescriptor.ts +17 -0
- package/src/kayenta/metricStore/stackdriver/index.ts +12 -0
- package/src/kayenta/metricStore/stackdriver/metricConfigurer.tsx +144 -0
- package/src/kayenta/metricStore/stackdriver/metricTypeSelector.spec.tsx +92 -0
- package/src/kayenta/metricStore/stackdriver/metricTypeSelector.tsx +113 -0
- package/src/kayenta/middleware/actionInterceptor.ts +29 -0
- package/src/kayenta/middleware/asyncDispatch.ts +37 -0
- package/src/kayenta/middleware/epics.ts +211 -0
- package/src/kayenta/middleware/index.ts +3 -0
- package/src/kayenta/navigation/canary.states.stub.ts +28 -0
- package/src/kayenta/navigation/canary.states.ts +182 -0
- package/src/kayenta/reducers/app.ts +56 -0
- package/src/kayenta/reducers/asyncRequest.ts +5 -0
- package/src/kayenta/reducers/data.ts +169 -0
- package/src/kayenta/reducers/editingTemplate.ts +54 -0
- package/src/kayenta/reducers/group.ts +82 -0
- package/src/kayenta/reducers/index.ts +245 -0
- package/src/kayenta/reducers/prometheusMetricConfig.spec.ts +33 -0
- package/src/kayenta/reducers/prometheusMetricConfig.ts +56 -0
- package/src/kayenta/reducers/selectedConfig.spec.ts +190 -0
- package/src/kayenta/reducers/selectedConfig.ts +566 -0
- package/src/kayenta/reducers/selectedRun.ts +101 -0
- package/src/kayenta/reducers/signalFxMetricConfig.ts +36 -0
- package/src/kayenta/reducers/stackdriverMetricConfig.spec.ts +33 -0
- package/src/kayenta/reducers/stackdriverMetricConfig.ts +41 -0
- package/src/kayenta/reducers/templates.spec.ts +192 -0
- package/src/kayenta/reducers/validators.ts +118 -0
- package/src/kayenta/report/detail/allMetricResultsHeader.tsx +32 -0
- package/src/kayenta/report/detail/clickableHeader.tsx +21 -0
- package/src/kayenta/report/detail/colors.ts +47 -0
- package/src/kayenta/report/detail/detail.less +16 -0
- package/src/kayenta/report/detail/detail.tsx +48 -0
- package/src/kayenta/report/detail/detailLoader.tsx +55 -0
- package/src/kayenta/report/detail/graph/graph.tsx +37 -0
- package/src/kayenta/report/detail/graph/metricSetPairGraph.service.ts +35 -0
- package/src/kayenta/report/detail/graph/semiotic/boxplot.less +45 -0
- package/src/kayenta/report/detail/graph/semiotic/boxplot.tsx +283 -0
- package/src/kayenta/report/detail/graph/semiotic/chartHeader.tsx +19 -0
- package/src/kayenta/report/detail/graph/semiotic/chartLegend.less +26 -0
- package/src/kayenta/report/detail/graph/semiotic/chartLegend.tsx +42 -0
- package/src/kayenta/report/detail/graph/semiotic/circleIcon.tsx +16 -0
- package/src/kayenta/report/detail/graph/semiotic/config.less +5 -0
- package/src/kayenta/report/detail/graph/semiotic/config.ts +38 -0
- package/src/kayenta/report/detail/graph/semiotic/customAxisTickLabel.tsx +17 -0
- package/src/kayenta/report/detail/graph/semiotic/declarations/labella.d.ts +16 -0
- package/src/kayenta/report/detail/graph/semiotic/declarations/react-container-dimensions.d.ts +3 -0
- package/src/kayenta/report/detail/graph/semiotic/declarations/semiotic.d.ts +160 -0
- package/src/kayenta/report/detail/graph/semiotic/differenceArea.less +17 -0
- package/src/kayenta/report/detail/graph/semiotic/differenceArea.tsx +186 -0
- package/src/kayenta/report/detail/graph/semiotic/histogram.less +22 -0
- package/src/kayenta/report/detail/graph/semiotic/histogram.tsx +251 -0
- package/src/kayenta/report/detail/graph/semiotic/index.tsx +19 -0
- package/src/kayenta/report/detail/graph/semiotic/noValidDataSign.less +5 -0
- package/src/kayenta/report/detail/graph/semiotic/noValidDataSign.tsx +10 -0
- package/src/kayenta/report/detail/graph/semiotic/secondaryTSXAxis.less +6 -0
- package/src/kayenta/report/detail/graph/semiotic/secondaryTSXAxis.tsx +58 -0
- package/src/kayenta/report/detail/graph/semiotic/semiotic.service.ts +32 -0
- package/src/kayenta/report/detail/graph/semiotic/semioticGraph.less +53 -0
- package/src/kayenta/report/detail/graph/semiotic/semioticGraph.tsx +49 -0
- package/src/kayenta/report/detail/graph/semiotic/timeSeries.less +42 -0
- package/src/kayenta/report/detail/graph/semiotic/timeSeries.tsx +473 -0
- package/src/kayenta/report/detail/graph/semiotic/tooltip.tsx +55 -0
- package/src/kayenta/report/detail/graph/semiotic/utils.ts +90 -0
- package/src/kayenta/report/detail/graphTypeSelector.less +4 -0
- package/src/kayenta/report/detail/graphTypeSelector.tsx +50 -0
- package/src/kayenta/report/detail/groupScores.tsx +68 -0
- package/src/kayenta/report/detail/header.less +70 -0
- package/src/kayenta/report/detail/header.tsx +39 -0
- package/src/kayenta/report/detail/headerArrow.tsx +13 -0
- package/src/kayenta/report/detail/loadStates.tsx +31 -0
- package/src/kayenta/report/detail/metricResultActions.less +29 -0
- package/src/kayenta/report/detail/metricResultActions.tsx +87 -0
- package/src/kayenta/report/detail/metricResultClassification.tsx +22 -0
- package/src/kayenta/report/detail/metricResultDetail.tsx +20 -0
- package/src/kayenta/report/detail/metricResultDetailLayout.tsx +19 -0
- package/src/kayenta/report/detail/metricResultDeviation.tsx +25 -0
- package/src/kayenta/report/detail/metricResultStats.less +9 -0
- package/src/kayenta/report/detail/metricResultStats.tsx +120 -0
- package/src/kayenta/report/detail/metricResults.less +12 -0
- package/src/kayenta/report/detail/metricResults.tsx +52 -0
- package/src/kayenta/report/detail/metricResultsClassificationFilters.tsx +65 -0
- package/src/kayenta/report/detail/metricResultsColumns.tsx +27 -0
- package/src/kayenta/report/detail/metricResultsList.less +44 -0
- package/src/kayenta/report/detail/metricResultsList.tsx +120 -0
- package/src/kayenta/report/detail/metricSetPairLoadStates.tsx +22 -0
- package/src/kayenta/report/detail/multipleResultsTable.tsx +81 -0
- package/src/kayenta/report/detail/reportException.tsx +57 -0
- package/src/kayenta/report/detail/reportExplanation.less +12 -0
- package/src/kayenta/report/detail/reportExplanation.tsx +32 -0
- package/src/kayenta/report/detail/reportMetadata.tsx +167 -0
- package/src/kayenta/report/detail/reportScores.less +47 -0
- package/src/kayenta/report/detail/reportScores.tsx +80 -0
- package/src/kayenta/report/detail/score.tsx +33 -0
- package/src/kayenta/report/detail/sourceLinks.tsx +69 -0
- package/src/kayenta/report/list/configLink.tsx +32 -0
- package/src/kayenta/report/list/executionList.less +7 -0
- package/src/kayenta/report/list/loadStates.tsx +32 -0
- package/src/kayenta/report/list/pipelineLink.tsx +15 -0
- package/src/kayenta/report/list/reportLink.tsx +33 -0
- package/src/kayenta/report/list/table.tsx +309 -0
- package/src/kayenta/report/report.tsx +11 -0
- package/src/kayenta/selectors/filterTemplatesSelectors.ts +87 -0
- package/src/kayenta/selectors/index.ts +62 -0
- package/src/kayenta/service/canaryConfig.service.ts +122 -0
- package/src/kayenta/service/canaryRun.service.ts +60 -0
- package/src/kayenta/service/delegateFactory.ts +24 -0
- package/src/kayenta/service/metricsServiceMetadata.service.ts +9 -0
- package/src/kayenta/stages/kayentaStage/AnalysisType.spec.tsx +47 -0
- package/src/kayenta/stages/kayentaStage/AnalysisType.tsx +49 -0
- package/src/kayenta/stages/kayentaStage/CanaryExecutionLabel.tsx +26 -0
- package/src/kayenta/stages/kayentaStage/analysisType.component.ts +12 -0
- package/src/kayenta/stages/kayentaStage/canaryRunSummaries.component.ts +12 -0
- package/src/kayenta/stages/kayentaStage/canaryRunSummaries.less +5 -0
- package/src/kayenta/stages/kayentaStage/canaryRunSummaries.tsx +136 -0
- package/src/kayenta/stages/kayentaStage/forAnalysisType.component.ts +45 -0
- package/src/kayenta/stages/kayentaStage/kayentaStage.controller.ts +789 -0
- package/src/kayenta/stages/kayentaStage/kayentaStage.html +528 -0
- package/src/kayenta/stages/kayentaStage/kayentaStage.less +5 -0
- package/src/kayenta/stages/kayentaStage/kayentaStage.transformer.ts +179 -0
- package/src/kayenta/stages/kayentaStage/kayentaStage.ts +221 -0
- package/src/kayenta/stages/kayentaStage/kayentaStageConfigSection.component.ts +21 -0
- package/src/kayenta/stages/kayentaStage/kayentaStageExecutionDetails.controller.ts +88 -0
- package/src/kayenta/stages/kayentaStage/kayentaStageExecutionDetails.html +114 -0
- package/src/kayenta/stages/kayentaStage/kayentaStageExecutionDetails.less +6 -0
- package/src/kayenta/stages/kayentaStage/stageTypes.ts +5 -0
- package/src/kayenta/utils/duration.spec.ts +69 -0
- package/src/kayenta/utils/duration.ts +48 -0
- package/src/lazy.ts +29 -0
- package/src/stub.ts +60 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { mount } from 'enzyme';
|
|
2
|
+
import { ICanaryMetricConfig } from 'kayenta';
|
|
3
|
+
import * as Creators from 'kayenta/actions/creators';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Provider } from 'react-redux';
|
|
6
|
+
import { createMockStore } from 'redux-test-utils';
|
|
7
|
+
|
|
8
|
+
import EditMetricModal from './editMetricModal';
|
|
9
|
+
|
|
10
|
+
describe('EditMetricModal', () => {
|
|
11
|
+
const mockProps = {
|
|
12
|
+
metric: {
|
|
13
|
+
id: '1',
|
|
14
|
+
name: 'Test Metric',
|
|
15
|
+
groups: ['Test Group'],
|
|
16
|
+
type: 'Test Type',
|
|
17
|
+
analysisConfigurations: {
|
|
18
|
+
canary: {
|
|
19
|
+
direction: 'increase',
|
|
20
|
+
nanStrategy: 'default',
|
|
21
|
+
critical: false,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
groups: ['Group 1', 'Group 2'],
|
|
26
|
+
isTemplateValid: true,
|
|
27
|
+
useInlineTemplateEditor: false,
|
|
28
|
+
disableEdit: false,
|
|
29
|
+
validationErrors: {},
|
|
30
|
+
rename: jest.fn(),
|
|
31
|
+
changeGroup: jest.fn(),
|
|
32
|
+
updateDirection: jest.fn(),
|
|
33
|
+
updateNanStrategy: jest.fn(),
|
|
34
|
+
updateCriticality: jest.fn(),
|
|
35
|
+
updateDataRequired: jest.fn(),
|
|
36
|
+
confirm: jest.fn(),
|
|
37
|
+
cancel: jest.fn(),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const mockState = {
|
|
41
|
+
app: {
|
|
42
|
+
disableConfigEdit: false,
|
|
43
|
+
},
|
|
44
|
+
selectedConfig: {
|
|
45
|
+
editingMetric: {
|
|
46
|
+
name: 'Test Metric',
|
|
47
|
+
query: {
|
|
48
|
+
serviceType: 'prometheus',
|
|
49
|
+
},
|
|
50
|
+
groups: ['Group 1'],
|
|
51
|
+
},
|
|
52
|
+
editingTemplate: {},
|
|
53
|
+
group: {
|
|
54
|
+
list: ['Group 1', 'Group 2'],
|
|
55
|
+
},
|
|
56
|
+
metricList: [] as ICanaryMetricConfig[],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const store = createMockStore(mockState);
|
|
61
|
+
store.dispatch = jest.fn();
|
|
62
|
+
|
|
63
|
+
const buildComponent = (props: object) =>
|
|
64
|
+
mount(
|
|
65
|
+
<Provider store={store}>
|
|
66
|
+
<EditMetricModal {...mockProps} {...props} />
|
|
67
|
+
</Provider>,
|
|
68
|
+
).find(EditMetricModal);
|
|
69
|
+
|
|
70
|
+
it('renders without crashing', () => {
|
|
71
|
+
const component = buildComponent({});
|
|
72
|
+
expect(component.exists()).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('calls cancel when the cancel button is clicked', () => {
|
|
76
|
+
const component = buildComponent({});
|
|
77
|
+
const cancelBtn = component
|
|
78
|
+
.find('button')
|
|
79
|
+
.filterWhere((btn) => btn.text().trim() === 'Cancel')
|
|
80
|
+
.at(0);
|
|
81
|
+
cancelBtn.simulate('click');
|
|
82
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.editMetricCancel());
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('calls confirm when the confirm button is clicked', () => {
|
|
86
|
+
const component = buildComponent({});
|
|
87
|
+
const confirmBtn = component
|
|
88
|
+
.find('button')
|
|
89
|
+
.filterWhere((btn) => btn.text().trim() === 'OK')
|
|
90
|
+
.at(0);
|
|
91
|
+
confirmBtn.simulate('click');
|
|
92
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.editMetricConfirm());
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('calls updateDirection when a direction radio button is clicked', () => {
|
|
96
|
+
const component = buildComponent({});
|
|
97
|
+
const changeDirectionEvent = { target: { value: 'increase', dataset: { id: '1' } } };
|
|
98
|
+
component.find('input[name="direction"][value="increase"]').simulate('change', changeDirectionEvent);
|
|
99
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.updateMetricDirection({ id: '1', direction: 'increase' }));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('calls updateNanStrategy when the nan strategy is changed', () => {
|
|
103
|
+
const component = buildComponent({});
|
|
104
|
+
const changeNanStrategyEvent = { target: { value: 'replace', dataset: { id: '1' } } };
|
|
105
|
+
component.find('input[name="nanStrategy"][value="replace"]').simulate('change', changeNanStrategyEvent);
|
|
106
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.updateMetricNanStrategy({ id: '1', strategy: 'replace' }));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('calls updateOutlierStrategy when the outlier strategy is changed', () => {
|
|
110
|
+
const component = buildComponent({});
|
|
111
|
+
const changeOutlierStrategyEvent = { target: { value: 'remove', dataset: { id: '1' } } };
|
|
112
|
+
component.find('input[name="outlierStrategy"][value="remove"]').simulate('change', changeOutlierStrategyEvent);
|
|
113
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.updateMetricOutlierStrategy({ id: '1', strategy: 'remove' }));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('calls updateCriticality when the criticality checkbox is changed', () => {
|
|
117
|
+
const component = buildComponent({});
|
|
118
|
+
const changeCriticalityEvent = { target: { checked: true, dataset: { id: '1' } } };
|
|
119
|
+
component.find('input[type="checkbox"][name="criticality"]').simulate('change', changeCriticalityEvent);
|
|
120
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.updateMetricCriticality({ id: '1', critical: true }));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('calls updateDataRequired when the data required checkbox is changed', () => {
|
|
124
|
+
const component = buildComponent({ disableEdit: true });
|
|
125
|
+
const changeDataRequiredEvent = { target: { checked: true, dataset: { id: '1' } } };
|
|
126
|
+
component.find('input[type="checkbox"][name="dataRequired"]').simulate('change', changeDataRequiredEvent);
|
|
127
|
+
expect(store.dispatch).toHaveBeenCalledWith(Creators.updateMetricDataRequired({ id: '1', mustHaveData: true }));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import * as Creators from 'kayenta/actions/creators';
|
|
3
|
+
import { CanarySettings } from 'kayenta/canary.settings';
|
|
4
|
+
import { ICanaryMetricConfig } from 'kayenta/domain';
|
|
5
|
+
import { DISABLE_EDIT_CONFIG, DisableableInput, DisableableSelect } from 'kayenta/layout/disableable';
|
|
6
|
+
import FormRow from 'kayenta/layout/formRow';
|
|
7
|
+
import RadioChoice from 'kayenta/layout/radioChoice';
|
|
8
|
+
import Styleguide from 'kayenta/layout/styleguide';
|
|
9
|
+
import metricStoreConfigService from 'kayenta/metricStore/metricStoreConfig.service';
|
|
10
|
+
import { ICanaryState } from 'kayenta/reducers';
|
|
11
|
+
import { editingMetricValidationErrorsSelector } from 'kayenta/selectors';
|
|
12
|
+
import { isTemplateValidSelector, useInlineTemplateEditorSelector } from 'kayenta/selectors/filterTemplatesSelectors';
|
|
13
|
+
import { isNull, values } from 'lodash';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { Modal } from 'react-bootstrap';
|
|
16
|
+
import { connect } from 'react-redux';
|
|
17
|
+
|
|
18
|
+
import { noop } from '@spinnaker/core';
|
|
19
|
+
|
|
20
|
+
import EditMetricEffectSizes from './editMetricEffectSizes';
|
|
21
|
+
import { ICanaryMetricValidationErrors } from './editMetricValidation';
|
|
22
|
+
import FilterTemplateSelector from './filterTemplateSelector';
|
|
23
|
+
import InlineTemplateEditor from './inlineTemplateEditor';
|
|
24
|
+
import MetricConfigurerDelegator from './metricConfigurerDelegator';
|
|
25
|
+
|
|
26
|
+
import './editMetricModal.less';
|
|
27
|
+
|
|
28
|
+
interface IEditMetricModalDispatchProps {
|
|
29
|
+
rename: (event: any) => void;
|
|
30
|
+
changeGroup: (event: any) => void;
|
|
31
|
+
updateDirection: (event: any) => void;
|
|
32
|
+
updateNanStrategy: (event: any) => void;
|
|
33
|
+
updateOutlierStrategy: (event: any) => void;
|
|
34
|
+
updateCriticality: (event: any) => void;
|
|
35
|
+
updateDataRequired: (event: any) => void;
|
|
36
|
+
confirm: () => void;
|
|
37
|
+
cancel: () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface IEditMetricModalStateProps {
|
|
41
|
+
metric: ICanaryMetricConfig;
|
|
42
|
+
groups: string[];
|
|
43
|
+
isTemplateValid: boolean;
|
|
44
|
+
useInlineTemplateEditor: boolean;
|
|
45
|
+
disableEdit: boolean;
|
|
46
|
+
validationErrors: ICanaryMetricValidationErrors;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
* Modal to edit metric details.
|
|
51
|
+
*/
|
|
52
|
+
function EditMetricModal({
|
|
53
|
+
metric,
|
|
54
|
+
rename,
|
|
55
|
+
changeGroup,
|
|
56
|
+
groups,
|
|
57
|
+
confirm,
|
|
58
|
+
cancel,
|
|
59
|
+
isTemplateValid,
|
|
60
|
+
updateDirection,
|
|
61
|
+
updateNanStrategy,
|
|
62
|
+
updateOutlierStrategy,
|
|
63
|
+
updateCriticality,
|
|
64
|
+
updateDataRequired,
|
|
65
|
+
useInlineTemplateEditor,
|
|
66
|
+
disableEdit,
|
|
67
|
+
validationErrors,
|
|
68
|
+
}: IEditMetricModalDispatchProps & IEditMetricModalStateProps) {
|
|
69
|
+
if (!metric) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const direction = metric.analysisConfigurations?.canary?.direction ?? 'either';
|
|
74
|
+
const nanStrategy = metric.analysisConfigurations?.canary?.nanStrategy ?? 'default';
|
|
75
|
+
const outlierStrategy = metric.analysisConfigurations?.canary?.outliers?.strategy ?? 'default';
|
|
76
|
+
const critical = metric.analysisConfigurations?.canary?.critical ?? false;
|
|
77
|
+
const dataRequired = metric.analysisConfigurations?.canary?.mustHaveData ?? false;
|
|
78
|
+
const isConfirmDisabled =
|
|
79
|
+
!isTemplateValid ||
|
|
80
|
+
disableEdit ||
|
|
81
|
+
CanarySettings.disableConfigEdit ||
|
|
82
|
+
values(validationErrors).some((e) => !isNull(e));
|
|
83
|
+
|
|
84
|
+
const metricGroup = metric.groups.length ? metric.groups[0] : groups[0];
|
|
85
|
+
const templatesEnabled =
|
|
86
|
+
metricStoreConfigService.getDelegate(metric.query.type) &&
|
|
87
|
+
metricStoreConfigService.getDelegate(metric.query.type).useTemplates &&
|
|
88
|
+
CanarySettings.templatesEnabled;
|
|
89
|
+
return (
|
|
90
|
+
<Modal bsSize="large" show={true} onHide={noop} className={classNames('kayenta-edit-metric-modal')}>
|
|
91
|
+
<Styleguide>
|
|
92
|
+
<Modal.Header>
|
|
93
|
+
<Modal.Title>
|
|
94
|
+
{disableEdit || CanarySettings.disableConfigEdit ? 'Metric Details' : 'Configure Metric'}
|
|
95
|
+
</Modal.Title>
|
|
96
|
+
</Modal.Header>
|
|
97
|
+
<Modal.Body>
|
|
98
|
+
<FormRow label="Group" inputOnly={true}>
|
|
99
|
+
{metric.groups.length > 1 && (
|
|
100
|
+
<DisableableInput
|
|
101
|
+
type="text"
|
|
102
|
+
value={metric.groups}
|
|
103
|
+
data-id={metric.id}
|
|
104
|
+
onChange={changeGroup}
|
|
105
|
+
disabled={CanarySettings.disableConfigEdit}
|
|
106
|
+
disabledStateKeys={[DISABLE_EDIT_CONFIG]}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
{metric.groups.length < 2 && (
|
|
110
|
+
<DisableableSelect
|
|
111
|
+
value={metricGroup}
|
|
112
|
+
onChange={changeGroup}
|
|
113
|
+
className="form-control input-sm"
|
|
114
|
+
disabled={CanarySettings.disableConfigEdit}
|
|
115
|
+
disabledStateKeys={[DISABLE_EDIT_CONFIG]}
|
|
116
|
+
>
|
|
117
|
+
{groups.map((g) => (
|
|
118
|
+
<option key={g} value={g}>
|
|
119
|
+
{g}
|
|
120
|
+
</option>
|
|
121
|
+
))}
|
|
122
|
+
</DisableableSelect>
|
|
123
|
+
)}
|
|
124
|
+
</FormRow>
|
|
125
|
+
<FormRow label="Name" error={validationErrors?.name?.message ?? null} inputOnly={true}>
|
|
126
|
+
<DisableableInput
|
|
127
|
+
type="text"
|
|
128
|
+
value={metric.name}
|
|
129
|
+
data-id={metric.id}
|
|
130
|
+
onChange={rename}
|
|
131
|
+
disabled={CanarySettings.disableConfigEdit}
|
|
132
|
+
disabledStateKeys={[DISABLE_EDIT_CONFIG]}
|
|
133
|
+
/>
|
|
134
|
+
</FormRow>
|
|
135
|
+
<FormRow label="Fail on">
|
|
136
|
+
<RadioChoice
|
|
137
|
+
value="increase"
|
|
138
|
+
label="Increase"
|
|
139
|
+
name="direction"
|
|
140
|
+
current={direction}
|
|
141
|
+
action={updateDirection}
|
|
142
|
+
/>
|
|
143
|
+
<RadioChoice
|
|
144
|
+
value="decrease"
|
|
145
|
+
label="Decrease"
|
|
146
|
+
name="direction"
|
|
147
|
+
current={direction}
|
|
148
|
+
action={updateDirection}
|
|
149
|
+
/>
|
|
150
|
+
<RadioChoice value="either" label="Either" name="direction" current={direction} action={updateDirection} />
|
|
151
|
+
</FormRow>
|
|
152
|
+
<FormRow label="Criticality" checkbox={true}>
|
|
153
|
+
<label>
|
|
154
|
+
<DisableableInput
|
|
155
|
+
type="checkbox"
|
|
156
|
+
name="criticality"
|
|
157
|
+
checked={critical}
|
|
158
|
+
onChange={updateCriticality}
|
|
159
|
+
disabled={CanarySettings.disableConfigEdit}
|
|
160
|
+
disabledStateKeys={[DISABLE_EDIT_CONFIG]}
|
|
161
|
+
/>
|
|
162
|
+
Fail the canary if this metric fails
|
|
163
|
+
</label>
|
|
164
|
+
</FormRow>
|
|
165
|
+
<FormRow label="Data Required" checkbox={true}>
|
|
166
|
+
<label>
|
|
167
|
+
<DisableableInput
|
|
168
|
+
type="checkbox"
|
|
169
|
+
name="dataRequired"
|
|
170
|
+
checked={dataRequired}
|
|
171
|
+
onChange={updateDataRequired}
|
|
172
|
+
disabled={CanarySettings.disableConfigEdit}
|
|
173
|
+
disabledStateKeys={[DISABLE_EDIT_CONFIG]}
|
|
174
|
+
/>
|
|
175
|
+
Fail the metric if data is missing
|
|
176
|
+
</label>
|
|
177
|
+
</FormRow>
|
|
178
|
+
<FormRow label="NaN Strategy" helpId="canary.config.nanStrategy">
|
|
179
|
+
<RadioChoice
|
|
180
|
+
value="default"
|
|
181
|
+
label="Default (remove)"
|
|
182
|
+
name="nanStrategy"
|
|
183
|
+
current={nanStrategy}
|
|
184
|
+
action={updateNanStrategy}
|
|
185
|
+
/>
|
|
186
|
+
<RadioChoice
|
|
187
|
+
value="replace"
|
|
188
|
+
label="Replace with zero"
|
|
189
|
+
name="nanStrategy"
|
|
190
|
+
current={nanStrategy}
|
|
191
|
+
action={updateNanStrategy}
|
|
192
|
+
/>
|
|
193
|
+
<RadioChoice
|
|
194
|
+
value="remove"
|
|
195
|
+
label="Remove"
|
|
196
|
+
name="nanStrategy"
|
|
197
|
+
current={nanStrategy}
|
|
198
|
+
action={updateNanStrategy}
|
|
199
|
+
/>
|
|
200
|
+
</FormRow>
|
|
201
|
+
<FormRow label="Outlier Strategy" helpId="canary.config.outlierStrategy">
|
|
202
|
+
<RadioChoice
|
|
203
|
+
value="default"
|
|
204
|
+
label="Default (keep)"
|
|
205
|
+
name="outlierStrategy"
|
|
206
|
+
current={outlierStrategy}
|
|
207
|
+
action={updateOutlierStrategy}
|
|
208
|
+
/>
|
|
209
|
+
<RadioChoice
|
|
210
|
+
value="remove"
|
|
211
|
+
label="Remove"
|
|
212
|
+
name="outlierStrategy"
|
|
213
|
+
current={outlierStrategy}
|
|
214
|
+
action={updateOutlierStrategy}
|
|
215
|
+
/>
|
|
216
|
+
<RadioChoice
|
|
217
|
+
value="keep"
|
|
218
|
+
label="Keep"
|
|
219
|
+
name="outlierStrategy"
|
|
220
|
+
current={outlierStrategy}
|
|
221
|
+
action={updateOutlierStrategy}
|
|
222
|
+
/>
|
|
223
|
+
</FormRow>
|
|
224
|
+
<EditMetricEffectSizes />
|
|
225
|
+
<MetricConfigurerDelegator />
|
|
226
|
+
{templatesEnabled && !useInlineTemplateEditor && <FilterTemplateSelector />}
|
|
227
|
+
{templatesEnabled && useInlineTemplateEditor && <InlineTemplateEditor />}
|
|
228
|
+
</Modal.Body>
|
|
229
|
+
<Modal.Footer>
|
|
230
|
+
<ul className="list-inline pull-right">
|
|
231
|
+
<li>
|
|
232
|
+
<button className="passive" onClick={cancel}>
|
|
233
|
+
Cancel
|
|
234
|
+
</button>
|
|
235
|
+
</li>
|
|
236
|
+
<li>
|
|
237
|
+
<button className="primary" disabled={isConfirmDisabled} onClick={confirm}>
|
|
238
|
+
OK
|
|
239
|
+
</button>
|
|
240
|
+
</li>
|
|
241
|
+
</ul>
|
|
242
|
+
</Modal.Footer>
|
|
243
|
+
</Styleguide>
|
|
244
|
+
</Modal>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function mapDispatchToProps(dispatch: any): IEditMetricModalDispatchProps {
|
|
249
|
+
return {
|
|
250
|
+
rename: (event: any) => {
|
|
251
|
+
dispatch(Creators.renameMetric({ id: event.target.dataset.id, name: event.target.value }));
|
|
252
|
+
},
|
|
253
|
+
changeGroup: (event: any) => {
|
|
254
|
+
dispatch(Creators.updateMetricGroup({ id: event.target.dataset.id, group: event.target.value }));
|
|
255
|
+
},
|
|
256
|
+
cancel: () => {
|
|
257
|
+
dispatch(Creators.editMetricCancel());
|
|
258
|
+
dispatch(Creators.editTemplateCancel());
|
|
259
|
+
},
|
|
260
|
+
confirm: () => {
|
|
261
|
+
dispatch(Creators.editMetricConfirm());
|
|
262
|
+
dispatch(Creators.editTemplateCancel());
|
|
263
|
+
},
|
|
264
|
+
updateDirection: ({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
|
265
|
+
dispatch(Creators.updateMetricDirection({ id: target.dataset.id, direction: target.value }));
|
|
266
|
+
},
|
|
267
|
+
updateNanStrategy: ({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
|
268
|
+
dispatch(Creators.updateMetricNanStrategy({ id: target.dataset.id, strategy: target.value }));
|
|
269
|
+
},
|
|
270
|
+
updateOutlierStrategy: ({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
|
271
|
+
dispatch(Creators.updateMetricOutlierStrategy({ id: target.dataset.id, strategy: target.value }));
|
|
272
|
+
},
|
|
273
|
+
updateCriticality: ({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
|
274
|
+
dispatch(Creators.updateMetricCriticality({ id: target.dataset.id, critical: Boolean(target.checked) }));
|
|
275
|
+
},
|
|
276
|
+
updateDataRequired: ({ target }: React.ChangeEvent<HTMLInputElement>) => {
|
|
277
|
+
dispatch(Creators.updateMetricDataRequired({ id: target.dataset.id, mustHaveData: Boolean(target.checked) }));
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function mapStateToProps(state: ICanaryState): IEditMetricModalStateProps {
|
|
283
|
+
return {
|
|
284
|
+
metric: state.selectedConfig.editingMetric,
|
|
285
|
+
groups: state.selectedConfig.group.list.sort(),
|
|
286
|
+
isTemplateValid: isTemplateValidSelector(state),
|
|
287
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
288
|
+
useInlineTemplateEditor: useInlineTemplateEditorSelector(state),
|
|
289
|
+
disableEdit: state.app.disableConfigEdit || CanarySettings.disableConfigEdit,
|
|
290
|
+
validationErrors: editingMetricValidationErrorsSelector(state),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export default connect(mapStateToProps, mapDispatchToProps)(EditMetricModal);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ICanaryMetricConfig } from '../domain';
|
|
2
|
+
import { ICanaryMetricValidationErrors, validateMetric, validateMetricName } from './editMetricValidation';
|
|
3
|
+
|
|
4
|
+
describe('Canary metric validation', () => {
|
|
5
|
+
let errors: ICanaryMetricValidationErrors;
|
|
6
|
+
let editingMetric: ICanaryMetricConfig;
|
|
7
|
+
let metricList: ICanaryMetricConfig[];
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
errors = createErrors();
|
|
11
|
+
editingMetric = createEditingMetric('A', 'a');
|
|
12
|
+
metricList = createMetricList();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('validateMetricName', () => {
|
|
16
|
+
it('Does not update errors when metric name is valid', () => {
|
|
17
|
+
editingMetric.name = 'D';
|
|
18
|
+
expect(validateMetricName(errors, editingMetric, metricList).name).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
it('Updates errors appropriately when metric name is empty', () => {
|
|
21
|
+
editingMetric.name = '';
|
|
22
|
+
expect(validateMetricName(errors, editingMetric, metricList).name).toEqual({
|
|
23
|
+
message: 'Name is required',
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it('Updates errors appropriately when metric name is not unique', () => {
|
|
27
|
+
editingMetric.name = 'B';
|
|
28
|
+
expect(validateMetricName(errors, editingMetric, metricList).name).toEqual({
|
|
29
|
+
message: "Metric 'B' already exists",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('validateMetric', () => {
|
|
35
|
+
it('Does not update errors when all fields are valid', () => {
|
|
36
|
+
expect(validateMetric(editingMetric, metricList)).toEqual(errors);
|
|
37
|
+
});
|
|
38
|
+
it('Reduces validation of all fields into one object', () => {
|
|
39
|
+
editingMetric.name = '';
|
|
40
|
+
expect(validateMetric(editingMetric, metricList)).toEqual({
|
|
41
|
+
name: { message: 'Name is required' },
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function createErrors(): ICanaryMetricValidationErrors {
|
|
48
|
+
return {
|
|
49
|
+
name: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createEditingMetric(name: string, id: string): ICanaryMetricConfig {
|
|
54
|
+
return {
|
|
55
|
+
name,
|
|
56
|
+
id,
|
|
57
|
+
scopeName: 'default',
|
|
58
|
+
} as ICanaryMetricConfig;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createMetricList(): ICanaryMetricConfig[] {
|
|
62
|
+
return [createEditingMetric('A', 'a'), createEditingMetric('B', 'b'), createEditingMetric('C', 'c')];
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import { ICanaryMetricConfig } from '../domain';
|
|
3
|
+
|
|
4
|
+
export interface ICanaryMetricValidationError {
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ICanaryMetricValidationErrors {
|
|
9
|
+
[key: string]: ICanaryMetricValidationError;
|
|
10
|
+
}
|
|
11
|
+
export type MetricValidatorFunction = (
|
|
12
|
+
errors: ICanaryMetricValidationErrors,
|
|
13
|
+
editingMetric: ICanaryMetricConfig,
|
|
14
|
+
metricList?: ICanaryMetricConfig[],
|
|
15
|
+
) => ICanaryMetricValidationErrors;
|
|
16
|
+
|
|
17
|
+
export function validateMetricName(
|
|
18
|
+
errors: ICanaryMetricValidationErrors,
|
|
19
|
+
editingMetric: ICanaryMetricConfig,
|
|
20
|
+
metricList: ICanaryMetricConfig[],
|
|
21
|
+
): ICanaryMetricValidationErrors {
|
|
22
|
+
const nextErrors = { ...errors };
|
|
23
|
+
|
|
24
|
+
const editingMetricName = get(editingMetric, 'name', '');
|
|
25
|
+
if (!editingMetricName) {
|
|
26
|
+
nextErrors.name = { message: 'Name is required' };
|
|
27
|
+
return nextErrors;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isNameUnique = metricList.every((m) => m.name !== editingMetricName || m.id === editingMetric.id);
|
|
31
|
+
if (!isNameUnique) {
|
|
32
|
+
nextErrors.name = { message: `Metric '${editingMetricName}' already exists` };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return nextErrors;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function validateMetric(
|
|
39
|
+
editingMetric: ICanaryMetricConfig,
|
|
40
|
+
metricList: ICanaryMetricConfig[],
|
|
41
|
+
): ICanaryMetricValidationErrors {
|
|
42
|
+
const errors: ICanaryMetricValidationErrors = {
|
|
43
|
+
name: null,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return [validateMetricName].reduce(
|
|
47
|
+
(reducedErrors, validator) => validator(reducedErrors, editingMetric, metricList),
|
|
48
|
+
errors,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.template-editor-textarea {
|
|
2
|
+
// Prevent horizontal resizing
|
|
3
|
+
min-width: 100%;
|
|
4
|
+
max-width: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.template-editor-value-formatted {
|
|
8
|
+
margin: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.filter-template-option {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { mount } from 'enzyme';
|
|
2
|
+
import { DisableableInput, DisableableTextarea } from 'kayenta/layout/disableable';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Provider } from 'react-redux';
|
|
5
|
+
import Select, { Option } from 'react-select';
|
|
6
|
+
import { createMockStore } from 'redux-test-utils';
|
|
7
|
+
|
|
8
|
+
import { noop, ValidationMessage } from '@spinnaker/core';
|
|
9
|
+
|
|
10
|
+
import { FilterTemplateSelector, IFilterTemplateSelectorProps } from './filterTemplateSelector';
|
|
11
|
+
|
|
12
|
+
const buildComponent = (props: IFilterTemplateSelectorProps) =>
|
|
13
|
+
mount(
|
|
14
|
+
<Provider store={createMockStore()}>
|
|
15
|
+
<FilterTemplateSelector {...props} />
|
|
16
|
+
</Provider>,
|
|
17
|
+
).find(FilterTemplateSelector);
|
|
18
|
+
|
|
19
|
+
describe('<FilterTemplateSelector />', () => {
|
|
20
|
+
let defaultProps: IFilterTemplateSelectorProps;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
defaultProps = {
|
|
23
|
+
editedTemplateName: null,
|
|
24
|
+
editedTemplateValue: null,
|
|
25
|
+
selectedTemplateName: 'my-filter-template',
|
|
26
|
+
templates: {
|
|
27
|
+
'my-filter-template': 'metadata.user_labels."app"="${scope}"',
|
|
28
|
+
'my-other-filter-template': 'metadata.user_labels."app"="${location}"',
|
|
29
|
+
},
|
|
30
|
+
validation: { warnings: {}, errors: {} },
|
|
31
|
+
deleteTemplate: noop,
|
|
32
|
+
editTemplateBegin: noop,
|
|
33
|
+
editTemplateCancel: noop,
|
|
34
|
+
editTemplateConfirm: noop,
|
|
35
|
+
editTemplateName: noop,
|
|
36
|
+
editTemplateValue: noop,
|
|
37
|
+
selectTemplate: noop,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
it('builds options from filter template map', () => {
|
|
41
|
+
const component = buildComponent(defaultProps);
|
|
42
|
+
const allProps: any = component.find(Select).first().props();
|
|
43
|
+
|
|
44
|
+
expect(allProps.options.map((o: Option) => o.value)).toEqual([
|
|
45
|
+
'my-filter-template',
|
|
46
|
+
'my-other-filter-template',
|
|
47
|
+
null,
|
|
48
|
+
]); // null is "Create new" option
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('renders filter template', () => {
|
|
52
|
+
let component = buildComponent(defaultProps);
|
|
53
|
+
|
|
54
|
+
let pre = component.find('pre').first();
|
|
55
|
+
expect(pre.html()).toContain('${scope}');
|
|
56
|
+
|
|
57
|
+
component = buildComponent({
|
|
58
|
+
...defaultProps,
|
|
59
|
+
selectedTemplateName: 'my-other-filter-template',
|
|
60
|
+
});
|
|
61
|
+
pre = component.find('pre').first();
|
|
62
|
+
expect(pre.html()).toContain('${location}');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('does not render filter template if not selected', () => {
|
|
66
|
+
const component = buildComponent({
|
|
67
|
+
...defaultProps,
|
|
68
|
+
selectedTemplateName: null,
|
|
69
|
+
});
|
|
70
|
+
expect(component.find('pre').length).toEqual(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('renders errors when appropriate', () => {
|
|
74
|
+
let component = buildComponent(defaultProps);
|
|
75
|
+
expect(component.find(ValidationMessage).length).toEqual(0);
|
|
76
|
+
|
|
77
|
+
component = buildComponent({
|
|
78
|
+
...defaultProps,
|
|
79
|
+
editedTemplateName: '',
|
|
80
|
+
editedTemplateValue: 'metadata.user_labels."app"="${scope}"',
|
|
81
|
+
validation: {
|
|
82
|
+
warnings: {},
|
|
83
|
+
errors: {
|
|
84
|
+
templateName: {
|
|
85
|
+
message: 'Template name is required',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
expect(component.find(ValidationMessage).first().props().message).toEqual('Template name is required');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('renders input and textarea when editing template', () => {
|
|
94
|
+
let component = buildComponent(defaultProps);
|
|
95
|
+
expect(component.find(DisableableInput).length).toEqual(0);
|
|
96
|
+
expect(component.find(DisableableTextarea).length).toEqual(0);
|
|
97
|
+
|
|
98
|
+
component = buildComponent({
|
|
99
|
+
...defaultProps,
|
|
100
|
+
editedTemplateName: 'edited name',
|
|
101
|
+
editedTemplateValue: 'edited value',
|
|
102
|
+
});
|
|
103
|
+
expect(component.find(DisableableInput).length).toEqual(1);
|
|
104
|
+
expect(component.find(DisableableTextarea).length).toEqual(1);
|
|
105
|
+
});
|
|
106
|
+
});
|