Skip to content

Commit

Permalink
fix: Hides unhealthy tag (#5158)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoapolo authored Feb 25, 2025
1 parent 0592f83 commit e4f2a49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 0 additions & 1 deletion frontend/web/components/modals/CreateFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ const CreateFlag = class extends Component {
tooltip={Constants.strings.TAGS_DESCRIPTION}
component={
<AddEditTags
hideTagsByType={['UNHEALTHY']}
readOnly={!!identity || !createFeature}
projectId={`${this.props.projectId}`}
value={this.state.tags}
Expand Down
20 changes: 15 additions & 5 deletions frontend/web/components/tags/AddEditTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useDeleteTagMutation,
useGetTagsQuery,
} from 'common/services/useTag'
import { TagType, Tag as TTag } from 'common/types/responses'
import { Tag as TTag } from 'common/types/responses'
import Tag from './Tag'
import CreateEditTag from './CreateEditTag'
import Input from 'components/base/forms/Input'
Expand All @@ -20,14 +20,12 @@ import TagUsage from 'components/TagUsage'

type AddEditTagsType = {
value?: number[]
hideTagsByType?: TagType[]
readOnly?: boolean
onChange: (value: number[]) => void
projectId: string
}

const AddEditTags: FC<AddEditTagsType> = ({
hideTagsByType = [],
onChange,
projectId,
readOnly,
Expand All @@ -36,11 +34,22 @@ const AddEditTags: FC<AddEditTagsType> = ({
const { data, isLoading: tagsLoading } = useGetTagsQuery({
projectId,
})

const isFeatureHealthEnabled = Utils.getFlagsmithHasFeature('feature_health')

const unhealthyTagId = useMemo(() => {
return data?.find((tag) => tag?.type === 'UNHEALTHY')?.id
}, [data])

const projectTags = useMemo(() => {
if (!isFeatureHealthEnabled) {
return data
}

return data?.filter(
(projectTag) => !hideTagsByType.includes(projectTag.type),
(projectTag) => !['UNHEALTHY'].includes(projectTag.type),
)
}, [data, hideTagsByType])
}, [data, isFeatureHealthEnabled])

const [filter, setFilter] = useState('')
const [isOpen, setIsOpen] = useState(false)
Expand Down Expand Up @@ -142,6 +151,7 @@ const AddEditTags: FC<AddEditTagsType> = ({
<Row className='inline-tags mt-2'>
<TagValues
hideNames={false}
hideTags={unhealthyTagId ? [unhealthyTagId] : undefined}
projectId={projectId}
onAdd={readOnly ? undefined : toggle}
value={value}
Expand Down
6 changes: 5 additions & 1 deletion frontend/web/components/tags/TagValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ type TagValuesType = {
children?: ReactNode
inline?: boolean
hideNames?: boolean
hideTags?: number[]
}

const TagValues: FC<TagValuesType> = ({
children,
hideNames = true,
hideTags = [],
inline,
onAdd,
projectId,
value,
}) => {
const { data: tags } = useGetTagsQuery({ projectId })
const { data } = useGetTagsQuery({ projectId })
const Wrapper = inline ? Fragment : Row
const permissionType = 'MANAGE_TAGS'

const tags = data?.filter((tag) => !hideTags?.includes(tag.id))

const { permission: createEditTagPermission } = useHasPermission({
id: projectId,
level: 'project',
Expand Down

0 comments on commit e4f2a49

Please sign in to comment.