Skip to content

Commit

Permalink
#75 Added model Repository and transforms/repository for github api.
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed Jan 3, 2021
1 parent edaa849 commit d0d8318
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/components/Header/components/BranchStep/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Body = () => {
const [bodyOpen, setBodyOpen] = useUIProperty('bodyOpen');
const [filtered, setFiltered] = useState(items);
const { selected: repository } = useSelector(repositoriesSlice.selectors.getState);
const { default_branch } = repository || {};
const { defaultBranch } = repository || {};

const changeSearch = useMemo(
() => debounce(
Expand Down Expand Up @@ -111,7 +111,7 @@ const Body = () => {
const Item = useCallback(
({ index, style }) => {
const item = filtered[index];
const isDefault = default_branch === item.name;
const isDefault = defaultBranch === item.name;

return (
<ListItem
Expand All @@ -138,7 +138,7 @@ const Body = () => {
</ListItem>
);
},
[filtered, default_branch, onClick, search],
[filtered, defaultBranch, onClick, search],
);

useEffect(
Expand Down
8 changes: 4 additions & 4 deletions src/components/Header/components/RepositoryStep/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ const Body = () => {
>
<ListItemAvatar>
<Avatar>
{item.private ? <BookLockIcon /> : (
item.fork ? <SourceRepositoryIcon /> : <BookIcon />
{item.isPrivate ? <BookLockIcon /> : (
item.isFork ? <SourceRepositoryIcon /> : <BookIcon />
)}
</Avatar>
</ListItemAvatar>
<ListItemText
primary={(
<Primary>
{item.private && <Marker>private</Marker>}
{item.fork && <Marker>fork</Marker>}
{item.isPrivate && <Marker>private</Marker>}
{item.isFork && <Marker>fork</Marker>}
<Highlight search={search} text={item.name} />
</Primary>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header/components/RepositoryStep/Secondary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Secondary = ({ item }) => (
<Property title="Stars">
<StarIcon size={16} />
<PropertyValue>
{item.stargazers_count}
{item.stars}
</PropertyValue>
</Property>
<Property title="Watchers">
Expand All @@ -60,7 +60,7 @@ const Secondary = ({ item }) => (
<Property title="Opened issues">
<AlertCircleOutlineIcon size={16} />
<PropertyValue>
{item.open_issues}
{item.openIssues}
</PropertyValue>
</Property>
</Properties>
Expand Down
2 changes: 1 addition & 1 deletion src/components/StageController/useStageBranches.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useStageBranches = (name) => {
const { selected, items } = useSelector(branchesSlice.selectors.getState);

const { login: owner } = profile || {};
const { name: repo, default_branch: defaultBranch } = repository || {};
const { name: repo, defaultBranch } = repository || {};
const { name: branch } = selected || {};

useEffect(
Expand Down
37 changes: 37 additions & 0 deletions src/models/Repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const Repository = ({
id,
name,
description,
url,
language,
forks = 0,
stars = 0,
watchers = 0,
openIssues = 0,
isFork,
isPrivate,
isArchived,
isLocked,
updateAt,
createAt,
pushedAt,
...rest
}) => ({
id,
name,
description,
url,
language: language || 'multi',
forks,
stars,
watchers,
openIssues,
isFork,
isPrivate,
isArchived,
isLocked,
updateAt,
createAt,
pushedAt,
mics: rest,
});
3 changes: 2 additions & 1 deletion src/redux/api/github/getRepositories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseRateLimit, parsePageInfo } from '@/redux/api/github/utils';
import { withCancellation } from '@/redux/utils';
import getClient from './getClient';
import { repository } from './transforms';

/**
* Gets repositories of an owner
Expand All @@ -23,7 +24,7 @@ export const getRepositories = ({ owner, perPage = 10, page }) =>
});

return {
data: data?.data || [],
data: (data?.data || []).map(repository),
pageInfo: parsePageInfo(data?.headers),
rateLimit: parseRateLimit(data?.headers),
};
Expand Down
16 changes: 16 additions & 0 deletions src/redux/api/github/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Repository } from '@/models/Repository';

export const repository = (item) => Repository({
...item,
defaultBranch: item.default_branch,
url: item.html_url,
openIssues: item.open_issues,
stars: item.stargazers_count,
isPrivate: item.private,
isFork: item.fork,
isArchived: item.archived,
isLocked: item.disabled,
updateAt: Date.parse(item.update_at),
createAt: Date.parse(item.create_at),
pushedAt: Date.parse(item.pushed_at),
});
2 changes: 2 additions & 0 deletions src/redux/api/githubGQL/getRepositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const getRepositories = ({ owner, page = '', perPage = 10 }) =>
},
});

// TODO add transforms/repository

return {
data: data?.profile?.repositories?.nodes,
pageInfo: parsePageInfo(data?.profile?.repositories),
Expand Down

0 comments on commit d0d8318

Please sign in to comment.