-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Wildcard Field UI #722
base: master
Are you sure you want to change the base?
Conversation
const noCustomWildcardFields: CustomWildcardField[] = []; | ||
const customWildcardFields = customWildcardFieldReducer( | ||
noCustomWildcardFields, | ||
const noCustomWildcardFieldDefs: CustomWildcardFieldDef[] = []; |
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.
Just use []
, the name is unnecessary and is a bit confusing the first time I saw it.
if (isWildcard(fieldDef.field)) { | ||
if (fieldDef.field === '?') { | ||
fields = schema.fieldNames() | ||
.filter(field => schema.vlType(field) === type); |
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 would just tab by two empty space. (The current tabbing isn't aligned anyway)
|
||
let field; | ||
let popupComponent; | ||
let isCustomWildcardField; |
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.
Why do you need let
for isCustomWildcardField
? You can just use const
here.
const key = isWildcard(fieldDef.field) ? stringify(fieldDef) : fieldDef.field; | ||
|
||
let field; | ||
let popupComponent; |
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.
For popupComponent, you may want to extract a method.
const {schema, filters, handleAction} = this.props; | ||
const key = isWildcard(fieldDef.field) ? stringify(fieldDef) : fieldDef.field; | ||
|
||
let field; |
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.
Why do you need let
for field
? Just use const
if possible.
|
||
private renderField(fieldDef: ShelfFieldDef, popupComponent?: JSX.Element) { | ||
const {schema, filters, handleAction} = this.props; | ||
let filterShow; |
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.
use const for filterShow
src/components/data-pane/index.tsx
Outdated
config: VoyagerConfig; | ||
customWildcardFieldDefs: CustomWildcardFieldDef[]; |
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 doesn't seem to be used anywhere?
src/components/field/index.tsx
Outdated
@@ -48,7 +49,8 @@ export interface FieldPropsBase { | |||
/** Remove field event handler. If not provided, remove button will disappear. */ | |||
onRemove?: () => void; | |||
|
|||
handleAction?: (action: FilterAction | ShelfAction | DatasetSchemaChangeFieldType) => void; | |||
handleAction?: (action: CustomWildcardAction | FilterAction | |
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.
Better make it implement ActionHandler?
|
||
export interface CustomWildcardFieldDropZonePropsBase { | ||
schema: Schema; | ||
handleAction?: (action: CustomWildcardAction) => void; |
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.
Why is this optional? Better just make it implements ActionHandler
customWildcardField: CustomWildcardFieldDef; | ||
schema: Schema; | ||
index: number; | ||
handleAction?: (action: CustomWildcardAction) => void; |
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.
Why is this optional? Better just make it implements ActionHandler
|
||
let fields; | ||
if (isWildcard(fieldDef.field)) { | ||
if (fieldDef.field === '?') { |
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.
Use SHORT_WILDCARD
over question mark
fields = schema.fieldNames() | ||
.filter(field => schema.vlType(field) === type); | ||
} else { | ||
fields = fieldDef.field.enum.concat([]); |
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.
Why concat []?
return; | ||
} | ||
|
||
const {fieldDef} = monitor.getItem() as DraggedFieldIdentifier; |
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.
Why do we need as
here?
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.
Bad type inference. Monitor.getItem() is inferred simply as type 'Object' -- it doesn't know the object contains the property fieldDef
. I casted to DraggedFieldIdentifier so it could infer fieldDef and let me write const {fieldDef} =
. We do the same thing in encoding-shelf.tsx
for the encodingShelfTarget
.
}); | ||
} | ||
|
||
private handleDescriptionChange(event: 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.
onDescriptionChange
); | ||
} | ||
|
||
protected customWildcardRemoveField(field: string) { |
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.
Use consistent name onRemoveField
(we use on... elsewhere in the project)
(customWildcardRemoveField
isn't consistent with handleDescriptionChange
.)
return connectDropTarget(this.props.children[0]); | ||
} | ||
|
||
private customWildcardRemove() { |
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.
Why do you need this remove here?
a892f0c
to
81425d7
Compare
1c5b259
to
187272a
Compare
187272a
to
9ec6fb1
Compare
cc: @kanitw |
92d5004
to
8015021
Compare
Is this ready? If so, rebase? |
CustomWildcardField ==> CustomWildcardFieldDef
Trying to make Field both a dragsource and droptarget
8015021
to
aef4b0f
Compare
cc @kanitw Rebased. |
There is a conflict -- do you want to rebase and squash to one commit (or a few commits that are more useful?) |
fields = schema.fieldNames() | ||
.filter(field => schema.vlType(field) === type); | ||
} else { | ||
fields = droppedFieldDef.field.enum.concat([]); |
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.
Why concat empty string?
(state: State) => { | ||
return { | ||
// Somehow TS does not infer type that CustomWildcardFieldDefs can be a ShelfFieldDef | ||
fieldDefs: selectCustomWildcardFieldDefs(state) as ShelfFieldDef[], |
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.
There are so too casting in this PR -- I doubt if we really need all of them.
Can you see if upgrading to the latest TS allow you to eliminate a lot of these as
?
|
||
if (isCustomWildcardField) { | ||
const fields = (fieldDef as CustomWildcardFieldDef).field.enum; // TS isn't the inferring correct type | ||
customWildcardFieldDescription = "(" + fields.length + ") " + (description || fields.toString()); |
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.
fields.toString()
This will add comma without space -- is that what you want?
Wouldn't it be better to .join(', ')
?
@@ -109,32 +124,54 @@ class FieldBase extends React.PureComponent<FieldProps, FieldState> { | |||
fnName = fn; | |||
} | |||
|
|||
const component = ( | |||
const isCustomWildcardField = isWildcardDef(fieldDef.field); | |||
let customWildcardFieldDescription = ""; |
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.
Please always use single quote for TS code. (Do the same for the whole PR)
import {ShelfFieldDef} from './shelf/spec/encoding'; | ||
|
||
export type CustomWildcardField = { | ||
fields: string[]; | ||
export type CustomWildcardFieldDef = { |
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.
Rename the file accordingly?
@@ -0,0 +1,23 @@ | |||
.drop-zone { |
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.
-
Instead of declaring a totally new CSS, can this extend some style of Field
-
The old version of Voyager has nicer CSS here
- We should rounded corner like normal Field
- It should be semi-transparent
Fix #555