From 73b7b611a4aecf8705df47b2ee80921af87afe4b Mon Sep 17 00:00:00 2001 From: bakhirev Date: Sat, 10 Aug 2024 01:08:00 +0300 Subject: [PATCH] update --- src/ts/components/DataView/index.tsx | 6 +- .../UiKit/components/SelectWithButtons.tsx | 21 ++- .../YearChart/helpers/getCommitsByMonth.ts | 6 +- src/ts/helpers/DataGrip/components/author.ts | 4 +- src/ts/helpers/DataGrip/components/scope.ts | 5 +- .../helpers/DataGrip/components/timestamp.ts | 4 +- src/ts/helpers/DataGrip/components/week.ts | 5 +- src/ts/helpers/DataGrip/index.ts | 31 +--- src/ts/helpers/formatter.ts | 6 +- src/ts/interfaces/Commit.ts | 2 +- .../PageWrapper/components/header/Button.tsx | 6 +- .../PageWrapper/components/header/Input.tsx | 8 +- src/ts/pages/Person/components/Tasks.tsx | 2 +- src/ts/pages/Team/components/Author.tsx | 2 +- src/ts/pages/Team/components/Extension.tsx | 2 +- .../components/FileAnalytics/Extension.tsx | 2 +- .../Team/components/FileAnalytics/Type.tsx | 2 +- src/ts/pages/Team/components/Release.tsx | 2 +- src/ts/pages/Team/components/Scope.tsx | 2 +- src/ts/pages/Team/components/Tasks.tsx | 2 +- src/ts/pages/Team/components/Type.tsx | 2 +- src/ts/pages/Team/components/Week.tsx | 2 +- src/ts/store/DataGrip.ts | 39 +++-- src/ts/store/Settings.ts | 144 ------------------ src/ts/store/ViewSettings.ts | 69 --------- 25 files changed, 80 insertions(+), 296 deletions(-) delete mode 100644 src/ts/store/Settings.ts delete mode 100644 src/ts/store/ViewSettings.ts diff --git a/src/ts/components/DataView/index.tsx b/src/ts/components/DataView/index.tsx index 4a0950b..51b8721 100644 --- a/src/ts/components/DataView/index.tsx +++ b/src/ts/components/DataView/index.tsx @@ -5,11 +5,11 @@ import { useTranslation } from 'react-i18next'; import ISort from 'ts/interfaces/Sort'; import Table from 'ts/components/Table'; import Cards from 'ts/components/Cards'; -import viewSettings from 'ts/store/ViewSettings'; import { downloadExcel } from 'ts/helpers/File'; import isMobile from 'ts/helpers/isMobile'; import fullScreen from 'ts/store/FullScreen'; +import dataViewStore from './store'; import style from './index.module.scss'; import PageWrapper from '../Page/wrapper'; @@ -41,7 +41,7 @@ function DataView({ }: IDataViewProps): React.ReactElement | null { const { t } = useTranslation(); const urlParams = useParams(); - const defaultType = viewSettings.getItem(urlParams, isMobile ? 'cards' : 'table'); + const defaultType = dataViewStore.getItem(urlParams, isMobile ? 'cards' : 'table'); const [localType, setType] = useState(type || defaultType); if (!rows || !rows.length) return null; @@ -89,7 +89,7 @@ function DataView({ onClick={() => { const newType = localType === 'table' ? 'cards' : 'table'; setType(newType); - viewSettings.setItem(urlParams, newType, 'table'); + dataViewStore.setItem(urlParams, newType, 'table'); }} /> )} diff --git a/src/ts/components/UiKit/components/SelectWithButtons.tsx b/src/ts/components/UiKit/components/SelectWithButtons.tsx index 8a62836..c4b6ad7 100644 --- a/src/ts/components/UiKit/components/SelectWithButtons.tsx +++ b/src/ts/components/UiKit/components/SelectWithButtons.tsx @@ -1,5 +1,8 @@ import React from 'react'; +import CustomSelect from 'ts/components/CustomSelect'; +import isMobile from 'ts/helpers/isMobile'; + import { IUiKitWrapperProps } from './Wrapper'; import UiKitButton from './Button'; import UiKitSelect from './Select'; @@ -41,11 +44,19 @@ function UiKitSelectWithButtons({ > « - + {isMobile ? ( + + ) : ( + + )} { - return money + settingsStore.getMiddleSalaryInMonth(name); + return money + userSettings.getCurrentSalaryInMonth(name); // TODO: need middle salary in month }, 0); } } @@ -95,4 +95,4 @@ export default function getCommitsByMonth( addCommitsInMonth(prev, monthsByDate, commits); return months; -} \ No newline at end of file +} diff --git a/src/ts/helpers/DataGrip/components/author.ts b/src/ts/helpers/DataGrip/components/author.ts index 55d4f18..bff2231 100644 --- a/src/ts/helpers/DataGrip/components/author.ts +++ b/src/ts/helpers/DataGrip/components/author.ts @@ -4,7 +4,6 @@ import IHashMap from 'ts/interfaces/HashMap'; import { ONE_DAY } from 'ts/helpers/formatter'; import { increment } from 'ts/helpers/Math'; -import settingsStore from 'ts/store/Settings'; import userSettings from 'ts/store/UserSettings'; export default class DataGripByAuthor { @@ -138,10 +137,9 @@ export default class DataGripByAuthor { return total; } - updateTotalInfo() { + updateTotalInfo(lastCommit: ICommit) { const HOLIDAYS = 118 + 22; // праздники + выходные + отпуск const WORK_AND_HOLIDAYS = (HOLIDAYS / (365 - HOLIDAYS)); - const lastCommit = settingsStore.commits[settingsStore.commits.length - 1]; const dismissedLimit = lastCommit?.milliseconds - 32 * ONE_DAY; this.employment = { diff --git a/src/ts/helpers/DataGrip/components/scope.ts b/src/ts/helpers/DataGrip/components/scope.ts index 9c58905..c3db627 100644 --- a/src/ts/helpers/DataGrip/components/scope.ts +++ b/src/ts/helpers/DataGrip/components/scope.ts @@ -1,6 +1,6 @@ import ICommit from 'ts/interfaces/Commit'; import IHashMap from 'ts/interfaces/HashMap'; -import settingsStore from 'ts/store/Settings'; +import userSettings from 'ts/store/UserSettings'; import { increment } from 'ts/helpers/Math'; interface IStatByAuthor { @@ -85,7 +85,8 @@ export default class DataGripByScope { for (let name in dot.authors) { const user = dot.authors[name]; const days: number = Object.keys(user.days).length; - salaryCache[name] = salaryCache[name] || settingsStore.getMiddleSalaryInDay(name); + // TODO: need middle salary in month; + salaryCache[name] = salaryCache[name] || userSettings.getCurrentSalaryInMonth(name); cost += days * salaryCache[name]; dot.authors[name] = { ...user, days }; } diff --git a/src/ts/helpers/DataGrip/components/timestamp.ts b/src/ts/helpers/DataGrip/components/timestamp.ts index 6f418a2..fe2f284 100644 --- a/src/ts/helpers/DataGrip/components/timestamp.ts +++ b/src/ts/helpers/DataGrip/components/timestamp.ts @@ -1,6 +1,6 @@ import ICommit from 'ts/interfaces/Commit'; import IHashMap from 'ts/interfaces/HashMap'; -import settingsStore from 'ts/store/Settings'; +import userSettings from 'ts/store/UserSettings'; import { increment } from 'ts/helpers/Math'; import MinMaxCounter from './counter'; @@ -119,7 +119,7 @@ export default class DataGripByTimestamp { #getWeekendPaymentByAuthor(statistic: any, dataGripByAuthor: any) { if (dataGripByAuthor.isStaff) return 0; - const salaryInDay = settingsStore.getMiddleSalaryInDay(dataGripByAuthor.author); + const salaryInDay = userSettings.getCurrentSalaryInMonth(dataGripByAuthor.author); // TODO: need middle salary in month const saturday = statistic.workByDay[5] * salaryInDay; const sunday = statistic.workByDay[6] * salaryInDay; return saturday + sunday; diff --git a/src/ts/helpers/DataGrip/components/week.ts b/src/ts/helpers/DataGrip/components/week.ts index a964d5f..e18c8a5 100644 --- a/src/ts/helpers/DataGrip/components/week.ts +++ b/src/ts/helpers/DataGrip/components/week.ts @@ -1,6 +1,5 @@ import ICommit from 'ts/interfaces/Commit'; import IHashMap from 'ts/interfaces/HashMap'; -import settingsStore from 'ts/store/Settings'; import { increment } from 'ts/helpers/Math'; export default class DataGripByWeek { @@ -79,8 +78,8 @@ export default class DataGripByWeek { authorsLength += 1; workDays[name] = Object.keys(dot.workDays[name]).length; workDaysTotal += workDays[name]; - - const limit = settingsStore.workDays[name] || settingsStore.defaultWorkDays; + // userSettings.getCurrentWorkDaysInWeek(name); TODO: need middle salary in month + const limit = 5; const lazyDaysValue = limit - workDays[name]; const weekDaysValue = workDays[name] - limit; diff --git a/src/ts/helpers/DataGrip/index.ts b/src/ts/helpers/DataGrip/index.ts index 5380e3b..cd0ed05 100644 --- a/src/ts/helpers/DataGrip/index.ts +++ b/src/ts/helpers/DataGrip/index.ts @@ -1,6 +1,5 @@ import ICommit, { ISystemCommit } from 'ts/interfaces/Commit'; -import settingsStore from 'ts/store/Settings'; import Recommendations from 'ts/helpers/Recommendations'; import DataGripByAuthor from './components/author'; @@ -40,10 +39,6 @@ class DataGrip { release: any = new DataGripByRelease(); - initializationInfo: any = {}; - - hash: number = 0; - clear() { this.firstLastCommit.clear(); this.author.clear(); @@ -75,8 +70,8 @@ class DataGrip { } } - #updateTotalInfo() { - this.author.updateTotalInfo(); + updateTotalInfo() { + this.author.updateTotalInfo(this.firstLastCommit.maxData); this.team.updateTotalInfo(this.author); this.scope.updateTotalInfo(); this.type.updateTotalInfo(); @@ -87,28 +82,6 @@ class DataGrip { this.tasks.updateTotalInfo(this.pr); this.release.updateTotalInfo(); } - - updateByInitialization() { - this.#updateTotalInfo(); - this.initializationInfo = this.author.statistic - .reduce((info: any, author: any) => { - info[author.author] = { ...author }; - return info; - }, {}); - } - - updateByFilters() { - this.clear(); - settingsStore.commits.forEach((commit: ICommit) => { - const author = this.initializationInfo[commit.author] || { commits: 0 }; - if (commit.timestamp < settingsStore.from - || commit.timestamp > settingsStore.to - || author.commits < settingsStore.minCommits) return; - this.addCommit(commit); - }); - this.#updateTotalInfo(); - this.hash = Math.random(); - } } const dataGrip = new DataGrip(); diff --git a/src/ts/helpers/formatter.ts b/src/ts/helpers/formatter.ts index a75e7ca..fa67dae 100644 --- a/src/ts/helpers/formatter.ts +++ b/src/ts/helpers/formatter.ts @@ -47,10 +47,6 @@ export function get2Number(time: number) { return time < 10 ? `0${time}` : time; } -export function getClearHTML(text: string) { - return (text || '').trim().replace(/(>[\s\r\n]*<)/gim, '><'); -} - export function getDate(timestamp: string) { if (!timestamp) return ''; const date = new Date(timestamp); @@ -81,7 +77,7 @@ function getCurrencyFromUSD(money: number, currency: string) { const k = { USD: 1, EUR: 0.92, - RUB: 98, + RUB: 90, CNY: 7.26, JPY: 158, KRW: 1360, diff --git a/src/ts/interfaces/Commit.ts b/src/ts/interfaces/Commit.ts index 90ebabf..3dfc9c1 100644 --- a/src/ts/interfaces/Commit.ts +++ b/src/ts/interfaces/Commit.ts @@ -22,7 +22,7 @@ export interface ILog { month: number; // 1, year: number; // 2021, timestamp: string; // 2021-02-09", - milliseconds: number; // 1612828800000, + milliseconds: number; // 1612828800000, week: number; // 42, // user diff --git a/src/ts/pages/PageWrapper/components/header/Button.tsx b/src/ts/pages/PageWrapper/components/header/Button.tsx index 8100384..4e31b70 100644 --- a/src/ts/pages/PageWrapper/components/header/Button.tsx +++ b/src/ts/pages/PageWrapper/components/header/Button.tsx @@ -1,7 +1,8 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; -import settingsStore from 'ts/store/Settings'; +import filtersInHeaderStore from 'ts/store/FiltersInHeader'; +import dataGripStore from 'ts/store/DataGrip'; import style from '../../styles/filters.module.scss'; @@ -19,7 +20,8 @@ function Button({