Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Prototype network/storage mapping builder (single-select source variant) #25

Merged

Conversation

mturley
Copy link
Collaborator

@mturley mturley commented Sep 3, 2020

Closes #7.

Based on #24, this converts the mapping arrow-box groups so that each maps only a single source to a single target, and the same target can be selected in more than one group. This addresses some feedback that @vconzola had about the multi-select source control being confusing. This also simplifies the state management a bit, since it is closer to the actual API data structure.

Only one of #24 or #25 should be merged, the other will be closed after we review the two designs.

Screen Shot 2020-09-03 at 1 20 45 PM

@konveyor-preview-bot
Copy link

🚀 Deployed Preview: http://konveyor-virt-ui-pr-25-preview.surge.sh

@mturley mturley mentioned this pull request Sep 3, 2020
@mturley mturley force-pushed the mapping-builder-prototype-single-sources branch from 3ed5195 to 4ebaee3 Compare September 4, 2020 16:10
@mturley mturley marked this pull request as ready for review September 8, 2020 15:41
@mturley mturley requested a review from a team September 8, 2020 15:41
{builderItems.map((item, itemIndex) => {
let key = '';
if (mappingType === MappingType.Network) {
const t = item.source as IVMwareNetwork | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Very cool use of typescript type assertion.

Copy link
Collaborator Author

@mturley mturley Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly though I can't remember why I used the variable name t. I think it came from when these were keyed by unique targets. I'll change it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, turns out I didn't need this at all. Both types of sources have an id property. I'll remove the whole condition

options={options}
value={[selectedOption]}
onChange={(selection) => {
setSource((selection as OptionWithValue<MappingSource>).value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looking good

Comment on lines +35 to +41
if (mappingType === MappingType.Network) {
return (target as ICNVNetwork).name;
}
if (mappingType === MappingType.Storage) {
return target as string;
}
return '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a cleaner way to code this? I have used a similar pattern in the past but tried recently to switch to ternary expressions for these. It would probably be overkill for a switch statement. This works fine but I am always wishing there was some sort of middle ground.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking of a ternary expression, but that requires choosing either network or storage as the condition and then having "other" be assumed to be the other. i.e. if it's a network mapping do this, else do this. I don't know if we'll ever need to add a third kind of mapping, but this allows for that. Could always refactor that later, so if you think it should be a ternary I'm fine with that.

Copy link
Contributor

@ibolton336 ibolton336 Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with if statements if there are more than 2 conditions. & maybe we switch to switch statements if there are more than 3. Its more of a gripe with JS than with your PR :)

options={targetOptions}
value={[selectedOption]}
onChange={(selection) => {
setTarget((selection as OptionWithValue<MappingTarget>).value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I had proper generics support in SimpleSelect this wouldn't even be necessary 😄

export const getSourceById = (sources: MappingSource[], id: string): MappingSource | undefined =>
sources.find((source) => source.id === id);

export const getBuilderItemsFromMapping = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but it can be used to pre-populate the state here from API mappings when we add edit functionality.

import { IMappingBuilderItem } from './MappingBuilder';
import { IVMwareProvider, ICNVProvider } from '@app/Providers/types';

export const getSourceById = (sources: MappingSource[], id: string): MappingSource | undefined =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever called?

Copy link
Collaborator Author

@mturley mturley Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called in getBuilderItemsFromMapping. Maybe not necessary to export it.

Copy link
Contributor

@ibolton336 ibolton336 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@ibolton336 ibolton336 merged commit d479bb9 into kubev2v:master Sep 8, 2020
@mturley
Copy link
Collaborator Author

mturley commented Sep 8, 2020

Awesome! Thanks @ibolton336

@mturley mturley deleted the mapping-builder-prototype-single-sources branch September 8, 2020 21:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build prototype of mapping creation widget
3 participants