Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add confirmations when removing features, segments and environments #4210

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/common/providers/FeatureListProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const FeatureListProvider = class extends React.Component {
usageData: FeatureListStore.getFeatureUsage(),
})
})
this.listenTo(FeatureListStore, 'removed', (data) => {
this.props.onRemove?.(data)
})

this.listenTo(FeatureListStore, 'saved', (data) => {
this.props.onSave && this.props.onSave(data)
Expand Down
4 changes: 2 additions & 2 deletions frontend/common/providers/ProjectProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const ProjectProvider = class extends React.Component {
),
)
})
this.listenTo(ProjectStore, 'removed', () => {
this.props.onRemoveEnvironment && this.props.onRemoveEnvironment()
this.listenTo(ProjectStore, 'removed', (data) => {
this.props.onRemoveEnvironment && this.props.onRemoveEnvironment(data)
})
this.listenTo(OrganisationStore, 'removed', () => {
this.props.onRemove && this.props.onRemove()
Expand Down
1 change: 1 addition & 0 deletions frontend/common/stores/feature-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ const controller = {
)
store.model.lastSaved = new Date().valueOf()
store.saved({})
store.trigger('removed', flag)
})
},
searchFeatures: _.throttle(
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/stores/project-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const controller = {
getStore().dispatch(
environmentService.util.invalidateTags(['Environment']),
)
store.trigger('removed')
store.trigger('removed', env)
store.saved()
AppActions.refreshOrganisation()
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ declare global {
) => void
const openConfirm: (data: OpenConfirm) => void
const Row: typeof Component
const toast: (value: string, theme?: string, expiry?: number) => void
const toast: (value: ReactNode, theme?: string, expiry?: number) => void
const Flex: typeof Component
const isMobile: boolean
const FormGroup: typeof Component
Expand Down
7 changes: 6 additions & 1 deletion frontend/web/components/pages/EnvironmentSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const EnvironmentSettingsPage = class extends Component {
)
}

onRemoveEnvironment = () => {
onRemoveEnvironment = (environment) => {
const envs = ProjectStore.getEnvs()
if (envs && envs.length) {
this.context.router.history.replace(
Expand All @@ -139,6 +139,11 @@ const EnvironmentSettingsPage = class extends Component {
`/project/${this.props.match.params.projectId}/environment/create`,
)
}
toast(
<div>
Removed Environment: <strong>{environment.name}</strong>
</div>,
)
}

saveEnv = (e) => {
Expand Down
20 changes: 18 additions & 2 deletions frontend/web/components/pages/FeaturesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import EnvironmentDocumentCodeHelp from 'components/EnvironmentDocumentCodeHelp'
import TableOwnerFilter from 'components/tables/TableOwnerFilter'
import TableGroupsFilter from 'components/tables/TableGroupsFilter'
import TableValueFilter from 'components/tables/TableValueFilter'
import classNames from 'classnames'

const FeaturesPage = class extends Component {
static displayName = 'FeaturesPage'
Expand Down Expand Up @@ -226,7 +227,17 @@ const FeaturesPage = class extends Component {
id='features-page'
className='app-container container'
>
<FeatureListProvider onSave={this.onSave} onError={this.onError}>
<FeatureListProvider
onRemove={(feature) =>
toast(
<div>
Removed feature: <strong>{feature.name}</strong>
</div>,
)
}
onSave={this.onSave}
onError={this.onError}
>
{(
{
environmentFlags,
Expand All @@ -237,6 +248,7 @@ const FeaturesPage = class extends Component {
{ removeFlag, toggleFlag },
) => {
const isLoading = !FeatureListStore.hasLoaded
const isSaving = FeatureListStore.isSaving
const featureLimitAlert = Utils.calculateRemainingLimitsPercentage(
totalFeatures,
maxFeaturesAllowed,
Expand Down Expand Up @@ -327,7 +339,11 @@ const FeaturesPage = class extends Component {
id={this.props.match.params.environmentId}
>
{({ permission }) => (
<FormGroup className='mb-4'>
<FormGroup
className={classNames('mb-4', {
'opacity-50': isSaving,
})}
>
<PanelSearch
className='no-pad overflow-visible'
id='features-list'
Expand Down
11 changes: 10 additions & 1 deletion frontend/web/components/pages/SegmentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,16 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
const segment = find(segments, { id })
if (segment) {
confirmRemove(segment, () => {
removeSegment({ id, projectId })
removeSegment({ id, projectId }).then(
(res) => {
toast(
<div>
Removed Segment:{' '}
<strong>{segment.name}</strong>
</div>,
)
},
)
})
}
}}
Expand Down
Loading