Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch/3.6.8 #3508

Open
wants to merge 79 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5188299
Restore indic languages to patch branch
kathyavini Sep 17, 2024
be66259
Merge pull request #3452 from LiteFarmOrg/restore-indic-languages-on-…
kathyavini Sep 17, 2024
a8b6807
Add a healthy gap between day of week buttons for mobile fat fingers …
Duncan-Brain Sep 18, 2024
19e7265
LF-4450 Return getGenderOptionLabel() from hook
kathyavini Sep 18, 2024
ac80ddc
LF-4450 Clean up getDefaultGender()
kathyavini Sep 18, 2024
59d3b01
USes the filterDeleted modifier to creat the repeatable graph
Duncan-Brain Sep 18, 2024
750d01f
LF-4450 Pass namespace in option object
kathyavini Sep 18, 2024
a830f66
LF-4450 Put default value calculating function in hook as well
kathyavini Sep 18, 2024
b4b183a
Use glob import to make future proof language imnporting
Duncan-Brain Sep 18, 2024
6f2bdd6
Add existing locales as base for crowdin despite redundancy
Duncan-Brain Sep 18, 2024
1246a16
Apply the locales directly onto the Calendar component instead of imp…
Duncan-Brain Sep 18, 2024
b2610bc
LF-4436 polyfill datetimeformat
antsgar Sep 19, 2024
2668d96
Merge pull request #3456 from LiteFarmOrg/LF-4450-clean-up-get-gender…
kathyavini Sep 19, 2024
25ff95e
Merge pull request #3455 from LiteFarmOrg/LF-4426-days-of-the-week-co…
kathyavini Sep 19, 2024
6631461
LF-4422 Add AI-translated calendar files for Punjabi and Hindi
kathyavini Sep 19, 2024
117d831
Merge pull request #3459 from LiteFarmOrg/LF-4422-investigate-rc-year…
kathyavini Sep 19, 2024
38f6611
Merge pull request #3453 from LiteFarmOrg/LF-4451-make-new-sensor-imp…
kathyavini Sep 18, 2024
9e52533
Merge pull request #3461 from LiteFarmOrg/LF-4451-make-new-sensor-imp…
kathyavini Sep 19, 2024
1bc8c31
Merge pull request #3465 from LiteFarmOrg/run-api-tests-on-patch-bran…
kathyavini Sep 19, 2024
6a367d3
LF-4449 Format shared sensor validation files
kathyavini Sep 20, 2024
925ac5f
LF-4449 Create validator property additionalVariables and pass the al…
kathyavini Sep 20, 2024
bc6f62e
LF-4449 Use allowed_reading_types variable in error message string
kathyavini Sep 20, 2024
439660d
LF-4436 pass current date if date is undefined in weatherboard
antsgar Sep 20, 2024
a6924b7
Change language after setting language if not already that language
Duncan-Brain Sep 20, 2024
4cbc9c3
New Crowdin translations by GitHub Action
crowdin-bot Sep 20, 2024
0fc58c2
New Crowdin translations by GitHub Action
crowdin-bot Sep 20, 2024
6c429f8
New Crowdin translations by GitHub Action
crowdin-bot Sep 20, 2024
d042c57
Merge pull request #3468 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 20, 2024
8b9565e
Remove ml from PR
kathyavini Sep 20, 2024
53b4293
Remove ml from PR
kathyavini Sep 20, 2024
84a951d
Commit package-lock.json regenerated from npm install
kathyavini Sep 20, 2024
68fa843
Merge pull request #3446 from LiteFarmOrg/l10n_crowdin_translations_p…
Duncan-Brain Sep 20, 2024
45cf491
Merge pull request #3466 from LiteFarmOrg/update-api-tests-github-wor…
Duncan-Brain Sep 20, 2024
56b6ce4
Merge pull request #3469 from LiteFarmOrg/LF-4449-the-user-is-not-abl…
Duncan-Brain Sep 20, 2024
1b503cf
Fix fallback to english
Duncan-Brain Sep 20, 2024
68f102c
Fix fallback to english
Duncan-Brain Sep 20, 2024
e96d9e9
Merge branch 'patch/translations' into LF-4440-cannot-repeat-manageme…
Duncan-Brain Sep 20, 2024
263f968
Bump version number to 3.6.8
Duncan-Brain Sep 23, 2024
d1bc41d
Merge pull request #3467 from LiteFarmOrg/l10n_crowdin_translations_p…
Duncan-Brain Sep 23, 2024
2c0a64c
Merge pull request #3457 from LiteFarmOrg/LF-4440-cannot-repeat-manag…
kathyavini Sep 23, 2024
ba74c82
LF-4436 fix undefined date error
antsgar Sep 23, 2024
5fcc043
Merge pull request #3470 from LiteFarmOrg/LF-4455-on-sso-login-langua…
kathyavini Sep 24, 2024
0de465d
Merge branch 'patch/translations' into LF-4436-Dates-are-not-displaye…
antsgar Sep 24, 2024
9056769
New Crowdin translations by GitHub Action
crowdin-bot Sep 24, 2024
46159fa
Continue to ignore ml for the time being
kathyavini Sep 24, 2024
f83f5d7
Merge pull request #3471 from LiteFarmOrg/LF-4402-fix-fallback
kathyavini Sep 24, 2024
6e859c9
LF-4436 add copyright
antsgar Sep 24, 2024
672a093
Merge pull request #3475 from LiteFarmOrg/l10n_crowdin_translations_p…
antsgar Sep 25, 2024
7a18295
Merge pull request #3472 from LiteFarmOrg/patch/3.6.8-update-version-…
antsgar Sep 25, 2024
8d748f5
Merge pull request #3462 from LiteFarmOrg/LF-4436-Dates-are-not-displ…
Duncan-Brain Sep 25, 2024
13119ff
New Crowdin translations by GitHub Action
crowdin-bot Sep 25, 2024
cd13a2d
New Crowdin translations by GitHub Action
crowdin-bot Sep 25, 2024
e1bcb08
New Crowdin translations by GitHub Action
crowdin-bot Sep 25, 2024
de50469
New Crowdin translations by GitHub Action
crowdin-bot Sep 25, 2024
024e5fb
New Crowdin translations by GitHub Action
crowdin-bot Sep 25, 2024
a2da4e0
Merge pull request #3445 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 25, 2024
70a8622
Merge pull request #3476 from LiteFarmOrg/l10n_crowdin_translations_p…
Duncan-Brain Sep 25, 2024
f5469d4
Merge pull request #3433 from LiteFarmOrg/l10n_crowdin_translations_p…
Duncan-Brain Sep 25, 2024
e939bd3
Keep first pass crop and disease translations for now
kathyavini Sep 25, 2024
32618c3
Merge pull request #3477 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 25, 2024
c26854c
Maintain previous consent files in languages other than ml
kathyavini Sep 25, 2024
d1993b3
Merge pull request #3431 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 25, 2024
833b26e
New Crowdin translations by GitHub Action
crowdin-bot Sep 26, 2024
2e650fe
New Crowdin translations by GitHub Action
crowdin-bot Sep 26, 2024
16a288a
Merge pull request #3479 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 26, 2024
d9401d2
Merge pull request #3480 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 26, 2024
cac5d8b
New Crowdin translations by GitHub Action
crowdin-bot Sep 26, 2024
87ee19e
Merge pull request #3482 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 26, 2024
12d383c
New Crowdin translations by GitHub Action
crowdin-bot Sep 26, 2024
7c73ee2
Merge pull request #3483 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Sep 26, 2024
1972be8
LF-4434 Add ml export server readme PDF
kathyavini Oct 21, 2024
d818907
New Crowdin translations by GitHub Action
crowdin-bot Oct 21, 2024
ca9749b
LF-4434 Add and integrate Welcome Screen
kathyavini Oct 21, 2024
cff41ff
Merge pull request #3504 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Oct 21, 2024
81286ae
New Crowdin translations by GitHub Action
crowdin-bot Oct 21, 2024
a75aecd
Merge pull request #3506 from LiteFarmOrg/LF-4434-complete-malayalam
SayakaOno Oct 21, 2024
7e142a9
Merge pull request #3503 from LiteFarmOrg/l10n_crowdin_translations_p…
kathyavini Oct 21, 2024
b1ae43d
bump formatjs version
antsgar Oct 21, 2024
d081796
Merge pull request #3507 from LiteFarmOrg/formatjs-version-bump
kathyavini Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/automated_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ on:
pull_request:
branches:
- integration
- "patch/**"

