Skip to content

Commit

Permalink
Change: Replace withUserName HOC by useUserName hook
Browse files Browse the repository at this point in the history
Use more modern react. Hooks are easier to understand then HOCs.
  • Loading branch information
bjoernricks committed Mar 6, 2025
1 parent d9ccc42 commit f26ee10
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
74 changes: 37 additions & 37 deletions src/web/entities/EntityNameTableData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,60 @@ import DetailsLink from 'web/components/link/DetailsLink';
import TableData from 'web/components/table/Data';
import {RowDetailsToggle} from 'web/entities/Row';
import ObserverIcon from 'web/entity/icon/ObserverIcon';
import useUserName from 'web/hooks/useUserName';
import PropTypes from 'web/utils/PropTypes';
import withUsername from 'web/utils/withUserName';


const EntityNameTableData = ({
entity,
links = true,
displayName,
username,
type = getEntityType(entity),
children,
onToggleDetailsClick,
}) => (
<TableData>
<Layout align={'space-between'} columns={2}>
<div>
{entity.isOrphan() && <b>{_('Orphan')}</b>}
{isDefined(onToggleDetailsClick) ? (
<span>
<RowDetailsToggle name={entity.id} onClick={onToggleDetailsClick}>
{entity.name}
</RowDetailsToggle>
{entity.deprecated && <b> ({_('Deprecated')})</b>}
</span>
) : (
<span>
<DetailsLink id={entity.id} textOnly={!links} type={type}>
{entity.name}
</DetailsLink>
{entity.deprecated && <b> ({_('Deprecated')})</b>}
</span>
)}
{isDefined(entity.comment) && <Comment>({entity.comment})</Comment>}
{children}
</div>
<Layout>
<ObserverIcon
displayName={displayName}
entity={entity}
userName={username}
/>
}) => {
const [username] = useUserName();
return (
<TableData>
<Layout align={'space-between'} columns={2}>
<div>
{entity.isOrphan() && <b>{_('Orphan')}</b>}
{isDefined(onToggleDetailsClick) ? (
<span>
<RowDetailsToggle name={entity.id} onClick={onToggleDetailsClick}>
{entity.name}
</RowDetailsToggle>
{entity.deprecated && <b> ({_('Deprecated')})</b>}
</span>
) : (
<span>
<DetailsLink id={entity.id} textOnly={!links} type={type}>
{entity.name}
</DetailsLink>
{entity.deprecated && <b> ({_('Deprecated')})</b>}
</span>
)}
{isDefined(entity.comment) && <Comment>({entity.comment})</Comment>}
{children}
</div>
<Layout>
<ObserverIcon
displayName={displayName}
entity={entity}
userName={username}
/>
</Layout>
</Layout>
</Layout>
</TableData>
);
</TableData>
);
};

EntityNameTableData.propTypes = {
children: PropTypes.node,
displayName: PropTypes.string.isRequired,
entity: PropTypes.model.isRequired,
links: PropTypes.bool,
type: PropTypes.string,
username: PropTypes.string.isRequired,
onToggleDetailsClick: PropTypes.func,
};

export default withUsername(EntityNameTableData);
export default EntityNameTableData;
8 changes: 3 additions & 5 deletions src/web/pages/audits/Row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import TableData from 'web/components/table/Data';
import TableRow from 'web/components/table/Row';
import {RowDetailsToggle} from 'web/entities/Row';
import ObserverIcon from 'web/entity/icon/ObserverIcon';
import useUserName from 'web/hooks/useUserName';
import Actions from 'web/pages/audits/Actions';
import AuditStatus from 'web/pages/tasks/Status';
import PropTypes from 'web/utils/PropTypes';
import withUserName from 'web/utils/withUserName';


const renderAuditReport = (report, links) => {
if (!isDefined(report)) {
Expand Down Expand Up @@ -65,10 +64,10 @@ const Row = ({
actionsComponent: ActionsComponent = Actions,
entity,
links = true,
username,
onToggleDetailsClick,
...props
}) => {
const [username] = useUserName();
const {scanner, observers} = entity;
const obs = [];

Expand Down Expand Up @@ -148,8 +147,7 @@ Row.propTypes = {
actionsComponent: PropTypes.component,
entity: PropTypes.model.isRequired,
links: PropTypes.bool,
username: PropTypes.string.isRequired,
onToggleDetailsClick: PropTypes.func.isRequired,
};

export default withUserName(Row);
export default Row;

0 comments on commit f26ee10

Please sign in to comment.