@hestia-earth/ui-components 0.43.14 → 0.43.16

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.
@@ -515,6 +515,11 @@ const distributionSourceMessage = {
515
515
  posterior: 'This was flagged against HESTIA Cycle data for this product in this country.'
516
516
  };
517
517
  const isMigrationError = ({ params }) => params?.current && 'expected' in params;
518
+ /**
519
+ * "Check the Emission value you provided" — the term's own type names what to look at, and it is
520
+ * dropped entirely when the error carries no term, so the sentence never reads "the N/A value".
521
+ */
522
+ const termTypeValueLabel = (term) => [term?.termType ? termTypeLabel(term.termType) : '', 'value'].filter(Boolean).join(' ');
518
523
  /**
519
524
  * Builds the error formatting functions for a given presentation (`renderer`) and link
520
525
  * configuration (`urls`). The error catalog below is the single source of truth; the
@@ -531,9 +536,14 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
531
536
  const guideLink = (guidePath, title) => r.link(`${urls.baseUrl()}/guide/${guidePath}`, title);
532
537
  const glossaryTypeLink = (type, text = termTypeLabel(type)) => r.link(`${urls.glossaryBaseUrl()}?termType=${type}`, text);
533
538
  const termLink = ({ id, name }) => r.link(`${urls.baseUrl()}/term/${id}`, name || id);
539
+ const humanizeTermId = (id) => id
540
+ .replace(/([a-z])([A-Z])/g, (_, lower, upper) => `${lower} ${upper.toLowerCase()}`)
541
+ .replace(/^./, (char) => char.toUpperCase());
534
542
  const listAsCode = (values) => (values ?? []).map(value => r.code(value)).join(', ');
535
543
  const joinWithAnd = (values) => values.length > 1 ? `${values.slice(0, -1).join(', ')} and ${values[values.length - 1]}` : values.join('');
536
544
  const listAsCodeWithAnd = (values) => joinWithAnd((values ?? []).map(value => r.code(value)));
545
+ const listAsTermLinksWithAnd = (termIds) => joinWithAnd((termIds ?? []).map(id => termLink({ id })));
546
+ const glossaryQueryLink = (query, type) => r.link(`${urls.glossaryBaseUrl()}?query=${encodeURIComponent(query)}&termType=${type}`, query);
537
547
  const joinValues = (values) => (values || [])
538
548
  .filter(Boolean)
539
549
  .map(value => r.code(value))
@@ -800,7 +810,7 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
800
810
  ${params?.threshold ? `Our threshold is ±${threshold(params?.threshold)}.` : ''}
801
811
  Please either:
802
812
  ${formatList([
803
- 'Check the ${params?.term.termType} value you provided;',
813
+ `Check the ${termTypeValueLabel(params?.term)} you provided;`,
804
814
  'Check the data you provided which is the input into this model;',
805
815
  'Carefully read the documentation to understand if we used a default property as part of the calculations.'
806
816
  ], 'decimal')}`
@@ -850,12 +860,24 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
850
860
  'is too generic': ({ params }) => `You have the following Product ${code(params?.product?.name)} however,
851
861
  you have used a generic ${glossaryTypeLink(params?.term?.termType)} term ${code(params?.term?.name)}.
852
862
  Use a more specific term for the ${glossaryTypeLink(params?.term?.termType)} which reflects the specific ${glossaryTypeLink(params?.product?.termType)}.`,
853
- 'should not use identical terms with different units': ({ params }) => `You have added the same ${code(params?.term?.termType)} in ${params?.units
854
- ?.map(unit => code(unit))
855
- .join(' and ')} units.
856
- If these terms refer to the same ${code(params?.term?.termType)}, this will lead to double counting.${params?.units?.includes('kg N')
857
- ? ` Instead use the ${termLink({ id: 'nitrogenContent', name: 'Nitrogen Content' })} Property on the ${code('kg')} term to define the nitrogen content of the ${code(params?.term?.termType)}.`
858
- : ''}`,
863
+ 'should not use several terms describing the same product': ({ params }) => {
864
+ const isFertiliser = params?.term?.termType === TermTermType.organicFertiliser;
865
+ const blankNode = isFertiliser ? 'Input' : 'Product';
866
+ const subject = isFertiliser ? 'the same application' : 'the same animals';
867
+ const fix = isFertiliser
868
+ ? `nutrient content Properties, such as ${termLink({
869
+ id: 'nitrogenContent',
870
+ name: 'Nitrogen Content'
871
+ })}, to state how much of each nutrient it carries`
872
+ : `${glossaryQueryLink('Processing conversion', TermTermType.property)} Properties to state the other weights`;
873
+ return `You have added ${termLink({
874
+ id: params?.term?.['@id'],
875
+ name: params?.term?.name
876
+ })} alongside ${listAsTermLinksWithAnd(params?.termIds)}.
877
+ These ${glossaryTypeLink(params?.term?.termType)} terms are alternative ways of stating the same quantity,
878
+ so if they refer to ${subject}, this will lead to double counting.
879
+ Instead keep a single ${blankNode} and add the relevant ${fix}.`;
880
+ },
859
881
  'is missing required bibliographic information': () => `The automatic bibliography search failed for this Bibliography. Either:
860
882
  ${formatList([
861
883
  `Manually fill-in the ${r.bold('required')} bibliographic information as per ${schemaLink(SchemaType.Bibliography, 'our schema')}.`,
@@ -1106,6 +1128,16 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
1106
1128
  : ''}`,
1107
1129
  'invalid water salinity': ({ params }) => `The water type ${params?.current} is not consistent with the Water salinity you specified.
1108
1130
  Make sure the Water salinity value is correct and either fix it or update the water type accordingly.`,
1131
+ 'requires a water salinity measurement': ({ params: { term, expected } = {} }) => {
1132
+ const measurements = (expected || []).map(id => externalNodeLink({ '@type': NodeType.Term, '@id': id, name: humanizeTermId(id) }));
1133
+ return `You have recorded the product ${code(term?.name || term?.['@id'])}, but this species can be reared in more
1134
+ than one salinity type and does not have a ${code('defaultSalinity')} value, so we cannot gap-fill the salinity
1135
+ of the water.
1136
+ Please specify the salinity of the system by adding ${measurements.length > 0
1137
+ ? `one of ${joinWithAnd(measurements)} to the ${schemaLink('Site#measurements', 'Site measurements')}`
1138
+ : `a water salinity measurement to the ${schemaLink('Site#measurements', 'Site measurements')}`}.
1139
+ This will allow us to model the emissions accurately.`;
1140
+ },
1109
1141
  'measurements for the same termType must be consistent': ({ params }) => `The information you have provided for ${code(params.termType)} Measurements is not consistent across all Measurements.
1110
1142
  Please ensure that all your ${code(params.termType)} Measurements have a ${code('dates')} field if at least one ${code(params.termType)} Measurement has a ${code('dates')} field specified.
1111
1143
  Please also ensure that all your ${code(params.termType)} Measurements have ${code('depthUpper')} and ${code('depthLower')} fields if at least one ${code(params.termType)} Measurement has ${code('depthUpper')} and ${code('depthLower')} fields specified.`,
@@ -1169,6 +1201,12 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
1169
1201
  })}.
1170
1202
  This input should be present in each plantation Cycle in your upload, with the ${code('value')} being the total number of ${code('Saplings')} used divided by the number of possible Cycles in the plantation's lifespan.
1171
1203
  See the ${guideLink('guide-file-upload-special-cases', 'special upload case')} for more details.`,
1204
+ 'must use the depreciated term': ({ params }) => `${code(params.term?.name || params.term?.['@id'])} is used over more than one Cycle, so a Cycle Input must record only the amount depreciated over this Cycle.
1205
+ Use ${termLink({
1206
+ id: params.expected,
1207
+ name: humanizeTermId(params.expected)
1208
+ })} instead, with the ${code('value')} being the total amount used divided by the number of Cycles over its lifespan.
1209
+ Alternatively, record it on the Site as an ${schemaLink('Infrastructure')} input with a ${code('lifespan')}, and HESTIA will calculate the depreciated amount for you.`,
1172
1210
  'must be linked to a verified country-level Impact Assessment': ({ params }) => [
1173
1211
  'This Input must be linked to a country-level verified aggregation, but none could be found.',
1174
1212
  params?.current ? 'Note: using a verified World aggregation is not valid.' : ''