Общий метод форматирования координат вынесен в утилиты

This commit is contained in:
goodmice 2022-10-13 16:45:30 +05:00
parent 847cfce2b6
commit 93e6d2171d
No known key found for this signature in database
GPG Key ID: 63EA771203189CF1
4 changed files with 11 additions and 15 deletions

View File

@ -11,11 +11,9 @@ import {
} from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory'
import { AdminClusterService, AdminDepositService } from '@api'
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { arrayOrDefault, coordsFormat, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules'
import { coordsFixed } from './DepositController'
const ClusterController = memo(() => {
const [deposits, setDeposits] = useState([])
const [clusters, setClusters] = useState([])
@ -41,8 +39,8 @@ const ClusterController = memo(() => {
sorter: makeStringSorter('caption'),
formItemRules: min1,
}),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFormat }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFormat }),
makeTimezoneColumn('Зона', 'timezone', null, true, { width: 150 }),
], [deposits])

View File

@ -3,16 +3,14 @@ import { Input } from 'antd'
import { invokeWebApiWrapperAsync } from '@components/factory'
import { EditableTable, makeColumn, defaultPagination, makeTimezoneColumn } from '@components/Table'
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { arrayOrDefault, coordsFormat, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules'
import { AdminDepositService } from '@api'
export const coordsFixed = (coords) => coords && isFinite(coords) ? (+coords).toPrecision(10) : '-'
const depositColumns = [
makeColumn('Название', 'caption', { width: 200, editable: true, formItemRules: min1 }),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFormat }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFormat }),
makeTimezoneColumn('Зона', 'timezone', null, true, { width: 150 }),
]

View File

@ -21,9 +21,7 @@ import {
import { invokeWebApiWrapperAsync } from '@components/factory'
import { TelemetryView, CompanyView } from '@components/views'
import TelemetrySelect from '@components/selectors/TelemetrySelect'
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { coordsFixed } from '../DepositController'
import { arrayOrDefault, coordsFormat, wrapPrivateComponent } from '@utils'
const wellTypes = [
{ value: 1, label: 'Наклонно-направленная' },
@ -98,8 +96,8 @@ const WellController = memo(() => {
editable: true,
sorter: makeNumericSorter('idWellType'),
}),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFormat }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFormat }),
makeColumn('Телеметрия', 'telemetry', {
editable: true,
render: (telemetry) => <TelemetryView telemetry={telemetry} />,

View File

@ -59,3 +59,5 @@ export const makeDisplayValue = ({
if (Number.isFinite(f)) return f.toFixed(fixed)
return typeof inf === 'function' ? inf(f) : inf
}
export const coordsFormat = (coords?: string) => (typeof coords === 'string') && isFinite(Number(coords)) ? Number(coords).toPrecision(10) : '-'