From 7985bb35bb909f7b057a1d28e51b7ff5e4485596 Mon Sep 17 00:00:00 2001 From: Camila Sosa Morales Date: Mon, 13 Mar 2023 15:56:17 -0500 Subject: [PATCH] chore: UI implement changes feedback (#173) * style: combobox add cursor pointer property * chore: make repository row clickable * style: fix scroll on repositories list * chore: select main/master by deafult branch * chore: add required icon on label form and max characters length * Update ui/src/components/core/combobox/combobox.tsx Co-authored-by: Felipe Mendes * chore: remove commented line * chore: replace Form.MaxLength * styles: fix styles for combobox icon * chore: default branch based on repo config --------- Co-authored-by: Felipe Mendes --- ui/src/components/core/combobox/combobox.tsx | 4 +-- ui/src/components/core/icon/icon-library.tsx | 2 ++ ui/src/components/form/form.styles.ts | 9 ++++++ ui/src/components/form/form.tsx | 19 +++++++++++-- .../github/async-thunk/fetch-branches.ts | 4 +-- .../github/async-thunk/fetch-repositories.ts | 9 +----- ui/src/store/features/github/github-client.ts | 10 ++++++- ui/src/store/features/github/github-slice.ts | 5 ++-- .../repo-branch-commit-fields.tsx | 23 ++++++++++++--- .../repo-configuration-body.tsx | 2 +- .../github-repository-selection.tsx | 25 ++--------------- .../repositories-list.tsx | 1 + .../repository.tsx | 4 +-- .../mint/github-step/steps/repository-row.tsx | 28 +++++++++++++++++++ .../fields/app-description-field.tsx | 8 +++++- .../form-step/fields/app-name-field.tsx | 7 ++++- .../fields/ens-domain-field/domain-field.tsx | 2 +- .../fields/logo-field/logo-field.tsx | 2 +- 18 files changed, 112 insertions(+), 52 deletions(-) create mode 100644 ui/src/views/mint/github-step/steps/repository-row.tsx diff --git a/ui/src/components/core/combobox/combobox.tsx b/ui/src/components/core/combobox/combobox.tsx index 8ba2371..7816faf 100644 --- a/ui/src/components/core/combobox/combobox.tsx +++ b/ui/src/components/core/combobox/combobox.tsx @@ -31,7 +31,7 @@ const ComboboxInput = ({ handleInputChange, handleInputClick, }: ComboboxInputProps) => ( -
+
( - ({ children, ...props }, ref) => ( + ({ children, isRequired, ...props }, ref) => ( - {children} + {children}{' '} + {isRequired && *} ) ); + static readonly MaxLength = forwardRef( + ({ children, ...props }, ref) => { + return ( + + {children} + + ); + } + ); + static readonly Error = forwardRef( ({ children, ...props }, ref) => ( @@ -55,7 +66,9 @@ export namespace Form { children: React.ReactNode; } & React.ComponentProps; - export type LabelProps = React.ComponentProps; + export type LabelProps = { isRequired?: boolean } & React.ComponentProps< + typeof FormStyles.Label + >; export type ErrorProps = React.ComponentProps; diff --git a/ui/src/store/features/github/async-thunk/fetch-branches.ts b/ui/src/store/features/github/async-thunk/fetch-branches.ts index a85643c..dee72bf 100644 --- a/ui/src/store/features/github/async-thunk/fetch-branches.ts +++ b/ui/src/store/features/github/async-thunk/fetch-branches.ts @@ -1,4 +1,4 @@ -import { DropdownItem } from '@/components'; +import { ComboboxItem } from '@/components'; import { githubActions, RootState } from '@/store'; import { AppLog } from '@/utils'; import { createAsyncThunk } from '@reduxjs/toolkit'; @@ -23,7 +23,7 @@ export const fetchBranchesThunk = createAsyncThunk( const branches = await githubClient.fetchBranches(owner, repository); - dispatch(githubActions.setBranches(branches as DropdownItem[])); + dispatch(githubActions.setBranches(branches as ComboboxItem[])); } catch (error) { AppLog.errorToast( 'We have a problem trying to get your branches. Please try again later.' diff --git a/ui/src/store/features/github/async-thunk/fetch-repositories.ts b/ui/src/store/features/github/async-thunk/fetch-repositories.ts index f153e36..765fcf1 100644 --- a/ui/src/store/features/github/async-thunk/fetch-repositories.ts +++ b/ui/src/store/features/github/async-thunk/fetch-repositories.ts @@ -16,14 +16,7 @@ export const fetchRepositoriesThunk = createAsyncThunk( const repositories = await githubClient.fetchRepos(url); - dispatch( - githubActions.setRepositories( - repositories.map((repo: any) => ({ - name: repo.name, - url: repo.html_url, - })) - ) - ); + dispatch(githubActions.setRepositories(repositories)); } catch (error) { console.log(error); dispatch(githubActions.setQueryState('failed')); diff --git a/ui/src/store/features/github/github-client.ts b/ui/src/store/features/github/github-client.ts index b27c729..a74bca7 100644 --- a/ui/src/store/features/github/github-client.ts +++ b/ui/src/store/features/github/github-client.ts @@ -1,5 +1,6 @@ import { DropdownItem } from '@/components'; import { Octokit } from 'octokit'; +import { GithubState } from './github-slice'; export type UserData = { value: string; @@ -50,7 +51,14 @@ export class GithubClient { }, }).then((res) => res.json()); - return repos; + return repos.map( + (repo: any) => + ({ + name: repo.name, + url: repo.html_url, + defaultBranch: repo.default_branch, + } as GithubState.Repository) + ); } catch (error) { return error; } diff --git a/ui/src/store/features/github/github-slice.ts b/ui/src/store/features/github/github-slice.ts index dc4203a..eebc21f 100644 --- a/ui/src/store/features/github/github-slice.ts +++ b/ui/src/store/features/github/github-slice.ts @@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { RootState } from '@/store'; import { useAppSelector } from '@/store/hooks'; import * as asyncThunk from './async-thunk'; -import { DropdownItem } from '@/components'; +import { ComboboxItem } from '@/components'; import { UserData } from './github-client'; export namespace GithubState { @@ -23,11 +23,12 @@ export namespace GithubState { export type Repository = { name: string; url: string; + defaultBranch: string; }; export type Repositories = Array; - export type Branches = Array; + export type Branches = Array; } export interface GithubState { diff --git a/ui/src/views/mint/github-step/steps/github-repo-configuration/repo-branch-commit-fields.tsx b/ui/src/views/mint/github-step/steps/github-repo-configuration/repo-branch-commit-fields.tsx index 1c6b002..2acb453 100644 --- a/ui/src/views/mint/github-step/steps/github-repo-configuration/repo-branch-commit-fields.tsx +++ b/ui/src/views/mint/github-step/steps/github-repo-configuration/repo-branch-commit-fields.tsx @@ -1,7 +1,7 @@ -import { Dropdown, DropdownItem, Flex, Form, Spinner } from '@/components'; +import { useEffect } from 'react'; +import { Combobox, ComboboxItem, Flex, Form, Spinner } from '@/components'; import { githubActions, useAppDispatch, useGithubStore } from '@/store'; import { Mint } from '@/views/mint/mint.context'; -import { useEffect } from 'react'; export const RepoBranchCommitFields = () => { const { queryLoading, branches } = useGithubStore(); @@ -27,7 +27,21 @@ export const RepoBranchCommitFields = () => { } }, [queryLoading, dispatch]); - const handleBranchChange = (dropdownOption: DropdownItem) => { + useEffect(() => { + if (queryLoading === 'success' && branches.length > 0) { + const defaultBranch = branches.find( + (branch) => + branch.label.toLowerCase() === + repositoryName.defaultBranch.toLowerCase() + ); + if (defaultBranch) { + setBranchName(defaultBranch); + setCommitHash(defaultBranch.value); + } + } + }, [queryLoading, branches]); + + const handleBranchChange = (dropdownOption: ComboboxItem) => { setBranchName(dropdownOption); setCommitHash(dropdownOption.value); }; @@ -54,7 +68,8 @@ export const RepoBranchCommitFields = () => { <> Git Branch - { diff --git a/ui/src/views/mint/github-step/steps/github-repository-selection/github-repository-selection.tsx b/ui/src/views/mint/github-step/steps/github-repository-selection/github-repository-selection.tsx index 7b906bd..d8234b8 100644 --- a/ui/src/views/mint/github-step/steps/github-repository-selection/github-repository-selection.tsx +++ b/ui/src/views/mint/github-step/steps/github-repository-selection/github-repository-selection.tsx @@ -20,27 +20,6 @@ export const Loading = () => ( ); -type RepoRowProps = { - repo: string; - button: React.ReactNode; -} & React.ComponentProps; - -export const RepoRow = forwardRef( - ({ repo, button, ...props }, ref) => ( - - - - {repo} - - {button} - - ) -); - export const GithubRepositoryConnection: React.FC = () => { const { queryLoading, queryUserAndOrganizations } = useGithubStore(); const [searchValue, setSearchValue] = useState(''); @@ -64,14 +43,14 @@ export const GithubRepositoryConnection: React.FC = () => { }; return ( - + - + { overflowX: 'hidden', overflowY: 'scroll', flexDirection: 'column', + pr: '$3h', }} > {filteredRepositories.length > 0 ? ( diff --git a/ui/src/views/mint/github-step/steps/github-repository-selection/repository.tsx b/ui/src/views/mint/github-step/steps/github-repository-selection/repository.tsx index 2a0b0e6..7eb3e6f 100644 --- a/ui/src/views/mint/github-step/steps/github-repository-selection/repository.tsx +++ b/ui/src/views/mint/github-step/steps/github-repository-selection/repository.tsx @@ -1,7 +1,7 @@ import { Button, Separator } from '@/components'; import { githubActions, GithubState, useAppDispatch } from '@/store'; import { Mint } from '@/views/mint/mint.context'; -import { RepoRow } from './github-repository-selection'; +import { RepoRow } from '../repository-row'; type RepositoryProps = { repository: GithubState.Repository; @@ -21,13 +21,13 @@ export const Repository = ({ repository, index, length }: RepositoryProps) => { return ( <> Use for NFA diff --git a/ui/src/views/mint/github-step/steps/repository-row.tsx b/ui/src/views/mint/github-step/steps/repository-row.tsx new file mode 100644 index 0000000..60f262b --- /dev/null +++ b/ui/src/views/mint/github-step/steps/repository-row.tsx @@ -0,0 +1,28 @@ +import { Flex, Icon } from '@/components'; +import { forwardRef } from 'react'; + +type RepoRowProps = { + repo: string; + button: React.ReactNode; +} & React.ComponentProps; + +export const RepoRow = forwardRef( + ({ repo, button, ...props }, ref) => ( + + + + {repo} + + {button} + + ) +); diff --git a/ui/src/views/mint/nfa-step/form-step/fields/app-description-field.tsx b/ui/src/views/mint/nfa-step/form-step/fields/app-description-field.tsx index d268c21..8c063e3 100644 --- a/ui/src/views/mint/nfa-step/form-step/fields/app-description-field.tsx +++ b/ui/src/views/mint/nfa-step/form-step/fields/app-description-field.tsx @@ -1,24 +1,30 @@ import { Form } from '@/components'; import { Mint } from '../../../mint.context'; +const maxCharacters = 250; + export const AppDescriptionField = () => { const { appDescription, setAppDescription } = Mint.useContext(); const handleAppDescriptionChange = ( e: React.ChangeEvent ) => { + if (e.target.value.length > maxCharacters) return; setAppDescription(e.target.value); }; return ( - Description + Description + + {appDescription.length}/{maxCharacters} + ); }; diff --git a/ui/src/views/mint/nfa-step/form-step/fields/app-name-field.tsx b/ui/src/views/mint/nfa-step/form-step/fields/app-name-field.tsx index 3f36959..ca9cfdd 100644 --- a/ui/src/views/mint/nfa-step/form-step/fields/app-name-field.tsx +++ b/ui/src/views/mint/nfa-step/form-step/fields/app-name-field.tsx @@ -1,6 +1,8 @@ import { Form } from '@/components'; import { Mint } from '../../../mint.context'; +const maxCharacters = 100; + export const AppNameField = () => { const { appName, setAppName } = Mint.useContext(); @@ -9,12 +11,15 @@ export const AppNameField = () => { }; return ( - Name + Name + + {appName.length}/{maxCharacters} + ); }; diff --git a/ui/src/views/mint/nfa-step/form-step/fields/ens-domain-field/domain-field.tsx b/ui/src/views/mint/nfa-step/form-step/fields/ens-domain-field/domain-field.tsx index bf3f25e..bce006d 100644 --- a/ui/src/views/mint/nfa-step/form-step/fields/ens-domain-field/domain-field.tsx +++ b/ui/src/views/mint/nfa-step/form-step/fields/ens-domain-field/domain-field.tsx @@ -9,7 +9,7 @@ export const DomainField = () => { }; return ( - Domain + Domain { return ( - Logo + Logo {errorMessage && {errorMessage}}