Merge pull request 'project fix filters' (#101) from fix-logic-limitation into test
Reviewed-on: #101
This commit is contained in:
commit
086adc0992
@ -26,7 +26,7 @@ const TablesList = ({ filteredTables, query, basePath = '/table', formInfo, isPr
|
||||
groups[year] = [...(groups[year] || []), table];
|
||||
return groups;
|
||||
}, {}),
|
||||
).sort(([firstYear], [secondYear]) => Number(secondYear) - Number(firstYear))
|
||||
).sort(([firstYear], [secondYear]) => Number(firstYear) - Number(secondYear))
|
||||
: [];
|
||||
|
||||
return (
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
import { Box, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, MenuItem, TextField, Typography } from '@mui/material';
|
||||
import React from 'react';
|
||||
import { useAuth } from '../../../../app/context/AuthProvider';
|
||||
import { DangerOutlinedButton, PrimaryButton } from '../../../../components/common/Buttons/Buttons';
|
||||
import { DEVELOMENT_BLOCK, FUNDING_BY_DECISION } from '../../constants';
|
||||
import { canEditFirstTableField } from '../../constants/fieldAccess';
|
||||
|
||||
const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNames = {} }) => {
|
||||
const { user } = useAuth();
|
||||
const [formData, setFormData] = React.useState(rowData || {});
|
||||
|
||||
React.useEffect(() => {
|
||||
@ -66,6 +69,7 @@ const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNa
|
||||
// Компонент для поля ввода
|
||||
const renderField = (field) => {
|
||||
const rawValue = formData[field.key];
|
||||
const isFieldDisabled = field.disabled || !canEditFirstTableField(field.key, user?.role_id);
|
||||
const fieldValue = field.valueType === 'boolean' && rawValue !== null && rawValue !== undefined
|
||||
? String(rawValue)
|
||||
: (rawValue ?? '');
|
||||
@ -93,7 +97,7 @@ const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNa
|
||||
multiline={field.multiline || false}
|
||||
rows={field.rows || 1}
|
||||
select={Boolean(field.options)}
|
||||
disabled={field.disabled || isSaving}
|
||||
disabled={isFieldDisabled || isSaving}
|
||||
InputLabelProps={field.type === 'date' ? { shrink: true } : undefined}
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
|
||||
@ -8,6 +8,7 @@ import { ROLES_NAME_ID } from '../../../../constants/constants';
|
||||
|
||||
const TableFilters = ({ onBranchChange, onSearchChange, selectedBranch, searchQuery }) => {
|
||||
const [branches, setBranches] = useState([]);
|
||||
const [branchInputValue, setBranchInputValue] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const { user } = useAuth();
|
||||
|
||||
@ -44,6 +45,10 @@ const TableFilters = ({ onBranchChange, onSearchChange, selectedBranch, searchQu
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
|
||||
useEffect(() => {
|
||||
setBranchInputValue(selectedBranch?.title || '');
|
||||
}, [selectedBranch]);
|
||||
|
||||
return (
|
||||
<Paper
|
||||
elevation={0}
|
||||
@ -71,6 +76,10 @@ const TableFilters = ({ onBranchChange, onSearchChange, selectedBranch, searchQu
|
||||
getOptionLabel={(option) => option.title || ''}
|
||||
getOptionKey={(option) => option.id}
|
||||
value={selectedBranch || null}
|
||||
inputValue={branchInputValue}
|
||||
onInputChange={(event, newInputValue) => {
|
||||
setBranchInputValue(newInputValue);
|
||||
}}
|
||||
onChange={(event, newValue) => {
|
||||
onBranchChange(newValue || '');
|
||||
}}
|
||||
@ -100,7 +109,7 @@ const TableFilters = ({ onBranchChange, onSearchChange, selectedBranch, searchQu
|
||||
</li>
|
||||
)}
|
||||
clearOnBlur={false}
|
||||
isOptionEqualToValue={(option, value) => option === value}
|
||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
@ -135,6 +144,7 @@ const TableFilters = ({ onBranchChange, onSearchChange, selectedBranch, searchQu
|
||||
label='Сбросить фильтры'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setBranchInputValue('');
|
||||
onBranchChange('');
|
||||
onSearchChange('');
|
||||
}}
|
||||
|
||||
35
web/src/pages/ProjectPages/constants/fieldAccess.js
Normal file
35
web/src/pages/ProjectPages/constants/fieldAccess.js
Normal file
@ -0,0 +1,35 @@
|
||||
import { ROLES_NAME_ID } from '../../../constants/constants';
|
||||
|
||||
const ADMIN_ROLES = [ROLES_NAME_ID.admin];
|
||||
const DFIP_ROLES = [ROLES_NAME_ID.admin, ROLES_NAME_ID.executor_dfip];
|
||||
const RF_ROLES = [ROLES_NAME_ID.admin, ROLES_NAME_ID.executor_rf];
|
||||
|
||||
// Матрица доступа к полям первой таблицы.
|
||||
// Поля «авто» доступны для ручного редактирования только администратору.
|
||||
export const FIRST_TABLE_FIELD_ACCESS = {
|
||||
name: ADMIN_ROLES,
|
||||
org_unit_id: ADMIN_ROLES,
|
||||
status: DFIP_ROLES,
|
||||
technical_number: ADMIN_ROLES,
|
||||
object_address: ADMIN_ROLES,
|
||||
vsp_format: ADMIN_ROLES,
|
||||
placement_type: ADMIN_ROLES,
|
||||
staff_count: ADMIN_ROLES,
|
||||
total_area: ADMIN_ROLES,
|
||||
project_type: ADMIN_ROLES,
|
||||
krf_decision_date: RF_ROLES,
|
||||
fk_decision_date: RF_ROLES,
|
||||
board_decision_date: RF_ROLES,
|
||||
open_relocate_close_date: RF_ROLES,
|
||||
funding_by_ko_decision: DFIP_ROLES,
|
||||
year: ADMIN_ROLES,
|
||||
is_in_plan: DFIP_ROLES,
|
||||
is_in_plan_q2: DFIP_ROLES,
|
||||
is_in_plan_q3: DFIP_ROLES,
|
||||
is_in_plan_q4: DFIP_ROLES,
|
||||
development_block: DFIP_ROLES,
|
||||
reserve_to_prrs_ahr: DFIP_ROLES,
|
||||
reserve_to_prrs_kv: DFIP_ROLES,
|
||||
};
|
||||
|
||||
export const canEditFirstTableField = (fieldKey, roleId) => FIRST_TABLE_FIELD_ACCESS[fieldKey]?.includes(roleId) ?? false;
|
||||
Loading…
x
Reference in New Issue
Block a user