Skip to content

Commit c04887a

Browse files
authored
chore: type safe icons (#17617)
* refactor: move svg provider to root util directory * chore: typesafe config icons * refactor: improve types * chore: improve comment * chore: update ignore files * refactor: move typedEntries to array utils * chore: fix action panel types * refactor: simplify naming * chore: conversation actions type * chore: svg provider mocks type * chore: context menu type * chore: remove license from non-gh file * chore: remove comment
1 parent 16b52e5 commit c04887a

33 files changed

+176
-82
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
'src/ext/',
2222
'src/script/localization/**/webapp*.js',
2323
'src/worker/',
24+
'src/script/generated/',
2425
'*.js',
2526
],
2627
parserOptions: {

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/keys
99
/package-lock.json
1010
/resource
11+
/src/script/generated
1112
/temp
1213
CHANGELOG.md
1314
node_modules

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ src/i18n/
77
/resource
88
/assets
99
/src/ext
10+
/src/script/generated
1011
CHANGELOG.md
1112
node_modules
1213
npm-debug.log

bin/generate_icon_names.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2024 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*
18+
*/
19+
import fs from 'fs';
20+
21+
const fileLocation = 'resource/image/icon';
22+
const fileList = fs.readdirSync(fileLocation).filter(file => file.endsWith('.svg'));
23+
24+
const fileContent = `
25+
/*
26+
* This file is generated by bin/generate_icons.ts
27+
* To refetch all the icons and regenerate their names, run yarn configure.
28+
*/
29+
export const iconFileNames = [${fileList.map(name => `'${name}'`).join(', ')}] as const;
30+
`;
31+
32+
const dir = 'src/script/generated';
33+
34+
if (!fs.existsSync(dir)) {
35+
fs.mkdirSync(dir);
36+
}
37+
fs.writeFileSync(`${dir}/iconFileNames.ts`, fileContent);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@
176176
"changelog:production": "ts-node ./bin/changelog.ts production",
177177
"changelog:staging": "ts-node ./bin/changelog.ts staging",
178178
"changelog:rc": "ts-node ./bin/changelog.ts production master",
179-
"configure": "copy-config",
179+
"configure": "copy-config && yarn generate-icon-names",
180+
"generate-icon-names": "ts-node ./bin/generate_icon_names.ts",
180181
"deploy": "yarn build:prod && eb deploy",
181182
"dev": "yarn start",
182183
"docker": "node ./bin/push_docker.js",

src/script/auth/component/WirelessContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import {FormattedMessage, useIntl} from 'react-intl';
2424

2525
import {CloseIcon, Content, Footer, Header, Link, Small} from '@wireapp/react-ui-kit';
2626

27+
import {getSVG} from 'Util/SVGProvider';
28+
2729
import {Config} from '../../Config';
2830
import {cookiePolicyStrings, footerStrings} from '../../strings';
2931
import {EXTERNAL_ROUTE} from '../externalRoute';
30-
import {getSVG} from '../util/SVGProvider';
3132

3233
export interface Props extends React.HTMLAttributes<HTMLDivElement> {
3334
children: React.ReactNode;

src/script/auth/page/CustomEnvironmentRedirect.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {initialRootState} from '../module/reducer';
2626
import {mockStoreFactory} from '../util/test/mockStoreFactory';
2727
import {mountComponent} from '../util/test/TestUtil';
2828

29-
jest.mock('../util/SVGProvider');
29+
jest.mock('Util/SVGProvider');
3030
function createMockedURLSearchParams(value: string) {
3131
return class MockedURLSearchParams extends window.URLSearchParams {
3232
constructor() {

src/script/auth/page/CustomEnvironmentRedirect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {AnyAction, Dispatch} from 'redux';
2727
import {Runtime, UrlUtil} from '@wireapp/commons';
2828
import {COLOR, ContainerXS, FlexBox, Text} from '@wireapp/react-ui-kit';
2929

30+
import {getSVG} from 'Util/SVGProvider';
3031
import {afterRender} from 'Util/util';
3132

3233
import {Page} from './Page';
@@ -35,7 +36,6 @@ import {customEnvRedirectStrings} from '../../strings';
3536
import {actionRoot} from '../module/action';
3637
import {bindActionCreators} from '../module/reducer';
3738
import {QUERY_KEY} from '../route';
38-
import {getSVG} from '../util/SVGProvider';
3939

4040
const REDIRECT_DELAY = 5000;
4141
const CustomEnvironmentRedirectComponent = ({doNavigate, doSendNavigationEvent}: DispatchProps) => {

src/script/auth/page/Index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {ROUTE} from '../route';
2929
import {mockStoreFactory} from '../util/test/mockStoreFactory';
3030
import {mountComponent} from '../util/test/TestUtil';
3131

32-
jest.mock('../util/SVGProvider');
32+
jest.mock('Util/SVGProvider');
3333

3434
jest.mock('react-router-dom', () => ({
3535
...jest.requireActual('react-router-dom'),

src/script/auth/page/Index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {AnyAction, Dispatch} from 'redux';
2828
import {UrlUtil} from '@wireapp/commons';
2929
import {Button, ButtonVariant, ContainerXS, ErrorMessage, Text} from '@wireapp/react-ui-kit';
3030

31+
import {getSVG} from 'Util/SVGProvider';
32+
3133
import {Page} from './Page';
3234

3335
import {Config} from '../../Config';
@@ -36,7 +38,6 @@ import {indexStrings, logoutReasonStrings} from '../../strings';
3638
import {bindActionCreators, RootState} from '../module/reducer';
3739
import * as AuthSelector from '../module/selector/AuthSelector';
3840
import {QUERY_KEY, ROUTE} from '../route';
39-
import {getSVG} from '../util/SVGProvider';
4041

4142
type Props = React.HTMLProps<HTMLDivElement>;
4243

0 commit comments

Comments
 (0)