Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 669ffe38

Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)

Refactoring after code review

Zobrazit rozdíly:

webapp/pages/documents/annotator/index.tsx
13 13
import {
14 14
    CheckCircleOutlined,
15 15
    ClockCircleOutlined,
16
    SearchOutlined,
17 16
    SyncOutlined,
18 17
} from '@ant-design/icons';
18
import { getColumnSearchProps, getLocaleProps } from '../../../utils/tableUtils';
19 19

  
20 20
function UserDocumentPage() {
21 21
    const redirecting = useUnauthRedirect('/login');
......
39 39
        }
40 40
    }, [logout, redirecting, role, router]);
41 41

  
42
    const handleSearch = (
43
        selectedKeys: React.SetStateAction<string>[],
44
        confirm: () => void
45
    ) => {
46
        confirm();
47
    };
48

  
49
    const handleReset = (clearFilters: () => void) => {
50
        clearFilters();
51
    };
52

  
53
    const getColumnSearchProps = (dataIndex: string, searchLabel: string) => ({
54
        // @ts-ignore
55
        filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
56
            <div style={{ padding: 8 }}>
57
                <Input
58
                    placeholder={`Vyhledat ${searchLabel}`}
59
                    value={selectedKeys[0]}
60
                    onChange={(e) =>
61
                        setSelectedKeys(e.target.value ? [e.target.value] : [])
62
                    }
63
                    onPressEnter={() => handleSearch(selectedKeys, confirm)}
64
                    style={{ marginBottom: 8, display: 'block' }}
65
                />
66
                <Space>
67
                    <Button
68
                        type="primary"
69
                        onClick={() => handleSearch(selectedKeys, confirm)}
70
                        icon={<SearchOutlined />}
71
                        style={{ width: 90 }}
72
                    >
73
                        Hledat
74
                    </Button>
75
                    <Button
76
                        onClick={() => handleReset(clearFilters)}
77
                        style={{ width: 90 }}
78
                    >
79
                        Smazat
80
                    </Button>
81
                </Space>
82
            </div>
83
        ),
84
        filterIcon: (filtered: any) => (
85
            <SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />
86
        ),
87
        onFilter: (value: string, record: { [x: string]: { toString: () => string } }) =>
88
            record[dataIndex]
89
                ? record[dataIndex].toString().toLowerCase().includes(value.toLowerCase())
90
                : '',
91
    });
92

  
93 42
    const columns = [
94 43
        {
95 44
            title: 'Název dokumentu',
96 45
            dataIndex: 'documentName',
97 46
            key: 'documentName',
98 47
            ...getColumnSearchProps('documentName', 'název'),
48
            // @ts-ignore
49
            sorter: (a, b) => a.documentName.localeCompare(b.documentName),
99 50
        },
100 51
        {
101 52
            title: 'Stav anotace',
......
163 114
                <FontAwesomeIcon icon={faFileLines} /> Dokumenty
164 115
            </Typography.Title>
165 116
            <Table
166
                locale={{
167
                    triggerDesc: 'Seřadit sestupně',
168
                    triggerAsc: 'Seřadit vzestupně',
169
                    cancelSort: 'Vypnout řazení',
170
                }}
117
                locale={{ ...getLocaleProps() }}
171 118
                // @ts-ignore
172 119
                columns={columns}
173 120
                // @ts-ignore

Také k dispozici: Unified diff