Remove lodash from selection-state.ts

Change-type: patch
Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
Lorenzo Alberto Maria Ambrosi 2020-09-02 17:39:40 +02:00
parent 8fa6e618c4
commit 14a89b3b8a

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
import * as _ from 'lodash';
import { SourceMetadata } from '../components/source-selector/source-selector'; import { SourceMetadata } from '../components/source-selector/source-selector';
import * as availableDrives from './available-drives'; import * as availableDrives from './available-drives';
@ -60,48 +59,44 @@ export function getSelectedDevices(): string[] {
*/ */
export function getSelectedDrives(): any[] { export function getSelectedDrives(): any[] {
const drives = availableDrives.getDrives(); const drives = availableDrives.getDrives();
return _.map(getSelectedDevices(), (device) => { return getSelectedDevices().map((device) => {
return _.find(drives, { device }); return drives.find((drive) => drive.device === device);
}); });
} }
/** /**
* @summary Get the selected image * @summary Get the selected image
*/ */
export function getImage(): SourceMetadata { export function getImage(): SourceMetadata | undefined {
return _.get(store.getState().toJS(), ['selection', 'image']); return store.getState().toJS().selection.image;
} }
export function getImagePath(): string { export function getImagePath(): string {
return _.get(store.getState().toJS(), ['selection', 'image', 'path']); return store.getState().toJS().selection.image?.path;
} }
export function getImageSize(): number { export function getImageSize(): number {
return _.get(store.getState().toJS(), ['selection', 'image', 'size']); return store.getState().toJS().selection.image?.size;
} }
export function getImageUrl(): string { export function getImageUrl(): string {
return _.get(store.getState().toJS(), ['selection', 'image', 'url']); return store.getState().toJS().selection.image?.url;
} }
export function getImageName(): string { export function getImageName(): string {
return _.get(store.getState().toJS(), ['selection', 'image', 'name']); return store.getState().toJS().selection.image?.name;
} }
export function getImageLogo(): string { export function getImageLogo(): string {
return _.get(store.getState().toJS(), ['selection', 'image', 'logo']); return store.getState().toJS().selection.image?.logo;
} }
export function getImageSupportUrl(): string { export function getImageSupportUrl(): string {
return _.get(store.getState().toJS(), ['selection', 'image', 'supportUrl']); return store.getState().toJS().selection.image?.supportUrl;
} }
export function getImageRecommendedDriveSize(): number { export function getImageRecommendedDriveSize(): number {
return _.get(store.getState().toJS(), [ return store.getState().toJS().selection.image?.recommendedDriveSize;
'selection',
'image',
'recommendedDriveSize',
]);
} }
/** /**
@ -115,7 +110,7 @@ export function hasDrive(): boolean {
* @summary Check if there is a selected image * @summary Check if there is a selected image
*/ */
export function hasImage(): boolean { export function hasImage(): boolean {
return !_.isEmpty(getImage()); return getImage() !== undefined;
} }
/** /**
@ -136,7 +131,7 @@ export function deselectImage() {
} }
export function deselectAllDrives() { export function deselectAllDrives() {
_.each(getSelectedDevices(), deselectDrive); getSelectedDevices().forEach(deselectDrive);
} }
/** /**
@ -156,5 +151,5 @@ export function isDriveSelected(driveDevice: string) {
} }
const selectedDriveDevices = getSelectedDevices(); const selectedDriveDevices = getSelectedDevices();
return _.includes(selectedDriveDevices, driveDevice); return selectedDriveDevices.includes(driveDevice);
} }