jobs:
automated_tests:
runs-on: ubuntu-20.04
container: node:16.15.0
container: node:18.16.1
services:
postgres:
image: postgres:13
Expand Down
3 changes: 2 additions & 1 deletion packages/api/babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
],
"plugins": [
"transform-es2015-modules-commonjs",
"babel-plugin-transform-import-meta"
"babel-plugin-transform-import-meta",
"@babel/plugin-syntax-import-assertions"
]
}
6,454 changes: 5,956 additions & 498 deletions packages/api/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litefarm-api",
"version": "3.6.7",
"version": "3.6.8",
"description": "LiteFarm API server",
"main": "./api/src/server.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/managementPlanController.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const managementPlanController = {
const managementPlanGraph = await ManagementPlanModel.query(trx)
.where('management_plan_id', management_plan_id)
.withGraphFetched(
'crop_management_plan.[planting_management_plans.[managementTasks.[task.[pest_control_task, irrigation_task, scouting_task, soil_task, soil_amendment_task, soil_amendment_task_products.[purpose_relationships], field_work_task, harvest_task, cleaning_task, locationTasks]], plant_task.[task.[locationTasks]], transplant_task.[task.[locationTasks]], bed_method, container_method, broadcast_method, row_method]]',
'crop_management_plan.[planting_management_plans.[managementTasks.[task.[pest_control_task, irrigation_task, scouting_task, soil_task, soil_amendment_task, soil_amendment_task_products(filterDeleted).[purpose_relationships], field_work_task, harvest_task, cleaning_task, locationTasks]], plant_task.[task.[locationTasks]], transplant_task.[task.[locationTasks]], bed_method, container_method, broadcast_method, row_method]]',
)
.modifyGraph(
'crop_management_plan.[planting_management_plans.managementTasks]',
Expand Down
16 changes: 11 additions & 5 deletions packages/api/src/controllers/sensorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ import knex from '../util/knex.js';
const getSensorTranslations = async (language) => {
// Remove country identifier from language preference
const parsedLanguage = language.includes('-') ? language.split('-')[0] : language;
let translations = await import(`../../../shared/locales/${parsedLanguage}/sensorCSV.json`, {
assert: { type: 'json' },
});
// Default to english in case where user language not supported
if (!translations) {
let translations;
try {
translations = await import(`../../../shared/locales/${parsedLanguage}/sensorCSV.json`, {
assert: { type: 'json' },
});
// Default to english in case where user language not supported
if (!translations) {
throw 'Translations not found';
}
} catch (error) {
console.log(error);
translations = await import(`../../../shared/locales/en/sensorCSV.json`, {
assert: { type: 'json' },
});
Expand Down
9 changes: 1 addition & 8 deletions packages/api/src/jobs/locales/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import Backend from 'i18next-fs-backend';
i18n.use(Backend).init(
{
fallbackLng: 'en',
preload: [
'en',
'es',
'pt',
'fr',
'de',
// 'hi', 'pa', 'ml'
],
preload: ['en', 'es', 'pt', 'fr', 'de', 'hi', 'pa', 'ml'],
ns: ['translation', 'crop'],
defaultNS: 'translation',
nsSeparator: ':',
Expand Down
9 changes: 1 addition & 8 deletions packages/api/src/jobs/locales/i18next-parser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@ export default {
output: 'src/jobs/locales/$LOCALE/$NAMESPACE.json',
sort: true,
defaultValue: 'MISSING',
locales: [
'en',
'es',
'pt',
'fr',
'de',
// 'hi', 'pa', 'ml'
],
locales: ['en', 'es', 'pt', 'fr', 'de', 'hi', 'pa', 'ml'],
};
Binary file added packages/api/src/jobs/locales/ml/readme.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/api/src/jobs/locales/ml/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"EXPORT_README_TITLE": "നിങ്ങളുടെ സർട്ടിഫിക്കേഷൻ എക്സ്പോർറ്റ് മനസ്സിലാക്കുന്നു",
"EXPORT_README_TITLE": "നിങ്ങളുടെ സർട്ടിഫിക്കേഷൻ എക്സ്‌പോർട്ട് മനസ്സിലാക്കുന്നു",
"N": "ഇല്ല",
"N/A": "ബാധകമല്ല",
"NO": "ഇല്ല",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (process.env.SENTRY_DSN && environment !== 'development') {
// Automatically instrument Node.js libraries and frameworks
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
release: '3.6.7',
release: '3.6.8',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
Expand Down
5 changes: 2 additions & 3 deletions packages/api/src/templates/locales/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
"PRIVACY": "ലൈറ്റ്ഫാമിൽ, ഞങ്ങൾ നിങ്ങളുടെ സ്വകാര്യത ഗൗരവമായി കാണുന്നു, അതിനാൽ നിങ്ങളുടെ എക്സ്പോർറ്റ് ആക്‌സസ് ചെയ്യുന്നതിന് മുമ്പ് നിങ്ങൾ ലോഗിൻ ചെയ്യേണ്ടതുണ്ട്. എന്തെങ്കിലും അസൗകര്യം ഉണ്ടായതിൽ ഖേദിക്കുന്നു. നിങ്ങളുടെ സമർപ്പണത്തിന് ആശംസകൾ, ലൈറ്റ്ഫാം ഉപയോഗിച്ചതിന് നന്ദി!",
"SUBJECT": "ലൈറ്റ്ഫാമിൽ നിന്ന് നിങ്ങളുടെ സർട്ടിഫിക്കേഷൻ രേഖകൾ എക്സ്പോർറ്റ് ചെയ്യുന്നു",
"HI": "നമസ്തേ",
"GET_YOUR_EXPORT": "രേഖകൾ നേടുക",
"LANGUAGE_DELAY": ""
"GET_YOUR_EXPORT": "രേഖകൾ നേടുക"
},
"COMMON": {
"JOIN": "ചേരുക",
Expand All @@ -102,4 +101,4 @@
"WORKER": "തൊഴിലാളി",
"EXTENSION_OFFICER": "എക്സ്റ്റൻഷൻ ഓഫീസർ"
}
}
}
9 changes: 1 addition & 8 deletions packages/api/src/templates/sendEmailTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ const emailTransporter = new EmailTemplates({
root: path.join(dir, 'emails'),
},
i18n: {
locales: [
'en',
'es',
'fr',
'pt',
'de',
// 'hi', 'pa', 'ml'
],
locales: ['en', 'es', 'fr', 'pt', 'de', 'hi', 'pa', 'ml'],
directory: path.join(dir, 'locales'),
objectNotation: true,
},
Expand Down
17 changes: 17 additions & 0 deletions packages/shared/locales/hi/sensorCSV.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"CSV_HEADER_TRANSLATIONS": {
"name": "नाम",
"latitude": "अक्षांश",
"longitude": "देशांतर",
"reading_types": "पठन_प्रकार",
"external_id": "बाह्य_ID",
"depth": "गहराई_सेमी",
"brand": "ब्रांड",
"model": "मॉडल"
},
"READING_TYPE_TRANSLATIONS": {
"soil_water_content": "मृदा_जल_सामग्री",
"soil_water_potential": "मृदा_जल_क्षमता",
"temperature": "तापमान"
}
}
17 changes: 17 additions & 0 deletions packages/shared/locales/ml/sensorCSV.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"CSV_HEADER_TRANSLATIONS": {
"name": "പേര്",
"latitude": "അക്ഷാംശം",
"longitude": "രേഖാംശം",
"reading_types": "വായന_തരങ്ങൾ",
"external_id": "ബാഹ്യ_ഐഡി",
"depth": "ആഴം_സെ.മീ",
"brand": "ബ്രാൻഡ്",
"model": "മോഡൽ"
},
"READING_TYPE_TRANSLATIONS": {
"soil_water_content": "മണ്ണ്_ജലം_ഉള്ളടക്കം",
"soil_water_potential": "മണ്ണ്_ജലം_ ശേഷി",
"temperature": "താപനില"
}
}
17 changes: 17 additions & 0 deletions packages/shared/locales/pa/sensorCSV.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"CSV_HEADER_TRANSLATIONS": {
"name": "ਨਾਮ",
"latitude": "ਵਿਥਕਾਰ",
"longitude": "ਲੰਬਕਾਰ",
"reading_types": "ਪੜ੍ਹਨਾ_ਕਿਸਮਾਂ",
"external_id": "ਬਾਹਰੀ_ID",
"depth": "ਡੂੰਘਾਈ_ਸੈ.ਮੀ",
"brand": "ਬ੍ਰਾਂਡ",
"model": "ਮਾਡਲ"
},
"READING_TYPE_TRANSLATIONS": {
"soil_water_content": "ਮਿੱਟੀ_ਪਾਣੀ_ਸਮੱਗਰੀ",
"soil_water_potential": "ਮਿੱਟੀ_ਪਾਣੀ_ਸੰਭਾਵੀ",
"temperature": "ਤਾਪਮਾਨ"
}
}
49 changes: 33 additions & 16 deletions packages/shared/validation/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ const parseCsv = (
lang,
validators,
headerTranslations,
missingColumnsErrorKey = 'MISSING_COLUMNS',
missingColumnsErrorKey = "MISSING_COLUMNS",
validateUniqueDataKeys = true,
getDataKeyFromRow = (r) => r[validators[0].key],
maxRows = null,
delimiter = ',',
delimiter = ","
) => {
// regex checks for delimiters that are not contained within quotation marks
const regex = new RegExp(`(?!\\B"[^"]*)${delimiter}(?![^"]*"\\B)`)
const regex = new RegExp(`(?!\\B"[^"]*)${delimiter}(?![^"]*"\\B)`);

// check if the length of the string is 0 or if the string contains no line returns
if (csvString.length === 0 || !/\r\b|\r|\n/.test(csvString)) {
return { data: [], errors: [] };
}

const rows = csvString.split(/\r\n|\r|\n/).filter((elem) => elem !== '');
const rows = csvString.split(/\r\n|\r|\n/).filter((elem) => elem !== "");

if (rows.length === 0) {
return { data: [], errors: []}
return { data: [], errors: [] };
}

const headers = rows[0].split(regex).map((h) => h.trim());
Expand All @@ -77,7 +77,11 @@ const parseCsv = (
const headerErrors = [];
requiredHeaders.forEach((header) => {
if (!headers.includes(header)) {
headerErrors.push({ row: 1, column: header, translation_key: missingColumnsErrorKey });
headerErrors.push({
row: 1,
column: header,
translation_key: missingColumnsErrorKey,
});
}
});
if (headerErrors.length > 0) {
Expand All @@ -96,17 +100,21 @@ const parseCsv = (
{
row: 1,
column: "N/A",
translation_key: 'FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.FILE_ROW_LIMIT_EXCEEDED',
value: ""
}
]
}
translation_key:
"FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.FILE_ROW_LIMIT_EXCEEDED",
value: "",
},
],
};
}
// Set to keep track of the unique keys - used to make sure only one data entry is uploaded
// with a particular key defined by getDataKeyFromRow if duplicates are in the file
const uniqueDataKeys = new Set();

