Skip to content
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

fix: Tidy up ld import #3276

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export type Req = {
environmentId: string
featureId: string
enabled: boolean
feature_segment: featureSegment
feature_segment: {
segment: number
}
feature_state_value: FeatureStateValue
}
getRoles: { organisation_id: string }
Expand Down Expand Up @@ -130,9 +132,15 @@ export type Req = {
getGetSubscriptionMetadata: { id: string }
getEnvironment: { id: string }
getSubscriptionMetadata: { id: string }
createLaunchDarklyProjectImport: { project_id: string }
getLaunchDarklyProjectImport: { project_id: string }
getLaunchDarklyProjectsImport: { project_id: string; import_id: string }
createLaunchDarklyProjectImport: {
project_id: string
body: {
project_key: string
token: string
}
}
getLaunchDarklyProjectImport: { project_id: string; import_id: string }
getLaunchDarklyProjectsImport: { project_id: string }
getUserWithRoles: { org_id: string; user_id: string }
deleteUserWihRole: { org_id: string; user_id: string; role_id: string }
getGroupWithRole: { org_id: string; group_id: string }
Expand Down
34 changes: 23 additions & 11 deletions frontend/web/components/pages/ImportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { useEffect, useState } from 'react'
import React, { FC, useEffect, useState } from 'react'
import _data from 'common/data/base/_data'
import {
useCreateLaunchDarklyProjectImportMutation,
useGetLaunchDarklyProjectImportQuery,
} from 'common/services/useLaunchDarklyProjectImport'
import AppLoader from 'components/AppLoader'
import InfoMessage from 'components/InfoMessage'
import Input from 'components/base/forms/Input'
import Utils from 'common/utils/utils'
import Button from 'components/base/forms/Button'
import PanelSearch from 'components/PanelSearch'

type ImportPageType = {
projectId: string
Expand All @@ -14,21 +18,24 @@ type ImportPageType = {

const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
const [LDKey, setLDKey] = useState<string>('')
const [importId, setImportId] = useState<string>('')
const [importId, setImportId] = useState<number>()
const [isLoading, setIsLoading] = useState<boolean>(false)
const [isAppLoading, setAppIsLoading] = useState<boolean>(false)
const [projects, setProjects] = useState<string>([])
const [projects, setProjects] = useState<{ key: string; name: string }[]>([])
const [createLaunchDarklyProjectImport, { data, isSuccess }] =
useCreateLaunchDarklyProjectImportMutation()

const {
data: status,
isSuccess: statusLoaded,
refetch,
} = useGetLaunchDarklyProjectImportQuery({
import_id: importId,
project_id: projectId,
})
} = useGetLaunchDarklyProjectImportQuery(
{
import_id: `${importId}`,
project_id: projectId,
},
{ skip: !importId },
)

useEffect(() => {
const checkImportStatus = async () => {
Expand All @@ -50,7 +57,7 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
}, [statusLoaded, status, refetch])

useEffect(() => {
if (isSuccess) {
if (isSuccess && data?.id) {
setImportId(data.id)
refetch()
}
Expand All @@ -62,7 +69,7 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
.get(`https://app.launchdarkly.com/api/v2/projects`, '', {
'Authorization': LDKey,
})
.then((res) => {
.then((res: { items: { key: string; name: string }[] }) => {
setIsLoading(false)
setProjects(res.items)
})
Expand Down Expand Up @@ -100,7 +107,9 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
<Input
value={LDKey}
name='ldkey'
onChange={(e) => setLDKey(Utils.safeParseEventValue(e))}
onChange={(e: InputEvent) =>
setLDKey(Utils.safeParseEventValue(e))
}
type='text'
placeholder='My LaunchDarkly key'
/>
Expand Down Expand Up @@ -129,7 +138,10 @@ const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => {
listClassName='row mt-n2 gy-4'
title='LaunchDarkly Projects'
items={projects}
renderRow={({ key, name }, i) => {
renderRow={(
{ key, name }: { key: string; name: string },
i: number,
) => {
return (
<>
<Button
Expand Down