Remove some anys

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-04-29 19:37:31 +02:00
parent 44fc429f64
commit e62add6893
6 changed files with 48 additions and 46 deletions

View File

@ -41,8 +41,8 @@ const TargetDetail = styled((props) => <Txt.span {...props}></Txt.span>)`
interface TargetSelectorProps { interface TargetSelectorProps {
targets: any[]; targets: any[];
disabled: boolean; disabled: boolean;
openDriveSelector: () => any; openDriveSelector: () => void;
reselectDrive: () => any; reselectDrive: () => void;
flashing: boolean; flashing: boolean;
show: boolean; show: boolean;
tooltip: string; tooltip: string;

View File

@ -27,12 +27,9 @@ import { FlashAnother } from '../flash-another/flash-another';
import { FlashResults } from '../flash-results/flash-results'; import { FlashResults } from '../flash-results/flash-results';
import { SVGIcon } from '../svg-icon/svg-icon'; import { SVGIcon } from '../svg-icon/svg-icon';
const restart = (options: any, goToMain: () => void) => { function restart(goToMain: () => void) {
if (!options.preserveImage) {
selectionState.deselectImage();
}
selectionState.deselectAllDrives(); selectionState.deselectAllDrives();
analytics.logEvent('Restart', options); analytics.logEvent('Restart');
// Reset the flashing workflow uuid // Reset the flashing workflow uuid
store.dispatch({ store.dispatch({
@ -41,9 +38,9 @@ const restart = (options: any, goToMain: () => void) => {
}); });
goToMain(); goToMain();
}; }
const formattedErrors = () => { function formattedErrors() {
const errors = _.map( const errors = _.map(
_.get(flashState.getFlashResults(), ['results', 'errors']), _.get(flashState.getFlashResults(), ['results', 'errors']),
(error) => { (error) => {
@ -51,7 +48,7 @@ const formattedErrors = () => {
}, },
); );
return errors.join('\n'); return errors.join('\n');
}; }
function FinishPage({ goToMain }: { goToMain: () => void }) { function FinishPage({ goToMain }: { goToMain: () => void }) {
const results = flashState.getFlashResults().results || {}; const results = flashState.getFlashResults().results || {};
@ -62,8 +59,10 @@ function FinishPage({ goToMain }: { goToMain: () => void }) {
<FlashResults results={results} errors={formattedErrors()} /> <FlashResults results={results} errors={formattedErrors()} />
<FlashAnother <FlashAnother
onClick={(options: any) => restart(options, goToMain)} onClick={() => {
></FlashAnother> restart(goToMain);
}}
/>
</div> </div>
<div className="box center"> <div className="box center">

View File

@ -26,17 +26,14 @@ const Div = styled.div<any>`
`; `;
export interface FlashAnotherProps { export interface FlashAnotherProps {
onClick: (options: { preserveImage: boolean }) => void; onClick: () => void;
} }
export const FlashAnother = (props: FlashAnotherProps) => { export const FlashAnother = (props: FlashAnotherProps) => {
return ( return (
<ThemedProvider> <ThemedProvider>
<Div position="absolute" right="152px"> <Div position="absolute" right="152px">
<BaseButton <BaseButton primary onClick={props.onClick}>
primary
onClick={props.onClick.bind(null, { preserveImage: true })}
>
Flash Another Flash Another
</BaseButton> </BaseButton>
</Div> </Div>

View File

@ -46,7 +46,7 @@ interface ProgressButtonProps {
percentage: number; percentage: number;
label: string; label: string;
disabled: boolean; disabled: boolean;
callback: () => any; callback: () => void;
} }
const colors = { const colors = {

View File

@ -61,7 +61,10 @@ const WarningModal = ({
interface Setting { interface Setting {
name: string; name: string;
label: string | JSX.Element; label: string | JSX.Element;
options?: any; options?: {
description: string;
confirmLabel: string;
};
hide?: boolean; hide?: boolean;
} }
@ -109,15 +112,19 @@ async function getSettingsList(): Promise<Setting[]> {
]; ];
} }
interface Warning {
setting: string;
settingValue: boolean;
description: string;
confirmLabel: string;
}
interface SettingsModalProps { interface SettingsModalProps {
toggleModal: (value: boolean) => void; toggleModal: (value: boolean) => void;
} }
export function SettingsModal({ toggleModal }: SettingsModalProps) { export function SettingsModal({ toggleModal }: SettingsModalProps) {
const [settingsList, setCurrentSettingsList]: [ const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
Setting[],
React.Dispatch<React.SetStateAction<Setting[]>>,
] = React.useState([]);
React.useEffect(() => { React.useEffect(() => {
(async () => { (async () => {
if (settingsList.length === 0) { if (settingsList.length === 0) {
@ -125,10 +132,9 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
} }
})(); })();
}); });
const [currentSettings, setCurrentSettings]: [ const [currentSettings, setCurrentSettings] = React.useState<
_.Dictionary<boolean>, _.Dictionary<boolean>
React.Dispatch<React.SetStateAction<_.Dictionary<boolean>>>, >({});
] = React.useState({});
React.useEffect(() => { React.useEffect(() => {
(async () => { (async () => {
if (_.isEmpty(currentSettings)) { if (_.isEmpty(currentSettings)) {
@ -136,14 +142,14 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
} }
})(); })();
}); });
const [warning, setWarning]: [ const [warning, setWarning] = React.useState<Warning | undefined>(undefined);
any,
React.Dispatch<React.SetStateAction<any>>,
] = React.useState({});
const toggleSetting = async (setting: string, options?: any) => { const toggleSetting = async (
setting: string,
options?: Setting['options'],
) => {
const value = currentSettings[setting]; const value = currentSettings[setting];
const dangerous = !_.isUndefined(options); const dangerous = options !== undefined;
analytics.logEvent('Toggle setting', { analytics.logEvent('Toggle setting', {
setting, setting,
@ -151,22 +157,22 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
dangerous, dangerous,
}); });
if (value || !dangerous) { if (value || options === undefined) {
await settings.set(setting, !value); await settings.set(setting, !value);
setCurrentSettings({ setCurrentSettings({
...currentSettings, ...currentSettings,
[setting]: !value, [setting]: !value,
}); });
setWarning({}); setWarning(undefined);
return; return;
} else {
// Show warning since it's a dangerous setting
setWarning({
setting,
settingValue: value,
...options,
});
} }
// Show warning since it's a dangerous setting
setWarning({
setting,
settingValue: value,
...options,
});
}; };
return ( return (
@ -206,7 +212,7 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
</div> </div>
</div> </div>
{_.isEmpty(warning) ? null : ( {warning === undefined ? null : (
<WarningModal <WarningModal
message={warning.description} message={warning.description}
confirmLabel={warning.confirmLabel} confirmLabel={warning.confirmLabel}
@ -216,10 +222,10 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
...currentSettings, ...currentSettings,
[warning.setting]: true, [warning.setting]: true,
}); });
setWarning({}); setWarning(undefined);
}} }}
cancel={() => { cancel={() => {
setWarning({}); setWarning(undefined);
}} }}
/> />
)} )}

View File

@ -41,7 +41,7 @@ export function percentageToFloat(percentage: any) {
/** /**
* @summary Check if obj has one or many specific props * @summary Check if obj has one or many specific props
*/ */
export function hasProps(obj: any, props: string[]): boolean { export function hasProps(obj: _.Dictionary<any>, props: string[]): boolean {
return _.every(props, (prop) => { return _.every(props, (prop) => {
return _.has(obj, prop); return _.has(obj, prop);
}); });