Reformat all project files to use the prettier config file.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {uniqBy} from "lodash";
|
||||
import { uniqBy } from "lodash";
|
||||
|
||||
/**
|
||||
* Get value from path
|
||||
@@ -6,7 +6,7 @@ import {uniqBy} from "lodash";
|
||||
* @param path
|
||||
* @returns {*}
|
||||
*/
|
||||
const getValueFromPath = (obj, path) => path.split('.').reduce((prev, curr) => prev?.[curr], obj);
|
||||
const getValueFromPath = (obj, path) => path.split(".").reduce((prev, curr) => prev?.[curr], obj);
|
||||
|
||||
/**
|
||||
* Generate options from array
|
||||
@@ -15,12 +15,15 @@ const getValueFromPath = (obj, path) => path.split('.').reduce((prev, curr) => p
|
||||
* @returns {unknown[]}
|
||||
*/
|
||||
const generateOptionsFromArray = (bodyshop, path) => {
|
||||
const options = getValueFromPath(bodyshop, path);
|
||||
return uniqBy(options.map((value) => ({
|
||||
label: value,
|
||||
value: value,
|
||||
})), 'value');
|
||||
}
|
||||
const options = getValueFromPath(bodyshop, path);
|
||||
return uniqBy(
|
||||
options.map((value) => ({
|
||||
label: value,
|
||||
value: value
|
||||
})),
|
||||
"value"
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Valid internal reflections
|
||||
@@ -28,12 +31,12 @@ const generateOptionsFromArray = (bodyshop, path) => {
|
||||
* @type {{special: string[], bodyshop: [{name: string, type: string}]}}
|
||||
*/
|
||||
const VALID_INTERNAL_REFLECTIONS = {
|
||||
bodyshop: [
|
||||
{
|
||||
name: 'md_ro_statuses.statuses',
|
||||
type: 'kv-to-v'
|
||||
}
|
||||
],
|
||||
bodyshop: [
|
||||
{
|
||||
name: "md_ro_statuses.statuses",
|
||||
type: "kv-to-v"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -45,12 +48,15 @@ const VALID_INTERNAL_REFLECTIONS = {
|
||||
* @returns {{label: *, value: *}[]}
|
||||
*/
|
||||
const generateOptionsFromObject = (bodyshop, path, labelPath, valuePath) => {
|
||||
const options = getValueFromPath(bodyshop, path);
|
||||
return uniqBy(Object.values(options).map((value) => ({
|
||||
label: value[labelPath],
|
||||
value: value[valuePath],
|
||||
})), 'value');
|
||||
}
|
||||
const options = getValueFromPath(bodyshop, path);
|
||||
return uniqBy(
|
||||
Object.values(options).map((value) => ({
|
||||
label: value[labelPath],
|
||||
value: value[valuePath]
|
||||
})),
|
||||
"value"
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate special reflections
|
||||
@@ -60,66 +66,69 @@ const generateOptionsFromObject = (bodyshop, path, labelPath, valuePath) => {
|
||||
* @returns {{label: *, value: *}[]|{label: *, value: *}[]|{label: string, value: *}[]|*[]}
|
||||
*/
|
||||
const generateSpecialReflections = (bodyshop, finalPath, t) => {
|
||||
switch (finalPath) {
|
||||
case 'payment_payers':
|
||||
return [
|
||||
{
|
||||
label: t("payments.labels.customer"),
|
||||
value: t("payments.labels.customer"),
|
||||
},
|
||||
{
|
||||
label: t("payments.labels.insurance"),
|
||||
value: t("payments.labels.insurance"),
|
||||
},
|
||||
// This is a weird one supposedly only used by one shop and could potentially be
|
||||
// placed behind a SplitSDK
|
||||
{
|
||||
label: t("payments.labels.external"),
|
||||
value: t("payments.labels.external"),
|
||||
}
|
||||
];
|
||||
case 'payment_types':
|
||||
return generateOptionsFromArray(bodyshop, 'md_payment_types');
|
||||
case 'alt_transports':
|
||||
return generateOptionsFromArray(bodyshop, 'appt_alt_transport');
|
||||
case 'lost_sale_reasons':
|
||||
return generateOptionsFromArray(bodyshop, 'md_lost_sale_reasons');
|
||||
// Special case because Referral Sources is an Array, not an Object.
|
||||
case 'referral_source':
|
||||
return generateOptionsFromArray(bodyshop, 'md_referral_sources');
|
||||
case 'class':
|
||||
return generateOptionsFromArray(bodyshop, 'md_classes');
|
||||
case 'cost_centers':
|
||||
return generateOptionsFromObject(bodyshop, 'md_responsibility_centers.costs', 'name', 'name');
|
||||
// Special case because Categories is an Array, not an Object.
|
||||
case 'categories':
|
||||
return generateOptionsFromArray(bodyshop, 'md_categories');
|
||||
case 'insurance_companies':
|
||||
return generateOptionsFromObject(bodyshop, 'md_ins_cos', 'name', 'name');
|
||||
case 'employee_teams':
|
||||
return generateOptionsFromObject(bodyshop, 'employee_teams', 'name', 'id');
|
||||
// Special case because Employees uses a concatenation of first_name and last_name
|
||||
case 'employees':
|
||||
const employeesOptions = getValueFromPath(bodyshop, 'employees');
|
||||
return uniqBy(Object.values(employeesOptions).map((value) => ({
|
||||
label: `${value.first_name} ${value.last_name}`,
|
||||
value: value.id,
|
||||
})), 'value');
|
||||
case 'last_names':
|
||||
return generateOptionsFromObject(bodyshop, 'employees', 'last_name', 'last_name');
|
||||
case 'first_names':
|
||||
return generateOptionsFromObject(bodyshop, 'employees', 'first_name', 'first_name');
|
||||
case 'job_statuses':
|
||||
const statusOptions = getValueFromPath(bodyshop, 'md_ro_statuses.statuses');
|
||||
return Object.values(statusOptions).map((value) => ({
|
||||
label: value,
|
||||
value
|
||||
}));
|
||||
default:
|
||||
console.error('Invalid Special reflection provided by Report Filters');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
switch (finalPath) {
|
||||
case "payment_payers":
|
||||
return [
|
||||
{
|
||||
label: t("payments.labels.customer"),
|
||||
value: t("payments.labels.customer")
|
||||
},
|
||||
{
|
||||
label: t("payments.labels.insurance"),
|
||||
value: t("payments.labels.insurance")
|
||||
},
|
||||
// This is a weird one supposedly only used by one shop and could potentially be
|
||||
// placed behind a SplitSDK
|
||||
{
|
||||
label: t("payments.labels.external"),
|
||||
value: t("payments.labels.external")
|
||||
}
|
||||
];
|
||||
case "payment_types":
|
||||
return generateOptionsFromArray(bodyshop, "md_payment_types");
|
||||
case "alt_transports":
|
||||
return generateOptionsFromArray(bodyshop, "appt_alt_transport");
|
||||
case "lost_sale_reasons":
|
||||
return generateOptionsFromArray(bodyshop, "md_lost_sale_reasons");
|
||||
// Special case because Referral Sources is an Array, not an Object.
|
||||
case "referral_source":
|
||||
return generateOptionsFromArray(bodyshop, "md_referral_sources");
|
||||
case "class":
|
||||
return generateOptionsFromArray(bodyshop, "md_classes");
|
||||
case "cost_centers":
|
||||
return generateOptionsFromObject(bodyshop, "md_responsibility_centers.costs", "name", "name");
|
||||
// Special case because Categories is an Array, not an Object.
|
||||
case "categories":
|
||||
return generateOptionsFromArray(bodyshop, "md_categories");
|
||||
case "insurance_companies":
|
||||
return generateOptionsFromObject(bodyshop, "md_ins_cos", "name", "name");
|
||||
case "employee_teams":
|
||||
return generateOptionsFromObject(bodyshop, "employee_teams", "name", "id");
|
||||
// Special case because Employees uses a concatenation of first_name and last_name
|
||||
case "employees":
|
||||
const employeesOptions = getValueFromPath(bodyshop, "employees");
|
||||
return uniqBy(
|
||||
Object.values(employeesOptions).map((value) => ({
|
||||
label: `${value.first_name} ${value.last_name}`,
|
||||
value: value.id
|
||||
})),
|
||||
"value"
|
||||
);
|
||||
case "last_names":
|
||||
return generateOptionsFromObject(bodyshop, "employees", "last_name", "last_name");
|
||||
case "first_names":
|
||||
return generateOptionsFromObject(bodyshop, "employees", "first_name", "first_name");
|
||||
case "job_statuses":
|
||||
const statusOptions = getValueFromPath(bodyshop, "md_ro_statuses.statuses");
|
||||
return Object.values(statusOptions).map((value) => ({
|
||||
label: value,
|
||||
value
|
||||
}));
|
||||
default:
|
||||
console.error("Invalid Special reflection provided by Report Filters");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate bodyshop reflections
|
||||
@@ -128,16 +137,16 @@ const generateSpecialReflections = (bodyshop, finalPath, t) => {
|
||||
* @returns {{label: *, value: *}[]|*[]}
|
||||
*/
|
||||
const generateBodyshopReflections = (bodyshop, finalPath) => {
|
||||
const options = getValueFromPath(bodyshop, finalPath);
|
||||
const reflectionRenderer = VALID_INTERNAL_REFLECTIONS.bodyshop.find(reflection => reflection.name === finalPath);
|
||||
if (reflectionRenderer?.type === 'kv-to-v') {
|
||||
return Object.values(options).map((value) => ({
|
||||
label: value,
|
||||
value
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
const options = getValueFromPath(bodyshop, finalPath);
|
||||
const reflectionRenderer = VALID_INTERNAL_REFLECTIONS.bodyshop.find((reflection) => reflection.name === finalPath);
|
||||
if (reflectionRenderer?.type === "kv-to-v") {
|
||||
return Object.values(options).map((value) => ({
|
||||
label: value,
|
||||
value
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate internal reflections based on the path and bodyshop
|
||||
@@ -147,15 +156,15 @@ const generateBodyshopReflections = (bodyshop, finalPath) => {
|
||||
* @param t - i18n
|
||||
* @returns {{label: *, value: *}[]|[]|{label: *, value: *}[]|{label: string, value: *}[]|{label: *, value: *}[]|*[]}
|
||||
*/
|
||||
const generateInternalReflections = ({bodyshop, upperPath, finalPath, t}) => {
|
||||
switch (upperPath) {
|
||||
case 'special':
|
||||
return generateSpecialReflections(bodyshop, finalPath, t);
|
||||
case 'bodyshop':
|
||||
return generateBodyshopReflections(bodyshop, finalPath);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
const generateInternalReflections = ({ bodyshop, upperPath, finalPath, t }) => {
|
||||
switch (upperPath) {
|
||||
case "special":
|
||||
return generateSpecialReflections(bodyshop, finalPath, t);
|
||||
case "bodyshop":
|
||||
return generateBodyshopReflections(bodyshop, finalPath);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export {generateInternalReflections}
|
||||
export { generateInternalReflections };
|
||||
|
||||
Reference in New Issue
Block a user