Добавлена дополнительная проверка данных

This commit is contained in:
Александр Сироткин 2021-12-22 12:45:30 +05:00
parent d3412492ff
commit c729ffa0f0
7 changed files with 19 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import {
makeStringSorter
} from '../../components/Table'
import { AdminClusterService, AdminDepositService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
export default function ClusterController() {
const [deposits, setDeposits] = useState([])
@ -33,7 +34,7 @@ export default function ClusterController() {
const updateTable = () => invokeWebApiWrapperAsync(
async () => {
const clusters = await AdminClusterService.getAll()
setClusters(clusters)
setClusters(arrayOrDefault(clusters))
},
setShowLoader,
`Не удалось загрузить список кустов`
@ -41,9 +42,9 @@ export default function ClusterController() {
useEffect(() => invokeWebApiWrapperAsync(
async () => {
let deposits = await AdminDepositService.getAll()
deposits = deposits?.map((deposit) => ({ value: deposit.id, label: deposit.caption }))
setDeposits(deposits ?? [])
let deposits = arrayOrDefault(await AdminDepositService.getAll())
deposits = deposits.map((deposit) => ({ value: deposit.id, label: deposit.caption }))
setDeposits(deposits)
},
setShowLoader,
`Не удалось загрузить список месторождений`

View File

@ -3,6 +3,7 @@ import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeActionHandler, makeStringSorter } from '../../components/Table'
import { AdminCompanyService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
const companyColumns = [
makeColumn('Название', 'caption', {
@ -24,7 +25,7 @@ export default function CompanyController() {
const updateTable = () => invokeWebApiWrapperAsync(
async() => {
const companies = await AdminCompanyService.getAll()
setCompanies(companies)
setCompanies(arrayOrDefault(companies))
},
setShowLoader,
`Не удалось загрузить список кустов`

View File

@ -3,6 +3,7 @@ import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeActionHandler } from '../../components/Table'
import { AdminDepositService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
const depositColumns = [
makeColumn('Название', 'caption', { width: 200, editable: true }),
@ -17,7 +18,7 @@ export default function DepositController() {
const updateTable = () => invokeWebApiWrapperAsync(
async() => {
const deposits = await AdminDepositService.getAll()
setDeposits(deposits)
setDeposits(arrayOrDefault(deposits))
},
setShowLoader,
`Не удалось загрузить список месторождении`

View File

@ -8,6 +8,7 @@ import {
makeStringSorter
} from '../../components/Table'
import { AdminPermissionService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
const columns = [
makeColumn('Название', 'name', {
@ -27,7 +28,7 @@ export const PermissionController = () => {
const updateTable = async () => invokeWebApiWrapperAsync(
async () => {
const permission = await AdminPermissionService.getAll()
setPermissions(permission ?? [])
setPermissions(arrayOrDefault(permission))
},
setShowLoader,
`Не удалось загрузить список прав`

View File

@ -4,6 +4,7 @@ import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler, makeStringSorter, makeNumericSorter } from '../../components/Table'
import { AdminCompanyService, AdminUserService } from '../../services/api'
import { createLoginRules, nameRules, phoneRules, emailRules } from '../../utils/validationRules'
import { arrayOrDefault } from '../../utils'
export default function UserController() {
const [companies, setCompanies] = useState([])
@ -54,7 +55,7 @@ export default function UserController() {
const updateTable = () => invokeWebApiWrapperAsync(
async() => {
const users = await AdminUserService.getAll()
setUsers(users)
setUsers(arrayOrDefault(users))
},
setShowLoader,
`Не удалось загрузить список пользователей`
@ -62,9 +63,9 @@ export default function UserController() {
useEffect(() => invokeWebApiWrapperAsync(
async () => {
let companies = await AdminCompanyService.getAll()
let companies = arrayOrDefault(await AdminCompanyService.getAll())
companies = companies?.map((company) => ({ value: company.id, label: company.caption }))
setCompanies(companies ?? [])
setCompanies(companies)
},
setShowLoader,
`Не удалось загрузить список компаний`

View File

@ -4,6 +4,7 @@ import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import { makeColumn, makeDateSorter, makeStringSorter, Table } from '../../components/Table'
import { RequerstTrackerService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
const columns = [
makeColumn('Логин', 'login', { sorter: makeStringSorter('login') }),
@ -20,7 +21,7 @@ export const VisitLog = () => {
useEffect(() => invokeWebApiWrapperAsync(
async () => {
const logData = await RequerstTrackerService.getUsersStat(1000)
const logData = arrayOrDefault(await RequerstTrackerService.getUsersStat(1000))
logData.forEach((log) => log.key = `${log.login}${log.ip}`)
setLogData(logData)
},

View File

@ -7,3 +7,5 @@ export const mainFrameSize = () => ({
width: window.innerWidth,
height: window.innerHeight - headerHeight
})
export const arrayOrDefault = <T extends unknown>(arr?: unknown, def: T[] = []): T[] => Array.isArray(arr) ? arr : def