-
Notifications
You must be signed in to change notification settings - Fork 27
Add network/storage mappings table component #23
Conversation
🚀 Deployed Preview: http://konveyor-virt-ui-pr-23-preview.surge.sh ✨ |
There was a problem hiding this 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.
src/app/Mappings/mocks/helpers.ts
Outdated
@@ -0,0 +1,32 @@ | |||
import { MappingType } from '../types'; | |||
|
|||
export const updateMockStorage = (params: any) => { |
There was a problem hiding this comment.
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([]); |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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([]); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 id
s 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
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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.
src/app/Mappings/types.ts
Outdated
@@ -28,7 +28,12 @@ export interface IStorageMappingItem { | |||
export interface ICommonMapping { | |||
type: MappingType; | |||
name: string; | |||
provider: { | |||
sourceProvider: { |
There was a problem hiding this comment.
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.
2b06e3c
to
1860609
Compare
* update TS support for network/storage mappings * add comment to remove throwaway function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Closes #31