More updates to event data report.

This commit is contained in:
Mike Cao 2023-07-04 22:51:23 -07:00
parent 7c467db27e
commit 2f4d669836
13 changed files with 202 additions and 173 deletions

View file

@ -1,16 +1,20 @@
import { useState } from 'react';
import { createPortal } from 'react-dom';
import { REPORT_PARAMETERS } from 'lib/constants';
import PopupForm from '../PopupForm';
import FieldSelectForm from '../FieldSelectForm';
import FieldAggregateForm from '../FieldAggregateForm';
import FieldFilterForm from '../FieldFilterForm';
import styles from './FieldAddForm.module.css';
export function FieldAddForm({ fields = [], type, element, onAdd, onClose }) {
export function FieldAddForm({ fields = [], group, element, onAdd, onClose }) {
const [selected, setSelected] = useState();
const handleSelect = value => {
if (type === 'groups') {
const { type } = value;
if (group === REPORT_PARAMETERS.groups || type === 'array' || type === 'boolean') {
value.value = group === REPORT_PARAMETERS.groups ? '' : 'total';
handleSave(value);
return;
}
@ -19,15 +23,19 @@ export function FieldAddForm({ fields = [], type, element, onAdd, onClose }) {
};
const handleSave = value => {
onAdd(type, value);
onAdd(group, value);
onClose();
};
return createPortal(
<PopupForm className={styles.popup} element={element} onClose={onClose}>
{!selected && <FieldSelectForm fields={fields} type={type} onSelect={handleSelect} />}
{selected && type === 'fields' && <FieldAggregateForm {...selected} onSelect={handleSave} />}
{selected && type === 'filters' && <FieldFilterForm {...selected} onSelect={handleSave} />}
{!selected && <FieldSelectForm fields={fields} onSelect={handleSelect} />}
{selected && group === REPORT_PARAMETERS.fields && (
<FieldAggregateForm {...selected} onSelect={handleSave} />
)}
{selected && group === REPORT_PARAMETERS.filters && (
<FieldFilterForm {...selected} onSelect={handleSave} />
)}
</PopupForm>,
document.body,
);