Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] - Migrate to TypeScript #1595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
147 changes: 115 additions & 32 deletions package-lock.json

Large diffs are not rendered by default.

File renamed without changes.
6 changes: 0 additions & 6 deletions packages/translations/src/intlHelper/intlHelper.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/translations/src/intlHelper/intlHelper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import IntlProvider from '../Provider';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const intlHelper = (message: any, settings: any) => <IntlProvider {...settings}>{message}</IntlProvider>;

export default intlHelper;
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
"react-router-dom": ">=4.2.2"
},
"dependencies": {
"@sentry/browser": "^5.4.0",
"@redhat-cloud-services/types": "^0.0.5",
"@sentry/browser": "^5.4.0",
"awesome-debounce-promise": "^2.1.0",
"axios": "^0.25.0",
"commander": ">=2.20.0",
"mkdirp": "^1.0.4",
"react-content-loader": ">=3.4.1"
},
"devDependencies": {
"@types/mkdirp": "^1.0.2",
"@types/react": "^16.9.34"
},
"sideEffects": false
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/mergeMessages/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/utils/src/mergeMessages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './mergeMessages';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const program = require('commander');
const fs = require('fs');
const { sync: globSync } = require('glob');
const { sync: mkdirpSync } = require('mkdirp');
const last = require('lodash/last');
import program from 'commander';
import fs from 'fs';
import { sync as globSync } from 'glob';
import { sync as mkdirpSync } from 'mkdirp';
import last from 'lodash/last';

let MESSAGES_PATTERN = 'build/messages/**/*.json';
let LANG_DIR = 'locales/';
Expand Down Expand Up @@ -41,7 +41,8 @@ if (program.langPattern) {

const mergedTranslations = globSync(`${rootFolder}${LANG_PATTERN}`)
.map((filename) => {
const locale = last(filename.split('/')).split('.json')[0];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const locale = last(filename.split('/'))!.split('.json')[0];
if (!IGNORED.includes(locale)) {
return { [locale]: JSON.parse(fs.readFileSync(filename, 'utf8')) };
}
Expand All @@ -59,7 +60,7 @@ const defaultMessages = globSync(`${rootFolder}${MESSAGES_PATTERN}`)
.map((filename) => fs.readFileSync(filename, 'utf8'))
.map((file) => JSON.parse(file))
.reduce((collection, descriptors) => {
descriptors.forEach(({ id, defaultMessage }) => {
descriptors.forEach(({ id, defaultMessage }: { id: never; defaultMessage: never }) => {
if (collection.hasOwnProperty(id)) {
throw new Error(`Duplicate message id: ${id}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useState } from 'react';
import * as reactRouterDom from 'react-router-dom';
import {
Expand All @@ -13,17 +14,27 @@ import {
} from '@patternfly/react-table';

console.error('"useInventory" hook is deprecated and will be removed in v4. Please use Chrome 2.0 compatible Inventory version.');
export const useInventory = ({ store, tableReducer, detailReducer, getRegistry }) => {
let cleenupCallback;
export const useInventory = ({
store,
tableReducer,
detailReducer,
getRegistry,
}: {
store: any;
tableReducer: any;
detailReducer: any;
getRegistry: any;
}) => {
let cleanupCallback: () => void;
const [inventory, setInventory] = useState({
newReducers: null,
rawReducers: null,
newReducers: null as any,
rawReducers: null as any,
});

const [inventoryComponents, setInventoryComponents] = useState({
InventoryTable: null,
InventoryDetail: null,
TagWithDialog: null,
InventoryTable: null as any,
InventoryDetail: null as any,
TagWithDialog: null as any,
});

useEffect(() => {
Expand Down Expand Up @@ -78,7 +89,7 @@ export const useInventory = ({ store, tableReducer, detailReducer, getRegistry }
}));

if (registry) {
cleenupCallback = registry?.register?.(newReducers);
cleanupCallback = registry?.register?.(newReducers);
}

setInventoryComponents(() => ({
Expand All @@ -93,8 +104,8 @@ export const useInventory = ({ store, tableReducer, detailReducer, getRegistry }
})();

return () => {
if (cleenupCallback && typeof cleenupCallback === 'function') {
cleenupCallback();
if (cleanupCallback && typeof cleanupCallback === 'function') {
cleanupCallback();
}
};
}, []);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"resolveJsonModule": true, /* Allows to import json files in ts files. */
},
"exclude": [
"packages/**/*.test.ts",
Expand Down