Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "@steroidsjs/eslint-config",
"extends": "@steroidsjs/eslint-config/frontend",
"rules": {
// "prettier/prettier": "off" disabled because
// Definition for rule 'prettier/prettier' was not found
// in every file
// remove if fixed
"prettier/prettier": "off",
"@typescript-eslint/ban-ts-comment": "off",
"no-undef": "off",
"no-redeclare": "off",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@steroidsjs/eslint-config": "^2.1.6",
"@steroidsjs/eslint-config": "^3.0.1",
"@testing-library/dom": "^8.20.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down
1 change: 1 addition & 0 deletions src/actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const init = (skipInitialized = false) => (dispatch, getState) => {

export const reInit = () => init();

// eslint-disable-next-line default-param-last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему дизейблится правило, а не меняется местами параметр?

export const login = (token, redirectPageId: string | boolean = 'root', params?: RouteParams) => (
dispatch,
getState,
Expand Down
1 change: 1 addition & 0 deletions src/actions/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const closeNotification = (id: string | null = null) => ({

export const showNotification = (
message: string,
// eslint-disable-next-line default-param-last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То же что и выше

level: ColorName = null,
params?: IShowNotificationParameters,
) => dispatch => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/HttpComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface IHttpComponent extends IHttpComponentConfig {
* Метод, который можно вызвать при login
* @param {{accessToken: string}} params Параметры для авторизации (accessToken).
*/
onLogin(params: {accessToken: string,}): void,
onLogin(params: {accessToken: string}): void,

/**
* Получение url по методу
Expand Down
3 changes: 2 additions & 1 deletion src/components/LocaleComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export default class LocaleComponent implements ILocaleComponent {
this.language = config.language || 'en';
this.sourceLanguage = config.sourceLanguage || 'ru';
this.backendTimeZone = null;
this.backendTimeDiff = null; // in microseconds
// in microseconds
this.backendTimeDiff = null;
this.translations = {};
// Publish to global
if (process.env.IS_SSR) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/ResourceComponent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable no-promise-executor-return */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ошибки в каком коде отключает это правило, и почему оно включено для всего файла?

import * as queryString from 'qs';
import _isArray from 'lodash-es/isArray';

Expand All @@ -9,8 +10,8 @@ declare global {
execute: (...args: any[]) => Promise<string>,
},
}
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем?

export interface IResourceComponentConfig {
/**
* API-ключ Google для использования Google Maps и других сервисов.
Expand Down Expand Up @@ -181,6 +182,7 @@ export default class ResourceComponent implements IResourceComponent {
lang: this.language || locale.language,
},
// @ts-ignore
// eslint-disable-next-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какую ошибку выключает эта и следующая команда?

() => new Promise(resolve => window.ymaps.ready(() => resolve(window.ymaps))),
);
}
Expand All @@ -195,6 +197,7 @@ export default class ResourceComponent implements IResourceComponent {
this.RESOURCE_TWITTER_WIDGET,
{},
// @ts-ignore
// eslint-disable-next-line
() => new Promise(resolve => window.twttr.ready(() => resolve(window.twttr))),
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/UiComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import _isFunction from 'lodash-es/isFunction';
import _isObject from 'lodash-es/isObject';
import _isString from 'lodash-es/isString';
Expand Down Expand Up @@ -102,7 +101,7 @@ export interface IUiApplicationComponent {
* Добавляет иконки.
* @param {{ [name: string]: string | ReactNode }} icons - Иконки.
*/
addIcons(icons: {[name: string]: string | ReactNode, }): void,
addIcons(icons: {[name: string]: string | ReactNode }): void,

/**
* Возвращает иконку по указанному имени.
Expand Down Expand Up @@ -156,7 +155,7 @@ export default class UiComponent implements IUiApplicationComponent {

protected _models: any;

icons: {[name: string]: string | number | ReactNode, } | any;
icons: {[name: string]: string | number | ReactNode } | any;

fields: any;

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import useMonthGrid from '../ui/content/CalendarSystem/hooks/useMonthGrid';
import useWeekGrid from '../ui/content/CalendarSystem/hooks/useWeekGrid';
import useDisplayDate from '../ui/content/CalendarSystem/hooks/useDisplayDate';
import useCalendarControls from '../ui/content/CalendarSystem/hooks/useCalendarControls';
import useAbsolutePositioning from './useAbsolutePositioning';
import useAddressBar from './useAddressBar';
import useApplication from './useApplication';
Expand All @@ -19,10 +23,6 @@ import useSsr from './useSsr';
import useUniqueId from './useUniqueId';
import useTheme from './useTheme';
import useTree from './useTree';
import useMonthGrid from '../ui/content/CalendarSystem/hooks/useMonthGrid';
import useWeekGrid from '../ui/content/CalendarSystem/hooks/useWeekGrid';
import useDisplayDate from '../ui/content/CalendarSystem/hooks/useDisplayDate';
import useCalendarControls from '../ui/content/CalendarSystem/hooks/useCalendarControls';
import useSaveCursorPosition from './useSaveCursorPosition';

export {
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useAbsolutePositioning.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';

import calculateComponentAbsolutePosition from '../utils/calculateComponentAbsolutePosition';

export interface IComponentStylePosition {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useAddressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const defaultFromStringConverter = (value, type, item) => {
case 'boolean':
return ['1', 't', 'y'].includes(String(value).substr(0, 1)) || null;

// eslint-disable-next-line default-case-last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут и дальше можно же просто подвинуть default-правило

default:
case 'string':
return value ? String(value) : null;
Expand All @@ -78,6 +79,7 @@ export const defaultToStringConverter = (value, type, item) => {
case 'boolean':
return value ? '1' : null;

// eslint-disable-next-line default-case-last
default:
case 'string':
case 'number':
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import ComponentsProvider, {IComponents} from '../providers/ComponentsProvider';
import Router, {IRouteItem, IRouterProps} from '../ui/nav/Router/Router';
import MetricsComponent from '../components/MetricsComponent';
import ScreenProvider, {IScreenProviderProps} from '../providers/ScreenProvider';
import useComponents from './useComponents';
import {IFetchConfig} from '../hooks/useFetch';
import useComponents from './useComponents';

export interface IComponentConfig {
className?: Record<string, any>,
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import _isString from 'lodash-es/isString';
import _isFunction from 'lodash-es/isFunction';
import _isEqual from 'lodash-es/isEqual';
import _uniqBy from 'lodash-es/uniqBy';

Copy link
Contributor

@fogarea fogarea Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно вернуть возможность отделять импорты пустой строкой, в идеале привести к такому виду

  1. импорты из реакта, стероидов и сторонних библиотек

// перенос строки

  1. импорты из корневых папок проекта, для них должен быть алиас, чтобы можно было не указывать весь путь

// перенос строки

  1. импорты внутри папки

Мне кажется, так сразу будет понятно, откуда что импортируется.

import React from 'react';
import useBem from '@steroidsjs/core/hooks/useBem';
import {DateFormatter} from '@steroidsjs/core/ui/format';
import {Text} from '@steroidsjs/core/ui/typography';
import {Link} from '@steroidsjs/core/ui/nav';

import BaseGrid from 'shared/BaseGrid';

import Button from './views/Button;

Подобное мы делали в Клиницисте, можно посмотреть тут

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fogarea @perlexed

Может имеет смысл сделать это в steroidsjs/eslint-config репозитории, а здесь впоследствии просто обновить версию?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как вариант

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProFIT1337 Давай так, да

import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {usePrevious} from 'react-use';
import {fieldsDataProviderSetItems} from '../actions/fields';
import {normalizeItems} from '../utils/data';
import {useComponents, useDispatch} from './index';
import Enum from '../base/Enum';
import {getDataProviderItems, getEnumLabels} from '../reducers/fields';
import {smartSearch} from '../utils/text';
import {useComponents, useDispatch} from './index';

export interface IAutoCompleteConfig {
/**
Expand All @@ -34,8 +33,8 @@ export interface IAutoCompleteConfig {
}

export type DataProviderItems = string
| ({new(): Enum,})
| (string | number | {id: string | number | boolean, label: string | Record<string, any> | number, [key: string]: any, })[];
| ({new(): Enum})
| (string | number | {id: string | number | boolean, label: string | Record<string, any> | number, [key: string]: any })[];

export interface IDataProvider {
/**
Expand Down Expand Up @@ -226,7 +225,8 @@ export default function useDataProvider(config: IDataProviderConfig): IDataProvi
);
const result = searchHandler(dataProvider.action, {
query: config.query,
...(isAuto ? {ids: config.initialSelectedIds} : null), // deprecated logic
// deprecated logic
...(isAuto ? {ids: config.initialSelectedIds} : null),
...(config.initialSelectedIds?.length > 0 ? {withIds: config.initialSelectedIds} : null),
...config.dataProvider.params,
});
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {useCallback, useRef, useState} from 'react';
import {useUnmount, useUpdateEffect, useEffectOnce} from 'react-use';
import _trim from 'lodash-es/trim';
import axios, {AxiosError} from 'axios';
import {useComponents, useSsr} from './index';
import {IComponents} from '../providers/ComponentsProvider';
import {useComponents, useSsr} from './index';

declare global {
interface Window {
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export function generateBackendUrl(props) {

export default function useFile(props: IFileInput): IFileOutput {
const {http} = useComponents();
http.getAccessToken(); // TODO Run promise..
// TODO Run promise..
http.getAccessToken();

const uploader = useInitial(() => new FileUp({
dropArea: {},
Expand All @@ -100,7 +101,8 @@ export default function useFile(props: IFileInput): IFileOutput {
...props.uploaderConfig,
headers: {
...props.uploaderConfig?.headers,
Authorization: 'Bearer ' + http._accessToken, // TODO how to get access token wuthout promise?
// TODO how to get access token wuthout promise?
Authorization: 'Bearer ' + http._accessToken,
},
},
...props.uploader,
Expand Down
14 changes: 8 additions & 6 deletions src/hooks/useLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import _merge from 'lodash-es/merge';
import _intersection from 'lodash-es/intersection';
import {useMount, usePrevious, useUpdateEffect} from 'react-use';
import {ROUTER_ROLE_LOGIN} from '../ui/nav/Router/Router';
import useSsr from './useSsr';
import {IComponents} from '../providers/ComponentsProvider';
import useComponents from './useComponents';
import {getRoute, getRoutesMap} from '../reducers/router';
import {getData, getInitializeCounter, getUser, isInitialized as getIsInitialized} from '../reducers/auth';
import useSelector from './useSelector';
import {init, setData, setUser} from '../actions/auth';
import useDispatch from './useDispatch';
import {setMeta} from '../actions/fields';
import {goToRoute} from '../actions/router';
import useDispatch from './useDispatch';
import useSelector from './useSelector';
import useComponents from './useComponents';
import useSsr from './useSsr';

export interface ILayout {
status?: string,
Expand Down Expand Up @@ -86,7 +86,8 @@ export const runInitAction = (
dispatch(
[
// Meta models & enums
Boolean(resultMeta) && setMeta(resultMeta), // TODO skip models
// TODO skip models
Boolean(resultMeta) && setMeta(resultMeta),
// User auth
setData(result),
// User auth
Expand Down Expand Up @@ -162,7 +163,8 @@ export default function useLayout(initAction: any = null): ILayout {
const pageRoles = route?.roles || [];
const userRoles = [].concat(user?.role || []).concat(user?.roles || []);
if (userRoles.length === 0) {
userRoles.push(null); // Guest
// Guest
userRoles.push(null);
}
if (_intersection(pageRoles, userRoles).length === 0) {
if (loginRouteId && route.id !== loginRouteId) {
Expand Down
14 changes: 9 additions & 5 deletions src/hooks/useList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
IInfiniteScrollProps,
normalizeInfiniteScrollProps,
} from '@steroidsjs/core/ui/list/InfiniteScroll/InfiniteScroll';
import useSelector from './useSelector';
import {getList} from '../reducers/list';
import useModel from '../hooks/useModel';
import useAddressBar, {IAddressBarConfig} from '../hooks/useAddressBar';
Expand All @@ -31,6 +30,7 @@ import {IEmptyProps, normalizeEmptyProps} from '../ui/list/Empty/Empty';
import {IFormProps} from '../ui/form/Form/Form';
import {Model} from '../components/MetaComponent';
import {Loader} from '../ui/layout';
import useSelector from './useSelector';

export type ListControlPosition = 'top' | 'bottom' | 'both' | string;

Expand Down Expand Up @@ -300,7 +300,8 @@ export const getDefaultSearchModel = ({
sort,
layoutNamesProps,
}) => ({
attributes: [ // default attributes
// default attributes
attributes: [
paginationProps.enable && {
type: 'number',
attribute: paginationProps.attribute,
Expand All @@ -312,7 +313,8 @@ export const getDefaultSearchModel = ({
defaultValue: paginationSizeProps.defaultValue,
},
sort.enable && {
type: 'string', // TODO Need list of strings
// TODO Need list of strings
type: 'string',
jsType: 'string[]',
attribute: sort.attribute,
defaultValue: sort.defaultValue,
Expand All @@ -339,8 +341,10 @@ export const createInitialValues = ({
[layoutNamesProps.attribute]: layoutNamesProps.defaultValue,
// TODO [this.props._layout.attribute]:
// this.props.clientStorage.get(this.props._layout.attribute) || this.props._layout.defaultValue,
...initialQuery, // Address bar
...configQuery, // Query from props
// Address bar
...initialQuery,
// Query from props
...configQuery,
});

const FIRST_PAGE = 1;
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useSaveCursorPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export default function useSaveCursorPosition(config: ISaveCursorPositionConfig)
config.inputParams.onChange(value || event.target?.value);
}, [config.inputParams, config.onChangeCallback]);

const onChangeWithDelay = useMemo(() => config.debounce?.enabled
const onChangeWithDelay = useMemo(
() => config.debounce?.enabled
&& _debounce(onChange, config.debounce?.delayMs ?? DEFAULT_DEBOUNCE_DELAY_MS),
[config.debounce, onChange]);
[config.debounce, onChange],
);
Comment on lines +50 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отступы поехали


return {
inputRef,
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import _pickBy from 'lodash-es/pickBy';
import {IRouteItem} from '@steroidsjs/core/ui/nav/Router/Router';
import {IButtonProps} from '@steroidsjs/core/ui/form/Button/Button';
import {useMount, useUnmount} from 'react-use';
import {getActiveRouteIds, getNavItems, getRouteId, getRouterParams} from '../reducers/router';
import useComponents from './useComponents';
import useSelector from './useSelector';
import {getActiveRouteIds, getNavItems, getRouteId, getRouterParams} from '../reducers/router';

export interface ITreeItem extends IButtonProps {
/**
Expand Down Expand Up @@ -285,7 +285,7 @@ export default function useTree(config: ITreeConfig): ITreeOutput {

const [selectedUniqueId, setSelectedUniqueId] = useState<string>(null);

const [expandedItems, setExpandedItems] = useState<{[key: string]: boolean,}>({});
const [expandedItems, setExpandedItems] = useState<{[key: string]: boolean}>({});

const {clientStorage} = useComponents();

Expand Down Expand Up @@ -319,7 +319,8 @@ export default function useTree(config: ITreeConfig): ITreeOutput {
// Выполняет поиск текущего роута в дереве: раскрывает дерево до элемента, делает элемент активным
const onItemFocus = useCallback(() => {
const currentRouteAsTreeItem = findChildById(items as ITreeItem[], selectedItemId, primaryKey);
const currentRouteUniqueIdParts = currentRouteAsTreeItem.uniqueId.split(DOT_SEPARATOR); // Get all parent levels of item
// Get all parent levels of item
const currentRouteUniqueIdParts = currentRouteAsTreeItem.uniqueId.split(DOT_SEPARATOR);

const itemsToExpand = {};
let itemToExpandKey: string;
Expand Down
13 changes: 7 additions & 6 deletions src/providers/SsrProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export const SsrProviderContext = React.createContext<ISsr>(null);
export interface ISsrProviderProps extends ISsr, PropsWithChildren<any> {}

export default function SsrProvider(props: ISsrProviderProps): JSX.Element {
const providerValue = React.useMemo(() => ({
history: props.history,
staticContext: props.staticContext,
preloadedData: props.preloadedData,
}), [props.history, props.preloadedData, props.staticContext]);

return (
<SsrProviderContext.Provider value={{
history: props.history,
staticContext: props.staticContext,
preloadedData: props.preloadedData,
}}
>
<SsrProviderContext.Provider value={providerValue}>
{props.children}
</SsrProviderContext.Provider>
);
Expand Down
1 change: 1 addition & 0 deletions src/reducers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const initialState = {
user: null,
data: null,
};
// eslint-disable-next-line default-param-last
export default (state = initialState, action) => {
switch (action.type) {
case AUTH_INIT:
Expand Down
Loading