Skip to content

Commit

Permalink
chore: Show tag usage when deleting (#3573)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Elwell <[email protected]>
  • Loading branch information
kyle-ssg and matthewelwell authored Mar 15, 2024
1 parent dc749d0 commit 8012407
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ export type Req = {
environment: string
user: string
}
getProjectFlags: { project: string; environmentId?: string }
getProjectFlags: {
project: string
environmentId?: string
tags?: string[]
is_archived?: boolean
}
getProjectFlag: { project: string; id: string }
getRolesPermissionUsers: { organisation_id: string; role_id: string }
deleteRolesPermissionUsers: {
Expand Down
33 changes: 33 additions & 0 deletions frontend/web/components/TagUsage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { FC } from 'react'
import { useGetProjectFlagsQuery } from 'common/services/useProjectFlag'
import WarningMessage from './WarningMessage'

type TagUsageType = {
projectId: string
tag: string
}

const TagUsage: FC<TagUsageType> = ({ projectId, tag }) => {
const { data } = useGetProjectFlagsQuery(
{
is_archived: false,
project: projectId,
tags: [tag],
},
{ refetchOnMountOrArgChange: true },
)
if (!data?.count) {
return null
}
return (
<div className='mt-4'>
<WarningMessage
warningMessage={`${data?.count} feature${
data?.count !== 1 ? 's are' : ' is'
} using this tag.`}
/>
</div>
)
}

export default TagUsage
2 changes: 2 additions & 0 deletions frontend/web/components/tags/AddEditTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import CreateEditTag from './CreateEditTag'
import Input from 'components/base/forms/Input'
import Button from 'components/base/forms/Button'
import Icon from 'components/Icon'
import TagUsage from 'components/TagUsage'

type AddEditTagsType = {
value?: number[]
Expand Down Expand Up @@ -71,6 +72,7 @@ const AddEditTags: FC<AddEditTagsType> = ({
<Tag tag={tag} />
</div>
? This action cannot be undone.
<TagUsage projectId={projectId} tag={tag.id} />
</div>
),
destructive: true,
Expand Down

0 comments on commit 8012407

Please sign in to comment.