Skip to content

Commit

Permalink
chore(datagrid): resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
makafsal committed Jul 3, 2024
2 parents 67ed3ce + 78962b1 commit 4fb3885
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ const ConditionBlock = (props) => {
}
: {};
};

const renderChildren = (popoverRef) => {
return (
<ItemComponent
conditionState={{
property,
operator,
value,
}}
onChange={onValueChangeHandler}
config={config}
data-name="valueField"
parentRef={popoverRef}
/>
);
};
return (
<div
className={cx(
Expand All @@ -159,7 +175,6 @@ const ConditionBlock = (props) => {
)}
role="row"
aria-label={conditionRowText}
tabIndex={-1}
{...getAriaAttributes()}
>
{conjunction ? (
Expand Down Expand Up @@ -240,19 +255,8 @@ const ConditionBlock = (props) => {
data-name="valueField"
condition={condition}
config={config}
>
<ItemComponent
conditionState={{
property,
operator,
value,
}}
onChange={onValueChangeHandler}
config={config}
type={type}
data-name="valueField"
/>
</ConditionBuilderItem>
renderChildren={renderChildren}
/>
)}
<span role="gridcell" aria-label={removeConditionText}>
<ConditionBuilderButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ConditionBuilder.propTypes = {
/**
* Optional prop, if you need to pass translations to the texts on the component instead of the defined defaults.
* This callback function will receive the message id and you need to return the corresponding text for that id.
* The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidNumberWarnText"]
* The message id will be one of [ "ifText","addConditionText", "addConditionGroupText", "addSubgroupText", "conditionText", "propertyText", "operatorText", "valueText", "connectorText", "conditionRowText", "removeConditionText", "addConditionRowText", "startText", "endText", "clearSearchText", "actionsText", "then", "removeActionText", "addActionText", "invalidText", "invalidDateText", "invalidNumberWarnText"]
]
*/
translateWithId: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ export const valueRenderers = {
},
date: (value) => {
if (Array.isArray(value) && value.length > 1) {
const start = value?.[0] ? formatDate(new Date(value[0])) : '';
const end = value?.[1] ? formatDate(new Date(value[1])) : '';
const start =
value?.[0] && !isNaN(new Date(value[0]))
? formatDate(new Date(value[0]))
: '';
const end =
value?.[1] && !isNaN(new Date(value[1]))
? formatDate(new Date(value[1]))
: '';
return `${start} To ${end}`;
} else if (Array.isArray(value) && !isNaN(new Date(value[0]))) {
return formatDate(new Date(value[0]));
} else {
return value && new Date(value) ? formatDate(new Date(value)) : value;
return value;
}
},
custom: (value) => value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ export const translationsObject = {
removeActionText: 'Remove Action',
addActionText: 'Add action',
invalidText: 'Incomplete',
invalidDateText: 'Invalid Date',
invalidNumberWarnText: 'Invalid number, must be 0 or greater',
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,37 @@ export const ConditionBuilderItem = ({
condition,
popOverClassName,
config,
renderChildren,
...rest
}) => {
const contentRef = useRef(null);
const popoverRef = useRef(null);
const [open, setOpen] = useState(false);

const [invalidText, addConditionText, labelText] = useTranslations([
'invalidText',
'addConditionText',
label,
]);
const [invalidText, addConditionText, labelText, invalidDateText] =
useTranslations([
'invalidText',
'addConditionText',
label,
'invalidDateText',
]);
const getPropertyDetails = () => {
if (label === 'INVALID') {
return {
propertyLabel: invalidText,
isInvalid: true,
};
} else if (label === 'INVALID_DATE') {
return {
propertyLabel: invalidDateText,
isInvalid: true,
};
}
const propertyId =
rest['data-name'] == 'valueField' && type
? valueRenderers[type](label, config)
: labelText;

return {
isInvalid: false,
propertyLabel: propertyId,
Expand All @@ -59,23 +69,23 @@ export const ConditionBuilderItem = ({
//if any condition is changed, state prop is triggered
if (condition.popoverToOpen && currentField !== condition.popoverToOpen) {
// close the previous popover
setOpen(false);
closePopover();
} else if (
currentField == 'valueField' &&
type == 'option' &&
condition.operator !== 'oneOf'
) {
//close the current popover if the field is valueField and is a single select dropdown. For all other inputs ,popover need to be open on value changes.
setOpen(false);
closePopover();
}
if (condition.popoverToOpen == currentField) {
//current popover need to be opened
setOpen(true);
openPopOver();
}
} else {
// when we change any statement(if/ excl.if) which is not part of condition state, label change is triggered.
//close popOver when statement is changed.
setOpen(false);
closePopover();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [condition, label]);
Expand All @@ -91,22 +101,23 @@ export const ConditionBuilderItem = ({
}
}, [contentRef, open]);

const closePopover = () => setOpen(false);
const openPopOver = () => setOpen(true);
const togglePopover = () => setOpen(!open);

return (
<Popover
open={open}
isTabTip
role="gridcell"
className={popOverClassName}
onRequestClose={() => {
setOpen(false);
}}
ref={popoverRef}
onRequestClose={closePopover}
>
<ConditionBuilderButton
label={propertyLabel ?? addConditionText}
hideLabel={!label ? true : false}
onClick={() => {
children ? setOpen(!open) : null;
}}
onClick={togglePopover}
className={className}
aria-haspopup
aria-expanded={open}
Expand All @@ -126,7 +137,7 @@ export const ConditionBuilderItem = ({
<Layer>
<h1 className={`${blockClass}__item__title`}>{title}</h1>
<div ref={contentRef} className={`${blockClass}__popover-content`}>
{children}
{renderChildren ? renderChildren(popoverRef) : children}
</div>
</Layer>
</PopoverContent>
Expand Down Expand Up @@ -169,6 +180,11 @@ ConditionBuilderItem.propTypes = {
*/
popOverClassName: PropTypes.string,

/**
* callback prop that returns the jsx for children
*/
renderChildren: PropTypes.func,

/**
* Optional prop to allow overriding the icon rendering.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ import { useTranslations } from '../../utils/useTranslations';

const blockClass = `${pkg.prefix}--condition-builder`;

export const ConditionBuilderItemDate = ({ conditionState, onChange }) => {
export const ConditionBuilderItemDate = ({
conditionState,
onChange,
parentRef,
}) => {
const DatePickerInputRef = useRef();
const [startText, endText] = useTranslations(['startText', 'endText']);
const datePickerType =
conditionState.operator == 'between' ? 'range' : 'single';

const onCloseHandler = (selectedDate) => {
onChange(
selectedDate && selectedDate.length > 0 ? selectedDate : 'INVALID_DATE'
);
};
return (
<div className={`${blockClass}__item-date `}>
{datePickerType == 'single' && (
<DatePicker
ref={DatePickerInputRef}
dateFormat="d/m/Y"
datePickerType="single"
onClose={onChange}
value={conditionState.value}
onClose={onCloseHandler}
appendTo={parentRef?.current}
>
<DatePickerInput
id="datePicker"
Expand All @@ -37,8 +47,9 @@ export const ConditionBuilderItemDate = ({ conditionState, onChange }) => {
ref={DatePickerInputRef}
dateFormat="d/m/Y"
datePickerType={datePickerType}
onClose={onChange}
onClose={onCloseHandler}
value={conditionState.value}
appendTo={parentRef?.current}
>
<DatePickerInput
id="datePickerStart"
Expand All @@ -65,4 +76,9 @@ ConditionBuilderItemDate.propTypes = {
* callback to update state oin date change
*/
onChange: PropTypes.func,

/**
* reference to the popover node
*/
parentRef: PropTypes.object,
};
18 changes: 12 additions & 6 deletions packages/ibm-products/src/components/Datagrid/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
UseFiltersInstanceProps,
UsePaginationInstanceProps,
UseResizeColumnsColumnProps,
UseResizeColumnsOptions,
UseResizeColumnsState,
UseRowSelectInstanceProps,
UseRowSelectRowProps,
Expand Down Expand Up @@ -150,7 +151,9 @@ export interface DatagridTableHooks<T extends object = any>

export interface DatagridColumn<T extends object = any>
extends ColumnInstance<T>,
UseSortByOptions<T> {
UseSortByOptions<T>,
Partial<UseResizeColumnsColumnProps<T>>,
UseResizeColumnsOptions<T> {
sticky?: 'left' | 'right';
className?: string;
rightAlignedColumn?: boolean;
Expand Down Expand Up @@ -188,11 +191,7 @@ export interface DataGridHeaderGroup<T extends object = any>
extends HeaderGroup<T>,
UseResizeColumnsColumnProps<T> {}

export interface TableProps {
className?: string;
role?: string;
style?: CSSStyleDeclaration;
}
export interface DataGridTableProps extends TableCommonProps {}

interface DataGridTableState
extends UseResizeColumnsState<any>,
Expand All @@ -211,6 +210,7 @@ export interface DataGridTableInstance<T extends object = any>
toggleAllRowsLabel?: string;
};
};
withSelectRows?: boolean;
}

export interface RowAction {
Expand Down Expand Up @@ -327,6 +327,12 @@ export interface DataGridState<T extends object = any>
ExpandedRowContentComponent?: JSXElementConstructor<any>;
}

export interface DataGridData {
instance?: DataGridTableInstance;
column?: DatagridColumn;
cell?: DataGridCell;
}

// DatagridHeaderRow related types
export interface ResizeHeaderProps {
resizerProps?: ResizerProps;
Expand Down
Loading

0 comments on commit 4fb3885

Please sign in to comment.