Skip to content

Commit 951b216

Browse files
authored
chore: rtk segment identities (#5121)
1 parent a1dcdb8 commit 951b216

File tree

12 files changed

+261
-251
lines changed

12 files changed

+261
-251
lines changed

frontend/common/dispatcher/action-constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const Actions = Object.assign({}, require('./base/_action-constants'), {
3232
'GET_FEATURE_USAGE': 'GET_FEATURE_USAGE',
3333
'GET_FLAGS': 'GET_FLAGS',
3434
'GET_IDENTITY': 'GET_IDENTITY',
35-
'GET_IDENTITY_SEGMENTS': 'GET_IDENTITY_SEGMENTS',
3635
'GET_ORGANISATION': 'GET_ORGANISATION',
3736
'GET_PROJECT': 'GET_PROJECT',
3837
'INVALIDATE_INVITE_LINK': 'INVALIDATE_INVITE_LINK',

frontend/common/dispatcher/app-actions.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,6 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
260260
id,
261261
})
262262
},
263-
getIdentitySegments(projectId, id) {
264-
Dispatcher.handleViewAction({
265-
actionType: Actions.GET_IDENTITY_SEGMENTS,
266-
id,
267-
projectId,
268-
})
269-
},
270263
getOrganisation(organisationId) {
271264
Dispatcher.handleViewAction({
272265
actionType: Actions.GET_ORGANISATION,

frontend/common/providers/IdentitySegmentsProvider.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Res } from 'common/types/responses'
2+
import { Req } from 'common/types/requests'
3+
import { service } from 'common/service'
4+
import Utils from 'common/utils/utils'
5+
import transformCorePaging from 'common/transformCorePaging'
6+
import { sortBy } from 'lodash'
7+
8+
export const identitySegmentService = service
9+
.enhanceEndpoints({ addTagTypes: ['IdentitySegment'] })
10+
.injectEndpoints({
11+
endpoints: (builder) => ({
12+
getIdentitySegments: builder.query<
13+
Res['identitySegments'],
14+
Req['getIdentitySegments']
15+
>({
16+
providesTags: (res) => [{ id: res?.id, type: 'IdentitySegment' }],
17+
query: ({ projectId, ...query }: Req['getIdentitySegments']) => ({
18+
url: `/projects/${projectId}/segments/?${Utils.toParam(query)}`,
19+
}),
20+
transformResponse: (
21+
res: Res['identitySegments'],
22+
_,
23+
req: Req['getIdentitySegments'],
24+
) =>
25+
transformCorePaging(req, {
26+
...res,
27+
results: sortBy(res.results, 'name'),
28+
}),
29+
}),
30+
// END OF ENDPOINTS
31+
}),
32+
})
33+
34+
export async function getIdentitySegments(
35+
store: any,
36+
data: Req['getIdentitySegments'],
37+
options?: Parameters<
38+
typeof identitySegmentService.endpoints.getIdentitySegments.initiate
39+
>[1],
40+
) {
41+
return store.dispatch(
42+
identitySegmentService.endpoints.getIdentitySegments.initiate(
43+
data,
44+
options,
45+
),
46+
)
47+
}
48+
// END OF FUNCTION_EXPORTS
49+
50+
export const {
51+
useGetIdentitySegmentsQuery,
52+
// END OF EXPORTS
53+
} = identitySegmentService
54+
55+
/* Usage examples:
56+
const { data, isLoading } = useGetIdentitySegmentsQuery({ id: 2 }, {}) //get hook
57+
const [createIdentitySegments, { isLoading, data, isSuccess }] = useCreateIdentitySegmentsMutation() //create hook
58+
identitySegmentService.endpoints.getIdentitySegments.select({id: 2})(store.getState()) //access data from any function
59+
*/

frontend/common/stores/identity-segments-store.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

frontend/common/types/requests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,5 +568,10 @@ export type Req = {
568568
getAuditLogWebhooks: { organisationId: string }
569569
updateAuditLogWebhooks: { organisationId: string; data: Webhook }
570570
deleteAuditLogWebhook: { organisationId: string; id: number }
571+
getIdentitySegments: PagedRequest<{
572+
q?: string
573+
identity: string
574+
projectId: string
575+
}>
571576
// END OF TYPES
572577
}

frontend/common/types/responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ export type Res = {
795795
metadata_xml: string
796796
}
797797
samlAttributeMapping: PagedResponse<SAMLAttributeMapping>
798+
identitySegments: PagedResponse<Segment>
798799
organisationWebhooks: PagedResponse<Webhook>
799800
// END OF TYPES
800801
}

frontend/global.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ declare global {
2727
) => void
2828
const openConfirm: (data: OpenConfirm) => void
2929
const Row: typeof Component
30-
const toast: (value: ReactNode, theme?: string, expiry?: number, action?: { buttonText: string; onClick: () => void }) => void
30+
const toast: (
31+
value: ReactNode,
32+
theme?: string,
33+
expiry?: number,
34+
action?: { buttonText: string; onClick: () => void },
35+
) => void
3136
const Flex: typeof Component
3237
const isMobile: boolean
3338
const FormGroup: typeof Component

frontend/web/components/EnvironmentSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC, useMemo } from 'react'
22
import { useGetEnvironmentsQuery } from 'common/services/useEnvironment'
33
import { Props } from 'react-select/lib/Select'
44

5-
export type EnvironmentSelectType = Partial<Props> & {
5+
export type EnvironmentSelectType = Partial<Omit<Props, 'value'>> & {
66
projectId: string
77
value?: string
88
label?: string

frontend/web/components/modals/AuditLogWebhooks.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const AuditLogWebhooks: FC<AuditLogWebhooksType> = ({ organisationId }) => {
6969
<h5 className='mb-2'>Audit Webhooks</h5>
7070
<p className='fs-small lh-sm mb-4'>
7171
Audit webhooks let you know when audit logs occur. You can configure
72-
1 or more audit webhooks per organisation.<br/>
72+
1 or more audit webhooks per organisation.
73+
<br />
7374
<Button
7475
theme='text'
7576
href='https://docs.flagsmith.com/system-administration/webhooks'
@@ -87,7 +88,7 @@ const AuditLogWebhooks: FC<AuditLogWebhooksType> = ({ organisationId }) => {
8788
) : (
8889
<PanelSearch
8990
id='webhook-list'
90-
className="no-pad"
91+
className='no-pad'
9192
items={webhooks?.results}
9293
renderRow={(webhook: Webhook) => (
9394
<Row

0 commit comments

Comments
 (0)