Skip to content

Commit

Permalink
chore: Remove user override (#3559)
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 13, 2024
1 parent b377442 commit 3838f83
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 102 deletions.
3 changes: 2 additions & 1 deletion frontend/common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
projectId,
})
},
removeUserFlag({ environmentId, identity, identityFlag }) {
removeUserFlag({ cb, environmentId, identity, identityFlag }) {
Dispatcher.handleViewAction({
actionType: Actions.REMOVE_USER_FLAG,
cb,
environmentId,
identity,
identityFlag,
Expand Down
14 changes: 9 additions & 5 deletions frontend/common/stores/identity-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const controller = {
})
.catch((e) => API.ajaxHandler(store, e))
},
removeUserFlag(identity, identityFlag, environmentId) {
removeUserFlag(identity, identityFlag, environmentId, cb) {
store.saving()
API.trackEvent(Constants.events.REMOVE_USER_FEATURE)
data
Expand All @@ -169,9 +169,12 @@ const controller = {
}/`,
)
.then(() =>
controller
.getIdentity(environmentId, identity)
.then(() => store.saved()),
controller.getIdentity(environmentId, identity).then(() => {
store.saved()
if (cb) {
cb()
}
}),
)
},
toggleUserFlag({
Expand Down Expand Up @@ -239,6 +242,7 @@ const store = Object.assign({}, BaseStore, {
store.dispatcherIndex = Dispatcher.register(store, (payload) => {
const action = payload.action // this is our action from handleViewAction
const {
cb,
environmentFlag,
environmentId,
identity,
Expand Down Expand Up @@ -272,7 +276,7 @@ store.dispatcherIndex = Dispatcher.register(store, (payload) => {
controller.editTrait({ environmentId, identity, trait })
break
case Actions.REMOVE_USER_FLAG:
controller.removeUserFlag(identity, identityFlag, environmentId)
controller.removeUserFlag(identity, identityFlag, environmentId, cb)
break
case Actions.DELETE_IDENTITY_TRAIT:
controller.deleteIdentityTrait(action.envId, action.identity, action.id)
Expand Down
36 changes: 36 additions & 0 deletions frontend/web/components/RemoveUserOverride.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ConfirmRemoveFeature from './modals/ConfirmRemoveFeature'
import React from 'react'
import AppActions from 'common/dispatcher/app-actions'
import { FeatureState, ProjectFlag } from 'common/types/responses'
export const removeUserOverride = ({
cb,
environmentId,
identifier,
identity,
identityFlag,
projectFlag,
}: {
environmentId: string
identifier: string
identity: string
identityFlag: FeatureState
projectFlag: ProjectFlag
cb?: () => void
}) => {
const onConfirm = () => {
AppActions.removeUserFlag({
cb,
environmentId,
identity,
identityFlag,
})
}
openModal2(
'Reset User Feature',
<ConfirmRemoveFeature
identity={identifier}
projectFlag={projectFlag}
cb={onConfirm}
/>,
)
}
2 changes: 1 addition & 1 deletion frontend/web/components/modals/ConfirmRemoveFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ConfirmRemoveFeature: FC<ConfirmRemoveFeatureType> = ({
const submit = (e: FormEvent) => {
e.preventDefault()
if (challenge == projectFlag.name) {
closeModal()
closeModal2()
cb()
}
}
Expand Down
149 changes: 90 additions & 59 deletions frontend/web/components/modals/CreateFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import ModalHR from './ModalHR'
import FeatureValue from 'components/FeatureValue'
import FlagOwnerGroups from 'components/FlagOwnerGroups'
import ExistingChangeRequestAlert from 'components/ExistingChangeRequestAlert'
import Button from 'components/base/forms/Button'
import { removeUserOverride } from 'components/RemoveUserOverride'

const CreateFlag = class extends Component {
static displayName = 'CreateFlag'
Expand Down Expand Up @@ -1460,69 +1462,98 @@ const CreateFlag = class extends Component {
</div>
)
}
renderRow={({
enabled,
feature_state_value,
id,
identity,
}) => (
<Row
space
className='list-item cursor-pointer'
key={id}
>
<Row>
<div
className='table-column'
style={{ width: '65px' }}
>
<Switch
checked={enabled}
onChange={() =>
this.toggleUserFlag({
enabled,
id,
identity,
})
}
disabled={Utils.getIsEdge()}
/>
</div>
<div className='font-weight-medium fs-small lh-sm'>
{identity.identifier}
</div>
</Row>
<Row>
<div
className='table-column'
style={{ width: '188px' }}
>
{feature_state_value !==
null && (
<FeatureValue
value={
feature_state_value
renderRow={(identityFlag) => {
const {
enabled,
feature_state_value,
id,
identity,
} = identityFlag
return (
<Row
space
className='list-item cursor-pointer'
key={id}
>
<Row>
<div
className='table-column'
style={{ width: '65px' }}
>
<Switch
checked={enabled}
onChange={() =>
this.toggleUserFlag({
enabled,
id,
identity,
})
}
disabled={Utils.getIsEdge()}
/>
)}
</div>
<div className='table-column'>
<Button
target='_blank'
href={`/project/${this.props.projectId}/environment/${this.props.environmentId}/users/${identity.identifier}/${identity.id}?flag=${projectFlag.name}`}
className='btn btn-link fs-small lh-sm font-weight-medium'
</div>
<div className='font-weight-medium fs-small lh-sm'>
{identity.identifier}
</div>
</Row>
<Row>
<div
className='table-column'
style={{ width: '188px' }}
>
<Icon
name='edit'
width={20}
fill='#6837FC'
/>{' '}
Edit
</Button>
</div>
{feature_state_value !==
null && (
<FeatureValue
value={
feature_state_value
}
/>
)}
</div>
<div className='table-column'>
<Button
target='_blank'
href={`/project/${this.props.projectId}/environment/${this.props.environmentId}/users/${identity.identifier}/${identity.id}?flag=${projectFlag.name}`}
className='btn btn-link fs-small lh-sm font-weight-medium'
>
<Icon
name='edit'
width={20}
fill='#6837FC'
/>{' '}
Edit
</Button>
<Button
onClick={(e) => {
e.stopPropagation()
removeUserOverride({
cb: () =>
this.userOverridesPage(
1,
),
environmentId:
this.props
.environmentId,
identifier:
identity.identifier,
identity: identity.id,
identityFlag,
projectFlag,
})
}}
className='btn ml-2 btn-with-icon'
>
<Icon
name='trash-2'
width={20}
fill='#656D7B'
/>
</Button>
</div>
</Row>
</Row>
</Row>
)}
)
}}
renderNoResults={
<Row className='list-item'>
<div className='table-column'>
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/pages/AuditLogItemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type AuditLogItemPageType = {
const AuditLogItemPage: FC<AuditLogItemPageType> = ({ match }) => {
const { data, error, isLoading } = useGetAuditLogItemQuery({
id: match.params.id,
projectId: match.params.projectId
projectId: match.params.projectId,
})

const index = (ProjectStore.getEnvs() as Environment[] | null)?.findIndex(
Expand Down
4 changes: 3 additions & 1 deletion frontend/web/components/pages/ChangeRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ const ChangeRequestsPage = class extends Component {
this.fetchFeature(featureId)
}
const user =
changeRequest && changeRequest.user && orgUsers.find((v) => v.id === changeRequest.user)
changeRequest &&
changeRequest.user &&
orgUsers.find((v) => v.id === changeRequest.user)
const committedBy =
(changeRequest.committed_by &&
orgUsers &&
Expand Down
8 changes: 4 additions & 4 deletions frontend/web/components/pages/ChangeRequestsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ const ChangeRequestsPage = class extends Component {
<div className='list-item-subtitle mt-1'>
Created{' '}
{moment(created_at).format('Do MMM YYYY HH:mma')}{' '}
by {user && user.first_name || 'Unknown'}{' '}
{user && user.last_name || 'user'}
by {(user && user.first_name) || 'Unknown'}{' '}
{(user && user.last_name) || 'user'}
{description ? ` - ${description}` : ''}
</div>
</Flex>
Expand Down Expand Up @@ -283,8 +283,8 @@ const ChangeRequestsPage = class extends Component {
<div className='list-item-subtitle mt-1'>
Live from{' '}
{moment(created_at).format('Do MMM YYYY HH:mma')}{' '}
by {user && user.first_name || 'Unknown'}{' '}
{user && user.last_name || 'user'}
by {(user && user.first_name) || 'Unknown'}{' '}
{(user && user.last_name) || 'user'}
</div>
</Flex>
<div className='table-column'>
Expand Down
52 changes: 22 additions & 30 deletions frontend/web/components/pages/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getViewMode, setViewMode } from 'common/useViewMode'
import classNames from 'classnames'
import IdentifierString from 'components/IdentifierString'
import Button from 'components/base/forms/Button'
import { removeUserOverride } from 'components/RemoveUserOverride'
const width = [200, 48, 78]
const valuesEqual = (actualValue, flagValue) => {
const nullFalseyA =
Expand All @@ -39,6 +40,7 @@ const valuesEqual = (actualValue, flagValue) => {
}
return actualValue === flagValue
}

const UserPage = class extends Component {
static displayName = 'UserPage'

Expand Down Expand Up @@ -223,18 +225,6 @@ const UserPage = class extends Component {
)
}

confirmRemove = (projectFlag, cb, identity) => {
openModal(
'Reset User Feature',
<ConfirmRemoveFeature
identity={identity}
environmentId={this.props.match.params.environmentId}
projectFlag={projectFlag}
cb={cb}
/>,
)
}

removeTrait = (id, trait_key) => {
openConfirm(
'Delete Trait',
Expand Down Expand Up @@ -843,27 +833,29 @@ const UserPage = class extends Component {
theme='text'
size='xSmall'
disabled={!permission}
onClick={() =>
this.confirmRemove(
_.find(projectFlags, {
onClick={() => {
const projectFlag = _.find(
projectFlags,
{
id,
}),
() => {
removeFlag({
environmentId:
this.props.match
.params
.environmentId,
identity:
this.props.match
.params.id,
identityFlag,
})
},
identity.identity
.identifier,
)
}
const environmentId =
this.props.match.params
.environmentId

removeUserOverride({
environmentId,
identifier:
identity.identity
.identifier,
identity:
this.props.match.params
.id,
identityFlag,
projectFlag,
})
}}
>
<Icon
name='refresh'
Expand Down

0 comments on commit 3838f83

Please sign in to comment.