Procházet zdrojové kódy

Fixed so that we can not change base threshold

Hugo Häggmark před 7 roky
rodič
revize
0b1aea905a

+ 15 - 0
packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx

@@ -111,6 +111,21 @@ describe('Remove threshold', () => {
 });
 
 describe('change threshold value', () => {
+  it('should not change threshold at index 0', () => {
+    const thresholds = [
+      { index: 0, value: -Infinity, color: '#7EB26D' },
+      { index: 1, value: 50, color: '#EAB839' },
+      { index: 2, value: 75, color: '#6ED0E0' },
+    ];
+    const instance = setup({ thresholds });
+
+    const mockEvent = { target: { value: 12 } };
+
+    instance.onChangeThresholdValue(mockEvent, thresholds[0]);
+
+    expect(instance.state.thresholds).toEqual(thresholds);
+  });
+
   it('should update value', () => {
     const instance = setup();
     const thresholds = [

+ 4 - 0
packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx

@@ -91,6 +91,10 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
   };
 
   onChangeThresholdValue = (event: any, threshold: Threshold) => {
+    if (threshold.index === 0) {
+      return;
+    }
+
     const { thresholds } = this.state;
 
     const newThresholds = thresholds.map(t => {