Skip to content

Commit cb0231e

Browse files
committed
Add ColumnVisibilityToggle
1 parent 3bd35c5 commit cb0231e

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

src/components/view/view-event-list.tsx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ const Column = styled.div<{ role: 'cell' | 'columnheader' }>`
100100
${columnStyles}
101101
`;
102102

103+
const ColumnVisibilityToggle = inject('uiStore')(observer(({ columnName, uiStore, children }: {
104+
columnName: string,
105+
uiStore?: UiStore,
106+
children?: React.ReactNode
107+
}) => {
108+
//Render by default
109+
let renderComponent = true;
110+
111+
if (uiStore) {
112+
const { visibleViewColumns } = uiStore;
113+
renderComponent = visibleViewColumns.get(columnName) === true
114+
}
115+
116+
return (
117+
<>
118+
{renderComponent && (children ?? children)}
119+
</>
120+
)
121+
}));
122+
103123
const RowPin = styled(
104124
filterProps(Icon, 'pinned')
105125
).attrs((p: { pinned: boolean }) => ({
@@ -160,9 +180,11 @@ const BaseTimestamp = ({ timestamp, role = 'cell', className, children }: {
160180
children?: React.ReactNode
161181
}) => {
162182
return (
163-
<div role={role} className={className}>
164-
{timestamp != null ? (new Date(timestamp).toLocaleTimeString()) : (children ?? '-')}
165-
</div>
183+
<ColumnVisibilityToggle columnName='Timestamp'>
184+
<div role={role} className={className}>
185+
{timestamp != null ? (new Date(timestamp).toLocaleTimeString()) : (children ?? '-')}
186+
</div>
187+
</ColumnVisibilityToggle>
166188
);
167189
};
168190

@@ -223,12 +245,14 @@ const BaseDuration = observer(({ exchange, role = 'cell', className, children }:
223245
duration = calculateAndFormatDuration({ timingEvents: exchange.timingEvents });
224246
}
225247
return (
226-
<div role={role} className={className}>
227-
{duration ?
228-
duration :
229-
(children ?? 'Duration')
230-
}
231-
</div>
248+
<ColumnVisibilityToggle columnName='Duration'>
249+
<div role={role} className={className}>
250+
{duration ?
251+
duration :
252+
(children ?? 'Duration')
253+
}
254+
</div>
255+
</ColumnVisibilityToggle>
232256
);
233257
});
234258

0 commit comments

Comments
 (0)