Skip to content

Commit

Permalink
update to v2.1.6-beta-1
Browse files Browse the repository at this point in the history
  • Loading branch information
relaxdd committed Jun 4, 2023
1 parent 617eb3c commit e9b4cfb
Show file tree
Hide file tree
Showing 23 changed files with 413 additions and 214 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "working-hours",
"homepage": "/working-hours/",
"version": "2.1.5-beta-4",
"version": "2.1.6-beta-1",
"private": true,
"dependencies": {
"bootstrap": "^5.2.3",
Expand Down
5 changes: 5 additions & 0 deletions src/assets/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ code {
--bs-btn-font-size: 0.875rem;
--bs-btn-border-radius: 0.25rem;
}

.offcanvas-footer {
flex-shrink: 1;
padding: var(--bs-offcanvas-padding-y) var(--bs-offcanvas-padding-x);
}
5 changes: 3 additions & 2 deletions src/context/TableContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, Dispatch, useContext } from 'react'
import { DTEnum, IAppSettings, ITableOptions, IWorkTable, IWorkTableRow } from '@/types'
import { defAppSetting } from '@/utils/login'
import Random from '@/utils/class/Random'

type DispatchRewrite<T extends Object, K extends keyof T = keyof T> = { key: K, value: T[K] }
type RewriteDispatch2 = <T extends ITableStore, K extends keyof T>(key: K, value: T[K]) => DispatchRewrite<T>
Expand Down Expand Up @@ -29,7 +30,7 @@ export type IModalVisible = {

type DispatchTable =
({ key: 'id' | 'start' | 'finish' | 'description', value: string }
| { key: 'entity', value: string }
| { key: 'entityId', value: string | null }
| { key: 'isPaid', value: boolean }) & { id: string }

type DispatchFilter =
Expand Down Expand Up @@ -105,7 +106,7 @@ export const defOptions: ITableOptions = {
down: 'ArrowDown',
},
listOfTech: [
{ key: 'base', text: 'Базовый', rate: 200 },
{ id: Random.uuid(10), key: 'base', text: 'Базовый', rate: 200 },
],
}

Expand Down
4 changes: 2 additions & 2 deletions src/defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// prev = 214023

export const appVersion = {
name: '2.1.5-beta-4',
code: 215024,
name: '2.1.6-beta-1',
code: 216021,
}
73 changes: 47 additions & 26 deletions src/service/ImportService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { ITableOptionsEntity, IWorkTableRow } from '@/types'
import Random from '@/utils/class/Random'
import TableService from '@/service/TableService'

type EventHandlers = {
update: null | ((list: ITableOptionsEntity[]) => void),
success: null | ((table: IWorkTableRow[]) => void)
}

