Skip to content

Commit 172a32a

Browse files
committed
refactor: migrate project settings to TS and break into smaller components
1 parent e643d78 commit 172a32a

File tree

18 files changed

+928
-675
lines changed

18 files changed

+928
-675
lines changed

frontend/common/services/useProject.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,52 @@ export const projectService = service
77
.enhanceEndpoints({ addTagTypes: ['Project'] })
88
.injectEndpoints({
99
endpoints: (builder) => ({
10+
deleteProject: builder.mutation<void, Req['deleteProject']>({
11+
invalidatesTags: [{ id: 'LIST', type: 'Project' }],
12+
query: ({ id }: Req['deleteProject']) => ({
13+
method: 'DELETE',
14+
url: `projects/${id}/`,
15+
}),
16+
}),
1017
getProject: builder.query<Res['project'], Req['getProject']>({
1118
providesTags: (res) => [{ id: res?.id, type: 'Project' }],
1219
query: (query: Req['getProject']) => ({
1320
url: `projects/${query.id}/`,
1421
}),
1522
}),
23+
getProjectPermissions: builder.query<
24+
Res['userPermissions'],
25+
Req['getProjectPermissions']
26+
>({
27+
query: ({ projectId }: Req['getProjectPermissions']) => ({
28+
url: `projects/${projectId}/user-permissions/`,
29+
}),
30+
}),
1631
getProjects: builder.query<Res['projects'], Req['getProjects']>({
1732
providesTags: [{ id: 'LIST', type: 'Project' }],
1833
query: (data) => ({
1934
url: `projects/?organisation=${data.organisationId}`,
2035
}),
2136
transformResponse: (res) => sortBy(res, (v) => v.name.toLowerCase()),
2237
}),
38+
migrateProject: builder.mutation<void, Req['migrateProject']>({
39+
invalidatesTags: (res, error, { id }) => [{ id, type: 'Project' }],
40+
query: ({ id }: Req['migrateProject']) => ({
41+
method: 'POST',
42+
url: `projects/${id}/migrate-to-edge/`,
43+
}),
44+
}),
45+
updateProject: builder.mutation<Res['project'], Req['updateProject']>({
46+
invalidatesTags: (res) => [
47+
{ id: res?.id, type: 'Project' },
48+
{ id: 'LIST', type: 'Project' },
49+
],
50+
query: ({ body, id }: Req['updateProject']) => ({
51+
body,
52+
method: 'PUT',
53+
url: `projects/${id}/`,
54+
}),
55+
}),
2356
// END OF ENDPOINTS
2457
}),
2558
})
@@ -47,8 +80,12 @@ export async function getProject(
4780
// END OF FUNCTION_EXPORTS
4881

4982
export const {
83+
useDeleteProjectMutation,
84+
useGetProjectPermissionsQuery,
5085
useGetProjectQuery,
5186
useGetProjectsQuery,
87+
useMigrateProjectMutation,
88+
useUpdateProjectMutation,
5289
// END OF EXPORTS
5390
} = projectService
5491

frontend/common/types/requests.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
Segment,
1111
Tag,
1212
ProjectFlag,
13+
Project,
1314
Environment,
1415
UserGroup,
1516
AttributeName,
1617
Identity,
17-
ChangeRequest,
1818
ProjectChangeRequest,
1919
Role,
2020
RolePermission,
@@ -580,6 +580,10 @@ export type Req = {
580580
id: string
581581
}
582582
getProject: { id: string }
583+
updateProject: { id: string; body: Partial<Project> }
584+
deleteProject: { id: string }
585+
migrateProject: { id: string }
586+
getProjectPermissions: { projectId: string }
583587
createGroup: {
584588
orgId: string
585589
data: Omit<UserGroup, 'id' | 'users'>

frontend/common/types/responses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export type Project = {
136136
total_features?: number
137137
stale_flags_limit_days?: number
138138
total_segments?: number
139+
only_allow_lower_case_feature_names?: boolean
140+
feature_name_regex?: string | null
139141
environments: Environment[]
140142
}
141143
export type ImportStrategy = 'SKIP' | 'OVERWRITE_DESTRUCTIVE'

frontend/global.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ declare global {
7070
const closeModal2: () => void
7171
const toast: (message: string) => void
7272
const Tooltip: FC<TooltipProps>
73+
const API: {
74+
trackPage: (title: string) => void
75+
trackEvent: (data: {
76+
category: string
77+
event: string
78+
label?: string
79+
extra?: Record<string, any>
80+
}) => void
81+
trackTraits: (traits: Record<string, any>) => void
82+
[key: string]: any
83+
}
7384
interface Window {
7485
$crisp: Crisp
7586
engagement: {

0 commit comments

Comments
 (0)