Skip to content

Commit

Permalink
chore(ts): fix circular deps completely
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Sep 26, 2023
1 parent 4011e86 commit 45f6e9f
Show file tree
Hide file tree
Showing 40 changed files with 306 additions and 257 deletions.
2 changes: 1 addition & 1 deletion src/app/Dashboard/AddCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { Observable, of } from 'rxjs';
import { ChartContext } from './Charts/ChartContext';
import { ChartContext } from './Charts/context';
import { CardConfig, DashboardCardDescriptor, PropControl } from './types';
import { getCardDescriptorByTitle, getDashboardCards } from './utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { ErrorView } from '@app/ErrorView/ErrorView';
import { authFailMessage, isAuthFail } from '@app/ErrorView/types';
import { LoadingView } from '@app/Shared/Components/LoadingView';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { CategorizedRuleEvaluations, AutomatedAnalysisScore } from '@app/Shared/Services/api.types';
import { Flex, FlexItem } from '@patternfly/react-core';
import {
Expand All @@ -37,7 +37,7 @@ import {
} from '@patternfly/react-table';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { transformAADescription } from '../utils';
import { transformAADescription } from './utils';

export interface AutomatedAnalysisCardListProps {
evaluations: CategorizedRuleEvaluations[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { AutomatedAnalysisScore, RuleEvaluation } from '@app/Shared/Services/api.types';
import { portalRoot } from '@app/utils/utils';
import { Label, LabelProps, Popover } from '@patternfly/react-core';
Expand All @@ -22,7 +22,7 @@ import { css } from '@patternfly/react-styles';
import popoverStyles from '@patternfly/react-styles/css/components/Popover/popover';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { transformAADescription } from '../utils';
import { transformAADescription } from './utils';

export interface ClickableAutomatedAnalysisLabelProps {
label: RuleEvaluation;
Expand Down
38 changes: 38 additions & 0 deletions src/app/Dashboard/AutomatedAnalysis/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as React from 'react';

export const transformAADescription = (description: string): JSX.Element => {
const splitDesc = description.split('\n\n');
const boldRegex = /^([^:]+:\s?)/; // match text up to and including the first colon

return (
<>
{splitDesc.map((item, index) => {
const boldMatch = item.match(boldRegex);
const boldText = boldMatch ? boldMatch[0] : '';
const restOfText = boldMatch ? item.replace(boldRegex, '') : item;
const style = index > 0 ? { paddingTop: '0.7rem' } : {};
return (
<p key={index} style={style}>
{boldText && <strong>{boldText}</strong>}
{restOfText}
</p>
);
})}
</>
);
};
File renamed without changes.
4 changes: 2 additions & 2 deletions src/app/Dashboard/Charts/jfr/JFRMetricsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { CustomRecordingFormData } from '@app/CreateRecording/types';
import {
DashboardCardTypeProps,
Expand Down Expand Up @@ -46,7 +46,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { interval } from 'rxjs';
import { DashboardCard } from '../../DashboardCard';
import { ChartContext } from './../ChartContext';
import { ChartContext } from '../context';
import { ControllerState, RECORDING_NAME } from './JFRMetricsChartController';

export interface JFRMetricsChartCardProps extends DashboardCardTypeProps {
Expand Down
4 changes: 2 additions & 2 deletions src/app/Dashboard/Charts/mbean/MBeanMetricsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import {
DashboardCardTypeProps,
DashboardCardFC,
Expand Down Expand Up @@ -46,7 +46,7 @@ import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { interval } from 'rxjs';
import { DashboardCard } from '../../DashboardCard';
import { ChartContext } from './../ChartContext';
import { ChartContext } from '../context';

export interface MBeanMetricsChartCardProps extends DashboardCardTypeProps {
themeColor: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { AddCard } from './AddCard';
import { ChartContext } from './Charts/ChartContext';
import { ChartContext } from './Charts/context';
import { JFRMetricsChartController } from './Charts/jfr/JFRMetricsChartController';
import { MBeanMetricsChartController } from './Charts/mbean/MBeanMetricsChartController';
import { DashboardCardActionMenu } from './DashboardCardActionMenu';
Expand Down
5 changes: 3 additions & 2 deletions src/app/Dashboard/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { Card, CardProps } from '@patternfly/react-core';
import { css } from '@patternfly/react-styles';
import * as React from 'react';
import { DRAGGABLE_REF_KLAZZ } from './const';
import { DashboardCardContext } from './context';
import { DraggableRef } from './DraggableRef';
import { ResizableRef } from './ResizableRef';
import { DashboardCardSizes } from './types';
import { DashboardCardContext, DRAGGABLE_REF_KLAZZ } from './utils';

export interface DashboardCardProps extends CardProps {
dashboardId: number;
Expand Down
3 changes: 2 additions & 1 deletion src/app/Dashboard/DashboardLayoutCreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import {
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { DEFAULT_DASHBOARD_NAME } from './const';
import { BlankLayout } from './cryostat-dashboard-templates';
import { LayoutTemplatePicker } from './LayoutTemplatePicker';
import { SelectedLayoutTemplate } from './types';
import { DashboardLayoutNamePattern, DEFAULT_DASHBOARD_NAME, layoutize, LayoutTemplateContext } from './utils';
import { DashboardLayoutNamePattern, layoutize, LayoutTemplateContext } from './utils';

export interface DashboardLayoutCreateModalProps {
oldName?: string;
Expand Down
8 changes: 2 additions & 6 deletions src/app/Dashboard/DashboardLayoutSetAsTemplateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ import { ValidatedOptions } from '@patternfly/react-core/dist/js/helpers';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import {
DashboardLayoutNamePattern,
LayoutTemplateDescriptionPattern,
LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT,
templatize,
} from './utils';
import { LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT } from './const';
import { DashboardLayoutNamePattern, LayoutTemplateDescriptionPattern, templatize } from './utils';

export interface DashboardLayoutSetAsTemplateModalProps {
visible: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/app/Dashboard/DashboardLayoutToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { AddCard } from './AddCard';
import { DEFAULT_DASHBOARD_NAME } from './const';
import { BlankLayout } from './cryostat-dashboard-templates';
import { DashboardLayoutCreateModal } from './DashboardLayoutCreateModal';
import { DashboardLayoutSetAsTemplateModal } from './DashboardLayoutSetAsTemplateModal';
import { LayoutTemplateUploadModal } from './LayoutTemplateUploadModal';
import { SelectedLayoutTemplate, DashboardLayout } from './types';
import { DEFAULT_DASHBOARD_NAME, getUniqueIncrementingName, LayoutTemplateContext } from './utils';
import { getUniqueIncrementingName, LayoutTemplateContext } from './utils';

export interface DashboardLayoutToolbarProps {
children?: React.ReactNode;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Dashboard/DraggableRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { dashboardConfigReorderCardIntent } from '@app/Shared/Redux/ReduxStore';
import { clickOutside } from '@app/utils/utils';
import { css } from '@patternfly/react-styles';
import React from 'react';
import { useDispatch } from 'react-redux';
import { DRAGGABLE_REF_KLAZZ } from './const';
import { handleDisabledElements } from './ResizableRef';
import { DRAGGABLE_REF_KLAZZ } from './utils';

const getOverlapScales = (dragIndex: number, hoverIndex: number): [number, number] => {
let leftScale = OFFSET_SCALE;
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/JvmDetails/JvmDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { NodeType, Target } from '@app/Shared/Services/api.types';
import { FeatureLevel } from '@app/Shared/Services/service.types';
import { ServiceContext } from '@app/Shared/Services/Services';
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/LayoutTemplatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { InnerScrollContainer, OuterScrollContainer } from '@patternfly/react-ta
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { ChartContext } from './Charts/ChartContext';
import { ChartContext } from './Charts/context';
import { CryostatLayoutTemplates, BlankLayout } from './cryostat-dashboard-templates';
import { LayoutTemplateGroup, smallestFeatureLevel } from './LayoutTemplateGroup';
import { SearchAutocomplete } from './SearchAutocomplete';
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/LayoutTemplateUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { forkJoin, from, Observable, of } from 'rxjs';
import { catchError, concatMap, defaultIfEmpty, first } from 'rxjs/operators';
import { LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT } from './const';
import { smallestFeatureLevel } from './LayoutTemplateGroup';
import {
LayoutTemplate,
Expand All @@ -36,7 +37,6 @@ import {
} from './types';
import {
DashboardLayoutNamePattern,
LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT,
LayoutTemplateContext,
LayoutTemplateDescriptionPattern,
mockSerialLayoutTemplate,
Expand Down
14 changes: 7 additions & 7 deletions src/app/Dashboard/ResizableRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import { dashboardConfigResizeCardIntent, RootState } from '@app/Shared/Redux/ReduxStore';
import { gridSpans } from '@patternfly/react-core';
import _ from 'lodash';
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { CardConfig, DashboardCardSizes } from './types';
import { DashboardCardContext } from './utils';
import { DashboardCardContext } from './context';
import type { CardConfig, DashboardCardSizes } from './types';

export interface ResizableRefProps {
cardId: number;
cardSizes: DashboardCardSizes;
}

function normalizeAsGridSpans(val: number, min: number, max: number, a: gridSpans, b: gridSpans): gridSpans {
const normalizeAsGridSpans = (val: number, min: number, max: number, a: gridSpans, b: gridSpans): gridSpans => {
if (val < min) val = min;
else if (val > max) val = max;
const ans = Math.round((b - a) * ((val - min) / (max - min)) + a);
return _.clamp(ans, a, b) as gridSpans;
}
};

export function handleDisabledElements(disabled: boolean): void {
export const handleDisabledElements = (disabled: boolean): void => {
const disabledElements: HTMLElement[] = Array.from(document.querySelectorAll('.disabled-pointer'));
disabledElements.forEach((el) => (el.style['pointer-events'] = disabled ? 'none' : 'auto'));
}
};

export const ResizableRef: React.FC<ResizableRefProps> = ({
cardId: dashboardId,
Expand Down
18 changes: 18 additions & 0 deletions src/app/Dashboard/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const DEFAULT_DASHBOARD_NAME = 'Default';
export const DRAGGABLE_REF_KLAZZ = `draggable-ref`;
export const LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT = 100;
18 changes: 18 additions & 0 deletions src/app/Dashboard/context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as React from 'react';

export const DashboardCardContext = React.createContext<React.RefObject<HTMLDivElement>>(React.createRef());
32 changes: 2 additions & 30 deletions src/app/Dashboard/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint import/no-cycle: 0 */

import cryostatLogo from '@app/assets/cryostat_icon_rgb_default.svg';
import cryostatLogoDark from '@app/assets/cryostat_icon_rgb_reverse.svg';
import { dashboardConfigDeleteCardIntent } from '@app/Shared/Redux/ReduxStore';
Expand All @@ -23,7 +23,7 @@ import { Button, ButtonVariant } from '@patternfly/react-core';
import { FileIcon, UnknownIcon, UserIcon } from '@patternfly/react-icons';
import { nanoid } from '@reduxjs/toolkit';
import { TFunction } from 'i18next';
import React from 'react';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { AutomatedAnalysisCardDescriptor } from './AutomatedAnalysis/AutomatedAnalysisCard';
Expand All @@ -45,10 +45,6 @@ import {
ValidationError,
} from './types';

export const DEFAULT_DASHBOARD_NAME = 'Default';
export const DRAGGABLE_REF_KLAZZ = `draggable-ref`;
export const LAYOUT_TEMPLATE_DESCRIPTION_WORD_LIMIT = 100;

export const DashboardLayoutNamePattern = /^[a-zA-Z0-9_.-]+( [a-zA-Z0-9_.-]+)*$/;
export const LayoutTemplateDescriptionPattern = /^[a-zA-Z0-9\s.,\-'";?!@#$%^&*()[\]_+=:{}]*$/;

Expand Down Expand Up @@ -286,27 +282,3 @@ export const validateCardConfig = ({ name, props }: CardConfig, cardIndex: numbe
callForAction: errs.length ? <RemoveCardAction cardIndex={cardIndex} /> : undefined,
};
};

export const transformAADescription = (description: string): JSX.Element => {
const splitDesc = description.split('\n\n');
const boldRegex = /^([^:]+:\s?)/; // match text up to and including the first colon

return (
<>
{splitDesc.map((item, index) => {
const boldMatch = item.match(boldRegex);
const boldText = boldMatch ? boldMatch[0] : '';
const restOfText = boldMatch ? item.replace(boldRegex, '') : item;
const style = index > 0 ? { paddingTop: '0.7rem' } : {};
return (
<p key={index} style={style}>
{boldText && <strong>{boldText}</strong>}
{restOfText}
</p>
);
})}
</>
);
};

export const DashboardCardContext = React.createContext<React.RefObject<HTMLDivElement>>(React.createRef());
Loading

0 comments on commit 45f6e9f

Please sign in to comment.