/**
* Пока что реализован импорт без сущностей
*
* TODO: Поменять формат импорта на {table: [...], entities: [{ key? text? rate? }]}
* TODO: Переписать связи с entity в tableRow и по умолчанию кидать невидимую entity 0 (Добавить)
* TODO: Дописать проверку в настройках и изменение entity в данных таблицы
*/
class ImportService {
private reader: FileReader
private handlers: EventHandlers
Expand Down Expand Up @@ -46,7 +55,10 @@ class ImportService {
if (!this.handlers.update) return

const list = entity.filter(key => !prevTech.includes(key)).map((it, i) => ({
key: it, text: `Текст - ${i + 1}`, rate: 100,
id: Random.uuid(10),
key: it,
text: `Ставка - ${i + 1}`,
rate: 150,
}))

this.handlers.update(list)
Expand All @@ -61,16 +73,16 @@ class ImportService {
const data = this.validate(any)
if (!data.length) return

const entity = data.reduce<string[]>((list, it) => {
if (!list.includes(it.entity)) list.push(it.entity)
return list
}, [])

const prevTech = this.entities.map(({ key }) => key)
const extra = [...entity, ...prevTech]

if (extra.length !== prevTech.length)
this.insertEntities(entity, prevTech)
// const entity = data.reduce<string[]>((list, it) => {
// if (!list.includes(it.entity)) list.push(it.entity)
// return list
// }, [])
//
// const prevTech = this.entities.map(({ key }) => key)
// const extra = [...entity, ...prevTech]
//
// if (extra.length !== prevTech.length)
// this.insertEntities(entity, prevTech)

this.handlers.success(data)
} catch (err) {
Expand All @@ -93,14 +105,24 @@ class ImportService {
{ key: 'id', type: 'string', empty: false },
{ key: 'start', type: 'string', empty: false },
{ key: 'finish', type: 'string', empty: false },
{ key: 'entity', type: 'string', empty: false },
{ key: 'isPaid', type: 'boolean' },
{ key: 'description', type: 'string', empty: true },
]

const list = []
let order = this.length

const options = TableService.getActiveOptions(this.active)

if (!options) {
alert('Произошла непредвиденная ошибка при импорте!')
throw new Error('Нет данных о настройках таблицы!')
}

const entityId = options.listOfTech.length
? options.listOfTech[0]!.id
: null

for (const it of data) {
if (!(typeof it === 'object' && !Array.isArray(it)))
return []
Expand All @@ -111,21 +133,20 @@ class ImportService {
})

if (!check) continue
else {
const item: IWorkTableRow = {
id: it.id,
tableId: this.active,
start: it.start,
finish: it.finish,
entity: it.entity,
isPaid: it.isPaid,
description: it.description,
order: order + 1,
}

list.push(item)
order++

const item: IWorkTableRow = {
id: it.id,
tableId: this.active,
entityId,
start: it.start,
finish: it.finish,
isPaid: it.isPaid,
description: it.description,
order: order + 1,
}

list.push(item)
order++
}

return list
Expand Down
3 changes: 1 addition & 2 deletions src/temps/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { useEffect, useReducer, useState } from 'react'
import Bottom from './Bottom'
import Filter from './filter/Filter'
import { getAllIds, getTypedKeys, localStorageKeys } from '@/utils'
import { getAllIds, getTypedKeys } from '@/utils'
import Left from './left/Left'
import DescrModal from './modals/DescrModal'
import TableService from '@/service/TableService'
Expand All @@ -24,7 +24,6 @@ import CompareData from '@/utils/class/CompareData'
import { getAppSettings } from '@/utils/login'
import HelpModal from '@/temps/modals/HelpModal'
import AddingModal from '@/temps/modals/AddingModal'
import { getLsOptionsKey } from '@/data'

type BoundPartsOfStore = Pick<ITableStore, 'initialTable' | 'modifiedTable' | 'selectedRows'>

Expand Down
6 changes: 3 additions & 3 deletions src/temps/Bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const Bottom = () => {
}

const item: IWorkTableRow = {
id: Random.uuid(),
tableId: Random.uuid(),
id: Random.uuid(13),
tableId: activeTable!,
entityId: options.listOfTech[0]!.id,
start,
finish,
entity: options.listOfTech[0]!.key,
isPaid: false,
description: '',
order: modifiedTable.length + 1,
Expand Down
84 changes: 76 additions & 8 deletions src/temps/Updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ import { getLocalVersion, LS_VERSION_KEY } from '@/data'
import TableService from '@/service/TableService'
import { localStorageKeys } from '@/utils'
import { appVersion } from '@/defines'
import Random from '@/utils/class/Random'
import { ITableRowLegacy, IWorkTableRow } from '@/types'

type ListOfUpdates = { need: boolean, reformat: (need: boolean) => void }[]


function reformatLegacy215023(when: boolean) {
if (!when) return
/**
* Удалить все опции таблиц которые не были удалены до фикса
*/
function reformatLegacy215023(need: boolean) {
if (!need) return

const match = 'awenn2015_wh_options_'
const list = TableService.listOfTablesInfo
const ids = list.map(it => it.id)

if (!ids.length) return

localStorageKeys((key) => {
if (!key.includes(match)) return

Expand All @@ -29,17 +35,22 @@ function reformatLegacy215023(when: boolean) {
})
}

function reformatLegacy215024(when: boolean) {
if (!when) return
/**
* Переименовываем table.tech в table.entity и добавить поле order
*/
function reformatLegacy215024(need: boolean) {
if (!need) return

const list = TableService.listOfTablesInfo

if (!list.length) return

for (const { id } of list) {
const table = TableService.getActiveTableData(id)
const table = TableService.getActiveTableData(id) as ITableRowLegacy[]
if (!table.length) continue

for (let i = 0; i < table.length; i++) {
table[i]!['entity'] = table[i]?.['tech'] || table[i]!.entity
table[i]!['entity'] = table[i]?.['tech'] || table[i]!.entity!
delete table[i]?.['tech']

if (table[i]?.tableId !== id)
Expand All @@ -48,7 +59,56 @@ function reformatLegacy215024(when: boolean) {
table[i]!['order'] = i + 1
}

TableService.updateActiveTableData(id, table)
TableService.updateActiveTableData(id, table as IWorkTableRow[])
}
}

/**
* Добавляем всем сущностям уникальный id
*/
function reformatLegacy215040(need: boolean) {
if (!need) return

const list = TableService.listOfTablesInfo
if (!list.length) return

for (const { id } of list) {
const options = TableService.getActiveOptions(id)
if (!options || !options.listOfTech.length) continue

for (const entity of options.listOfTech)
entity['id'] = entity?.id || Random.uuid(10)

TableService.updateActiveOptions(id, options)
}
}

/**
* Переименовываем table.entity в table.entityId по id entity и поправить tableId
*/
function reformatLegacy216021(need: boolean) {
if (!need) return

const list = TableService.listOfTablesInfo
if (!list.length) return

for (const { id } of list) {
const table = TableService.getActiveTableData(id) as ITableRowLegacy[]
const options = TableService.getActiveOptions(id)

if (!options || !table.length) return

for (const row of table) {
row['entityId'] = row?.entityId || (row.entity && options.listOfTech.length
? options.listOfTech.find(({ key }) => key === row.entity)?.id || null
: null)

delete row['entity']

row['tableId'] = id
}

TableService.updateActiveTableData(id, table as IWorkTableRow[])
}
}

Expand All @@ -61,6 +121,14 @@ const listOfUpdates: ListOfUpdates = [
need: getLocalVersion() < 215024,
reformat: reformatLegacy215024,
},
{
need: getLocalVersion() < 215040,
reformat: reformatLegacy215040,
},
{
need: getLocalVersion() < 216021,
reformat: reformatLegacy216021,
},
]

const Updates = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/temps/filter/Filter.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
row-gap: 10px;
}

.overview {
Expand Down
4 changes: 2 additions & 2 deletions src/temps/filter/Filter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FilterTech from './FilterTech'
import FilterEntity from './FilterEntity'
import { Actions, defTableFilter, useTableContext } from '@/context/TableContext'
import FilterDate from './FilterDate'
import scss from './Filter.module.scss'
Expand Down Expand Up @@ -70,7 +70,7 @@ const FilterOverview = () => {
</div>

<div>
<FilterTech/>
<FilterEntity/>
</div>

<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import React, { ChangeEvent } from 'react'
import { Actions, useTableContext } from '@/context/TableContext'

const FilterTech = () => {
const FilterEntity = () => {
const [{ filter, options }, dispatch] = useTableContext()

function dispatchLang({ target }: ChangeEvent<HTMLSelectElement>) {
dispatch({
type: Actions.Filter,
payload: { key: 'entity', value: target.value },
payload: {
key: 'entity',
value: target.value !== 'none' ? options.listOfTech.find(it => it.key === target.value)!.id : 'none',
},
})
}

return (
<select
className="form-select"
value={filter.entity}
value={filter.entity !== 'none' ? options.listOfTech.find(it => it.id === filter.entity)?.key : 'none'}
onChange={dispatchLang}
>
<option value="none">Сущность</option>
Expand All @@ -26,4 +29,4 @@ const FilterTech = () => {
)
}

export default FilterTech
export default FilterEntity
Loading

0 comments on commit e9b4cfb

Please sign in to comment.