Skip to content

Commit c9c2ace

Browse files
committed
Fix: Delete unnecessary code
1 parent 6586b7d commit c9c2ace

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

frontend/common/dispatcher/app-actions.js

-6
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
104104
id,
105105
})
106106
},
107-
getEnv(environmentId) {
108-
Dispatcher.handleViewAction({
109-
actionType: Actions.GET_ENVIRONMENT,
110-
environmentId,
111-
})
112-
},
113107
deleteUser(id) {
114108
Dispatcher.handleViewAction({
115109
actionType: Actions.DELETE_USER,

frontend/common/stores/project-store.js

-11
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ const controller = {
8484
store.saved()
8585
})
8686
},
87-
getEnv: (envId) => {
88-
data.get(`${Project.api}environments/${envId}/`).then((environment) => {
89-
environment.total_segment_overrides =
90-
environment.total_segment_overrides || 0
91-
store.model = Object.assign(store.model, { environment })
92-
store.saved()
93-
})
94-
},
9587
getProject: (id, cb, force) => {
9688
if (force) {
9789
store.loading()
@@ -226,9 +218,6 @@ store.dispatcherIndex = Dispatcher.register(store, (payload) => {
226218
case Actions.EDIT_ENVIRONMENT:
227219
controller.editEnv(action.env)
228220
break
229-
case Actions.GET_ENVIRONMENT:
230-
controller.getEnv(action.environmentId)
231-
break
232221
case Actions.DELETE_ENVIRONMENT:
233222
controller.deleteEnv(action.env)
234223
break

frontend/web/components/App.js

-23
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import { resolveAuthFlow } from '@datadog/ui-extensions-sdk'
1919
import ConfigProvider from 'common/providers/ConfigProvider'
2020
import Permission from 'common/providers/Permission'
2121
import { getOrganisationUsage } from 'common/services/useOrganisationUsage'
22-
import { getSubscriptionMetadata } from 'common/services/useSubscriptionMetadata'
2322
import Button from './base/forms/Button'
2423
import Icon from './Icon'
2524
import AccountStore from 'common/stores/account-store'
2625
import InfoMessage from './InfoMessage'
27-
import Format from 'common/utils/format'
2826
import OrganisationLimit from './OrganisationLimit'
2927

3028
const App = class extends Component {
@@ -41,10 +39,8 @@ const App = class extends Component {
4139
asideIsVisible: !isMobile,
4240
lastEnvironmentId: '',
4341
lastProjectId: '',
44-
maxApiCalls: 50000,
4542
pin: '',
4643
showAnnouncement: true,
47-
totalApiCalls: 0,
4844
}
4945

5046
constructor(props, context) {
@@ -74,19 +70,11 @@ const App = class extends Component {
7470
AccountStore.getOrganisation()?.id &&
7571
this.state.activeOrganisation !== AccountStore.getOrganisation().id
7672
) {
77-
getSubscriptionMetadata(getStore(), {
78-
id: AccountStore.getOrganisation()?.id,
79-
}).then((res) => {
80-
this.setState({
81-
maxApiCalls: res?.data?.max_api_calls,
82-
})
83-
})
8473
getOrganisationUsage(getStore(), {
8574
organisationId: AccountStore.getOrganisation()?.id,
8675
}).then((res) => {
8776
this.setState({
8877
activeOrganisation: AccountStore.getOrganisation().id,
89-
totalApiCalls: res?.data?.totals.total,
9078
})
9179
})
9280
}
@@ -299,17 +287,6 @@ const App = class extends Component {
299287
)
300288
const dismissed = flagsmith.getTrait('dismissed_announcement')
301289
const showBanner = !dismissed || dismissed !== announcementValue.id
302-
const maxApiCallsPercentage = Utils.calculateRemainingLimitsPercentage(
303-
this.state.totalApiCalls,
304-
this.state.maxApiCalls,
305-
70,
306-
).percentage
307-
308-
const alertMaxApiCallsText = `You have used ${Format.shortenNumber(
309-
this.state.totalApiCalls,
310-
)}/${Format.shortenNumber(
311-
this.state.maxApiCalls,
312-
)} of your allowed requests.`
313290

314291
return (
315292
<Provider store={getStore()}>

frontend/web/components/Aside.js

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const Aside = class extends Component {
5050
? {}
5151
: { live_from_after: new Date().toISOString() },
5252
)
53-
AppActions.getEnv(this.props.environmentId)
5453
}
5554
})
5655
}
@@ -78,7 +77,6 @@ const Aside = class extends Component {
7877
? {}
7978
: { live_from_after: new Date().toISOString() },
8079
)
81-
AppActions.getEnv(this.props.environmentId)
8280
}
8381
}
8482
}

frontend/web/components/SegmentOverrides.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Permission from 'common/providers/Permission'
1414
import Constants from 'common/constants'
1515
import Icon from './Icon'
1616
import SegmentOverrideLimit from 'components/SegmentOverrideLimit'
17+
import { getStore } from 'common/store'
18+
import { getEnvironment } from 'common/services/useEnvironment'
1719

1820
const arrayMoveMutate = (array, from, to) => {
1921
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0])
@@ -425,7 +427,16 @@ class TheComponent extends Component {
425427

426428
constructor(props) {
427429
super(props)
428-
this.state = { segmentEditId: undefined }
430+
this.state = { segmentEditId: undefined, totalSegmentOverrides: 0 }
431+
}
432+
componentDidMount() {
433+
getEnvironment(getStore(), {
434+
id: this.props.environmentId,
435+
}).then((res) => {
436+
this.setState({
437+
totalSegmentOverrides: res[0].data.total_segment_overrides,
438+
})
439+
})
429440
}
430441

431442
addItem = () => {
@@ -540,6 +551,11 @@ class TheComponent extends Component {
540551

541552
const visibleValues = value && value.filter((v) => !v.toRemove)
542553

554+
const segmentOverrideLimitAlert = Utils.calculateRemainingLimitsPercentage(
555+
this.state.totalSegmentOverrides,
556+
ProjectStore.getMaxSegmentOverridesAllowed(),
557+
)
558+
543559
const isLimitReached =
544560
segmentOverrideLimitAlert.percentage &&
545561
segmentOverrideLimitAlert.percentage >= 100

frontend/web/components/modals/AssociatedSegmentOverrides.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import FlagSelect from 'components/FlagSelect'
1010
import InfoMessage from 'components/InfoMessage'
1111
import EnvironmentSelect from 'components/EnvironmentSelect'
1212
import SegmentOverrideLimit from 'components/SegmentOverrideLimit'
13+
import { getStore } from 'common/store'
14+
import { getEnvironment } from 'common/services/useEnvironment'
1315

1416
class TheComponent extends Component {
1517
state = {
@@ -379,12 +381,35 @@ export default class SegmentOverridesInner extends Component {
379381
}
380382

381383
class SegmentOverridesInnerAdd extends Component {
382-
state = {}
384+
state = { totalSegmentOverrides: 0 }
385+
386+
fetchTotalSegmentOverrides() {
387+
const { environmentId } = this.props
388+
const env = ProjectStore.getEnvs().find((v) => v.name === environmentId)
389+
390+
if (!env) {
391+
return
392+
}
393+
394+
const id = env.api_key
395+
396+
getEnvironment(getStore(), { id }).then((res) => {
397+
this.setState({
398+
totalSegmentOverrides: res[1].data.total_segment_overrides,
399+
})
400+
})
401+
}
383402

384403
componentDidMount() {
385404
ES6Component(this)
405+
this.fetchTotalSegmentOverrides()
386406
}
387407

408+
componentDidUpdate(prevProps) {
409+
if (prevProps.environmentId !== this.props.environmentId) {
410+
this.fetchTotalSegmentOverrides()
411+
}
412+
}
388413
render() {
389414
const { environmentId, id, ignoreFlags, projectId } = this.props
390415
const addValue = (featureId, feature) => {
@@ -415,7 +440,7 @@ class SegmentOverridesInnerAdd extends Component {
415440
// updateSegments(segmentOverrides.concat([newValue]))
416441
}
417442
const segmentOverrideLimitAlert =
418-
ProjectStore.getTotalSegmentOverrides >=
443+
this.state.totalSegmentOverrides >=
419444
ProjectStore.getMaxSegmentOverridesAllowed()
420445

421446
return (

0 commit comments

Comments
 (0)