forked from ddrilling/asb_cloud_front
Стилистические изменения
This commit is contained in:
parent
4afa7810ff
commit
78c7f78935
@ -1,26 +1,29 @@
|
|||||||
import { Form, Table, Button, Popconfirm } from "antd"
|
import { Form, Table, Button, Popconfirm } from 'antd'
|
||||||
import { EditOutlined, SaveOutlined, PlusOutlined, CloseCircleOutlined, DeleteOutlined } from '@ant-design/icons'
|
import { EditOutlined, SaveOutlined, PlusOutlined, CloseCircleOutlined, DeleteOutlined } from '@ant-design/icons'
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from 'react'
|
||||||
import { EditableCell } from './EditableCell'
|
import { EditableCell } from './EditableCell'
|
||||||
import { invokeWebApiWrapperAsync } from "../factory";
|
import { invokeWebApiWrapperAsync } from '../factory'
|
||||||
|
|
||||||
const newRowKeyValue = 'newRow'
|
const newRowKeyValue = 'newRow'
|
||||||
|
|
||||||
export const makeActionHandler = (action, { service, setLoader, errorMsg, onComplete }) => service && action && ((record) => invokeWebApiWrapperAsync(
|
export const makeActionHandler = (action, { service, setLoader, errorMsg, onComplete }) => service && action && (
|
||||||
|
(record) => invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
if (action === 'insert') {
|
if (action === 'insert') {
|
||||||
|
record.key = Date.now()
|
||||||
await service.insert(record)
|
await service.insert(record)
|
||||||
} else if (record.id) {
|
} else if (record.id) {
|
||||||
if (action === 'update')
|
if (action === 'update')
|
||||||
await service.delete(record.id)
|
|
||||||
else if (action === 'delete')
|
|
||||||
await service.put(record.id, record)
|
await service.put(record.id, record)
|
||||||
|
else if (action === 'delete')
|
||||||
|
await service.delete(record.id)
|
||||||
}
|
}
|
||||||
onComplete?.()
|
onComplete?.()
|
||||||
},
|
},
|
||||||
setLoader,
|
setLoader,
|
||||||
errorMsg
|
errorMsg
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
export const tryAddKeys = (items) => {
|
export const tryAddKeys = (items) => {
|
||||||
if (!items?.length || !items[0])
|
if (!items?.length || !items[0])
|
||||||
@ -56,8 +59,7 @@ export const EditableTable = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
if(editingKey === newRowKeyValue)
|
if (editingKey === newRowKeyValue) {
|
||||||
{
|
|
||||||
const newData = [...data]
|
const newData = [...data]
|
||||||
const index = newData.findIndex((item) => newRowKeyValue === item.key)
|
const index = newData.findIndex((item) => newRowKeyValue === item.key)
|
||||||
newData.splice(index, 1)
|
newData.splice(index, 1)
|
||||||
@ -71,6 +73,11 @@ export const EditableTable = ({
|
|||||||
...form.initialValues,
|
...form.initialValues,
|
||||||
key:newRowKeyValue
|
key:newRowKeyValue
|
||||||
}
|
}
|
||||||
|
// const newRow = { key: newRowKeyValue }
|
||||||
|
|
||||||
|
// for (let column of columns)
|
||||||
|
// newRow[column.dataIndex] = form.initialValues?.[column.dataIndex] ?? column.initialValue
|
||||||
|
|
||||||
const newData = [newRow, ...data]
|
const newData = [newRow, ...data]
|
||||||
setData(newData)
|
setData(newData)
|
||||||
edit(newRow)
|
edit(newRow)
|
||||||
@ -133,34 +140,35 @@ export const EditableTable = ({
|
|||||||
|
|
||||||
const operationColumn = {
|
const operationColumn = {
|
||||||
width: 82,
|
width: 82,
|
||||||
title: (!!onRowAdd) && <Button
|
title: !!onRowAdd && (
|
||||||
|
<Button
|
||||||
onClick={addNewRow}
|
onClick={addNewRow}
|
||||||
disabled={editingKey !== ''}
|
disabled={editingKey !== ''}
|
||||||
icon={<PlusOutlined/>}
|
icon={<PlusOutlined/>}
|
||||||
/>,
|
/>
|
||||||
|
),
|
||||||
dataIndex: 'operation',
|
dataIndex: 'operation',
|
||||||
render: (_, record) => {
|
render: (_, record) => isEditing(record) ? (
|
||||||
const editable = isEditing(record)
|
<span>
|
||||||
return editable
|
<Button onClick={() => save(record)} icon={<SaveOutlined/>}/>
|
||||||
?(<span>
|
<Button onClick={cancel} icon={<CloseCircleOutlined/>}/>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span>
|
||||||
|
{onRowEdit && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => save(record)}
|
|
||||||
icon={<SaveOutlined/>}/>
|
|
||||||
<Button
|
|
||||||
onClick={cancel}
|
|
||||||
icon={<CloseCircleOutlined/>}/>
|
|
||||||
</span>)
|
|
||||||
:(<span>
|
|
||||||
{onRowEdit&&<Button
|
|
||||||
disabled={editingKey !== ''}
|
disabled={editingKey !== ''}
|
||||||
onClick={() => edit(record)}
|
onClick={() => edit(record)}
|
||||||
icon={<EditOutlined/>}/>}
|
icon={<EditOutlined/>}
|
||||||
{onRowDelete&&
|
/>
|
||||||
<Popconfirm title="Удалить?" onConfirm={()=>deleteRow(record)}>
|
)}
|
||||||
|
{onRowDelete && (
|
||||||
|
<Popconfirm title={'Удалить?'} onConfirm={() => deleteRow(record)}>
|
||||||
<Button icon={<DeleteOutlined/>}/>
|
<Button icon={<DeleteOutlined/>}/>
|
||||||
</Popconfirm>}
|
</Popconfirm>
|
||||||
</span>)
|
)}
|
||||||
},
|
</span>
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleColumn = (col) => {
|
const handleColumn = (col) => {
|
||||||
|
@ -3,6 +3,7 @@ import { Select, Table as RawTable } from 'antd'
|
|||||||
import { OptionsType } from 'rc-select/lib/interface'
|
import { OptionsType } from 'rc-select/lib/interface'
|
||||||
import { tryAddKeys } from './EditableTable'
|
import { tryAddKeys } from './EditableTable'
|
||||||
import { makeNumericSorter, makeStringSorter} from './sorters'
|
import { makeNumericSorter, makeStringSorter} from './sorters'
|
||||||
|
import { Rule } from 'rc-field-form/lib/interface'
|
||||||
export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters'
|
export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters'
|
||||||
export { EditableTable, makeActionHandler } from './EditableTable'
|
export { EditableTable, makeActionHandler } from './EditableTable'
|
||||||
export { DatePickerWrapper } from './DatePickerWrapper'
|
export { DatePickerWrapper } from './DatePickerWrapper'
|
||||||
@ -55,7 +56,7 @@ interface columnPropsOther {
|
|||||||
// css класс для <FormItem/>, если требуется
|
// css класс для <FormItem/>, если требуется
|
||||||
formItemClass?: string
|
formItemClass?: string
|
||||||
// массив правил валидации значений https://ant.design/components/form/#Rule
|
// массив правил валидации значений https://ant.design/components/form/#Rule
|
||||||
formItemRules?: any[]
|
formItemRules?: Rule[]
|
||||||
// дефолтное значение при добавлении новой строки
|
// дефолтное значение при добавлении новой строки
|
||||||
initialValue?: string|number
|
initialValue?: string|number
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
type PointerIconColors = {
|
export type PointerIconColors = {
|
||||||
online?: string
|
online?: string
|
||||||
active?: string
|
active?: string
|
||||||
inactive?: string
|
inactive?: string
|
||||||
unknown?: string
|
unknown?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PointerIconProps {
|
export interface PointerIconProps {
|
||||||
width?: string | number
|
width?: string | number
|
||||||
height?: string | number
|
height?: string | number
|
||||||
online?: boolean
|
online?: boolean
|
||||||
|
5
src/components/icons/index.ts
Normal file
5
src/components/icons/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export type { PointerIconColors, PointerIconProps } from './PointerIcon'
|
||||||
|
export type { WellIconColors, WellIconProps } from './WellIcon'
|
||||||
|
|
||||||
|
export { PointerIcon } from './PointerIcon'
|
||||||
|
export { WellIcon } from './WellIcon'
|
Loading…
Reference in New Issue
Block a user