1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

Merge pull request #46 from muerwre/task/#25

Получение списка задач с github
This commit is contained in:
muerwre 2021-03-10 14:50:49 +07:00 committed by GitHub
commit f66f09572f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 19 deletions

View file

@ -9,7 +9,7 @@ interface IProps {
} }
const BorisStatsGit: FC<IProps> = ({ stats }) => { const BorisStatsGit: FC<IProps> = ({ stats }) => {
if (!stats.git.length) return null; if (!stats.issues.length) return null;
if (stats.is_loading) { if (stats.is_loading) {
return ( return (
@ -35,11 +35,12 @@ const BorisStatsGit: FC<IProps> = ({ stats }) => {
<img src="https://jenkins.vault48.org/api/badges/muerwre/vault-golang/status.svg" /> <img src="https://jenkins.vault48.org/api/badges/muerwre/vault-golang/status.svg" />
</div> </div>
{stats.git {stats.issues
.filter(data => data.commit && data.timestamp && data.subject) .filter(el => !el.pull_request)
.slice(0, 5) .slice(0, 10)
.sort(el => (el.state === 'open' ? 1 : -1))
.map(data => ( .map(data => (
<BorisStatsGitCard data={data} key={data.commit} /> <BorisStatsGitCard data={data} key={data.id} />
))} ))}
</div> </div>
); );

View file

@ -1,22 +1,33 @@
import React, { FC } from 'react'; import React, { FC, useMemo } from 'react';
import { IStatGitRow } from '~/redux/boris/reducer';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { getPrettyDate } from '~/utils/dom'; import { getPrettyDate } from '~/utils/dom';
import { IGithubIssue } from '~/redux/boris/types';
import classNames from 'classnames';
interface IProps { interface IProps {
data: Partial<IStatGitRow>; data: IGithubIssue;
} }
const BorisStatsGitCard: FC<IProps> = ({ data: { timestamp, subject } }) => { const stateLabels: Record<IGithubIssue['state'], string> = {
if (!subject || !timestamp) return null; open: 'Ожидает',
closed: 'Сделано',
};
const BorisStatsGitCard: FC<IProps> = ({ data: { created_at, title, html_url, state } }) => {
if (!title || !created_at) return null;
const date = useMemo(() => getPrettyDate(created_at), [created_at]);
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>
<div className={styles.time}> <div className={styles.time}>
{getPrettyDate(new Date(parseInt(`${timestamp}000`)).toISOString())} <span className={classNames(styles.icon, styles[state])}>{stateLabels[state]}</span>
{date}
</div> </div>
<div className={styles.subject}>{subject}</div> <a className={styles.subject} href={html_url} target="_blank">
{title}
</a>
</div> </div>
); );
}; };

View file

@ -12,10 +12,28 @@
.time { .time {
font: $font_12_regular; font: $font_12_regular;
line-height: 17px; line-height: 17px;
opacity: 0.3; color: transparentize(white, 0.7)
} }
.subject { .subject {
font: $font_14_regular; font: $font_14_regular;
word-break: break-word; word-break: break-word;
text-decoration: none;
color: inherit;
}
.icon {
font: $font_10_semibold;
margin-right: 5px;
border-radius: 2px;
padding: 2px 0;
text-transform: uppercase;
&.open {
color: $red;
}
&.closed {
color: $green;
}
} }

View file

@ -1,10 +1,20 @@
import git from '~/stats/git.json'; import git from '~/stats/git.json';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { api, resultMiddleware, errorMiddleware, cleanResult } from '~/utils/api'; import { api, cleanResult } from '~/utils/api';
import { IBorisState, IStatBackend } from './reducer'; import { IBorisState, IStatBackend } from './reducer';
import { IResultWithStatus } from '../types'; import axios from 'axios';
import { IGetGithubIssuesResult } from '~/redux/boris/types';
export const getBorisGitStats = () => Promise.resolve<IBorisState['stats']['git']>(git); export const getBorisGitStats = () => Promise.resolve<IBorisState['stats']['git']>(git);
export const getBorisBackendStats = () => export const getBorisBackendStats = () =>
api.get<IStatBackend>(API.BORIS.GET_BACKEND_STATS).then(cleanResult); api.get<IStatBackend>(API.BORIS.GET_BACKEND_STATS).then(cleanResult);
export const getGithubIssues = () => {
return axios
.get<IGetGithubIssuesResult>('https://api.github.com/repos/muerwre/vault-frontend/issues', {
params: { state: 'all', sort: 'created' },
})
.then(result => result.data)
.catch(() => []);
};

View file

@ -1,5 +1,6 @@
import { createReducer } from '~/utils/reducer'; import { createReducer } from '~/utils/reducer';
import { BORIS_HANDLERS } from './handlers'; import { BORIS_HANDLERS } from './handlers';
import { IGithubIssue } from '~/redux/boris/types';
export type IStatGitRow = { export type IStatGitRow = {
commit: string; commit: string;
@ -31,6 +32,7 @@ export type IStatBackend = {
export type IBorisState = Readonly<{ export type IBorisState = Readonly<{
stats: { stats: {
git: Partial<IStatGitRow>[]; git: Partial<IStatGitRow>[];
issues: IGithubIssue[];
backend?: IStatBackend; backend?: IStatBackend;
is_loading: boolean; is_loading: boolean;
}; };
@ -39,6 +41,7 @@ export type IBorisState = Readonly<{
const BORIS_INITIAL_STATE: IBorisState = { const BORIS_INITIAL_STATE: IBorisState = {
stats: { stats: {
git: [], git: [],
issues: [],
backend: undefined, backend: undefined,
is_loading: false, is_loading: false,
}, },

View file

@ -1,17 +1,17 @@
import { takeLatest, put, call } from 'redux-saga/effects'; import { call, put, takeLatest } from 'redux-saga/effects';
import { BORIS_ACTIONS } from './constants'; import { BORIS_ACTIONS } from './constants';
import { borisSetStats } from './actions'; import { borisSetStats } from './actions';
import { getBorisGitStats, getBorisBackendStats } from './api'; import { getBorisBackendStats, getGithubIssues } from './api';
import { Unwrap } from '../types'; import { Unwrap } from '../types';
function* loadStats() { function* loadStats() {
try { try {
yield put(borisSetStats({ is_loading: true })); yield put(borisSetStats({ is_loading: true }));
const git: Unwrap<typeof getBorisGitStats> = yield call(getBorisGitStats);
const backend: Unwrap<typeof getBorisBackendStats> = yield call(getBorisBackendStats); const backend: Unwrap<typeof getBorisBackendStats> = yield call(getBorisBackendStats);
const issues: Unwrap<typeof getGithubIssues> = yield call(getGithubIssues);
yield put(borisSetStats({ git, backend })); yield put(borisSetStats({ issues, backend }));
} catch (e) { } catch (e) {
yield put(borisSetStats({ git: [], backend: undefined })); yield put(borisSetStats({ git: [], backend: undefined }));
} finally { } finally {

12
src/redux/boris/types.ts Normal file
View file

@ -0,0 +1,12 @@
export interface IGithubIssue {
id: string;
url: string;
html_url: string;
body: string;
title: string;
state: 'open' | 'closed';
created_at: string;
pull_request?: unknown;
}
export type IGetGithubIssuesResult = IGithubIssue[];