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

Add network/storage mappings table component #23

Merged
merged 8 commits into from
Sep 9, 2020

Conversation

ibolton336
Copy link
Contributor

@ibolton336 ibolton336 commented Sep 2, 2020

  • Adds necessary logic to populate the shared mappings table with network or storage mappings.
  • Adds Add mapping button to the top of the shared table. This button opens the shared mappings modal
  • Uses mock data in local storage for testing. There are a few throwaway functions added to /mocks/helpers for this purpose. We can use these until we are ready for redux implementation.

Closes #31

@ibolton336 ibolton336 requested a review from a team September 2, 2020 15:21
@konveyor-preview-bot
Copy link

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

Copy link
Collaborator

@mturley mturley left a comment

Choose a reason for hiding this comment

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

Looking good! Just a couple things.

@@ -0,0 +1,32 @@
import { MappingType } from '../types';

export const updateMockStorage = (params: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to add a comment here that this is temporary, so we don't invest too much time making it better / spreading it.


const NetworkMappingsPage: React.FunctionComponent = () => {
const [networkMappings, setNetworkMappings] = React.useState([]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's throw a comment here too saying this is temporary, so we don't end up duplicating redux state here in react land


//TODO replace with real state from redux
const mockMapObj = localStorage.getItem('networkMappingsObject');
React.useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I'm not sure I get the useEffect code here, why does it have mockMapObj in its dependency array? That won't change here I don't think, so the useEffect will only be triggered once. I think we can get rid of the mockMapObj and have [] as the deps array for the effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mockMapObj is required in the dependency array because when I added an item to the local storage, there was no rerender triggered. This will for sure go away when we move to real redux state but it is needed temporarily for the mock localstorage code to work for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

got it. ok.


const StorageMappingsPage: React.FunctionComponent = () => {
const [storageMappings, setStorageMappings] = React.useState([]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comments here: comment about temporary state, remove mockMapObj (I think?)

variant="primary"
onClick={() => {
//TODO: Replace with a real redux call for adding a mapping
updateMockStorage({ mappingName, sourceProvider, targetProvider, mappingType });
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to change this after we merge #25, we can generate the whole mapping object with a helper function I wrote there

}: IMappingsTableProps) => {
const getSortValues = (mapping: ICommonMapping) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should use Mapping instead of ICommonMapping here. Mapping is a union of the two specific mapping interfaces, so a mapping with network-specific or storage-specific properties is a valid Mapping but not a valid ICommonMapping (which is just what those two interfaces extend).

const {
selectedItems: expandedMappings,
toggleItemSelected: toggleMappingExpanded,
} = useSelectionState<ICommonMapping>(sortedItems);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, Mapping instead of ICommonMapping. Maybe I shouldn't have even exported it.

const rows: IRow[] = [];
currentPageItems.forEach((mapping: ICommonMapping) => {
const { name, sourceProvider, targetProvider, items } = mapping;
const isExpanded = expandedMappings.includes(mapping);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be fine for now, but I'm actually realizing that if the mappings objects in redux are updated, this referential equality will fail to match and we'll lose our expanded state. We might need to use the isItemSelected function exported by the useSelectionState hook, and pass an isEqual function into it that uses ids or something. I do that in my examples here: https://konveyor.github.io/lib-ui/?path=/docs/hooks-useselectionstate--checkboxes

I probably need to make the same change elsewhere, that'll become apparent as we start to use redux for these

Copy link
Contributor Author

@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.

Added a comment for now. We should open a PR to pull in the useSelection state from lib-ui also. PR opened #32

{
title: <>{mappingType === MappingType.Network ? 'Network mappings' : 'Storage mappings'}</>,
transforms: [sortable],
cellTransforms: [compoundExpand],
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is another place where we need to remove compoundExpand, this and the import.

@@ -28,7 +28,12 @@ export interface IStorageMappingItem {
export interface ICommonMapping {
type: MappingType;
name: string;
provider: {
sourceProvider: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might conflict with #25, I think I made the same change there.

ibolton336 and others added 4 commits September 8, 2020 17:31
* update TS support for network/storage mappings

* add comment to remove throwaway function
Copy link
Collaborator

@mturley mturley left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@mturley mturley merged commit a8f1e6f into master Sep 9, 2020
@mturley mturley deleted the network-mappings-table branch September 9, 2020 20:11
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.

Replace compound expansion with simple expansion for mappings tables
3 participants