aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/settings
diff options
context:
space:
mode:
authorLibravatar muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com>2022-10-27 07:13:47 +0530
committerLibravatar GitHub <noreply@github.com>2022-10-27 01:43:47 +0000
commit81c43ecc3d17e0dbf7ad1d949b6d977f2c65bd48 (patch)
treedfa7c08cb54fb81b7d2e788d350de52c2ebd05d2 /src/components/settings
parent6.2.1-nightly.30 [skip ci] (diff)
downloadferdium-app-81c43ecc3d17e0dbf7ad1d949b6d977f2c65bd48.tar.gz
ferdium-app-81c43ecc3d17e0dbf7ad1d949b6d977f2c65bd48.tar.zst
ferdium-app-81c43ecc3d17e0dbf7ad1d949b6d977f2c65bd48.zip
fix: 'failed prop' warning in QuickSwitchModal, SettingsNavigation, SettingsWindow and Recipe component tree (#713)
* chore: turn off eslint rule @typescript-eslint/no-useless-constructor to initialize dynamic props & state Co-authored-by: Muhamed <> Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src/components/settings')
-rw-r--r--src/components/settings/navigation/SettingsNavigation.tsx (renamed from src/components/settings/navigation/SettingsNavigation.jsx)70
-rw-r--r--src/components/settings/recipes/RecipeItem.tsx (renamed from src/components/settings/recipes/RecipeItem.js)23
-rw-r--r--src/components/settings/recipes/RecipesDashboard.tsx (renamed from src/components/settings/recipes/RecipesDashboard.jsx)65
3 files changed, 76 insertions, 82 deletions
diff --git a/src/components/settings/navigation/SettingsNavigation.jsx b/src/components/settings/navigation/SettingsNavigation.tsx
index e1242a7fe..95c69027c 100644
--- a/src/components/settings/navigation/SettingsNavigation.jsx
+++ b/src/components/settings/navigation/SettingsNavigation.tsx
@@ -1,18 +1,13 @@
1import { Component } from 'react'; 1import { Component } from 'react';
2import PropTypes from 'prop-types'; 2import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
3import { defineMessages, injectIntl } from 'react-intl';
4import { inject, observer } from 'mobx-react'; 3import { inject, observer } from 'mobx-react';
5import { RouterStore } from '@superwf/mobx-react-router';
6
7import { NavLink } from 'react-router-dom'; 4import { NavLink } from 'react-router-dom';
5import { StoresProps } from '../../../@types/ferdium-components.types';
8import { 6import {
9 LOCAL_SERVER, 7 LOCAL_SERVER,
10 LIVE_FERDIUM_API, 8 LIVE_FERDIUM_API,
11 LIVE_FRANZ_API, 9 LIVE_FRANZ_API,
12} from '../../../config'; 10} from '../../../config';
13import UIStore from '../../../stores/UIStore';
14import SettingsStore from '../../../stores/SettingsStore';
15import UserStore from '../../../stores/UserStore';
16import globalMessages from '../../../i18n/globalMessages'; 11import globalMessages from '../../../i18n/globalMessages';
17 12
18const messages = defineMessages({ 13const messages = defineMessages({
@@ -50,40 +45,37 @@ const messages = defineMessages({
50 }, 45 },
51}); 46});
52 47
53class SettingsNavigation extends Component { 48interface IProps extends Partial<StoresProps>, WrappedComponentProps {
54 static propTypes = { 49 serviceCount: number;
55 stores: PropTypes.shape({ 50 workspaceCount: number;
56 ui: PropTypes.instanceOf(UIStore).isRequired, 51}
57 user: PropTypes.instanceOf(UserStore).isRequired, 52
58 settings: PropTypes.instanceOf(SettingsStore).isRequired, 53@inject('stores', 'actions')
59 router: PropTypes.instanceOf(RouterStore).isRequired, 54@observer
60 }).isRequired, 55class SettingsNavigation extends Component<IProps> {
61 actions: PropTypes.shape({ 56 constructor(props: IProps) {
62 settings: PropTypes.instanceOf(SettingsStore).isRequired, 57 super(props);
63 }).isRequired, 58 }
64 serviceCount: PropTypes.number.isRequired,
65 workspaceCount: PropTypes.number.isRequired,
66 };
67 59
68 handleLogout() { 60 handleLogout(): void {
69 const isUsingWithoutAccount = 61 const isUsingWithoutAccount =
70 this.props.stores.settings.app.server === LOCAL_SERVER; 62 this.props.stores!.settings.app.server === LOCAL_SERVER;
71 63
72 // Remove current auth token 64 // Remove current auth token
73 localStorage.removeItem('authToken'); 65 localStorage.removeItem('authToken');
74 66
75 if (isUsingWithoutAccount) { 67 if (isUsingWithoutAccount) {
76 // Reset server back to Ferdium API 68 // Reset server back to Ferdium API
77 this.props.actions.settings.update({ 69 this.props.actions!.settings.update({
78 type: 'app', 70 type: 'app',
79 data: { 71 data: {
80 server: LIVE_FERDIUM_API, 72 server: LIVE_FERDIUM_API,
81 }, 73 },
82 }); 74 });
83 } 75 }
84 this.props.stores.user.isLoggingOut = true; 76 this.props.stores!.user.isLoggingOut = true;
85 77
86 this.props.stores.router.push('/auth/welcome'); 78 this.props.stores!.router.push('/auth/welcome');
87 79
88 // Reload Ferdium, otherwise many settings won't sync correctly with the server 80 // Reload Ferdium, otherwise many settings won't sync correctly with the server
89 // after logging into another account 81 // after logging into another account
@@ -91,10 +83,9 @@ class SettingsNavigation extends Component {
91 } 83 }
92 84
93 render() { 85 render() {
94 const { serviceCount, workspaceCount, stores } = this.props; 86 const { serviceCount, workspaceCount, stores, intl } = this.props;
95 const { intl } = this.props; 87 const isUsingWithoutAccount = stores!.settings.app.server === LOCAL_SERVER;
96 const isUsingWithoutAccount = stores.settings.app.server === LOCAL_SERVER; 88 const isUsingFranzServer = stores!.settings.app.server === LIVE_FRANZ_API;
97 const isUsingFranzServer = stores.settings.app.server === LIVE_FRANZ_API;
98 89
99 return ( 90 return (
100 <div className="settings-navigation"> 91 <div className="settings-navigation">
@@ -163,12 +154,12 @@ class SettingsNavigation extends Component {
163 } 154 }
164 > 155 >
165 {intl.formatMessage(globalMessages.settings)} 156 {intl.formatMessage(globalMessages.settings)}
166 {stores.settings.app.automaticUpdates && 157 {stores!.settings.app.automaticUpdates &&
167 (stores.ui.showServicesUpdatedInfoBar || 158 (stores!.ui.showServicesUpdatedInfoBar ||
168 stores.app.updateStatus === 159 stores!.app.updateStatus ===
169 stores.app.updateStatusTypes.AVAILABLE || 160 stores!.app.updateStatusTypes.AVAILABLE ||
170 stores.app.updateStatus === 161 stores!.app.updateStatus ===
171 stores.app.updateStatusTypes.DOWNLOADED) && ( 162 stores!.app.updateStatusTypes.DOWNLOADED) && (
172 <span className="update-available">•</span> 163 <span className="update-available">•</span>
173 )} 164 )}
174 </NavLink> 165 </NavLink>
@@ -195,7 +186,8 @@ class SettingsNavigation extends Component {
195 <span className="settings-navigation__expander" /> 186 <span className="settings-navigation__expander" />
196 <button 187 <button
197 type="button" 188 type="button"
198 to="/auth/logout" 189 // @ts-ignore
190 to="/auth/logout" // TODO - [TS DEBT] Need to check if button take this prop
199 className="settings-navigation__link" 191 className="settings-navigation__link"
200 onClick={this.handleLogout.bind(this)} 192 onClick={this.handleLogout.bind(this)}
201 > 193 >
@@ -208,6 +200,4 @@ class SettingsNavigation extends Component {
208 } 200 }
209} 201}
210 202
211export default injectIntl( 203export default injectIntl(SettingsNavigation);
212 inject('stores', 'actions')(observer(SettingsNavigation)),
213);
diff --git a/src/components/settings/recipes/RecipeItem.js b/src/components/settings/recipes/RecipeItem.tsx
index df5b42222..432e4e6a1 100644
--- a/src/components/settings/recipes/RecipeItem.js
+++ b/src/components/settings/recipes/RecipeItem.tsx
@@ -1,14 +1,17 @@
1import { Component } from 'react'; 1import { Component, MouseEventHandler } from 'react';
2import PropTypes from 'prop-types';
3import { observer } from 'mobx-react'; 2import { observer } from 'mobx-react';
3import RecipePreview from '../../../models/RecipePreview';
4 4
5import RecipePreviewModel from '../../../models/RecipePreview'; 5interface IProps {
6 recipe: RecipePreview;
7 onClick: MouseEventHandler<HTMLButtonElement>;
8}
6 9
7class RecipeItem extends Component { 10@observer
8 static propTypes = { 11class RecipeItem extends Component<IProps> {
9 recipe: PropTypes.instanceOf(RecipePreviewModel).isRequired, 12 constructor(props: IProps) {
10 onClick: PropTypes.func.isRequired, 13 super(props);
11 }; 14 }
12 15
13 render() { 16 render() {
14 const { recipe, onClick } = this.props; 17 const { recipe, onClick } = this.props;
@@ -18,7 +21,7 @@ class RecipeItem extends Component {
18 {recipe.isDevRecipe && ( 21 {recipe.isDevRecipe && (
19 <span className="recipe-teaser__dev-badge">dev</span> 22 <span className="recipe-teaser__dev-badge">dev</span>
20 )} 23 )}
21 <img src={recipe.icons.svg} className="recipe-teaser__icon" alt="" /> 24 <img src={recipe.icons?.svg} className="recipe-teaser__icon" alt="" />
22 <span className="recipe-teaser__label">{recipe.name}</span> 25 <span className="recipe-teaser__label">{recipe.name}</span>
23 {recipe.aliases && recipe.aliases.length > 0 && ( 26 {recipe.aliases && recipe.aliases.length > 0 && (
24 <span className="recipe-teaser__alias_label"> 27 <span className="recipe-teaser__alias_label">
@@ -30,4 +33,4 @@ class RecipeItem extends Component {
30 } 33 }
31} 34}
32 35
33export default observer(RecipeItem); 36export default RecipeItem;
diff --git a/src/components/settings/recipes/RecipesDashboard.jsx b/src/components/settings/recipes/RecipesDashboard.tsx
index d6150d300..fc687bc79 100644
--- a/src/components/settings/recipes/RecipesDashboard.jsx
+++ b/src/components/settings/recipes/RecipesDashboard.tsx
@@ -1,17 +1,14 @@
1import { Component } from 'react'; 1import { Component } from 'react';
2import PropTypes from 'prop-types'; 2import { observer } from 'mobx-react';
3import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; 3import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
4import { defineMessages, injectIntl } from 'react-intl';
5import { NavLink } from 'react-router-dom'; 4import { NavLink } from 'react-router-dom';
6 5import withStyles, { WithStylesProps } from 'react-jss';
7import injectSheet from 'react-jss';
8
9import { mdiOpenInNew } from '@mdi/js'; 6import { mdiOpenInNew } from '@mdi/js';
10import Button from '../../ui/button'; 7import Button from '../../ui/button';
11import Input from '../../ui/input/index'; 8import Input from '../../ui/input/index';
12import { H1, H2, H3 } from '../../ui/headline'; 9import { H1, H2, H3 } from '../../ui/headline';
13import SearchInput from '../../ui/SearchInput'; 10import SearchInput from '../../ui/SearchInput';
14import Infobox from '../../ui/Infobox'; 11import Infobox from '../../ui/infobox';
15import RecipeItem from './RecipeItem'; 12import RecipeItem from './RecipeItem';
16import Loader from '../../ui/Loader'; 13import Loader from '../../ui/Loader';
17import Appear from '../../ui/effects/Appear'; 14import Appear from '../../ui/effects/Appear';
@@ -109,28 +106,32 @@ const styles = {
109 }, 106 },
110}; 107};
111 108
112class RecipesDashboard extends Component { 109interface IProps extends WithStylesProps<typeof styles>, WrappedComponentProps {
113 static propTypes = { 110 recipes: RecipePreview[];
114 recipes: MobxPropTypes.arrayOrObservableArray.isRequired, 111 customWebsiteRecipe?: RecipePreview;
115 customWebsiteRecipe: PropTypes.instanceOf(RecipePreview).isRequired, 112 isLoading: boolean;
116 isLoading: PropTypes.bool.isRequired, 113 hasLoadedRecipes: boolean;
117 hasLoadedRecipes: PropTypes.bool.isRequired, 114 showAddServiceInterface: (...args: any[]) => void;
118 showAddServiceInterface: PropTypes.func.isRequired, 115 searchRecipes: (e: string | null) => void;
119 searchRecipes: PropTypes.func.isRequired, 116 resetSearch: () => void;
120 resetSearch: PropTypes.func.isRequired, 117 serviceStatus: string[];
121 serviceStatus: MobxPropTypes.arrayOrObservableArray.isRequired, 118 searchNeedle: string | null;
122 searchNeedle: PropTypes.string, 119 recipeFilter?: string;
123 recipeFilter: PropTypes.string, 120 recipeDirectory: string;
124 recipeDirectory: PropTypes.string.isRequired, 121 openRecipeDirectory: () => void;
125 openRecipeDirectory: PropTypes.func.isRequired, 122 openDevDocs: () => void;
126 openDevDocs: PropTypes.func.isRequired, 123}
127 classes: PropTypes.object.isRequired, 124
128 }; 125interface IState {
126 searchNeedle: string | null;
127 recipeFilter: string;
128}
129 129
130 static defaultProps = { 130@observer
131 searchNeedle: '', 131class RecipesDashboard extends Component<IProps, IState> {
132 recipeFilter: 'all', 132 constructor(props: IProps) {
133 }; 133 super(props);
134 }
134 135
135 render() { 136 render() {
136 const { 137 const {
@@ -141,15 +142,15 @@ class RecipesDashboard extends Component {
141 showAddServiceInterface, 142 showAddServiceInterface,
142 searchRecipes, 143 searchRecipes,
143 resetSearch, 144 resetSearch,
144 serviceStatus, 145 serviceStatus = 'all',
145 searchNeedle, 146 searchNeedle = '',
146 recipeFilter, 147 recipeFilter,
147 recipeDirectory, 148 recipeDirectory,
148 openRecipeDirectory, 149 openRecipeDirectory,
149 openDevDocs, 150 openDevDocs,
150 classes, 151 classes,
152 intl,
151 } = this.props; 153 } = this.props;
152 const { intl } = this.props;
153 154
154 const communityRecipes = recipes.filter(r => !r.isDevRecipe); 155 const communityRecipes = recipes.filter(r => !r.isDevRecipe);
155 const devRecipes = recipes.filter(r => r.isDevRecipe); 156 const devRecipes = recipes.filter(r => r.isDevRecipe);
@@ -307,5 +308,5 @@ class RecipesDashboard extends Component {
307} 308}
308 309
309export default injectIntl( 310export default injectIntl(
310 injectSheet(styles, { injectTheme: true })(observer(RecipesDashboard)), 311 withStyles(styles, { injectTheme: true })(RecipesDashboard),
311); 312);