const renderItem = useMemo(() => (source) => {
const { name: sourceName } = source;
const labelClassName = `source__label-name source__label-name-${sourceName.toLowerCase()}`;
return (
<List.Item className="source">
<Checkbox
disabled={source.name === 'radius'}
checked={source.isSelected}
onChange={() => handleSourceChecked(source)}
className="source__checkbox"
/>
<span className={classNames('source__label', labelClassName)}>
{dataSourceLabelConfig[sourceName] || sourceName.toUpperCase() }
</span>
<span className="source__label">{`${source.nodeCount} nodes`}</span>
<span className="source__label source__label-date">
{fromNow(source.updated)}
</span>
<button className="source__button" type="button" onClick={() => handleSourceRefresh(source)}>
<Icon className="source__icon" type="reload" width="20" height="20" />
</button>
</List.Item>
);
}, [sources]);
const renderSourceList = useMemo(() => () => {
const newSources = [...sources];
if (newSources.length) {
newSources.push({
name: 'radius',
isSelected: false,
updated: newSources[0].updated,
nodeCount: 0
});
}
return (
<Card title="Sources">
<List
size="small"
dataSource={newSources}
renderItem={renderItem}
split={false}
/>
</Card>
);
}, [sources]);
renderSourceList = useMemo(() => {
if (newSources.length) {
// ...
}
return (
// ...
);
});