Skip to content

Commit c321147

Browse files
authored
HUL-48 | Adding new icons for sledging qualities (And migration to TypeScript) (#50)
* feat: add TypeScript support with incremental migration capability - Install TypeScript and essential type definitions (@types/react, @types/redux, etc.) - Add tsconfig.json with React/Redux configuration and path mapping - Update webpack config to handle .ts/.tsx files with ts-loader - Configure ESLint with TypeScript parser and plugins for .ts/.tsx files - Update Jest to support TypeScript testing with babel-jest - Add TypeScript preset to Babel configuration - Add type-check script to package.json for type validation - Update README.md with TypeScript migration guidelines - Maintain backward compatibility with existing .js/.jsx files * refactor: migrate Redux reducers and tests to TypeScript - Convert reducers/index.js to TypeScript with proper Redux Reducer types - Migrate test file from JS to TS with type-safe action definitions * feat: add centralized test utilities - Create test/testUtils.tsx with renderWithProviders helper - Move shared test utilities from inline definitions to dedicated module - Update Main.test.jsx to use centralized test utilities - Provide reusable Redux store and React Router setup for component testing * refactor: convert NotFound component to TypeScript - Convert NotFound.js to NotFound.tsx with proper TypeScript syntax - Modernize class component to functional component * fix: add TypeScript support to webpack configurations - Add ts-loader with transpileOnly option to cfg/dev.js for development builds - Add ts-loader with transpileOnly option to cfg/dist.js for production builds - Enables proper compilation of .ts and .tsx files in all webpack environments * refactor: convert ObservationItem to TypeScript with comprehensive test suite - Convert ObservationItem.js to ObservationItem.tsx with full TypeScript typing - Add comprehensive unit tests - Add UnitObservation interface in types.ts for proper typing - Use moment.js with Finnish locale for authentic date formatting * refactor: convert utils to TypeScript with comprehensive test suite - Convert utils.js to utils.ts with proper TypeScript typing - Add comprehensive unit tests * refactor: migrate UnitStatusSummary from JS to TypeScript - Convert UnitStatusSummary.js to UnitStatusSummary.tsx with proper TypeScript types - Add comprehensive test suite for UnitStatusSummary component - Update UnitMassEdit to use ObservationItem instead of legacy Observation component * refactor: convert Redux actions to TypeScript with comprehensive testing - Convert actions/index.js to TypeScript with proper typing - Create dedicated types.ts files for action-specific interfaces - Move ActionTypes constants to centralized constants.ts - Add comprehensive unit tests for all action creators * refactor: convert UnitDescriptiveStatusForm to TypeScript with comprehensive test suite - Migrate UnitDescriptiveStatusForm from JS class component to TS functional component - Add comprehensive unit tests - Fix unitId parameter type from string to number in enqueueObservation action - Update action type definitions to use consistent number types - Improve component logic with optional chaining and cleaner conditionals * refactor: convert municipal-services-client.js to TypeScript Rename municipal-services-client.js → municipalServicesClient.ts with full TypeScript conversion including proper type definitions, interfaces, and function overloads. Additional changes: - Consolidate type system by moving shared types to src/types.ts - Add comprehensive unit test suite - Update all import paths throughout codebase - Fix type inconsistencies in UnitObservation.value handling - Add API_URL environment variable setup for tests * refactor: convert UnitDetails component to TypeScript - Convert UnitDetails.js to UnitDetails.tsx with full type safety - Add proper TypeScript interfaces for component props - Export ObservableProperty and ObservablePropertyPanel components with types - Fix Redux selector performance issues with useMemo hooks - Create comprehensive unit tests * refactor: convert UnitList component to TypeScript - Convert UnitList.js to UnitList.tsx with full TypeScript typing - Replace withRouter HOC with useParams and useSelector hooks - Optimize Redux selectors with useMemo to prevent unnecessary re-renders - Add comprehensive unit tests - Update component imports in DashBoard.js and UpdateQueue.js * feat: migrate to ESLint flat config and fix linting errors - Migrate from deprecated .eslintrc to eslint.config.mjs flat config - Add comprehensive TypeScript ESLint support with @typescript-eslint rules - Configure proper indentation rules with SwitchCase support - Add Jest/testing environment globals for test files - Fix TypeScript type errors in test files and components * refactor: improve timezone handling and comments in ObservationItem tests * feat: add missing 'open' and 'weak' entries to ICONS constant - Add 'open': 'icon-smile-o' and 'weak': 'icon-meh-o' to ICONS mapping - Update test to include the new icon entries * fix: fix SonarQube errors * refactor: convert UnitHistory to TypeScript with modern hooks - Convert UnitHistory.js to UnitHistory.tsx with full TypeScript support - Replace withRouter HOC with useParams hook from react-router-dom - Replace connect HOC with useSelector and useDispatch hooks from react-redux - Convert class component to functional component with hooks - Add comprehensive unit tests - Add renderWithRoute helper function to testUtils for route-based testing * refactor: convert UpdateQueue to TypeScript with modern React hooks - Convert UpdateQueue.js to UpdateQueue.tsx with full TypeScript support - Replace connect HOC with useSelector/useDispatch hooks - Add useMemo optimization to prevent unnecessary re-renders - Add comprehensive unit tests * refactor: convert UpdateConfirmation component from JS to TypeScript - Convert class component to functional component using React hooks - Replace withRouter HOC and connect HOC with useParams, useSelector, and useDispatch hooks - Add comprehensive TypeScript typing for props, state, and function parameters - Implement useMemo optimization for selector performance to prevent unnecessary rerenders - Create extensive test suite covering all component functionality and edge cases - Fix routing warnings in tests by adding missing route definitions * refactor: convert DeleteConfirmation component to TypeScript - Convert DeleteConfirmation.js to TypeScript functional component - Replace class component with React hooks (useParams, useSelector, useDispatch, useMemo) - Extract ConfirmButton and TextualDescription as typed sub-components - Add comprehensive test suite * refactor: modernize GroupList component to TypeScript - Convert GroupList from JavaScript to TypeScript with proper types - Replace connect() with modern useSelector hook for Redux integration - Extract GroupListElement as typed functional sub-component - Add comprehensive unit test suite * feat: convert DashBoard component to TypeScript - Convert DashBoard.js to DashBoard.tsx with proper TypeScript types - Add comprehensive test suite for DashBoard component - Improve type safety across actions and reducers - Add jest-dom type declarations for better testing support * refactor: fix TypeScript compilation errors and modernize ESLint config - Replace manual global type declarations with globals package in ESLint config - Add globals package dependency to package.json - Restructure Redux action types with BaseAction interface for better compatibility - Fix function overload typing in municipalServicesClient.ts - Convert LoginScreen from JS to TypeScript with proper typing - Update Jest DOM types to avoid conflicts with @testing-library/jest-dom - Fix test mock data structures to match expected interfaces - Add comprehensive unit tests for LoginScreen component - Fix UserLocation type structure in action tests - Enable stricter TypeScript checking with skipLibCheck: false - Update test utilities with proper interface definitions * refactor: organize test files by module structure - Move component tests to src/components/__tests__/ - Move library tests to src/lib/__tests__/ * refactor: convert Main component to TypeScript - Convert Main.js to Main.tsx with full TypeScript support - Add proper TypeScript interfaces for AuthState and RootState - Convert class-based component to functional component with React hooks - Replace connect HOC with useSelector and useDispatch hooks - Replace withRouter HOC with useNavigate hook - Fix authentication logic to prevent data fetching when unauthenticated - Add comprehensive test coverage * refactor: convert UnitMassEditPropertySelect to TypeScript with comprehensive testing - Convert UnitMassEditPropertySelect.js to TypeScript (.tsx) - Replace class component with functional component using React hooks - Replace connect HOC and withRouter HOC with useSelector and useParams hooks - Add loading state handling to show proper loading indicator when data is fetching - Add null-safety checks for observableProperties to prevent runtime errors - Create comprehensive unit tests - Add React Router future flags to test utilities to resolve v7 deprecation warnings * refactor: convert UnitMassEdit to TypeScript and modernize test infrastructure - Convert UnitMassEdit component to TypeScript with enhanced type safety - Add proper interfaces for FormValues and AllowedValueWithProperty - Improve function typing and maintain redux-actions compatibility - Preserve all existing functionality with better type checking - Modernize testing library patterns across all test files - Replace fireEvent with userEvent for more realistic user interactions - Add @testing-library/user-event v14.6.1 dependency - Update 6 test files: DeleteConfirmation, LoginScreen, UnitDescriptiveStatusForm, UnitMassEdit, UpdateConfirmation, UpdateQueue - Convert to async/await patterns with userEvent.setup() - Clean up legacy code - Remove unused withRouter HOC from hooks/index.js - Minor formatting improvements in testUtils.tsx * refactor: exclude types.ts files from coverage collection * refactor: consolidate action types and service groups into a single TypeScript file * refactor: exclude mock_groups.js from coverage collection * refactor: convert time utilities to TypeScript - Convert src/util/time.js to TypeScript with proper type annotations - Add Moment type imports and function parameter/return types - Improve type safety for hoursToMinutes function with string|number input - Add comprehensive unit tests for time utilities * refactor: convert geolocation module to TypeScript - Convert src/lib/geolocation.js to TypeScript with proper types and interfaces - Add GeolocationCallback type and StagePositionOptions interface - Fix module-level DISABLED constant to runtime check (isGeolocationDisabled) - Add comprehensive unit tests * refactor: convert queueHandler to TypeScript with comprehensive tests - Convert src/actions/queueHandler.js to TypeScript - Add comprehensive unit tests * refactor: update Finnish labels in UnitMassEdit tests * refactor: improve code quality with modern patterns and optimizations - Replace _.filter() with _.find() for single item lookup in UnitMassEdit - Use stable property keys instead of array indices in component mapping - Convert nested if-else to else-if for cleaner control flow - Implement nullish coalescing operator (??=) for more concise assignments - Add proper error handling for geolocation with test environment detection - Replace parseFloat with Number.parseFloat for consistency * feat: enable type check in GitHub actions
1 parent 6d7550a commit c321147

95 files changed

Lines changed: 12452 additions & 6295 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"presets": [
33
"@babel/preset-env",
4-
"@babel/preset-react"
4+
"@babel/preset-react",
5+
"@babel/preset-typescript"
56
],
67
"plugins": [
78
[

.eslintrc

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ jobs:
1313
secrets: inherit
1414
with:
1515
node-version: 22
16+
typecheck: true # Enable type checking
1617
extra-commands: |
1718
cp .env.example .env

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ Run `npm install`
1919

2020
Run `npm start`
2121

22+
## TypeScript Support ##
23+
24+
This project supports incremental TypeScript migration alongside JavaScript. You can create new components as `.tsx` files or gradually convert existing `.js` files to TypeScript.
25+
26+
### Type Checking ###
27+
28+
Run `npm run typecheck` to check TypeScript types without emitting files.
29+
30+
### File Extensions ###
31+
32+
- Use `.tsx` for React components with TypeScript
33+
- Use `.ts` for utility files, actions, reducers with TypeScript
34+
- Existing `.js` and `.jsx` files continue to work unchanged
35+
36+
### Migration Strategy ###
37+
38+
1. Start with simple components that have no props
39+
2. Convert components that already have PropTypes defined
40+
3. Add type definitions for Redux state and actions
41+
4. Gradually convert remaining components
42+
43+
The build system automatically handles both JavaScript and TypeScript files.
44+
2245
# Production build #
2346

2447
1. Important! Update the version in `src/pulkka.appcache`

cfg/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
allowedHosts: 'all'
5353
},
5454
resolve: {
55-
extensions: ['.js', '.jsx'],
55+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
5656
fallback: {
5757
"process": require.resolve("process/browser.js")
5858
},

cfg/dev.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ let config = Object.assign({}, baseConfig, {
3535
});
3636

3737
// Add needed loaders to the defaults here
38+
config.module.rules.push({
39+
test: /\.(ts|tsx)$/,
40+
use: [
41+
{
42+
loader: require.resolve('babel-loader'),
43+
options: {
44+
plugins: [require.resolve('react-refresh/babel')],
45+
}
46+
},
47+
{
48+
loader: 'ts-loader',
49+
options: {
50+
transpileOnly: true
51+
}
52+
}
53+
],
54+
include: [].concat(
55+
[ path.join(__dirname, '/../src') ]
56+
)
57+
});
58+
3859
config.module.rules.push({
3960
test: /\.(js|jsx)$/,
4061
use: [

cfg/dist.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ config.module.rules.push({
4848
)
4949
});
5050

51+
config.module.rules.push({
52+
test: /\.(ts|tsx)$/,
53+
use: [
54+
'babel-loader',
55+
{
56+
loader: 'ts-loader',
57+
options: {
58+
transpileOnly: true
59+
}
60+
}
61+
],
62+
include: [].concat(
63+
[ path.join(__dirname, '/../src') ]
64+
)
65+
});
66+
5167
module.exports = config;

eslint.config.mjs

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import js from '@eslint/js';
22
import react from 'eslint-plugin-react';
33
import babelParser from '@babel/eslint-parser';
4+
import tseslint from '@typescript-eslint/eslint-plugin';
5+
import tsparser from '@typescript-eslint/parser';
6+
import globals from 'globals';
47

58
export default [
69
js.configs.recommended,
@@ -20,39 +23,63 @@ export default [
2023
},
2124
},
2225
globals: {
23-
// Node.js environment
24-
process: 'readonly',
25-
require: 'readonly',
26-
module: 'readonly',
27-
global: 'readonly',
28-
Buffer: 'readonly',
29-
__dirname: 'readonly',
30-
__filename: 'readonly',
31-
// Browser environment
32-
window: 'readonly',
33-
document: 'readonly',
34-
console: 'readonly',
35-
fetch: 'readonly',
36-
localStorage: 'readonly',
37-
navigator: 'readonly',
38-
setTimeout: 'readonly',
39-
clearTimeout: 'readonly',
40-
setInterval: 'readonly',
41-
clearInterval: 'readonly',
42-
// Test environment
43-
describe: 'readonly',
44-
it: 'readonly',
45-
beforeEach: 'readonly',
46-
afterEach: 'readonly',
47-
expect: 'readonly',
26+
...globals.browser,
27+
...globals.node,
28+
...globals.jest,
4829
},
4930
},
5031
rules: {
32+
'comma-dangle': 'warn',
5133
'quotes': ['warn', 'single'],
34+
'no-undef': 'warn',
35+
'no-extra-semi': 'warn',
5236
'no-console': 'off',
37+
'no-unused-vars': 'warn',
38+
'no-trailing-spaces': ['warn', { 'skipBlankLines': true }],
39+
'no-unreachable': 'warn',
5340
'no-alert': 'off',
5441
'react/jsx-uses-react': 'warn',
5542
'react/jsx-uses-vars': 'warn',
43+
'indent': ['error', 2, { 'SwitchCase': 1 }],
44+
},
45+
},
46+
{
47+
files: ['src/**/*.{ts,tsx}', 'test/**/*.{ts,tsx}'],
48+
plugins: {
49+
'@typescript-eslint': tseslint,
50+
react,
51+
},
52+
languageOptions: {
53+
parser: tsparser,
54+
parserOptions: {
55+
ecmaVersion: 2020,
56+
sourceType: 'module',
57+
ecmaFeatures: {
58+
jsx: true,
59+
},
60+
},
61+
globals: {
62+
...globals.browser,
63+
...globals.node,
64+
...globals.jest,
65+
},
66+
},
67+
rules: {
68+
// Base ESLint rules
69+
'comma-dangle': 'warn',
70+
'quotes': ['warn', 'single'],
71+
'no-undef': 'warn',
72+
'no-extra-semi': 'warn',
73+
'no-console': 'off',
74+
'no-trailing-spaces': ['warn', { 'skipBlankLines': true }],
75+
'no-unreachable': 'warn',
76+
'no-alert': 'off',
77+
'react/jsx-uses-react': 'warn',
78+
'react/jsx-uses-vars': 'warn',
79+
'indent': ['error', 2, { 'SwitchCase': 1 }],
80+
// TypeScript specific rules
81+
'@typescript-eslint/no-unused-vars': 'warn',
82+
'no-unused-vars': 'off', // Turn off base rule as it conflicts with @typescript-eslint version
5683
},
5784
},
5885
];

jest.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ module.exports = {
33
testEnvironment: 'jsdom',
44
setupFilesAfterEnv: ['<rootDir>/test/setupTests.js'],
55
testMatch: [
6-
'<rootDir>/{test,src}/**/__tests__/*.test.{js,jsx}'
6+
'<rootDir>/{test,src}/**/__tests__/*.test.{js,jsx,ts,tsx}'
77
],
8-
moduleFileExtensions: ['js', 'jsx'],
8+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
99
transform: {
10+
'^.+\\.(ts|tsx)$': ['babel-jest', { presets: ['@babel/preset-typescript'] }],
1011
'^.+\\.(js|jsx)$': 'babel-jest',
1112
},
1213
moduleNameMapper: {
@@ -23,9 +24,11 @@ module.exports = {
2324
moduleDirectories: ['node_modules', 'src'],
2425
collectCoverage: true,
2526
collectCoverageFrom: [
26-
'src/**/*.{js,jsx}',
27+
'src/**/*.{js,jsx,ts,tsx}',
2728
'!src/index.js',
2829
'!src/config/**',
30+
'!src/**/types.ts',
31+
'!src/**/mock_groups.js',
2932
],
3033
coverageProvider: 'v8',
3134
coverageDirectory: 'coverage',

0 commit comments

Comments
 (0)