From 95e9c6cb2493f206fd5781a12ad5feb8921fb74b Mon Sep 17 00:00:00 2001 From: Dominik Haentsch Date: Mon, 26 Feb 2024 13:53:32 +0100 Subject: [PATCH] feat: optional handlesNull attribute for lenses --- src/components/ui/Select/Select.tsx | 2 +- src/lenses/LensFactory.tsx | 29 ++++++++++++----------------- src/types/lenses.ts | 1 + 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/components/ui/Select/Select.tsx b/src/components/ui/Select/Select.tsx index 42808e1d..5fe494dd 100644 --- a/src/components/ui/Select/Select.tsx +++ b/src/components/ui/Select/Select.tsx @@ -23,7 +23,7 @@ interface SelectProps { } function defaultLabel(v?: T) { - return v?.toString() || 'None'; + return v?.toString() ?? 'None'; } function Select({ diff --git a/src/lenses/LensFactory.tsx b/src/lenses/LensFactory.tsx index f8117d4f..a2171da3 100644 --- a/src/lenses/LensFactory.tsx +++ b/src/lenses/LensFactory.tsx @@ -104,27 +104,22 @@ const LensFactory: FunctionComponent = ({ if (!isLensCompatible(LensComponent, types, allEditable)) return Incompatible View ({view}); - const context = { settings, onChangeSettings, sharedState, setSharedState }; - - const allValuesAreNull = values.every(_.isNull); + if (!LensComponent?.handlesNull && values.every(_.isNull)) return ; + const context = { settings, onChangeSettings, sharedState, setSharedState }; return ( - {allValuesAreNull ? ( - - ) : ( - - )} + ); diff --git a/src/types/lenses.ts b/src/types/lenses.ts index e6f65388..303bafdb 100644 --- a/src/types/lenses.ts +++ b/src/types/lenses.ts @@ -30,6 +30,7 @@ interface LensAttributes { selectedColumns: DataColumn[] ) => DataColumn[]; isSatisfied?: (columns: DataColumn[]) => boolean; + handlesNull?: boolean; } export type Lens = React.FunctionComponent> & LensAttributes;