Skip to content

Commit

Permalink
fix(sheets-filter-ui): fix the react compatibility issue with sheets …
Browse files Browse the repository at this point in the history
…filter
  • Loading branch information
jikkai committed Nov 30, 2024
1 parent d9b1149 commit 2a46482
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ export function FilterByCondition(props: { model: ByConditionsModel }) {
const localeService = useDependency(LocaleService);

// form state is from the model
const condition = useObservable(model.conditionItem$, undefined, true);
const formParams = useObservable(model.filterConditionFormParams$, undefined, true);
const { operator, numOfParameters } = condition;
const { operator1, operator2, val1, val2, and } = formParams;
const condition = useObservable(model.conditionItem$, undefined);
const formParams = useObservable(model.filterConditionFormParams$, undefined);

const radioValue = and ? 'AND' : 'OR';
const radioValue = formParams?.and ? 'AND' : 'OR';
const onRadioChange = useCallback((key: string | number | boolean) => {
model.onConditionFormChange({ and: key === 'AND' });
}, [model]);
Expand Down Expand Up @@ -79,20 +77,24 @@ export function FilterByCondition(props: { model: ByConditionsModel }) {
return (
<div className={styles.sheetsFilterPanelConditionsContainer}>
{/* primary condition */}
<Select value={operator} options={primaryOptions} onChange={onPrimaryConditionChange} />
{FilterConditionItems.getItemByOperator(operator).numOfParameters !== 0
? (
<div className={styles.sheetsFilterPanelConditionsContainerInner}>
{numOfParameters >= 1 && renderSecondaryCondition(operator1!, val1 ?? '', 'operator1')}
{numOfParameters >= 2 && renderSecondaryCondition(operator2!, val2 ?? '', 'operator2')}
<div className={styles.sheetsFilterPanelConditionsDesc}>
{localeService.t('sheets-filter.panel.?')}
<br></br>
{localeService.t('sheets-filter.panel.*')}
</div>
</div>
)
: null}
{(condition && formParams) && (
<>
<Select value={condition.operator} options={primaryOptions} onChange={onPrimaryConditionChange} />
{FilterConditionItems.getItemByOperator(condition.operator).numOfParameters !== 0
? (
<div className={styles.sheetsFilterPanelConditionsContainerInner}>
{condition.numOfParameters >= 1 && renderSecondaryCondition(formParams.operator1!, formParams.val1 ?? '', 'operator1')}
{condition.numOfParameters >= 2 && renderSecondaryCondition(formParams.operator2!, formParams.val2 ?? '', 'operator2')}
<div className={styles.sheetsFilterPanelConditionsDesc}>
{localeService.t('sheets-filter.panel.?')}
<br></br>
{localeService.t('sheets-filter.panel.*')}
</div>
</div>
)
: null}
</>
)}
</div>
);
}
Expand Down

0 comments on commit 2a46482

Please sign in to comment.