@eturnity/eturnity_reusable_components 8.16.9-EPDM-14690.2 → 8.16.9-EPDM-14690.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "8.16.9-EPDM-14690.2",
3
+ "version": "8.16.9-EPDM-14690.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -33,10 +33,8 @@
33
33
  <InputNumber
34
34
  :allow-negative="false"
35
35
  :disabled="isInputsDisabled"
36
- :error-message="null"
37
36
  input-height="36px"
38
- :is-border-error-only="true"
39
- :is-error="
37
+ :is-info-border="
40
38
  fieldMode === 'percentage'
41
39
  ? calculatePercentageTotal(item.label) !== 100
42
40
  : false
@@ -83,10 +81,9 @@
83
81
  :is-scrollable="isScrollable"
84
82
  >
85
83
  <InputNumber
86
- :error-message="$gettext('load_profile_not_add_up_to_100')"
87
84
  input-height="36px"
88
85
  :is-border-error-only="true"
89
- :is-error="
86
+ :is-info-border="
90
87
  fieldMode === 'percentage'
91
88
  ? calculatePercentageTotal(item.label) !== 100
92
89
  : false
@@ -127,11 +124,22 @@
127
124
  </FieldsWrapper>
128
125
  </FieldsContainer>
129
126
  </Container>
127
+ <InfoCardContainer
128
+ v-if="hasAnySegmentNotTotatTo100Percent && fieldMode === 'percentage'"
129
+ :yAxisWidth="yAxisWidth"
130
+ >
131
+ <InfoCard align-items="center" type="info">
132
+ <InfoCardBody>
133
+ {{ $gettext('load_profile_not_add_up_to_100') }}
134
+ </InfoCardBody>
135
+ </InfoCard>
136
+ </InfoCardContainer>
130
137
  </template>
131
138
 
132
139
  <script setup>
133
- import { ref, watch, watchEffect, onMounted } from 'vue'
140
+ import { ref, computed, watchEffect } from 'vue'
134
141
  import InputNumber from '../inputs/inputNumber'
142
+ import InfoCard from '../infoCard'
135
143
 
136
144
  import {
137
145
  Container,
@@ -143,6 +151,8 @@
143
151
  InputRow,
144
152
  TotalInputRow,
145
153
  InputGroup,
154
+ InfoCardContainer,
155
+ InfoCardBody,
146
156
  } from './styles/bottomFields'
147
157
 
