-
Notifications
You must be signed in to change notification settings - Fork 52
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
Enum custom field UI #2210
base: main
Are you sure you want to change the base?
Enum custom field UI #2210
Conversation
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 love to try this but the preview build is failing. 😞
Please fix all of the linting and formatting errors before a more thorough review.
Please install the pre-commit hook, as suggested in the |
Yes done now |
…n renamed to PersonFieldColumn, it was only used by PersonField.
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've taken an initial look, mostly focusing on the functional side (using the UI and seeing how it works). In that process I did find some problems that I've highlighted below. I will move on to do a full code review tomorrow but didn't want to hold you up if you do keep on working today.
src/features/views/components/ViewDataTable/columnTypes/PersonFieldColumnType.tsx
Outdated
Show resolved
Hide resolved
src/features/smartSearch/components/filters/PersonField/DisplayPersonField.tsx
Outdated
Show resolved
Hide resolved
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.
Awesome work on this major new feature! I have tried a local build (with some changes to match recent changes to the backend) and I have reviewed all the code. Most of it works really well! 💯
I did find some bugs, and some things that I think can be improved in the code, as well as a bunch of things where I don't feel entirely comfortable but can definitely be persuaded if I hear your reasoning. Please have a read and reach out if you want to discuss.
src/features/import/components/ImportDialog/Configure/Configuration/EnumConfigRow.tsx
Show resolved
Hide resolved
if (column.kind === ColumnKind.ENUM) { | ||
column.mapping.forEach((mappedColumn) => { | ||
if (mappedColumn.value === row[colIdx]) { | ||
personPreviewOp.data = { | ||
...personPreviewOp.data, | ||
[`${column.field}`]: row[colIdx], | ||
}; | ||
} | ||
}); | ||
} |
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 add a test case to createPreviewData.spec.ts
that encompasses this. Maybe this code is related to the fact that the preview doesn't seem to be working (see separate comment) and you can try to reproduce that in a test and TDD a solution?
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.
src/features/smartSearch/components/filters/PersonField/DisplayPersonField.tsx
Outdated
Show resolved
Hide resolved
src/features/smartSearch/components/filters/PersonField/DisplayPersonField.tsx
Outdated
Show resolved
Hide resolved
src/features/views/components/ViewDataTable/columnTypes/PersonFieldColumnType.tsx
Show resolved
Hide resolved
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 commented in two places where ""
is used and need to be translated to null
. Not sure if there are more? How about Smart Search?
if (mappedColumn.value === row.data[colIdx] && mappedColumn.key) { | ||
personImportOps[rowIndex].data = { | ||
...personImportOps[rowIndex].data, | ||
[`${column.field}`]: mappedColumn.key, |
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 should be translated to null
if ""
(could also be solved elsewhere, e.g. closer to the UI, but doing it here should make it testable).
fullWidth | ||
label={field.title} | ||
onChange={(ev) => { | ||
onChange(field.slug, ev.target.value); |
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.
Here we need to translate from ""
to null
.
valueGetter: (params) => { | ||
const cell = params.row[params.field]; | ||
if (column.config.enum_choices) { | ||
this.enumChoices = column.config.enum_choices; |
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.
Setting this.enumChoices
here and then relying on it in several other places feels risky. This instance is not for one specific column, it's for all columns of this type. So there is nothing guaranteeing (at least not type/syntax-wise) that this method will be called before, say, cellToString()
or that this method can't be called for another method before calling cellToString()
.
Most likely this will fail for views that have more than one column of enum type.
if (this.enumChoices) { | ||
const choice = this.enumChoices.find((c) => c.key == cell); | ||
return choice ? choice.label : ''; |
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.
As far as I can tell, this never happens when exporting a CSV, because this code is executed on the backend where getColDef
will have never been called, and that's where the this.enumChoices
state is (riskily) set.
I'm thinking it makes sense to pass in column
to these functions instead.
src/features/views/components/ViewDataTable/columnTypes/PersonFieldColumnType.tsx
Outdated
Show resolved
Hide resolved
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've gone over this again and I did find some additional bugs. Details below.
if (column.kind === ColumnKind.ENUM) { | ||
column.mapping.forEach((mappedColumn) => { | ||
if (mappedColumn.value === row.data[colIdx] && mappedColumn.key) { | ||
personImportOps[rowIndex].data = { | ||
...personImportOps[rowIndex].data, | ||
[`${column.field}`]: mappedColumn.key, | ||
}; | ||
} | ||
}); | ||
} |
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.
if (column.kind === ColumnKind.ENUM) { | ||
column.mapping.forEach((mappedColumn) => { | ||
if (mappedColumn.value === row[colIdx]) { | ||
personPreviewOp.data = { | ||
...personPreviewOp.data, | ||
[`${column.field}`]: row[colIdx], | ||
}; | ||
} | ||
}); | ||
} |
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.
Description
This PR adds UI for
enum_text
type custom fields.Screenshots
Changes
Notes to reviewer
This requires backend PR: zetkin/zetkin-platform#848