-
Notifications
You must be signed in to change notification settings - Fork 429
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: display warning and prevent creation on limit #2526
Merged
novakzaballa
merged 49 commits into
main
from
feature/display-warning-and-prevent-creation-on-limit
Sep 18, 2023
Merged
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
1398479
Return limits and maxs in the API response, validate disable button, …
novakzaballa d92fa99
Add validation for limit alerts
novakzaballa 273a07b
Update serializers
novakzaballa 03c8642
Add Test
novakzaballa cbc4d49
Update serializers
novakzaballa d00a307
Merge branch 'main' into feature/display-warning-and-prevent-creation…
novakzaballa 244f2c4
Add alert_warning design system, add read_only_fields
novakzaballa 420a7f4
Use annotate for calculate totals, move and rename test
novakzaballa 33004fa
Update env view
novakzaballa 71eecfa
Update limit alert
novakzaballa 3bd32ac
Add alert toast
novakzaballa c4b4397
Merge branch 'main' into feature/display-warning-and-prevent-creation…
novakzaballa c5522c2
Update toast text
novakzaballa b4b69cf
Add types to displayToastAlert function
novakzaballa 480733e
Merge branch 'main' into feature/display-warning-and-prevent-creation…
novakzaballa 5cd3658
Delete alertLimit component
novakzaballa 6188849
exclude deleted rows in totals
novakzaballa a9eaa10
Delete alert toast
novakzaballa 68c2881
add WarningMessage, Warning icon and styles
novakzaballa 417d301
Use WarningMessage
novakzaballa 96511af
Merge branch 'main' into feature/display-warning-and-prevent-creation…
novakzaballa 9a2ec99
Add types, add Number.MAX_SAFE_INTEGER, change warningMessage color
novakzaballa 72ab33e
Change Error message
novakzaballa fef7879
Update segmentOverrides
novakzaballa 5f6cfb3
Number.MAX_SAFE_INTEGER deleted
novakzaballa 01695e4
Update segmentOverrides
novakzaballa 772d6da
Bug with total segment overrides fixed
novakzaballa 46a5fa3
bug with select fixed and "create feature-specific segment" button is…
novakzaballa 264290d
Disable select when the limit is reached
novakzaballa 95f36f5
Adding default fallback values to limits and counts for backwards com…
novakzaballa e8d9b3f
Merge branch 'main' into feature/display-warning-and-prevent-creation…
matthewelwell d656954
Revert API changes
matthewelwell 210b0d7
merge main
novakzaballa c6836cd
solve conflicts
novakzaballa 5b6f3bb
Reset changelog
matthewelwell b8c5a18
Reset changelog
matthewelwell 6270848
Merge branch 'main' into feature/display-warning-and-prevent-creation…
matthewelwell 323e153
fix: Added a defualt value for threshold in calculateRemainingLimitsP…
novakzaballa e8f463d
fix: change percentage from 30 to 70
novakzaballa 5171523
Get the value of maxApiCalls from "get-subscription-metadata" endpoint
novakzaballa 3b7c45f
Wording / spacing changes
matthewelwell 98fbeea
Small tweak to wording / spacing
matthewelwell 3a6f086
Spacing
matthewelwell 75558d4
Remove upgrade icon
matthewelwell 62d2a4b
Merge branch 'main' into feature/display-warning-and-prevent-creation…
novakzaballa 6d30b9d
feat: Change max api calls alert banner
novakzaballa 16b7f8b
Migrate changes to RTK
kyle-ssg 6586b7d
fix: Add SegmentOverridesLimit
novakzaballa c9c2ace
Fix: Delete unnecessary code
novakzaballa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
*.json | ||
*.handlebars | ||
*.css | ||
.bablerc | ||
.bablerc | ||
**/CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const getSubscriptionMetadataService = service | ||
.enhanceEndpoints({ addTagTypes: ['GetSubscriptionMetadata'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
getSubscriptionMetadata: builder.query< | ||
Res['getSubscriptionMetadata'], | ||
Req['getSubscriptionMetadata'] | ||
>({ | ||
providesTags: (res) => [ | ||
{ id: res?.id, type: 'GetSubscriptionMetadata' }, | ||
], | ||
query: (query: Req['getSubscriptionMetadata']) => ({ | ||
url: `organisations/${query.id}/get-subscription-metadata/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getSubscriptionMetadata( | ||
store: any, | ||
data: Req['getSubscriptionMetadata'], | ||
options?: Parameters< | ||
typeof getSubscriptionMetadataService.endpoints.getSubscriptionMetadata.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
getSubscriptionMetadataService.endpoints.getSubscriptionMetadata.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useGetSubscriptionMetadataQuery, | ||
// END OF EXPORTS | ||
} = getSubscriptionMetadataService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetSubscriptionMetadataQuery({ id: 2 }, {}) //get hook | ||
const [getSubscriptionMetadata, { isLoading, data, isSuccess }] = useGetSubscriptionMetadataMutation() //create hook | ||
getSubscriptionMetadataService.endpoints.getSubscriptionMetadata.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,13 @@ import { resolveAuthFlow } from '@datadog/ui-extensions-sdk' | |
import ConfigProvider from 'common/providers/ConfigProvider' | ||
import Permission from 'common/providers/Permission' | ||
import { getOrganisationUsage } from 'common/services/useOrganisationUsage' | ||
import { getSubscriptionMetadata } from 'common/services/useSubscriptionMetadata' | ||
import Button from './base/forms/Button' | ||
import Icon from 'components/Icon' | ||
import Icon from './Icon' | ||
import AccountStore from 'common/stores/account-store' | ||
import InfoMessage from './InfoMessage' | ||
import Format from 'common/utils/format' | ||
import OrganisationLimit from './OrganisationLimit' | ||
|
||
const App = class extends Component { | ||
static propTypes = { | ||
|
@@ -38,6 +41,7 @@ const App = class extends Component { | |
asideIsVisible: !isMobile, | ||
lastEnvironmentId: '', | ||
lastProjectId: '', | ||
maxApiCalls: 50000, | ||
pin: '', | ||
showAnnouncement: true, | ||
totalApiCalls: 0, | ||
|
@@ -70,6 +74,13 @@ const App = class extends Component { | |
AccountStore.getOrganisation()?.id && | ||
this.state.activeOrganisation !== AccountStore.getOrganisation().id | ||
) { | ||
getSubscriptionMetadata(getStore(), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anymore |
||
id: AccountStore.getOrganisation()?.id, | ||
}).then((res) => { | ||
this.setState({ | ||
maxApiCalls: res?.data?.max_api_calls, | ||
}) | ||
}) | ||
getOrganisationUsage(getStore(), { | ||
organisationId: AccountStore.getOrganisation()?.id, | ||
}).then((res) => { | ||
|
@@ -288,6 +299,17 @@ const App = class extends Component { | |
) | ||
const dismissed = flagsmith.getTrait('dismissed_announcement') | ||
const showBanner = !dismissed || dismissed !== announcementValue.id | ||
const maxApiCallsPercentage = Utils.calculateRemainingLimitsPercentage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anymore |
||
this.state.totalApiCalls, | ||
this.state.maxApiCalls, | ||
70, | ||
).percentage | ||
|
||
const alertMaxApiCallsText = `You have used ${Format.shortenNumber( | ||
this.state.totalApiCalls, | ||
)}/${Format.shortenNumber( | ||
this.state.maxApiCalls, | ||
)} of your allowed requests.` | ||
|
||
return ( | ||
<Provider store={getStore()}> | ||
|
@@ -484,6 +506,11 @@ const App = class extends Component { | |
</div> | ||
) : ( | ||
<Fragment> | ||
{user && ( | ||
<OrganisationLimit | ||
id={AccountStore.getOrganisation()?.id} | ||
/> | ||
)} | ||
{user && | ||
showBanner && | ||
Utils.getFlagsmithHasFeature('announcement') && | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anymore?