148
158
  const props = defineProps({
@@ -207,6 +217,7 @@
207
217
  const data = item.data.map((d, dIndex) => ({
208
218
  label: d.label,
209
219
  value: d.value,
220
+ percentage: d.percentage,
210
221
  originalValue: currentSeriesData.length
211
222
  ? currentSeriesData[itemIndex].data[dIndex].originalValue
212
223
  : d.value,
@@ -266,58 +277,27 @@
266
277
  return data.find((d) => d.label === label)?.value
267
278
  }
268
279
 
269
- const value = data.find((d) => d.label === label)?.value || 0
270
-
271
- const total = seriesData.value.reduce((sum, series) => {
272
- const value =
273
- series.data.find((d) => d.label === label)?.originalValue || 0
274
- return sum + value
275
- }, 0)
276
-
277
- return shouldRound ? (value / total) * 100 : (value / total) * 100
280
+ return data.find((d) => d.label === label)?.percentage
278
281
  }
279
282
 
280
283
  const calculatePercentageTotal = (label) => {
281
- const originalTotal = seriesData.value.reduce((sum, series) => {
282
- const originalValue =
283
- series.data.find((d) => d.label === label)?.originalValue || 0
284
- return sum + originalValue
285
- }, 0)
286
-
287
- const totalPercentage = seriesData.value.reduce((sum, series) => {
288
- const value = series.data.find((d) => d.label === label)?.value || 0
289
- const percentage = originalTotal
290
- ? Number((value / originalTotal) * 100)
291
- : 0
284
+ const percentageTotal = seriesData.value.reduce((sum, series) => {
285
+ const percentage =
286
+ series.data.find((d) => d.label === label)?.percentage || 0
292
287
  return sum + percentage
293
288
  }, 0)
294
289
 
295
- return Math.round(totalPercentage)
290
+ return Math.round(percentageTotal)
296
291
  }
297
292
 
298
293
  const handleInputBlur = (_value, seriesName, label, currentSeriesData) => {
299
294
  let value = Number(_value)
300
295
 
301
- if (props.fieldMode === 'percentage') {
302
- const total = seriesData.value.reduce((sum, series) => {
303
- const value =
304
- series.data.find((d) => d.label === label)?.originalValue || 0
305
- return sum + value
306
- }, 0)
307
-
308
- value = (value / 100) * total
309
- }
310
-
311
296
  const payload = seriesName
312
297
  ? {
313
298
  seriesName,
314
299
  label,
315
300
  value,
316
- inputValue: _value,
317
- percentage: Number(
318
- getDisplayValue(currentSeriesData, label, false).toFixed(2)
319
- ),
320
- totalSeriesValue: calculateTotalOriginalValue(label),
321
301
  }
322
302
  : { label, value }
323
303
  emit('input-blur', payload)
@@ -345,15 +325,16 @@
345
325
  }
346
326
  }
347
327
 
328
+ const hasAnySegmentNotTotatTo100Percent = computed(() => {
329
+ return props.data.some((d) => {
330
+ return calculatePercentageTotal(d.label) !== 100
331
+ })
332
+ })
333
+
348
334
  const handleFieldsScroll = (event) => {
349
335
  emit('sync-scroll', event.target.scrollLeft)
350
336
  }
351
337
 
352
- const toFixedNoRounding = (number, decimals) => {
353
- const factor = Math.pow(10, decimals)
354
- return Math.floor(number * factor) / factor
355
- }
356
-
357
338
  defineExpose({
358
339
  syncScroll,
359
340
  })
@@ -68,3 +68,13 @@ export const InputGroup = styled('div', {
68
68
  border: 1px solid ${(props) => props.theme.colors.grey4} !important;
69
69
  }
70
70
  `
71
+
72
+ export const InfoCardContainer = styled('div', { yAxisWidth: String })`
73
+ margin-left: ${(props) => props.yAxisWidth};
74
+ padding: 12px;
75
+ margin-top: 12px;
76
+ `
77
+
78
+ export const InfoCardBody = styled.div`
79
+ padding: 8px 0;
80
+ `
@@ -73,7 +73,12 @@
73
73
  type: {
74
74
  required: false,
75
75
  type: String,
76
- default: 'info',
76
+ default: 'info_simple',
77
+ validator(value) {
78
+ return ['info_simple', 'warning', 'error_minor', 'info'].includes(
79
+ value
80
+ )
81
+ },
77
82
  },
78
83
  minWidth: {
79
84
  required: false,
@@ -112,8 +117,11 @@
112
117
  },
113
118
  },
114
119
  computed: {
115
- isInfo() {
120
+ isInfoSimple() {
116
121
  // this property is used for tests
122
+ return this.type === 'info_simple'
123
+ },
124
+ isInfo() {
117
125
  return this.type === 'info'
118
126
  },
119
127
  isWarning() {
@@ -144,9 +152,13 @@
144
152
  stylesCollection.borderStyle = 'dashed'
145
153
  stylesCollection.borderColor = theme.colors.pureRed
146
154
  stylesCollection.iconColor = theme.colors.pureRed
147
- } else {
155
+ } else if (this.isInfoSimple) {
148
156
  stylesCollection.borderStyle = 'dashed'
149
157
  stylesCollection.borderColor = theme.colors.grey4
158
+ } else {
159
+ stylesCollection.color = theme.semanticColors.teal[800]
160
+ stylesCollection.backgroundColor = theme.semanticColors.blue[300]
161
+ stylesCollection.iconColor = theme.semanticColors.teal[800]
150
162
  }
151
163
 
152
164
  return stylesCollection
@@ -45,19 +45,19 @@ describe('RCInfoCard.vue', () => {
45
45
  },
46
46
  })
47
47
 
48
- expect(wrapper.vm.isInfo).toBe(true)
48
+ expect(wrapper.vm.isInfoSimple).toBe(true)
49
49
  expect(wrapper.vm.isWarning).toBe(false)
50
50
  expect(wrapper.vm.isErrorMinor).toBe(false)
51
51
 
52
52
  await wrapper.setProps({ type: 'warning' })
53
53
 
54
- expect(wrapper.vm.isInfo).toBe(false)
54
+ expect(wrapper.vm.isInfoSimple).toBe(false)
55
55
  expect(wrapper.vm.isWarning).toBe(true)
56
56
  expect(wrapper.vm.isErrorMinor).toBe(false)
57
57
 
58
58
  await wrapper.setProps({ type: 'error_minor' })
59
59
 
60
- expect(wrapper.vm.isInfo).toBe(false)
60
+ expect(wrapper.vm.isInfoSimple).toBe(false)
61
61
  expect(wrapper.vm.isWarning).toBe(false)
62
62
  expect(wrapper.vm.isErrorMinor).toBe(true)
63
63
  })
@@ -53,6 +53,7 @@
53
53
  :is-border-error-only="isBorderErrorOnly"
54
54
  :is-disabled="disabled"
55
55
  :is-error="isError"
56
+ :is-info-border="isInfoBorder"
56
57
  :is-interactive="isInteractive"
57
58
  :min-width="minWidth"
58
59
  :no-border="noBorder"
@@ -210,6 +211,7 @@
210
211
  showArrowControls: Boolean,
211
212
  readOnly: Boolean,
212
213
  isBorderErrorOnly: Boolean,
214
+ isInfoBorder: Boolean,
213
215
  }
214
216
 
215
217
  const Container = styled('div', inputProps)`
@@ -222,7 +224,9 @@
222
224
 
223
225
  const InputContainer = styled('input', inputProps)`
224
226
  border: ${(props) =>
225
- props.isError
227
+ props.isInfoBorder
228
+ ? '1px solid ' + props.theme.semanticColors.blue[500]
229
+ : props.isError
226
230
  ? '1px solid ' + props.theme.colors.red
227
231
  : props.noBorder
228
232
  ? 'none'
@@ -708,6 +712,10 @@
708
712
  type: Boolean,
709
713
  default: false,
710
714
  },
715
+ isInfoBorder: {
716
+ type: Boolean,
717
+ default: false,
718
+ },
711
719
  },
712
720
  data() {
713
721
  return {