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: Improve the UI/UX for GitHub integrations #3907

Merged
merged 22 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bb14eba
fix: Improve the UI/UX for GitHub integrations
novakzaballa May 8, 2024
bfca370
Move GithubReposTable and deleteGithubRepos components to MyGitHubRep…
novakzaballa May 8, 2024
e6fb3d0
Add logic in MyGithubRepositoriesComponent, solve link PR issue
novakzaballa May 8, 2024
24bd50d
Update UI in the feature external resources components
novakzaballa May 8, 2024
fa38d29
Move components to ExternalResourcesTable
novakzaballa May 9, 2024
1b17e10
Solve issues in the GitHubSetupPage
novakzaballa May 9, 2024
4d97821
Rename PermanentRow to AddExternalResourceRow, Add constants
novakzaballa May 9, 2024
7c6be5e
Solve closeModal logic
novakzaballa May 9, 2024
859afbe
Solve Row render issue, Solve GithubSetupPage select project issue
novakzaballa May 10, 2024
d8de450
Solve Row render issue
novakzaballa May 10, 2024
b34ac52
Change confirm with a modal
novakzaballa May 10, 2024
079ec0e
Delete comment
novakzaballa May 10, 2024
d314723
Merge branch 'main' into fix/improve-the-ui-ux-for-github-integrations
novakzaballa May 10, 2024
08e1a35
Fix margin styles, Increase the emergent window size, solve select ov…
novakzaballa May 10, 2024
5da708f
fetch Github integration onFocus
novakzaballa May 10, 2024
8bbe4ab
Improve Issue/PR selects
novakzaballa May 10, 2024
2ee6f73
Solve select issue
novakzaballa May 14, 2024
4cbace3
fix: SelectRepositories return the incorrect values when has more tha…
novakzaballa May 15, 2024
2d71d67
Merge branch 'main' into fix/improve-the-ui-ux-for-github-integrations
novakzaballa May 16, 2024
3085c69
fix: Change the theme for the plus button
novakzaballa May 17, 2024
23d0c54
Create a new tab for the external resources in the createFlag modal
novakzaballa May 17, 2024
3969932
Move add External resources on the top to tab
novakzaballa May 17, 2024
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
4 changes: 4 additions & 0 deletions frontend/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ export default {
'TRAITS_ID': 150,
},
},
githubType: {
githubIssue: 'GitHub Issue',
githubPR: 'Github PR',
},
modals: {
'PAYMENT': 'Payment Modal',
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export type ExternalResource = {
id?: number
url: string
type: string
project: number
status: null | string
project?: number
metadata: null | { status: string }
feature: number
}

Expand Down Expand Up @@ -692,7 +692,7 @@ export type Res = {
groupSummaries: UserGroupSummary[]
externalResource: PagedResponse<ExternalResource>
githubIntegrations: PagedResponse<githubIntegration>
githubRepository: PagedResponse<GithubRepository> | { data: { id: string } }
githubRepository: PagedResponse<GithubRepository>
githubIssues: Issue[]
githubPulls: PullRequest[]
githubRepos: GithubPaginatedRepos<Repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React, { FC } from 'react'
import Button from './base/forms/Button'
import { useDeleteGithubIntegrationMutation } from 'common/services/useGithubIntegration'

type DeleteGithubIntegracionType = {
type DeleteGithubIntegrationType = {
organisationId: string
githubId: string
onConfirm: () => void
}

const DeleteGithubIntegracion: FC<DeleteGithubIntegracionType> = ({
const DeleteGithubIntegration: FC<DeleteGithubIntegrationType> = ({
githubId,
onConfirm,
organisationId,
Expand All @@ -18,6 +18,7 @@ const DeleteGithubIntegracion: FC<DeleteGithubIntegracionType> = ({
return (
<Button
id='delete-integration'
theme='danger'
data-test='delete-integration'
onClick={() =>
openConfirm({
Expand All @@ -37,7 +38,7 @@ const DeleteGithubIntegracion: FC<DeleteGithubIntegracionType> = ({
github_integration_id: githubId,
organisation_id: organisationId,
}).then(() => {
onConfirm()
window.location.reload()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im confused, does this work ? It doesnt look like the correct way to open a confirmation modal, there's no message onYes etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This closes the modal when you delete the installation.

})
},
title: 'Remove your Github Integration',
Expand All @@ -51,4 +52,4 @@ const DeleteGithubIntegracion: FC<DeleteGithubIntegracionType> = ({
)
}

export default DeleteGithubIntegracion
export default DeleteGithubIntegration
245 changes: 197 additions & 48 deletions frontend/web/components/ExternalResourcesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@ import PanelSearch from './PanelSearch'
import Button from './base/forms/Button'
import Icon from './Icon'
import {
useCreateExternalResourceMutation,
useGetExternalResourcesQuery,
useDeleteExternalResourceMutation,
} from 'common/services/useExternalResource'
import { ExternalResource } from 'common/types/responses'
import Constants from 'common/constants'
import Tooltip from './Tooltip'
import MyIssuesSelect from './MyIssuesSelect'
import MyGithubPullRequests from './MyPullRequestsSelect'

export type ExternalResourcesTableType = {
featureId: string
projectId: string
organisationId: string
repoName: string
repoOwner: string
}

const ExternalResourcesTable: FC<ExternalResourcesTableType> = ({
type ExternalResourceRowType = {
featureId: string
projectId: string
externalResource: ExternalResource
}

type PermanentRowType = ExternalResourcesTableType

type GitHubStatusType = {
value: number
label: string
}

const ExternalResourceRow: FC<ExternalResourceRowType> = ({
externalResource,
featureId,
projectId,
}) => {
const { data } = useGetExternalResourcesQuery({
feature_id: featureId,
project_id: projectId,
})

const [deleteExternalResource, { isSuccess: isDeleted }] =
useDeleteExternalResourceMutation()

Expand All @@ -30,6 +47,177 @@ const ExternalResourcesTable: FC<ExternalResourcesTableType> = ({
toast('External resources was deleted')
}
}, [isDeleted])
return (
<Row className='list-item' key={externalResource?.id}>
<Flex className='table-column mt-1'>
<Row className='font-weight-medium'>
{externalResource?.type === 'GITHUB_ISSUE'
Copy link
Member

@kyle-ssg kyle-ssg May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tied to GitHub unnecessarily and overly complex.

Why not just add the following in Constants

resourceTypes: {
GITHUB_ISSUE: {label:"GitHub Issue", type:"GITHUB", id:1}
}

then

 <Row className='font-weight-medium'>
 Constants.resourceTypes[externalResource?.type]?.label]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that constant and now I'm using it where it's needed.

? Constants.githubType.githubIssue
: Constants.githubType.githubPR}
<Button
theme='text'
href={`${externalResource?.url}`}
target='_blank'
className='fw-normal ml-1 mt-1'
>
<Tooltip
title={
<Row>
{`#${externalResource?.url.replace(/\D/g, '')}`}{' '}
<div className='ml-1 mb-1'>
<Icon name='open-external-link' width={14} fill='#6837fc' />
</div>
</Row>
}
place='right'
>
{`${externalResource?.url}`}
</Tooltip>
</Button>
</Row>
</Flex>
<div className='table-column text-center' style={{ width: '80px' }}>
<div className='font-weight-medium mb-1'>
{externalResource?.metadata?.status}
</div>
</div>
<div className='table-column text-center' style={{ width: '80px' }}>
<Button
onClick={() => {
deleteExternalResource({
external_resource_id: `${externalResource?.id}`,
feature_id: featureId,
project_id: projectId,
})
}}
className='btn btn-with-icon'
>
<Icon name='trash-2' width={20} fill='#656D7B' />
</Button>
</div>
</Row>
)
}

const PermanentRow: FC<PermanentRowType> = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term PermanentRow is confusing, it's not obvious what this is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

featureId,
organisationId,
projectId,
repoName,
repoOwner,
}) => {
const [externalResourceType, setExternalResourceType] = useState<string>('')
const [featureExternalResource, setFeatureExternalResource] =
useState<string>('')

const [createExternalResource] = useCreateExternalResourceMutation()
return (
<Row className='list-item'>
<Flex className='table-column px-3'>
<Select
size='select-md'
placeholder={'Select Type'}
onChange={(v: GitHubStatusType) => setExternalResourceType(v.label)}
options={[
{ id: 1, type: Constants.githubType.githubIssue },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following above comment this could be Object.values(Constants.resourceTypes).filter((v)=>v.type==='GITHUB')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{ id: 2, type: Constants.githubType.githubPR },
].map((e) => {
return { label: e.type, value: e.id }
})}
/>
</Flex>
<Flex className='table-column px-3'>
<Flex className='ml-4'>
{externalResourceType == Constants.githubType.githubIssue ? (
<MyIssuesSelect
orgId={organisationId}
onChange={(v) => setFeatureExternalResource(v)}
repoOwner={repoOwner}
repoName={repoName}
/>
) : externalResourceType == Constants.githubType.githubPR ? (
<MyGithubPullRequests
orgId={organisationId}
onChange={(v) => setFeatureExternalResource(v)}
repoOwner={repoOwner}
repoName={repoName}
/>
) : (
<></>
)}
</Flex>
</Flex>
<div className='table-column text-center' style={{ width: '80px' }}>
<Button
className='text-right btn-with-icon'
theme='primary'
onClick={() => {
createExternalResource({
body: {
feature: parseInt(featureId),
metadata: { status },
type:
externalResourceType === Constants.githubType.githubIssue
? 'GITHUB_ISSUE'
: 'GITHUB_PR',
url: featureExternalResource,
},
feature_id: featureId,
project_id: projectId,
})
}}
>
<Icon name='plus' width={30} fill='#656D7B' />
</Button>
</div>
</Row>
)
}

const ExternalResourcesTable: FC<ExternalResourcesTableType> = ({
featureId,
organisationId,
projectId,
repoName,
repoOwner,
}) => {
const { data } = useGetExternalResourcesQuery({
feature_id: featureId,
project_id: projectId,
})

const renderRowWithPermanentRow = (v: ExternalResource, index: number) => {
if (index === (data?.results.length || 0) - 1) {
return (
<>
<ExternalResourceRow
key={v.id}
featureId={featureId}
projectId={projectId}
externalResource={v}
/>
<PermanentRow
key='permanent-row'
featureId={featureId}
projectId={projectId}
organisationId={organisationId}
repoName={repoName}
repoOwner={repoOwner}
/>
</>
)
} else {
// Renderizar los elementos dinámicos normales
return (
<ExternalResourceRow
key={v.id}
featureId={featureId}
projectId={projectId}
externalResource={v}
/>
)
}
}

return (
<PanelSearch
Expand All @@ -38,52 +226,13 @@ const ExternalResourcesTable: FC<ExternalResourcesTableType> = ({
items={data?.results}
header={
<Row className='table-header'>
<Flex className='table-column px-3' style={{ 'minWidth': '280px' }}>
URL
</Flex>
<Flex className='table-column pl-1'>Type</Flex>
<div className='table-column text-center' style={{ width: '80px' }}>
<Flex className='table-column px-3'>Type</Flex>
<div className='table-column text-center' style={{ width: '240px' }}>
Status
</div>
<div className='table-column text-center' style={{ width: '80px' }}>
Remove
</div>
</Row>
}
renderRow={(v: ExternalResource) => (
<Row className='list-item' key={v.id}>
<Flex className='table-column px-3'>
<Button
theme='text'
href={`${v.url}`}
target='_blank'
className='fw-normal'
>
<p className='fs-small'>{v.url}</p>
</Button>
</Flex>
<Flex className='table-column px-3'>
<div className='font-weight-medium mb-1'>{v.type}</div>
</Flex>
<div className='table-column text-center' style={{ width: '80px' }}>
<div className='font-weight-medium mb-1'>{v.status}</div>
</div>
<div className='table-column text-center' style={{ width: '80px' }}>
<Button
onClick={() => {
deleteExternalResource({
external_resource_id: `${v.id}`,
feature_id: featureId,
project_id: projectId,
})
}}
className='btn btn-with-icon'
>
<Icon name='trash-2' width={20} fill='#656D7B' />
</Button>
</div>
</Row>
)}
renderRow={renderRowWithPermanentRow}
/>
)
}
Expand Down
Loading