Skip to content

Commit

Permalink
Minor tweaks from migrating SciGateway to Vite #393
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Mar 19, 2024
1 parent 37ae02f commit 2187b48
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 24 deletions.
30 changes: 26 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2015
"ecmaVersion": 2015,
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
Expand All @@ -12,17 +15,36 @@
"plugins": [
"react",
"react-hooks",
"@typescript-eslint"
"@typescript-eslint",
"cypress",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/stylistic",
"plugin:cypress/recommended",
"prettier"
],
"rules": {
"react/react-in-jsx-scope": "off",
"react/prop-types": "off"
"react/prop-types": "off",
// Emulate typescript style for unused variables, see
// https://typescript-eslint.io/rules/no-unused-vars/
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
]
},
"overrides": [
{
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ Deploys a static version of the build from the `dist` directory to port 5001. Us

For development purposes, use `yarn preview:build:dev` to build in watch mode so that changes are built automatically.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

## How to run

### Docker Setup
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"preview:build": "yarn build && yarn preview",
"preview:build:dev": "yarn build --watch & yarn preview",
"test": "vitest --coverage",
"lint:js": "eslint --max-warnings=0 --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src",
"lint": "eslint --max-warnings=0 --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src",
"build:e2e": "cross-env VITE_APP_BUILD_STANDALONE=true VITE_APP_INCLUDE_MSW=true GENERATE_SOURCEMAP=false yarn build",
"build:e2e:api": "cross-env VITE_APP_BUILD_STANDALONE=true VITE_APP_INCLUDE_MSW=false GENERATE_SOURCEMAP=false yarn build",
"e2e:serve": "yarn build:e2e && node ./server/e2e-test-server.js",
Expand Down
4 changes: 2 additions & 2 deletions src/catalogue/category/catalogueCategoryDialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ const CatalogueCategoryDialog = React.memo(
});

const uniqueDuplicateIndexes = Array.from(new Set(duplicateIndexes));
for (let i = 0; i < uniqueDuplicateIndexes.length; i++) {
for (const uniqueDuplicateIndex of uniqueDuplicateIndexes) {
setCatalogueItemPropertiesErrors((prev) => [
...prev,
{
index: uniqueDuplicateIndexes[i],
index: uniqueDuplicateIndex,
errors: {
fieldName: 'name',
errorMessage:
Expand Down
2 changes: 1 addition & 1 deletion src/catalogue/items/catalogueItemsDialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function isValidUrl(url: string) {
(parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') &&
parsedUrl.hostname.includes('.') // Checks for the typical top-level domain
);
} catch (error) {
} catch (_error) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('Catalogue Items Landing Page', () => {
});

it('prints when the button is clicked', async () => {
const spy = vi.spyOn(window, 'print').mockImplementation(() => {});
const spy = vi.spyOn(window, 'print');
createView('/catalogue/item/89');

await waitFor(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/catalogue/items/catalogueItemsTable.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ export interface CatalogueItemsTableProps {
onChangeObsoleteReplacementId?: (
obsoleteReplacementId: string | null
) => void;
selectedRowState?: { [x: string]: boolean };
selectedRowState?: Record<string, boolean>;
// Only for dense tables with a select - should return if a given catalogue item is
// selectable or not
isItemSelectable?: (item: CatalogueItem) => boolean;
requestOrigin?: 'move to' | 'obsolete';
}
export type PropertyFiltersType = {
export interface PropertyFiltersType {
boolean: 'select' | 'text' | 'range';
string: 'select' | 'text' | 'range';
number: 'select' | 'text' | 'range';
null: 'select' | 'text' | 'range';
};
}

const CatalogueItemsTable = (props: CatalogueItemsTableProps) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/items/itemsLandingPage.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Items Landing Page', () => {
});

it('prints when the button is clicked', async () => {
const spy = vi.spyOn(window, 'print').mockImplementation(() => {});
const spy = vi.spyOn(window, 'print');
createView('/catalogue/item/1/items/KvT2Ox7n');

await waitFor(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/manufacturer/manufacturerDialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function isValidUrl(url: string) {
(parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') &&
parsedUrl.hostname.includes('.') // Checks for the typical top-level domain
);
} catch (error) {
} catch (_error) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Manufacturer Landing page', () => {
});

it('prints when the button is clicked', async () => {
const spy = vi.spyOn(window, 'print').mockImplementation(() => {});
const spy = vi.spyOn(window, 'print');
createView('/manufacturers/1');

await waitFor(() => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.base.json",
// Exclude test files from build
"exclude": ["**/?*test.*", "src/setupTests.tsx", "src/testUtils.tsx"],
"exclude": ["**/?*test.*", "src/setupTests.ts", "src/testUtils.tsx"],
}
3 changes: 1 addition & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default defineConfig(({ mode }) => {
globals: true,
environment: 'jsdom',
globalSetup: './globalSetup.js',
setupFiles: ['src/setupTests.tsx'],
setupFiles: ['src/setupTests.ts'],
coverage: {
exclude: [
'public/*',
Expand All @@ -132,7 +132,6 @@ export default defineConfig(({ mode }) => {
'src/mocks/server.ts',
'src/vite-env.d.ts',
'src/main.tsx',
'src/testUtils.tsx',
],
},
},
Expand Down

0 comments on commit 2187b48

Please sign in to comment.