- Progress Commit, this fills agreed upon functionality
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
This documentation details the schema required for `.filters` files on the report server. It is used to dynamically
|
||||
modify the graphQL query and provide the user more power over their reports.
|
||||
|
||||
# Special Notes
|
||||
- When passing the data to the template server, the property filters and sorters is added to the data object and will reflect the filters and sorters the user has selected
|
||||
|
||||
## High level Schema Overview
|
||||
|
||||
```javascript
|
||||
@@ -36,6 +39,35 @@ const schema = {
|
||||
Filters effect the where clause of the graphQL query. They are used to filter the data returned from the server.
|
||||
A note on special notation used in the `name` field.
|
||||
|
||||
## Reflection
|
||||
Filters can make use of reflection to pre-fill select boxes, the following is an example of that in the filters file.
|
||||
|
||||
```
|
||||
{
|
||||
"name": "jobs.status",
|
||||
"translation": "jobs.fields.status",
|
||||
"label": "Status",
|
||||
"type": "string",
|
||||
"reflector": {
|
||||
"type": "internal",
|
||||
"name": "special.job_statuses"
|
||||
}
|
||||
},
|
||||
```
|
||||
|
||||
in this example, a reflector with the type 'internal' (all types at the moment require this, and it is used for future functionality), with a name of `special.job_statuses`
|
||||
|
||||
The following cases are available
|
||||
|
||||
- `special.job_statuses` - This will reflect the statuses of the jobs table `bodyshop.md_ro_statuses.statuses'`
|
||||
- `special.cost_centers` - This will reflect the cost centers `bodyshop.md_responsibility_centers.costs`
|
||||
- `special.categories` - This will reflect the categories `bodyshop.md_categories`
|
||||
- `special.insurance_companies` - This will reflect the insurance companies `bodyshop.md_ins_cos`'
|
||||
- `special.employee_teams` - This will reflect the employee teams `bodyshop.employee_teams`
|
||||
- `special.employees` - This will reflect the employees `bodyshop.employees`
|
||||
- `special.first_names` - This will reflect the first names `bodyshop.employees`
|
||||
- `special.last_names` - This will reflect the last names `bodyshop.employees`
|
||||
-
|
||||
### Path without brackets, multi level
|
||||
|
||||
`"name": "jobs.joblines.mod_lb_hrs",`
|
||||
@@ -71,7 +103,6 @@ query gendoc_hours_sold_detail_open($starttz: timestamptz!, $endtz: timestamptz!
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Path with brackets,top level
|
||||
`"name": "[jobs].joblines.mod_lb_hrs",`
|
||||
This will produce a where clause at the `jobs` level of the graphQL query.
|
||||
@@ -114,7 +145,6 @@ query gendoc_hours_sold_detail_open($starttz: timestamptz!, $endtz: timestamptz!
|
||||
- Do not add the ability to filter things that are already filtered as part of the original query, this would be redundant and could cause issues.
|
||||
- Do not add the ability to filter on things like FK constraints, must like the above example.
|
||||
|
||||
|
||||
## Sorters
|
||||
- Sorters follow the same schema as filters, however, they do not do square bracket wrapping to indicate level hoisting, a filter added on `job.md_status` would be added at the top level, and a filter added on `jobs.joblines.mod_lb_hrs` would be added at the `joblines` level.
|
||||
- Most of the reports currently do sorting on a template level, this will need to change to actually see the results using the sorters.
|
||||
|
||||
@@ -1,52 +1,336 @@
|
||||
import {Button, Card, Checkbox, Col, Form, Row, Select} from "antd";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {Button, Card, Checkbox, Col, Form, Input, InputNumber, Row, Select} from "antd";
|
||||
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
||||
import {fetchFilterData} from "../../utils/RenderTemplate";
|
||||
import {DeleteFilled} from "@ant-design/icons";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {getOrderOperatorsByType, getWhereOperatorsByType} from "../../utils/graphQLmodifier";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import {generateInternalReflections} from "./report-center-modal-utils";
|
||||
|
||||
export default function ReportCenterModalFiltersSortersComponent({form}) {
|
||||
|
||||
export default function ReportCenterModalFiltersSortersComponent({form, bodyshop}) {
|
||||
return (
|
||||
<Form.Item style={{margin: 0, padding: 0}} dependencies={["key"]}>
|
||||
{() => {
|
||||
const key = form.getFieldValue("key");
|
||||
return <RenderFilters form={form} templateId={key}/>;
|
||||
return <RenderFilters form={form} templateId={key} bodyshop={bodyshop}/>;
|
||||
}}
|
||||
</Form.Item>
|
||||
);
|
||||
}
|
||||
|
||||
function RenderFilters({templateId, form}) {
|
||||
/**
|
||||
* Filters Section
|
||||
* @param filters
|
||||
* @param form
|
||||
* @param bodyshop
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
function FiltersSection({filters, form, bodyshop}) {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return (
|
||||
<Card type='inner' title={t('reportcenter.labels.advanced_filters_filters')} style={{marginTop: '10px'}}>
|
||||
<Form.List name={["filters"]}>
|
||||
{(fields, {add, remove, move}) => {
|
||||
return (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={10}>
|
||||
<Form.Item
|
||||
key={`${index}field`}
|
||||
label="field"
|
||||
name={[field.name, "field"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
onChange={() => {
|
||||
// Clear related Fields
|
||||
form.setFieldValue(['filters', field.name, 'value'], null);
|
||||
form.setFieldValue(['filters', field.name, 'operator'], null);
|
||||
}}
|
||||
options={
|
||||
filters.map((f) => {
|
||||
return {
|
||||
value: f.name,
|
||||
label: f?.translation ? (t(f.translation) === f.translation ? f.label : t(f.translation)) : f.label,
|
||||
}
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Form.Item dependencies={[['filters', field.name, "field"]]}>
|
||||
{
|
||||
() => {
|
||||
const name = form.getFieldValue(['filters', field.name, "field"]);
|
||||
const type = filters.find(f => f.name === name)?.type;
|
||||
|
||||
return <Form.Item
|
||||
key={`${index}operator`}
|
||||
label="operator"
|
||||
name={[field.name, "operator"]}
|
||||
dependencies={[]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={getWhereOperatorsByType(type)}/>
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Form.Item dependencies={[['filters', field.name, "field"]]}>
|
||||
{
|
||||
() => {
|
||||
const name = form.getFieldValue(['filters', field.name, "field"]);
|
||||
const type = filters.find(f => f.name === name)?.type;
|
||||
const reflector = filters.find(f => f.name === name)?.reflector;
|
||||
|
||||
return <Form.Item
|
||||
key={`${index}value`}
|
||||
label="value"
|
||||
name={[field.name, "value"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
{
|
||||
(() => {
|
||||
const generateReflections = (reflector) => {
|
||||
if (!reflector) return [];
|
||||
|
||||
const {name} = reflector;
|
||||
const path = name?.split('.');
|
||||
const upperPath = path?.[0];
|
||||
const finalPath = path?.slice(1).join('.');
|
||||
|
||||
return generateInternalReflections({
|
||||
bodyshop,
|
||||
upperPath,
|
||||
finalPath
|
||||
});
|
||||
};
|
||||
|
||||
const reflections = reflector ? generateReflections(reflector) : [];
|
||||
|
||||
const fieldPath = [[field.name, "value"]];
|
||||
|
||||
if (reflections.length > 0) {
|
||||
return (
|
||||
<Select
|
||||
options={reflections}
|
||||
getPopupContainer={trigger => trigger.parentNode}
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({[fieldPath.join('.')]: value});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (type === "number") {
|
||||
return (
|
||||
<InputNumber
|
||||
onChange={(value) => form.setFieldValue(fieldPath, parseInt(value, 10))}/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Input
|
||||
onChange={(e) => form.setFieldsValue(fieldPath, e.target.value)}/>
|
||||
);
|
||||
})()
|
||||
}
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
</Form.Item>
|
||||
|
||||
</Col>
|
||||
<Col span={2}>
|
||||
<DeleteFilled
|
||||
style={{margin: "1rem", paddingTop: '23px'}}
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={() => {
|
||||
add();
|
||||
}}
|
||||
style={{width: "100%"}}
|
||||
>
|
||||
{t("general.actions.add")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.List>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorters Section
|
||||
* @param sorters
|
||||
* @param form
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
function SortersSection({sorters, form}) {
|
||||
const {t} = useTranslation();
|
||||
return (
|
||||
<Card type='inner' title={t('reportcenter.labels.advanced_filters_sorters')} style={{marginTop: '10px'}}>
|
||||
<Form.List name={["sorters"]}>
|
||||
{(fields, {add, remove, move}) => {
|
||||
return (
|
||||
<div>
|
||||
Sorters
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={11}>
|
||||
<Form.Item
|
||||
key={`${index}field`}
|
||||
label="field"
|
||||
name={[field.name, "field"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={
|
||||
sorters.map((f) => ({
|
||||
value: f.name,
|
||||
label: f?.translation ? (t(f.translation) === f.translation ? f.label : t(f.translation)) : f.label,
|
||||
}))
|
||||
}
|
||||
getPopupContainer={trigger => trigger.parentNode}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={11}>
|
||||
<Form.Item
|
||||
key={`${index}direction`}
|
||||
label="direction"
|
||||
name={[field.name, "direction"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={getOrderOperatorsByType()}
|
||||
getPopupContainer={trigger => trigger.parentNode}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col span={2}>
|
||||
<DeleteFilled
|
||||
style={{margin: "1rem", paddingTop: '23px'}}
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={() => {
|
||||
add();
|
||||
}}
|
||||
style={{width: "100%"}}
|
||||
>
|
||||
{t("general.actions.add")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.List>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Filters
|
||||
* @param templateId
|
||||
* @param form
|
||||
* @param bodyshop
|
||||
* @returns {JSX.Element|null}
|
||||
* @constructor
|
||||
*/
|
||||
function RenderFilters({templateId, form, bodyshop}) {
|
||||
const [state, setState] = useState(null);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const {t} = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
const fetch = async () => {
|
||||
setIsLoading(true);
|
||||
const data = await fetchFilterData({name: templateId});
|
||||
if (data?.success) {
|
||||
setState(data.data);
|
||||
} else {
|
||||
setState(null);
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
const fetch = useCallback(async () => {
|
||||
// Reset all the filters and Sorters.
|
||||
form.resetFields(['filters']);
|
||||
form.resetFields(['sorters']);
|
||||
|
||||
setIsLoading(true);
|
||||
|
||||
const data = await fetchFilterData({name: templateId});
|
||||
|
||||
if (data?.success) {
|
||||
setState(data.data);
|
||||
} else {
|
||||
setState(null);
|
||||
}
|
||||
setIsLoading(false);
|
||||
}, [templateId, form]);
|
||||
|
||||
useEffect(() => {
|
||||
if (templateId) {
|
||||
fetch();
|
||||
|
||||
}
|
||||
}, [templateId]);
|
||||
}, [templateId, fetch]);
|
||||
|
||||
const filters = useMemo(() => state?.filters || [], [state]);
|
||||
const sorters = useMemo(() => state?.sorters || [], [state]);
|
||||
|
||||
// Conditional display of filters and sorters
|
||||
if (!templateId) return null;
|
||||
if (isLoading) return <LoadingSkeleton/>;
|
||||
if (!state) return null;
|
||||
|
||||
// Filters and Sorters data available
|
||||
return (
|
||||
<div style={{marginTop: '10px'}}>
|
||||
<Checkbox
|
||||
@@ -56,202 +340,11 @@ function RenderFilters({templateId, form}) {
|
||||
/>
|
||||
{visible && (
|
||||
<div>
|
||||
{state.filters && state.filters.length > 0 && (
|
||||
<Card type='inner' title={ t('reportcenter.labels.advanced_filters_filters')} style={{marginTop: '10px'}}>
|
||||
<Form.List name={["filters"]}>
|
||||
{(fields, {add, remove, move}) => {
|
||||
return (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={10}>
|
||||
<Form.Item
|
||||
key={`${index}field`}
|
||||
label="field"
|
||||
name={[field.name, "field"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={
|
||||
state.filters
|
||||
? state.filters.map((f) => {
|
||||
return {
|
||||
value: f.name,
|
||||
label: f?.translation ? (t(f.translation) === f.translation ? f.label : t(f.translation)) : f.label,
|
||||
}
|
||||
})
|
||||
: []
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Form.Item dependencies={[['filters', field.name, "field"]]}>
|
||||
{
|
||||
() => {
|
||||
const name = form.getFieldValue(['filters', field.name, "field"]);
|
||||
const type = state.filters.find(f => f.name === name)?.type;
|
||||
|
||||
return <Form.Item
|
||||
key={`${index}operator`}
|
||||
label="operator"
|
||||
name={[field.name, "operator"]}
|
||||
dependencies={[]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={getWhereOperatorsByType(type)}/>
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
</Form.Item>
|
||||
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Form.Item dependencies={[['filters', field.name, "field"]]}>
|
||||
{
|
||||
() => {
|
||||
const name = form.getFieldValue(['filters', field.name, "field"]);
|
||||
const type = state.filters.find(f => f.name === name)?.type;
|
||||
const reflector = state.filters.find(f => f.name === name)?.reflector;
|
||||
|
||||
return <Form.Item
|
||||
key={`${index}value`}
|
||||
label="value"
|
||||
name={[field.name, "value"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<ReportCenterModalFiltersSortersComponent form={form} field={field} type={type} reflector={reflector}/>
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
</Form.Item>
|
||||
|
||||
</Col>
|
||||
<Col span={2}>
|
||||
<DeleteFilled
|
||||
style={{margin: "1rem"}}
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={() => {
|
||||
add();
|
||||
}}
|
||||
style={{width: "100%"}}
|
||||
>
|
||||
{t("general.actions.add")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.List>
|
||||
|
||||
</Card>
|
||||
{filters.length > 0 && (
|
||||
<FiltersSection filters={filters} form={form} bodyshop={bodyshop}/>
|
||||
)}
|
||||
{state.sorters && state.sorters.length > 0 && (
|
||||
<Card type='inner' title={ t('reportcenter.labels.advanced_filters_sorters')} style={{marginTop: '10px'}}>
|
||||
<Form.List name={["sorters"]}>
|
||||
{(fields, {add, remove, move}) => {
|
||||
return (
|
||||
<div>
|
||||
Sorters
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={11}>
|
||||
<Form.Item
|
||||
key={`${index}field`}
|
||||
label="field"
|
||||
name={[field.name, "field"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={
|
||||
state.sorters
|
||||
? state.sorters.map((f) => ({
|
||||
value: f.name,
|
||||
label: f?.translation ? (t(f.translation) === f.translation ? f.label : t(f.translation)) : f.label,
|
||||
}))
|
||||
: []
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={11}>
|
||||
<Form.Item
|
||||
key={`${index}direction`}
|
||||
label="direction"
|
||||
name={[field.name, "direction"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
//message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={getOrderOperatorsByType()}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col span={2}>
|
||||
<DeleteFilled
|
||||
style={{margin: "1rem"}}
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={() => {
|
||||
add();
|
||||
}}
|
||||
style={{width: "100%"}}
|
||||
>
|
||||
{t("general.actions.add")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.List>
|
||||
</Card>
|
||||
{sorters.length > 0 && (
|
||||
<SortersSection sorters={sorters} form={form}/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import {uniqBy} from "lodash";
|
||||
|
||||
/**
|
||||
* Get value from path
|
||||
* @param obj
|
||||
* @param path
|
||||
* @returns {*}
|
||||
*/
|
||||
const getValueFromPath = (obj, path) => path.split('.').reduce((prev, curr) => prev?.[curr], obj);
|
||||
|
||||
/**
|
||||
* Valid internal reflections
|
||||
* Note: This is intended for future functionality
|
||||
* @type {{special: string[], bodyshop: [{name: string, type: string}]}}
|
||||
*/
|
||||
const VALID_INTERNAL_REFLECTIONS = {
|
||||
bodyshop: [
|
||||
{
|
||||
name: 'md_ro_statuses.statuses',
|
||||
type: 'kv-to-v'
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate options
|
||||
* @param bodyshop
|
||||
* @param path
|
||||
* @param labelPath
|
||||
* @param valuePath
|
||||
* @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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate special reflections
|
||||
* @param bodyshop
|
||||
* @param finalPath
|
||||
* @returns {{label: *, value: *}[]|{label: *, value: *}[]|{label: string, value: *}[]|*[]}
|
||||
*/
|
||||
const generateSpecialReflections = (bodyshop, finalPath) => {
|
||||
switch (finalPath) {
|
||||
case 'cost_centers':
|
||||
return generateOptionsFromObject(bodyshop, 'md_responsibility_centers.costs', 'name', 'name');
|
||||
// Special case because Categories is an Array, not an Object.
|
||||
case 'categories':
|
||||
const catOptions = getValueFromPath(bodyshop, 'md_categories');
|
||||
return uniqBy(catOptions.map((value) => ({
|
||||
label: value,
|
||||
value: value,
|
||||
})), 'value');
|
||||
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
|
||||
* @param bodyshop
|
||||
* @param finalPath
|
||||
* @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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate internal reflections based on the path and bodyshop
|
||||
* @param bodyshop
|
||||
* @param upperPath
|
||||
* @param finalPath
|
||||
* @returns {{label: *, value: *}[]|[]|{label: *, value: *}[]|{label: string, value: *}[]|{label: *, value: *}[]|*[]}
|
||||
*/
|
||||
const generateInternalReflections = ({bodyshop, upperPath, finalPath}) => {
|
||||
switch (upperPath) {
|
||||
case 'special':
|
||||
return generateSpecialReflections(bodyshop, finalPath);
|
||||
case 'bodyshop':
|
||||
return generateBodyshopReflections(bodyshop, finalPath);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
generateInternalReflections,
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import {Input, InputNumber, Select} from "antd";
|
||||
import React from "react";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors";
|
||||
import {connect} from "react-redux";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser
|
||||
});
|
||||
|
||||
|
||||
export function ReportCenterModalValueSelectorComponent ({type, reflector, form, field, bodyshop, currentUser}) {
|
||||
|
||||
// TODO: Remove - used for debugging / development
|
||||
console.log(`Entering ReportCenterModalValueSelectorComponent`);
|
||||
console.log('Type')
|
||||
console.log(type)
|
||||
console.log('Reflector')
|
||||
console.dir(reflector, {depth: null})
|
||||
console.log('Bodyshop')
|
||||
console.dir(bodyshop, {depth: null})
|
||||
console.log('CurrentUser')
|
||||
console.dir(currentUser, {depth: null})
|
||||
|
||||
function generateReflections(reflector) {
|
||||
// const type = reflector?.type;
|
||||
// const name = reflector?.name;
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
// We have a reflector, so we can generate a list of options
|
||||
if (reflector) {
|
||||
const reflections = generateReflections(reflector);
|
||||
// We have options to display, so return a pre-populated select box
|
||||
if (reflections.length > 0) {
|
||||
return <Select options={reflections}/>
|
||||
}
|
||||
}
|
||||
|
||||
// Number Input
|
||||
if (type === "number") {
|
||||
return <InputNumber
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({
|
||||
[field.name]: {value: parseInt(value)}
|
||||
});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
||||
// Default to String Input
|
||||
return <Input
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({
|
||||
[field.name]: {value: value.toString()}
|
||||
});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ReportCenterModalValueSelectorComponent);
|
||||
@@ -16,9 +16,11 @@ import EmployeeSearchSelect from "../employee-search-select/employee-search-sele
|
||||
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
|
||||
import "./report-center-modal.styles.scss";
|
||||
import ReportCenterModalFiltersSortersComponent from "./report-center-modal-filters-sorters-component";
|
||||
import {selectBodyshop } from "../../redux/user/user.selectors";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
reportCenterModal: selectReportCenter,
|
||||
reportCenterModal: selectReportCenter,
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
@@ -28,7 +30,7 @@ export default connect(
|
||||
mapDispatchToProps
|
||||
)(ReportCenterModalComponent);
|
||||
|
||||
export function ReportCenterModalComponent({reportCenterModal}) {
|
||||
export function ReportCenterModalComponent({reportCenterModal, bodyshop}) {
|
||||
const [form] = Form.useForm();
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
@@ -181,7 +183,7 @@ export function ReportCenterModalComponent({reportCenterModal}) {
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
<ReportCenterModalFiltersSortersComponent form={form} />
|
||||
<ReportCenterModalFiltersSortersComponent form={form} bodyshop={bodyshop} />
|
||||
<Form.Item style={{margin: 0, padding: 0}} dependencies={["key"]}>
|
||||
{() => {
|
||||
const key = form.getFieldValue("key");
|
||||
|
||||
@@ -75,6 +75,8 @@ export default async function RenderTemplate(
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
footerpath: `/${bodyshop.imexshopid}/footer.html`,
|
||||
bodyshop: bodyshop,
|
||||
filters: templateObject?.filters,
|
||||
sorters: templateObject?.sorters,
|
||||
offset: bodyshop.timezone, //dayjs().utcOffset(),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user