forked from CITKParus/P8-Panels
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
/*
|
|
Парус 8 - Панели мониторинга - Таблица
|
|
Компонент: Панель инструментов столбца (правая)
|
|
*/
|
|
|
|
//---------------------
|
|
//Подключение библиотек
|
|
//---------------------
|
|
|
|
import React from "react"; //Классы React
|
|
import PropTypes from "prop-types"; //Контроль свойств компонента
|
|
import { IconButton, Icon } from "@mui/material"; //Интерфейсные компоненты
|
|
import { hasValue } from "./p8p_table_reducer"; //Редьюсер состояния
|
|
import { P8P_TABLE_COLUMN_ORDER_DIRECTIONS, P8P_TABLE_COLUMN_TOOL_BAR_ACTIONS } from "./p8p_table_constants"; //Константы таблицы
|
|
|
|
//-----------
|
|
//Тело модуля
|
|
//-----------
|
|
|
|
//Панель инструментов столбца (правая)
|
|
const P8PTableColumnToolBarRight = ({ columnDef, orders, filters, onItemClick }) => {
|
|
//Кнопка сортировки
|
|
const order = orders.find(o => o.name == columnDef.name);
|
|
let orderButton = null;
|
|
if (order)
|
|
orderButton = (
|
|
<IconButton onClick={() => (onItemClick ? onItemClick(P8P_TABLE_COLUMN_TOOL_BAR_ACTIONS.ORDER_TOGGLE, columnDef.name) : null)}>
|
|
<Icon>{order.direction === P8P_TABLE_COLUMN_ORDER_DIRECTIONS.ASC ? "arrow_upward" : "arrow_downward"}</Icon>
|
|
</IconButton>
|
|
);
|
|
|
|
//Кнопка фильтрации
|
|
const filter = filters.find(f => f.name == columnDef.name);
|
|
let filterButton = null;
|
|
if (hasValue(filter?.from) || hasValue(filter?.to))
|
|
filterButton = (
|
|
<IconButton onClick={() => (onItemClick ? onItemClick(P8P_TABLE_COLUMN_TOOL_BAR_ACTIONS.FILTER_TOGGLE, columnDef.name) : null)}>
|
|
<Icon>filter_alt</Icon>
|
|
</IconButton>
|
|
);
|
|
|
|
//Генерация содержимого
|
|
return (
|
|
<>
|
|
{orderButton}
|
|
{filterButton}
|
|
</>
|
|
);
|
|
};
|
|
|
|
//Контроль свойств - Панель инструментов столбца (правая)
|
|
P8PTableColumnToolBarRight.propTypes = {
|
|
columnDef: PropTypes.object.isRequired,
|
|
orders: PropTypes.array.isRequired,
|
|
filters: PropTypes.array.isRequired,
|
|
onItemClick: PropTypes.func
|
|
};
|
|
|
|
//----------------
|
|
//Интерфейс модуля
|
|
//----------------
|
|
|
|
export { P8PTableColumnToolBarRight };
|