Skip to content

Commit

Permalink
Merge pull request #438 from Renumics/feature/allow-lenses-to-handle-…
Browse files Browse the repository at this point in the history
…null

feat: optional handlesNull attribute for lenses
  • Loading branch information
neindochoh authored Feb 26, 2024
2 parents 64f9340 + 95e9c6c commit a06e2bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/ui/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface SelectProps<T extends Value> {
}

function defaultLabel<T extends Value>(v?: T) {
return v?.toString() || 'None';
return v?.toString() ?? 'None';
}

function Select<T extends Value>({
Expand Down
29 changes: 12 additions & 17 deletions src/lenses/LensFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,22 @@ const LensFactory: FunctionComponent<Props> = ({
if (!isLensCompatible(LensComponent, types, allEditable))
return <Info>Incompatible View ({view})</Info>;

const context = { settings, onChangeSettings, sharedState, setSharedState };

const allValuesAreNull = values.every(_.isNull);
if (!LensComponent?.handlesNull && values.every(_.isNull)) return <None />;

const context = { settings, onChangeSettings, sharedState, setSharedState };
return (
<LensContext.Provider value={context}>
<ErrorBoundary fallbackRender={fallbackRenderer}>
{allValuesAreNull ? (
<None />
) : (
<LensComponent
url={urls[0]}
urls={urls}
value={values[0]}
values={values}
column={columns[0]}
columns={columns}
rowIndex={rowIndex}
syncKey={syncKey}
/>
)}
<LensComponent
url={urls[0]}
urls={urls}
value={values[0]}
values={values}
column={columns[0]}
columns={columns}
rowIndex={rowIndex}
syncKey={syncKey}
/>
</ErrorBoundary>
</LensContext.Provider>
);
Expand Down
1 change: 1 addition & 0 deletions src/types/lenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface LensAttributes {
selectedColumns: DataColumn[]
) => DataColumn[];
isSatisfied?: (columns: DataColumn[]) => boolean;
handlesNull?: boolean;
}

export type Lens<T = unknown> = React.FunctionComponent<LensProps<T>> & LensAttributes;

0 comments on commit a06e2bb

Please sign in to comment.