Skip to content

Commit

Permalink
chore(ts): fix typescript type-checking errors (#1087)
Browse files Browse the repository at this point in the history
Signed-off-by: Thuan Vo <[email protected]>
(cherry picked from commit 5aa3f5c)

# Conflicts:
#	.github/workflows/ci.yaml
#	package.json
#	src/app/Settings/SettingsUtils.ts
#	src/app/Topology/Shared/utils.tsx
#	src/test/Rules/CreateRule.test.tsx
  • Loading branch information
Thuan Vo authored and andrewazores committed Aug 31, 2023
1 parent b7df7ce commit 329b988
Show file tree
Hide file tree
Showing 29 changed files with 295 additions and 257 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,35 @@ jobs:
- uses: bahmutov/npm-install@v1
- run: yarn format:check
- run: yarn eslint:check
<<<<<<< HEAD
- run: yarn build:notests
=======
type-check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- uses: bahmutov/npm-install@v1
- run: yarn type-check
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- uses: bahmutov/npm-install@v1
>>>>>>> 5aa3f5c (chore(ts): fix typescript type-checking errors (#1087))
- run: yarn test:ci
1 change: 1 addition & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"DOWNLOAD": "Download",
"EDIT": "Edit",
"FILTER_NAME": "Name",
"FILTER_TOPIC": "Topic",
"HELP": "Help",
"HOUR": "Hour",
"HOUR_one": "Hour",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"eslint:apply": "eslint --cache --ext .ts,.tsx,.js --fix ./src/",
"license:check": "license-check-and-add check -f license-config.json",
"license:apply": "license-check-and-add add -f license-config.json",
<<<<<<< HEAD
"lint": "npm-run-all -l -p format eslint",
=======
"lint": "concurrently -c 'auto' 'yarn:format' 'yarn:eslint' 'yarn:type-check'",
>>>>>>> 5aa3f5c (chore(ts): fix typescript type-checking errors (#1087))
"localize": "i18next \"src/**/*.{js,jsx,ts,tsx,json}\" -c ./i18next-parser.config.js",
"format": "npm-run-all format:check",
"format:check": "npm-run-all -l license:check prettier:check",
Expand All @@ -31,7 +35,8 @@
"build:bundle-analyze": "webpack-bundle-analyzer ./stats.json dist",
"build:bundle-profile-analyze": "npm-run-all -l build:bundle-profile build:bundle-analyze",
"yarn:install": "yarn install",
"yarn:frzinstall": "yarn install --immutable"
"yarn:frzinstall": "yarn install --immutable",
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@testing-library/dom": "^8.20.0",
Expand Down
4 changes: 2 additions & 2 deletions src/app/Dashboard/AutomatedAnalysis/AutomatedAnalysisCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ export const AutomatedAnalysisCard: React.FC<AutomatedAnalysisCardProps> = (prop
const [showListView, setShowListView] = React.useState<boolean>(false);

const targetAutomatedAnalysisFilters = useSelector((state: RootState) => {
const filters = state.automatedAnalysisFilters.state.targetFilters.filter(
const filters = state.automatedAnalysisFilters.targetFilters.filter(
(targetFilter: TargetAutomatedAnalysisFilters) => targetFilter.target === targetConnectURL
);
return filters.length > 0 ? filters[0].filters : emptyAutomatedAnalysisFilters;
}) as AutomatedAnalysisFiltersCategories;

const targetAutomatedAnalysisGlobalFilters = useSelector((state: RootState) => {
return state.automatedAnalysisFilters.state.globalFilters.filters;
return state.automatedAnalysisFilters.globalFilters.filters;
}) as AutomatedAnalysisGlobalFiltersCategories;

const categorizeEvaluation = React.useCallback(
Expand Down
68 changes: 44 additions & 24 deletions src/app/Dashboard/AutomatedAnalysis/AutomatedAnalysisFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,22 @@ export interface AutomatedAnalysisFiltersProps {
updateFilters: (target: string, updateFilterOptions: UpdateFilterOptions) => void;
}

export const AutomatedAnalysisFilters: React.FC<AutomatedAnalysisFiltersProps> = ({ updateFilters, ...props }) => {
export const AutomatedAnalysisFilters: React.FC<AutomatedAnalysisFiltersProps> = ({
updateFilters,
target,
evaluations,
filters,
..._props
}) => {
const dispatch = useDispatch<StateDispatch>();
const { t } = useTranslation();

const currentCategory = useSelector((state: RootState) => {
const targetAutomatedAnalysisFilters = state.automatedAnalysisFilters.state.targetFilters.filter(
(targetFilter) => targetFilter.target === props.target
const targetAutomatedAnalysisFilters = state.automatedAnalysisFilters.targetFilters.filter(
(targetFilter) => targetFilter.target === target
);
if (!targetAutomatedAnalysisFilters.length) {
return t('FILTER_NAME', { ns: 'common' });
return 'Name';
} // Target is not yet loaded
return targetAutomatedAnalysisFilters[0].selectedCategory;
});
Expand All @@ -96,33 +102,47 @@ export const AutomatedAnalysisFilters: React.FC<AutomatedAnalysisFiltersProps> =
const onCategorySelect = React.useCallback(
(category) => {
setIsCategoryDropdownOpen(false);
dispatch(automatedAnalysisUpdateCategoryIntent(props.target, category));
dispatch(automatedAnalysisUpdateCategoryIntent(target, category));
},
[dispatch, setIsCategoryDropdownOpen, props.target]
[dispatch, setIsCategoryDropdownOpen, target]
);

const onDelete = React.useCallback(
(category: string | ToolbarChipGroup, value) =>
updateFilters(props.target, { filterKey: category as string, filterValue: value, deleted: true }),
[updateFilters, props.target]
updateFilters(target, { filterKey: category as string, filterValue: value, deleted: true }),
[updateFilters, target]
);

const onDeleteGroup = React.useCallback(
(category: string | ToolbarChipGroup) =>
updateFilters(props.target, { filterKey: category as string, deleted: true, deleteOptions: { all: true } }),
[updateFilters, props.target]
updateFilters(target, { filterKey: category as string, deleted: true, deleteOptions: { all: true } }),
[updateFilters, target]
);

const onNameInput = React.useCallback(
(inputName: string) => updateFilters(props.target, { filterKey: currentCategory, filterValue: inputName }),
[updateFilters, currentCategory, props.target]
(inputName: string) => updateFilters(target, { filterKey: currentCategory, filterValue: inputName }),
[updateFilters, currentCategory, target]
);

const onTopicInput = React.useCallback(
(inputTopic: string) => {
updateFilters(props.target, { filterKey: currentCategory, filterValue: inputTopic });
updateFilters(target, { filterKey: currentCategory, filterValue: inputTopic });
},
[updateFilters, currentCategory, props.target]
[updateFilters, currentCategory, target]
);

const getCategoryDisplay = React.useCallback(
(category: string) => {
switch (category) {
case 'Name':
return t('FILTER_NAME', { ns: 'common' });
case 'Topic':
return t('FILTER_TOPIC', { ns: 'common' });
default:
throw new Error(`Unknown Automated Analysis Filter Category: ${category}`);
}
},
[t]
);

const categoryDropdown = React.useMemo(() => {
Expand All @@ -132,7 +152,7 @@ export const AutomatedAnalysisFilters: React.FC<AutomatedAnalysisFiltersProps> =
position={DropdownPosition.left}
toggle={
<DropdownToggle aria-label={currentCategory} onToggle={onCategoryToggle}>
<FilterIcon /> {currentCategory}
<FilterIcon /> {getCategoryDisplay(currentCategory)}
</DropdownToggle>
}
isOpen={isCategoryDropdownOpen}
Expand All @@ -143,37 +163,37 @@ export const AutomatedAnalysisFilters: React.FC<AutomatedAnalysisFiltersProps> =
))}
/>
);
}, [isCategoryDropdownOpen, currentCategory, onCategoryToggle, onCategorySelect]);
}, [isCategoryDropdownOpen, currentCategory, onCategoryToggle, onCategorySelect, getCategoryDisplay]);

const filterDropdownItems = React.useMemo(
() => [
<AutomatedAnalysisNameFilter
key={'name'}
evaluations={props.evaluations}
filteredNames={props.filters.Name}
evaluations={evaluations}
filteredNames={filters.Name}
onSubmit={onNameInput}
/>,
<AutomatedAnalysisTopicFilter
key={'topic'}
evaluations={props.evaluations}
filteredTopics={props.filters.Topic}
evaluations={evaluations}
filteredTopics={filters.Topic}
onSubmit={onTopicInput}
></AutomatedAnalysisTopicFilter>,
/>,
],
[props.evaluations, props.filters.Name, props.filters.Topic, onNameInput, onTopicInput]
[evaluations, filters.Name, filters.Topic, onNameInput, onTopicInput]
);

return (
<ToolbarToggleGroup toggleIcon={<FilterIcon />} breakpoint="xl">
<ToolbarGroup variant="filter-group">
<ToolbarItem>
{categoryDropdown}
{Object.keys(props.filters)
{Object.keys(filters)
.filter((f) => f !== 'Score')
.map((filterKey, i) => (
<ToolbarFilter
key={filterKey}
chips={props.filters[filterKey]}
chips={filters[filterKey]}
deleteChip={onDelete}
deleteChipGroup={onDeleteGroup}
categoryName={filterKey}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const AutomatedAnalysisScoreFilter: React.FC<AutomatedAnalysisScoreFilter
const dispatch = useDispatch<StateDispatch>();
const { t } = useTranslation();
const currentScore = useSelector((state: RootState) => {
const filters = state.automatedAnalysisFilters.state.globalFilters.filters;
const filters = state.automatedAnalysisFilters.globalFilters.filters;
if (!filters) return 0;
return filters.Score;
});
Expand Down
6 changes: 3 additions & 3 deletions src/app/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* SOFTWARE.
*/
import { FeatureFlag } from '@app/Shared/FeatureFlag/FeatureFlag';
import { DashboardConfigState } from '@app/Shared/Redux/Configurations/DashboardConfigSlice';
import { DashboardConfig } from '@app/Shared/Redux/Configurations/DashboardConfigSlice';
import {
dashboardConfigDeleteCardIntent,
dashboardConfigFirstRunIntent,
Expand Down Expand Up @@ -69,7 +69,7 @@ export const Dashboard: React.FC<DashboardComponentProps> = (_) => {
const serviceContext = React.useContext(ServiceContext);
const dispatch = useDispatch<StateDispatch>();
const { t } = useTranslation();
const dashboardConfigs: DashboardConfigState = useSelector((state: RootState) => state.dashboardConfigs);
const dashboardConfigs: DashboardConfig = useSelector((state: RootState) => state.dashboardConfigs);
const jfrChartController = React.useRef(
new JFRMetricsChartController(
serviceContext.api,
Expand All @@ -87,7 +87,7 @@ export const Dashboard: React.FC<DashboardComponentProps> = (_) => {
}, [dashboardConfigs]);

React.useEffect(() => {
const layouts = getFromLocalStorage('DASHBOARD_CFG', {}) as DashboardConfigState;
const layouts = getFromLocalStorage('DASHBOARD_CFG', {}) as DashboardConfig;
if (layouts._version === undefined) {
dispatch(dashboardConfigFirstRunIntent());
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/Recordings/RecordingFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const categoryIsDate = (fieldKey: string) => /date/i.test(fieldKey);

export interface RecordingFiltersProps {
target: string;
breakpoint: 'md' | 'lg' | 'xl' | '2xl';
breakpoint?: 'md' | 'lg' | 'xl' | '2xl';
isArchived: boolean;
recordings: Recording[];
filters: RecordingFiltersCategories;
Expand Down
2 changes: 1 addition & 1 deletion src/app/Settings/Language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Component = () => {
aria-label={t('SETTINGS.LANGUAGE.ARIA_LABELS.SELECT') || ''}
onToggle={handleLanguageToggle}
onSelect={handleLanguageSelect}
selections={localeReadable(i18n.language)}
selections={i18n.language}
isFlipEnabled
menuAppendTo="parent"
>
Expand Down
4 changes: 4 additions & 0 deletions src/app/Settings/SettingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import { hashCode } from '@app/utils/utils';
export interface _TransformedUserSetting extends Omit<UserSetting, 'content'> {
title: string;
description: React.ReactNode;
<<<<<<< HEAD
element: React.FunctionComponentElement<Record<string, never>>;
=======
element: React.ReactNode;
>>>>>>> 5aa3f5c (chore(ts): fix typescript type-checking errors (#1087))
orderInGroup: number;
featureLevel: FeatureLevel;
}
Expand Down
19 changes: 11 additions & 8 deletions src/app/Shared/Redux/Configurations/DashboardConfigSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { gridSpans } from '@patternfly/react-core';
import { createAction, createReducer } from '@reduxjs/toolkit';
import { getPersistedState } from '../utils';

export const _dashboardConfigVersion = '4';
export const _version = '4';

// Common action string format: "resource(s)/action"
export enum DashboardConfigAction {
Expand Down Expand Up @@ -253,7 +253,7 @@ export const dashboardConfigTemplateHistoryClearIntent = createAction(
})
);

export interface DashboardConfigState {
export interface DashboardConfig {
layouts: DashboardLayout[];
customTemplates: LayoutTemplate[];
templateHistory: LayoutTemplateRecord[];
Expand All @@ -263,20 +263,23 @@ export interface DashboardConfigState {

export const TEMPLATE_HISTORY_LIMIT = 5;

const INITIAL_STATE: DashboardConfigState = getPersistedState('DASHBOARD_CFG', _dashboardConfigVersion, {
export const defaultDashboardConfigs: DashboardConfig = {
layouts: [
{
name: 'Default',
cards: [],
favorite: true,
},
] as DashboardLayout[],
customTemplates: [] as LayoutTemplate[],
templateHistory: [] as LayoutTemplateRecord[],
],
customTemplates: [],
templateHistory: [],
current: 0,
});
_version: _version,
};

const INITIAL_STATE: DashboardConfig = getPersistedState('DASHBOARD_CFG', _version, defaultDashboardConfigs);

const getTemplateHistoryIndexForMutation = (state: DashboardConfigState, templateName: string) => {
const getTemplateHistoryIndexForMutation = (state: DashboardConfig, templateName: string) => {
const idx = state.templateHistory.findIndex((t) => t.name === templateName && t.vendor === LayoutTemplateVendor.USER);
return idx;
};
Expand Down
38 changes: 20 additions & 18 deletions src/app/Shared/Redux/Configurations/TopologyConfigSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,33 @@ export interface TopologyConfig {
displayOptions: DisplayOptions;
}

export const defaultDisplayOptions: DisplayOptions = {
show: {
connectionUrl: false,
badge: true,
status: true,
icon: true,
},
groupings: {
realmOnly: false,
collapseSingles: false,
export const defaultTopologyConfig: TopologyConfig = {
viewMode: 'graph',
displayOptions: {
show: {
connectionUrl: false,
badge: true,
status: true,
icon: true,
},
groupings: {
realmOnly: false,
collapseSingles: false,
},
},
};

export const showOptions: [string, string][] = Object.keys(defaultDisplayOptions.show).map((k) => {
export const showOptions: [string, string][] = Object.keys(defaultTopologyConfig.displayOptions.show).map((k) => {
return [getDisplayFieldName(k), k];
});

export const groupingOptions: [string, string][] = Object.keys(defaultDisplayOptions.groupings).map((k) => {
return [getDisplayFieldName(k), k];
});
export const groupingOptions: [string, string][] = Object.keys(defaultTopologyConfig.displayOptions.groupings).map(
(k) => {
return [getDisplayFieldName(k), k];
}
);

const INITIAL_STATE: TopologyConfig = getPersistedState('TOPOLOGY_CONFIG', _version, {
viewMode: 'graph',
displayOptions: defaultDisplayOptions,
});
const INITIAL_STATE: TopologyConfig = getPersistedState('TOPOLOGY_CONFIG', _version, defaultTopologyConfig);

export const topologyConfigReducer: ReducerWithInitialState<TopologyConfig> = createReducer(
INITIAL_STATE,
Expand Down
Loading

0 comments on commit 329b988

Please sign in to comment.