-
Notifications
You must be signed in to change notification settings - Fork 562
feat: wire CSV segments to the cohorts API #8295
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
Merged
+518
−35
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d998299
feat: wire CSV segments to the cohorts API
Zaimwa9 5889d04
fix: use cohort summary environment fields, cap identifier bytes clie…
Zaimwa9 f1386ba
fix: scope cohort retry to its form state and make cohort segments re…
Zaimwa9 6bdb2c8
fix: guard save and Add AND NOT button with isReadOnly for cohort-man…
Zaimwa9 73abef4
fix: add horizontal padding to CSV drawer and log submission errors
Zaimwa9 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 hidden or 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,82 @@ | ||
| import { Res } from 'common/types/responses' | ||
| import { Req } from 'common/types/requests' | ||
| import { service } from 'common/service' | ||
| import toFormData from 'common/utils/toFormData' | ||
|
|
||
| export const cohortService = service | ||
| .enhanceEndpoints({ addTagTypes: ['Cohort', 'Segment'] }) | ||
| .injectEndpoints({ | ||
| endpoints: (builder) => ({ | ||
| createCohort: builder.mutation<Res['cohort'], Req['createCohort']>({ | ||
| invalidatesTags: (q, e, arg) => [ | ||
| { id: 'LIST', type: 'Cohort' }, | ||
| { id: `LIST${arg.projectId}`, type: 'Segment' }, | ||
| ], | ||
| query: (query) => ({ | ||
| body: { | ||
| description: query.description, | ||
| metadata: query.metadata, | ||
| name: query.name, | ||
| }, | ||
| method: 'POST', | ||
| url: `environments/${query.environmentApiKey}/cohorts/`, | ||
| }), | ||
| }), | ||
| deleteCohort: builder.mutation<void, Req['deleteCohort']>({ | ||
| invalidatesTags: (q, e, arg) => [ | ||
| { id: 'LIST', type: 'Cohort' }, | ||
| { id: `LIST${arg.projectId}`, type: 'Segment' }, | ||
| ], | ||
| query: (query) => ({ | ||
| method: 'DELETE', | ||
| url: `environments/${query.environmentApiKey}/cohorts/${query.cohortId}/`, | ||
| }), | ||
| }), | ||
| syncCohortCsv: builder.mutation< | ||
| Res['cohortCsvSync'], | ||
| Req['syncCohortCsv'] | ||
| >({ | ||
| invalidatesTags: (q, e, arg) => [ | ||
| { id: arg.cohortId, type: 'Cohort' }, | ||
| { id: `LIST${arg.projectId}`, type: 'Segment' }, | ||
| ], | ||
| queryFn: async (query, baseQueryApi, extraOptions, baseQuery) => { | ||
| // projectId only feeds tag invalidation; keep it out of the form data. | ||
| const { cohortId, environmentApiKey, projectId: _, ...rest } = query | ||
| const formData = toFormData({ ...rest }) | ||
| const { data, error } = await baseQuery({ | ||
| body: formData, | ||
| method: 'POST', | ||
| url: `environments/${environmentApiKey}/cohorts/${cohortId}/sync-csv/`, | ||
| }) | ||
| return { data, error } as { | ||
| data: Res['cohortCsvSync'] | ||
| error: never | ||
| } | ||
| }, | ||
| }), | ||
| // END OF ENDPOINTS | ||
| }), | ||
| }) | ||
|
|
||
| export async function deleteCohort( | ||
| store: any, | ||
| data: Req['deleteCohort'], | ||
| options?: Parameters<typeof cohortService.endpoints.deleteCohort.initiate>[1], | ||
| ) { | ||
| return store.dispatch( | ||
| cohortService.endpoints.deleteCohort.initiate(data, options), | ||
| ) | ||
| } | ||
|
|
||
| export const { | ||
| useCreateCohortMutation, | ||
| useDeleteCohortMutation, | ||
| useSyncCohortCsvMutation, | ||
| // END OF EXPORTS | ||
| } = cohortService | ||
|
|
||
| /* Usage examples: | ||
| const [createCohort, { isLoading, data, isSuccess }] = useCreateCohortMutation() | ||
| const [syncCohortCsv, { isLoading }] = useSyncCohortCsvMutation() | ||
| */ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.