1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/feature/feature-tag-component.jsx
Fredrik Strand Oseberg 10eabb366f Offline mode (#312)
* move all icons to offline mode

* Reorder imports

* revert yarn.lock to original

* resolve errors

* use ConditionalRender, revert material icon css

* add all other font weights

* fix: add library icon

Co-authored-by: Aneesh Relan <aneesh.r@lucideustech.com>
2021-06-29 10:21:54 +02:00

113 lines
3.5 KiB
JavaScript

import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Chip } from '@material-ui/core';
import { Label } from '@material-ui/icons';
import ConditionallyRender from '../common/ConditionallyRender/ConditionallyRender';
import Dialogue from '../common/Dialogue';
import slackIcon from '../../assets/icons/slack.svg';
import jiraIcon from '../../assets/icons/jira.svg';
import webhookIcon from '../../assets/icons/webhooks.svg';
import { formatAssetPath } from '../../utils/format-path';
function FeatureTagComponent({
tags,
tagTypes,
featureToggleName,
untagFeature,
}) {
const [showDialog, setShowDialog] = useState(false);
const [selectedTag, setSelectedTag] = useState(undefined);
const onUntagFeature = tag => {
// eslint-disable-next-line no-alert
untagFeature(featureToggleName, tag);
setSelectedTag(undefined);
};
const tagIcon = typeName => {
let tagType = tagTypes.find(type => type.name === typeName);
const style = { width: '20px', height: '20px', marginRight: '5px' };
if (tagType && tagType.icon) {
switch (tagType.name) {
case 'slack':
return (
<img
style={style}
alt="slack"
src={formatAssetPath(slackIcon)}
/>
);
case 'jira':
return (
<img
style={style}
alt="jira"
src={formatAssetPath(jiraIcon)}
/>
);
case 'webhook':
return (
<img
style={style}
alt="webhook"
src={formatAssetPath(webhookIcon)}
/>
);
default:
return <Label />;
}
} else {
return <span>{typeName[0].toUpperCase()}</span>;
}
};
const renderTag = t => (
<Chip
icon={tagIcon(t.type)}
style={{ marginRight: '3px', fontSize: '0.8em' }}
label={t.value}
key={`${t.type}:${t.value}`}
onDelete={() => {
setSelectedTag(t);
setShowDialog(true);
}}
/>
);
return (
<ConditionallyRender
condition={tags && tags.length > 0}
show={
<div>
<Dialogue
open={showDialog}
onClose={() => {
setShowDialog(false);
setSelectedTag(undefined);
}}
onClick={() => {
onUntagFeature(selectedTag);
setShowDialog(false);
}}
title="Are you sure you want to delete this tag?"
/>
<p style={{ marginBottom: 0 }}>Tags</p>
{tags.map(renderTag)}
</div>
}
/>
);
}
FeatureTagComponent.propTypes = {
tags: PropTypes.array,
tagTypes: PropTypes.array,
featureToggleName: PropTypes.string.isRequired,
untagFeature: PropTypes.func,
};
export default FeatureTagComponent;