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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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