const headerMapping = getHeaderToValidatorMapping(validators, headerTranslations);
const headerMapping = getHeaderToValidatorMapping(
validators,
headerTranslations
);

const { data, errors } = dataRows.reduce(
(previous, row, rowIndex) => {
Expand All @@ -115,16 +123,25 @@ const parseCsv = (
const currentValidator = validators[headerMapping[current]];
if (allowedHeaders.includes(current)) {
// remove any surrounding quotation marks
const val = values[index].replace(/^(["'])(.*)\1$/, '$2');
const parsedVal = currentValidator.parse(values[index].replace(/^(["'])(.*)\1$/, '$2'), lang);
const val = values[index].replace(/^(["'])(.*)\1$/, "$2");
const parsedVal = currentValidator.parse(
values[index].replace(/^(["'])(.*)\1$/, "$2"),
lang
);
if (currentValidator.validate(parsedVal)) {
previousObj[currentValidator.key] = parsedVal;
} else {
previous.errors.push({
row: rowIndex + 2,
column: current,
translation_key: currentValidator.errorTranslationKey,
variables: { [currentValidator.key]: currentValidator.key.useParsedValForError ? parsedVal : val },
variables: {
[currentValidator.key]: currentValidator.key
.useParsedValForError
? parsedVal
: val,
...(currentValidator.additionalVariables ?? {}),
},
});
}
}
Expand All @@ -142,7 +159,7 @@ const parseCsv = (
}
return previous;
},
{ data: [], errors: [] },
{ data: [], errors: [] }
);

return { data, errors };
Expand Down
45 changes: 34 additions & 11 deletions packages/shared/validation/sensorCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ import parseCsv from "./csv.js";

// Sensor bulk upload error translation keys
export const sensorErrors = {
FILE_ROW_LIMIT_EXCEEDED: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.FILE_ROW_LIMIT_EXCEEDED",
FILE_ROW_LIMIT_EXCEEDED:
"FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.FILE_ROW_LIMIT_EXCEEDED",
MISSING_COLUMNS: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.MISSING_COLUMNS",
EXTERNAL_ID: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.EXTERNAL_ID",
SENSOR_NAME: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_NAME",
SENSOR_LATITUDE: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_LATITUDE",
SENSOR_LONGITUDE: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_LONGITUDE",
SENSOR_READING_TYPES: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_READING_TYPES",
SENSOR_READING_TYPES:
"FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_READING_TYPES",
SENSOR_DEPTH: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_DEPTH",
SENSOR_BRAND: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_BRAND",
SENSOR_MODEL: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_MODEL",
SENSOR_HARDWARE_VERSION: "FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_HARDWARE_VERSION",
SENSOR_ALREADY_OCCUPIED: "FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.ALREADY_OCCUPIED",
SENSOR_DOES_NOT_EXIST: "FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.DOES_NOT_EXIST",
INTERNAL_ERROR: "FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.INTERNAL_ERROR",
SENSOR_HARDWARE_VERSION:
"FARM_MAP.BULK_UPLOAD_SENSORS.VALIDATION.SENSOR_HARDWARE_VERSION",
SENSOR_ALREADY_OCCUPIED:
"FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.ALREADY_OCCUPIED",
SENSOR_DOES_NOT_EXIST:
"FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.DOES_NOT_EXIST",
INTERNAL_ERROR:
"FARM_MAP.BULK_UPLOAD_SENSORS.SENSOR_CLAIM_ERROR.INTERNAL_ERROR",
};

const sensorCsvValidators = (translations) => {
Expand Down Expand Up @@ -71,18 +77,33 @@ const sensorCsvValidators = (translations) => {
key: "reading_types",
parse: (val, lang) => {
const rawReadingTypes = val.replaceAll(" ", "").split(",");
return getReadableValuesForReadingTypes(lang, rawReadingTypes, translations);
return getReadableValuesForReadingTypes(
lang,
rawReadingTypes,
translations
);
},
validate: (val) => {
if (!val.length || (val.length === 1 && val[0] === "")) {
return false;
}
const allowedReadingTypes = ["soil_water_potential", "soil_water_content", "temperature"];
return val.every((readingType) => allowedReadingTypes.includes(readingType));
const allowedReadingTypes = [
"soil_water_potential",
"soil_water_content",
"temperature",
];
return val.every((readingType) =>
allowedReadingTypes.includes(readingType)
);
},
required: true,
errorTranslationKey: sensorErrors.SENSOR_READING_TYPES,
useParsedValForError: false,
additionalVariables: {
allowed_reading_types: Object.values(
translations.READING_TYPE_TRANSLATIONS
).join(", "),
},
},
{
key: "depth",
Expand Down Expand Up @@ -113,7 +134,9 @@ const sensorCsvValidators = (translations) => {

// Returns the readable values to save in the database based on the given translated reading types
const getReadableValuesForReadingTypes = (lang, readingTypes, translations) => {
const translationEntries = Object.entries(translations.READING_TYPE_TRANSLATIONS);
const translationEntries = Object.entries(
translations.READING_TYPE_TRANSLATIONS
);
return readingTypes.map((rt) => {
const entryWithReadableValue = translationEntries.find((e) => e[1] === rt);
return entryWithReadableValue ? entryWithReadableValue[0] : null;
Expand All @@ -137,7 +160,7 @@ export const parseSensorCsv = (csvString, lang, translations) => {
sensorErrors.MISSING_COLUMNS,
true,
generateSensorKey,
100,
100
);
};

Expand Down
Loading