-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui/dashboard): user segments management (#1426)
- Loading branch information
1 parent
cfe76a0
commit bd8710e
Showing
43 changed files
with
2,101 additions
and
20 deletions.
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
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
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,5 @@ | ||
export * from './user-segments-fetcher'; | ||
export * from './user-segment-creator'; | ||
export * from './user-segment-bulk-upload'; | ||
export * from './user-segment-fetcher'; | ||
export * from './user-segment-bulk-download'; |
23 changes: 23 additions & 0 deletions
23
ui/dashboard/src/@api/user-segment/user-segment-bulk-download.ts
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,23 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import pickBy from 'lodash/pickBy'; | ||
import { isNotEmpty } from 'utils/data-type'; | ||
|
||
export interface UserSegmentBulkDownloadParams { | ||
segmentId: string; | ||
environmentId: string; | ||
state?: 'INCLUDED' | 'EXCLUDED'; | ||
} | ||
|
||
export interface UserSegmentBulkDownloadResponse { | ||
data: string; | ||
} | ||
|
||
export const userSegmentBulkDownload = async ( | ||
params?: UserSegmentBulkDownloadParams | ||
): Promise<UserSegmentBulkDownloadResponse> => { | ||
return axiosClient | ||
.get<UserSegmentBulkDownloadResponse>('/v1/segment_users/bulk_download', { | ||
params: pickBy(params, v => isNotEmpty(v)) | ||
}) | ||
.then(response => response.data); | ||
}; |
16 changes: 16 additions & 0 deletions
16
ui/dashboard/src/@api/user-segment/user-segment-bulk-upload.ts
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,16 @@ | ||
import axiosClient from '@api/axios-client'; | ||
|
||
export interface UserSegmentBulkUploadParams { | ||
segmentId: string; | ||
environmentId?: string; | ||
data?: string; | ||
state?: 'INCLUDED' | 'EXCLUDED'; | ||
} | ||
|
||
export const userSegmentBulkUpload = async ( | ||
params?: UserSegmentBulkUploadParams | ||
) => { | ||
return axiosClient | ||
.post('/v1/segment_users/bulk_upload', params) | ||
.then(response => response.data); | ||
}; |
20 changes: 20 additions & 0 deletions
20
ui/dashboard/src/@api/user-segment/user-segment-creator.ts
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,20 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import { UserSegment } from '@types'; | ||
|
||
export interface UserSegmentCreatorParams { | ||
environmentId: string; | ||
name: string; | ||
description?: string; | ||
} | ||
|
||
export interface UserSegmentCreatorResponse { | ||
segment: UserSegment; | ||
} | ||
|
||
export const userSegmentCreator = async ( | ||
params?: UserSegmentCreatorParams | ||
): Promise<UserSegmentCreatorResponse> => { | ||
return axiosClient | ||
.post<UserSegmentCreatorResponse>('/v1/segment', params) | ||
.then(response => response.data); | ||
}; |
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,17 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import { pickBy } from 'lodash'; | ||
import { isNotEmpty } from 'utils/data-type'; | ||
import { stringifyParams } from 'utils/search-params'; | ||
|
||
export interface UserSegmentDeleteParams { | ||
id: string; | ||
environmentId: string; | ||
} | ||
|
||
export const userSegmentDelete = async (_params?: UserSegmentDeleteParams) => { | ||
const params = pickBy(_params, v => isNotEmpty(v)); | ||
|
||
return axiosClient | ||
.delete(`/v1/segment?${stringifyParams(params)}`) | ||
.then(response => response.data); | ||
}; |
23 changes: 23 additions & 0 deletions
23
ui/dashboard/src/@api/user-segment/user-segment-fetcher.ts
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,23 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import pickBy from 'lodash/pickBy'; | ||
import { UserSegment } from '@types'; | ||
import { isNotEmpty } from 'utils/data-type'; | ||
|
||
export interface UserSegmentFetcherParams { | ||
id: string; | ||
environmentId: string; | ||
} | ||
|
||
export interface UserSegmentResponse { | ||
segment: Array<UserSegment>; | ||
} | ||
|
||
export const userSegmentFetcher = async ( | ||
params?: UserSegmentFetcherParams | ||
): Promise<UserSegmentResponse> => { | ||
return axiosClient | ||
.get<UserSegmentResponse>('/v1/segment', { | ||
params: pickBy(params, v => isNotEmpty(v)) | ||
}) | ||
.then(response => response.data); | ||
}; |
21 changes: 21 additions & 0 deletions
21
ui/dashboard/src/@api/user-segment/user-segment-updater.ts
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,21 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import { UserSegment } from '@types'; | ||
|
||
export interface UserSegmentUpdaterParams { | ||
id: string; | ||
environmentId: string; | ||
name?: string; | ||
description?: string; | ||
} | ||
|
||
export interface UserSegmentUpdaterResponse { | ||
segment: UserSegment; | ||
} | ||
|
||
export const userSegmentUpdater = async ( | ||
params?: UserSegmentUpdaterParams | ||
): Promise<UserSegmentUpdaterResponse> => { | ||
return axiosClient | ||
.patch<UserSegmentUpdaterResponse>('/v1/segment', params) | ||
.then(response => response.data); | ||
}; |
25 changes: 25 additions & 0 deletions
25
ui/dashboard/src/@api/user-segment/user-segments-fetcher.ts
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,25 @@ | ||
import axiosClient from '@api/axios-client'; | ||
import pickBy from 'lodash/pickBy'; | ||
import { | ||
UserSegmentCollection, | ||
CollectionParams, | ||
FeatureSegmentStatus | ||
} from '@types'; | ||
import { isNotEmpty } from 'utils/data-type'; | ||
import { stringifyParams } from 'utils/search-params'; | ||
|
||
export interface UserSegmentsFetcherParams extends CollectionParams { | ||
environmentId?: string; | ||
isInUseStatus?: boolean; | ||
status?: FeatureSegmentStatus; | ||
} | ||
|
||
export const userSegmentsFetcher = async ( | ||
params?: UserSegmentsFetcherParams | ||
): Promise<UserSegmentCollection> => { | ||
const requestParams = stringifyParams(pickBy(params, v => isNotEmpty(v))); | ||
|
||
return axiosClient | ||
.get<UserSegmentCollection>(`/v1/segments?${requestParams}`) | ||
.then(response => response.data); | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
import { | ||
userSegmentsFetcher, | ||
UserSegmentsFetcherParams | ||
} from '@api/user-segment'; | ||
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import type { UserSegmentCollection, QueryOptionsRespond } from '@types'; | ||
|
||
type QueryOptions = QueryOptionsRespond<UserSegmentCollection> & { | ||
params?: UserSegmentsFetcherParams; | ||
}; | ||
|
||
export const USER_SEGMENTS_QUERY_KEY = 'user-segments'; | ||
|
||
export const useQueryUserSegments = (options?: QueryOptions) => { | ||
const { params, ...queryOptions } = options || {}; | ||
const query = useQuery({ | ||
queryKey: [USER_SEGMENTS_QUERY_KEY, params], | ||
queryFn: async () => { | ||
return userSegmentsFetcher(params); | ||
}, | ||
...queryOptions | ||
}); | ||
return query; | ||
}; | ||
|
||
export const usePrefetchUserSegments = (options?: QueryOptions) => { | ||
const { params, ...queryOptions } = options || {}; | ||
const queryClient = useQueryClient(); | ||
queryClient.prefetchQuery({ | ||
queryKey: [USER_SEGMENTS_QUERY_KEY, params], | ||
queryFn: async () => { | ||
return userSegmentsFetcher(params); | ||
}, | ||
...queryOptions | ||
}); | ||
}; | ||
|
||
export const prefetchUserSegments = ( | ||
queryClient: QueryClient, | ||
options?: QueryOptions | ||
) => { | ||
const { params, ...queryOptions } = options || {}; | ||
queryClient.prefetchQuery({ | ||
queryKey: [USER_SEGMENTS_QUERY_KEY, params], | ||
queryFn: async () => { | ||
return userSegmentsFetcher(params); | ||
}, | ||
...queryOptions | ||
}); | ||
}; | ||
|
||
export const invalidateUserSegments = (queryClient: QueryClient) => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [USER_SEGMENTS_QUERY_KEY] | ||
}); | ||
}; |
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
Oops, something went wrong.