From 1e810daabc55f87c4ed5c759ca706f3ef457f307 Mon Sep 17 00:00:00 2001 From: Liordino Neto Date: Fri, 21 Aug 2020 12:12:16 -0300 Subject: [PATCH] refactor: ramda function replacements to cleanup the code --- new-lamassu-admin/src/pages/Locales/helper.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/new-lamassu-admin/src/pages/Locales/helper.js b/new-lamassu-admin/src/pages/Locales/helper.js index f8415cc4..5c1fb79e 100644 --- a/new-lamassu-admin/src/pages/Locales/helper.js +++ b/new-lamassu-admin/src/pages/Locales/helper.js @@ -22,13 +22,6 @@ const allFields = (getData, auxElements = []) => { )(data) } - const findSuggestion = (it, machines) => { - const machine = R.compose(R.find(R.propEq('deviceId', it?.machine)))( - machines - ) - return machine ? [machine] : [] - } - const displayCodeArray = data => it => { if (!it) return it @@ -36,9 +29,9 @@ const allFields = (getData, auxElements = []) => { } const overridenMachines = R.map(override => override.machine, auxElements) - const suggestionFilter = R.filter( - it => !R.contains(it.deviceId, overridenMachines) - ) + + const suggestionFilter = it => + R.differenceWith((x, y) => x.deviceId === y, it, overridenMachines) const machineData = getData(['machines']) const countryData = getData(['countries']) @@ -54,9 +47,8 @@ const allFields = (getData, auxElements = []) => { input: Autocomplete, inputProps: { options: it => - R.concat( - suggestionFilter(machineData), - findSuggestion(it, machineData) + R.concat(it?.machine ? [it.machine] : [])( + suggestionFilter(machineData) ), valueProp: 'deviceId', getLabel: R.path(['name']),