@hestia-earth/ui-components 0.43.13 → 0.43.15

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.
@@ -531,9 +531,14 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
531
531
  const guideLink = (guidePath, title) => r.link(`${urls.baseUrl()}/guide/${guidePath}`, title);
532
532
  const glossaryTypeLink = (type, text = termTypeLabel(type)) => r.link(`${urls.glossaryBaseUrl()}?termType=${type}`, text);
533
533
  const termLink = ({ id, name }) => r.link(`${urls.baseUrl()}/term/${id}`, name || id);
534
+ const humanizeTermId = (id) => id
535
+ .replace(/([a-z])([A-Z])/g, (_, lower, upper) => `${lower} ${upper.toLowerCase()}`)
536
+ .replace(/^./, (char) => char.toUpperCase());
534
537
  const listAsCode = (values) => (values ?? []).map(value => r.code(value)).join(', ');
535
538
  const joinWithAnd = (values) => values.length > 1 ? `${values.slice(0, -1).join(', ')} and ${values[values.length - 1]}` : values.join('');
536
539
  const listAsCodeWithAnd = (values) => joinWithAnd((values ?? []).map(value => r.code(value)));
540
+ const listAsTermLinksWithAnd = (termIds) => joinWithAnd((termIds ?? []).map(id => termLink({ id })));
541
+ const glossaryQueryLink = (query, type) => r.link(`${urls.glossaryBaseUrl()}?query=${encodeURIComponent(query)}&termType=${type}`, query);
537
542
  const joinValues = (values) => (values || [])
538
543
  .filter(Boolean)
539
544
  .map(value => r.code(value))
@@ -850,12 +855,24 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
850
855
  'is too generic': ({ params }) => `You have the following Product ${code(params?.product?.name)} however,
851
856
  you have used a generic ${glossaryTypeLink(params?.term?.termType)} term ${code(params?.term?.name)}.
852
857
  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
- : ''}`,
858
+ 'should not use several terms describing the same product': ({ params }) => {
859
+ const isFertiliser = params?.term?.termType === TermTermType.organicFertiliser;
860
+ const blankNode = isFertiliser ? 'Input' : 'Product';
861
+ const subject = isFertiliser ? 'the same application' : 'the same animals';
862
+ const fix = isFertiliser
863
+ ? `nutrient content Properties, such as ${termLink({
864
+ id: 'nitrogenContent',
865
+ name: 'Nitrogen Content'
866
+ })}, to state how much of each nutrient it carries`
867
+ : `${glossaryQueryLink('Processing conversion', TermTermType.property)} Properties to state the other weights`;
868
+ return `You have added ${termLink({
869
+ id: params?.term?.['@id'],
870
+ name: params?.term?.name
871
+ })} alongside ${listAsTermLinksWithAnd(params?.termIds)}.
872
+ These ${glossaryTypeLink(params?.term?.termType)} terms are alternative ways of stating the same quantity,
873
+ so if they refer to ${subject}, this will lead to double counting.
874
+ Instead keep a single ${blankNode} and add the relevant ${fix}.`;
875
+ },
859
876
  'is missing required bibliographic information': () => `The automatic bibliography search failed for this Bibliography. Either:
860
877
  ${formatList([
861
878
  `Manually fill-in the ${r.bold('required')} bibliographic information as per ${schemaLink(SchemaType.Bibliography, 'our schema')}.`,
@@ -1106,6 +1123,16 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
1106
1123
  : ''}`,
1107
1124
  'invalid water salinity': ({ params }) => `The water type ${params?.current} is not consistent with the Water salinity you specified.
1108
1125
  Make sure the Water salinity value is correct and either fix it or update the water type accordingly.`,
1126
+ 'requires a water salinity measurement': ({ params: { term, expected } = {} }) => {
1127
+ const measurements = (expected || []).map(id => externalNodeLink({ '@type': NodeType.Term, '@id': id, name: humanizeTermId(id) }));
1128
+ return `You have recorded the product ${code(term?.name || term?.['@id'])}, but this species can be reared in more
1129
+ than one salinity type and does not have a ${code('defaultSalinity')} value, so we cannot gap-fill the salinity
1130
+ of the water.
1131
+ Please specify the salinity of the system by adding ${measurements.length > 0
1132
+ ? `one of ${joinWithAnd(measurements)} to the ${schemaLink('Site#measurements', 'Site measurements')}`
1133
+ : `a water salinity measurement to the ${schemaLink('Site#measurements', 'Site measurements')}`}.
1134
+ This will allow us to model the emissions accurately.`;
1135
+ },
1109
1136
  '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
1137
  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
1138
  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 +1196,12 @@ const createErrorFormatter = ({ renderer: r, urls }) => {
1169
1196
  })}.
1170
1197
  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
1198
  See the ${guideLink('guide-file-upload-special-cases', 'special upload case')} for more details.`,
1199
+ '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.
1200
+ Use ${termLink({
1201
+ id: params.expected,
1202
+ name: humanizeTermId(params.expected)
1203
+ })} instead, with the ${code('value')} being the total amount used divided by the number of Cycles over its lifespan.
1204
+ 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
1205
  'must be linked to a verified country-level Impact Assessment': ({ params }) => [
1173
1206
  'This Input must be linked to a country-level verified aggregation, but none could be found.',
1174
1207
  params?.current ? 'Note: using a verified World aggregation is not valid.' : ''