<commit_before>import React, { memo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import { Link } from 'react-router-dom';
import { Chip, IconButton, ListItem, Tooltip } from '@material-ui/core';
import { Undo } from '@material-ui/icons';

import TimeAgo from 'react-timeago';
import Status from '../../status-component';
import ConditionallyRender from '../../../common/ConditionallyRender/ConditionallyRender';

import { UPDATE_FEATURE } from '../../../providers/AccessProvider/permissions';
import { styles as commonStyles } from '../../../common';

import { useStyles } from './styles';
import { getTogglePath } from '../../../../utils/route-path-helpers';
import FeatureStatus from '../../FeatureView2/FeatureStatus/FeatureStatus';
import FeatureType from '../../FeatureView2/FeatureType/FeatureType';
import useProjects from '../../../../hooks/api/getters/useProjects/useProjects';

const FeatureToggleListItem = ({
    feature,
    toggleFeature,
    settings,
    metricsLastHour = { yes: 0, no: 0, isFallback: true },
    metricsLastMinute = { yes: 0, no: 0, isFallback: true },
    revive,
    hasAccess,
    flags = {},
    ...rest
}) => {
    const styles = useStyles();

    const { projects } = useProjects();
    const isArchive = !!revive;

    const { name, description, type, stale, createdAt, project, lastSeenAt } =
        feature;

    const isProjectDeleted = () => {
        let projectExist = projects.find(proj => proj.id === project);
        if (projectExist) {
            return true;
        }
        return false;
    };

    const reviveFeature = () => {
        if (isProjectDeleted()) {
            revive(feature.name);
        }
    };
    return (
        <ListItem
            {...rest}
            className={classnames(styles.listItem, rest.className)}
        >
            <span className={styles.listItemMetric}>
                <FeatureStatus lastSeenAt={lastSeenAt} />
            </span>
            <span
                className={classnames(
                    styles.listItemType,
                    commonStyles.hideLt600
                )}
            >
                <FeatureType type={type} />
            </span>
            <span className={classnames(styles.listItemLink)}>
                <ConditionallyRender
                    condition={!isArchive}
                    show={
                        <Link
                            to={getTogglePath(feature.project, name, flags.E)}
                            className={classnames(
                                commonStyles.listLink,
                                commonStyles.truncate
                            )}
                        >
                            <Tooltip title={description}>
                                <span className={commonStyles.toggleName}>
                                    {name}&nbsp;
                                </span>
                            </Tooltip>
                            <span className={styles.listItemToggle}></span>
                            <small>
                                <TimeAgo date={createdAt} live={false} />
                            </small>
                            <div>
                                <span className={commonStyles.truncate}>
                                    <small>{description}</small>
                                </span>
                            </div>
                        </Link>
                    }
                    elseShow={
                        <>
                            <Tooltip title={description}>
                                <span className={commonStyles.toggleName}>
                                    {name}&nbsp;{' '}
                                </span>
                            </Tooltip>
                            <span className={styles.listItemToggle}></span>
                            <small>
                                <TimeAgo date={createdAt} live={false} />
                            </small>
                            <div>
                                <span className={commonStyles.truncate}>
                                    <small>{description}</small>
                                </span>
                            </div>
                        </>
                    }
                />
            </span>
            <span
                className={classnames(
                    styles.listItemStrategies,
                    commonStyles.hideLt920
                )}
            >
                <Status stale={stale} showActive={false} />
                <Link
                    to={`/projects/${project}`}
                    style={{ textDecoration: 'none' }}
                    className={classnames({
                        [`${styles.disabledLink}`]: !isProjectDeleted(),
                    })}
                >
                    <Chip
                        color="primary"
                        variant="outlined"
                        className={styles.typeChip}
                        style={{ marginLeft: '8px', cursor: 'pointer' }}
                        title={`Project: ${project}`}
                        label={project}
                    />
                </Link>
            </span>
            <ConditionallyRender
                condition={revive}
                show={
                    <ConditionallyRender
                        condition={hasAccess(UPDATE_FEATURE, project)}
                        show={
                            <IconButton
                                onClick={reviveFeature}
                                disabled={!isProjectDeleted()}
                            >
                                <Undo />
                            </IconButton>
                        }
                        elseShow={<span style={{ width: '48px ' }} />}
                    />
                }
            />
        </ListItem>
    );
};

FeatureToggleListItem.propTypes = {
    feature: PropTypes.object,
    toggleFeature: PropTypes.func,
    settings: PropTypes.object,
    metricsLastHour: PropTypes.object,
    metricsLastMinute: PropTypes.object,
    revive: PropTypes.func,
    hasAccess: PropTypes.func.isRequired,
    flags: PropTypes.object,
};

export default memo(FeatureToggleListItem);
<commit_msg>fix: rename isProjectDeleted to projectExists and add PermissionIconButton<commit_after>import React, { memo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import { Link } from 'react-router-dom';
import { Chip, ListItem, Tooltip } from '@material-ui/core';
import { Undo } from '@material-ui/icons';

import TimeAgo from 'react-timeago';
import Status from '../../status-component';
import ConditionallyRender from '../../../common/ConditionallyRender/ConditionallyRender';

import { UPDATE_FEATURE } from '../../../providers/AccessProvider/permissions';
import { styles as commonStyles } from '../../../common';

import { useStyles } from './styles';
import { getTogglePath } from '../../../../utils/route-path-helpers';
import FeatureStatus from '../../FeatureView2/FeatureStatus/FeatureStatus';
import FeatureType from '../../FeatureView2/FeatureType/FeatureType';
import useProjects from '../../../../hooks/api/getters/useProjects/useProjects';
import PermissionIconButton from '../../../common/PermissionIconButton/PermissionIconButton';

const FeatureToggleListItem = ({
    feature,
    toggleFeature,
    settings,
    metricsLastHour = { yes: 0, no: 0, isFallback: true },
    metricsLastMinute = { yes: 0, no: 0, isFallback: true },
    revive,
    hasAccess,
    flags = {},
    ...rest
}) => {
    const styles = useStyles();

    const { projects } = useProjects();
    const isArchive = !!revive;

    const { name, description, type, stale, createdAt, project, lastSeenAt } =
        feature;

    const projectExists = () => {
        let projectExist = projects.find(proj => proj.id === project);
        if (projectExist) {
            return true;
        }
        return false;
    };

    const reviveFeature = () => {
        if (projectExists()) {
            revive(feature.name);
        }
    };
    return (
        <ListItem
            {...rest}
            className={classnames(styles.listItem, rest.className)}
        >
            <span className={styles.listItemMetric}>
                <FeatureStatus lastSeenAt={lastSeenAt} />
            </span>
            <span
                className={classnames(
                    styles.listItemType,
                    commonStyles.hideLt600
                )}
            >
                <FeatureType type={type} />
            </span>
            <span className={classnames(styles.listItemLink)}>
                <ConditionallyRender
                    condition={!isArchive}
                    show={
                        <Link
                            to={getTogglePath(feature.project, name, flags.E)}
                            className={classnames(
                                commonStyles.listLink,
                                commonStyles.truncate
                            )}
                        >
                            <Tooltip title={description}>
                                <span className={commonStyles.toggleName}>
                                    {name}&nbsp;
                                </span>
                            </Tooltip>
                            <span className={styles.listItemToggle}></span>
                            <small>
                                <TimeAgo date={createdAt} live={false} />
                            </small>
                            <div>
                                <span className={commonStyles.truncate}>
                                    <small>{description}</small>
                                </span>
                            </div>
                        </Link>
                    }
                    elseShow={
                        <>
                            <Tooltip title={description}>
                                <span className={commonStyles.toggleName}>
                                    {name}&nbsp;{' '}
                                </span>
                            </Tooltip>
                            <span className={styles.listItemToggle}></span>
                            <small>
                                <TimeAgo date={createdAt} live={false} />
                            </small>
                            <div>
                                <span className={commonStyles.truncate}>
                                    <small>{description}</small>
                                </span>
                            </div>
                        </>
                    }
                />
            </span>
            <span
                className={classnames(
                    styles.listItemStrategies,
                    commonStyles.hideLt920
                )}
            >
                <Status stale={stale} showActive={false} />
                <Link
                    to={`/projects/${project}`}
                    style={{ textDecoration: 'none' }}
                    className={classnames({
                        [`${styles.disabledLink}`]: !projectExists(),
                    })}
                >
                    <Chip
                        color="primary"
                        variant="outlined"
                        className={styles.typeChip}
                        style={{ marginLeft: '8px', cursor: 'pointer' }}
                        title={`Project: ${project}`}
                        label={project}
                    />
                </Link>
            </span>
            <ConditionallyRender
                condition={revive}
                show={
                    <PermissionIconButton
                        permission={UPDATE_FEATURE}
                        projectId={project}
                        disabled={!projectExists()}
                        onClick={reviveFeature}
                    >
                        <Undo />
                    </PermissionIconButton>
                }
            />
        </ListItem>
    );
};

FeatureToggleListItem.propTypes = {
    feature: PropTypes.object,
    toggleFeature: PropTypes.func,
    settings: PropTypes.object,
    metricsLastHour: PropTypes.object,
    metricsLastMinute: PropTypes.object,
    revive: PropTypes.func,
    hasAccess: PropTypes.func.isRequired,
    flags: PropTypes.object,
};

export default memo(FeatureToggleListItem);

{'fraction_non_alphanumeric': 0.1103916614024005, 'fraction_numerical': 0.0022109917877447885, 'mean_word_length': 1.107671825594941, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5532851', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2835, 'n_words': 538}