Skip to content
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

machines: fix issue with dialogs that are nested inside PF4 tables don't close when submitted #13488

Merged
merged 4 commits into from Feb 5, 2020

Conversation

KKoukiou
Copy link
Contributor

@KKoukiou KKoukiou commented Feb 4, 2020

No description provided.

pkg/lib/cockpit-components-table.jsx Show resolved Hide resolved
@@ -161,6 +164,7 @@ export class ListingTable extends React.Component {
// We need the following because of: https://github.com/patternfly/patternfly-react/issues/3090
if (props.cells.some(cell => typeof (cell.title) != 'string' || cell.title.toLowerCase() == 'id' || !cell.title))
tableBodyProps.rowKey = ({ rowData, rowIndex }) => rowIndex;
Copy link
Member

Choose a reason for hiding this comment

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

Using an ID for each row seems strange, though. This is the place that sets the keys for the rows, and obviously rowIndex is an useless value for a row key. IMHO it would be better to make rowKey a mandatory property of a table row component, and let the caller set it. Perhaps it could have a default like a hash value of rowData, but I'm not sure if that's possible/easy to do in JS.

@@ -186,7 +186,7 @@ class VmDisksTab extends React.Component {
);
columns.push({ title: diskActions });
}
return { columns };
return { columns, id: disk.target };
Copy link
Member

Choose a reason for hiding this comment

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

Passing a key: (or rowKey:) here would IMHO make more sense. keys can have a much more flexible content than IDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing a rowKey to the row properties won't make PF use it unfortunately.
I need to write some clean reproducer and submit an issue to PF, because the current way to have custom row keys (something else than index) is not very nice actually :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check my updated PR for implementation details.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

I only looked at the first commit for now, this needs more rework I'm afraid. Can you please revise the commit message? It has a lot of typos and grammar errors.

Thanks! Sorry that you have to wade through this brokenness :/

@@ -41,7 +41,8 @@ import './listing.less';
* - columns: { title: string, header: boolean, sortable: boolean }[] or string[]
* - rows: {
* columns: (React.Node or string)[],
* extraClasses: string[]
* extraClasses: string[],
* rowKey: ({ rowData: IRowData, rowIndex: Number }) => string | if not specified the rowIndex will be used as each row's key,
Copy link
Member

Choose a reason for hiding this comment

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

I suppose "IRowData" is a typo? Would be good to give an example of its structure, as by our IRC conversation this is an utterly strange object.

@@ -252,6 +252,7 @@ class HardwareInfo extends React.Component {

pci = (
<ListingTable caption={ _("PCI") }
rowKey={({ rowData, rowIndex }) => rowData.slot.title}
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, then .slot will change if the title is translated. And of course it's not entirely obvious what happens if you translate _("Slot") into a language which doesn't have lower case and such.. 😭

@@ -268,6 +269,7 @@ class HardwareInfo extends React.Component {
if (this.props.info.memory.length > 0) {
memory = (
<ListingTable caption={ _("Memory") }
rowKey={({ rowData, rowIndex }) => rowData.id.title}
Copy link
Member

Choose a reason for hiding this comment

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

Same here, probably needs to use rowData[_("ID").toLowerCase()] or something similarly ugly

…gTable

A consumer of ListingTable component can now pass a unique key to the `props`
object of each row, which will be then internally used by React as the
row's key.
Start using this property for the Tables in Hardware Info page, so that
we can drop the workaround for wrong key assignment in the ListingTable
implementation.

Closes cockpit-project#13488
… a disk

Specify a key in the props property so that a unique key is used for
each row of the PF4 Table.

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1791543
…a NIC

Specify a key in props property so that a unique key is used for each row of the
PF4 Table.
Note: As id, the {mac}-{address.bus}-{address.slot} is used.
When the NIC does not have an address element in the XML we use
the {mac}-{networkIndex} combination, which is though problematic if
more interfaces have the same MAC.

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1791543
This will prevent consumers of ListingTable to have rows with keys that
are just row indexes.

Fix all ListingTables occurances which didn't specify that key
attribute.
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Since the fourth commit makes it mandatory, there should be a follow-up PR that drops the fallback to rowIndex. However, that doesn't need to block this PR (and hence the release). Thanks!

// We need the following because of: https://github.com/patternfly/patternfly-react/issues/3090
if (props.cells.some(cell => typeof (cell.title) != 'string' || cell.title.toLowerCase() == 'id' || !cell.title))
tableBodyProps.rowKey = ({ rowData, rowIndex }) => rowIndex;
const tableBodyProps = { rowKey: ({ rowData, rowIndex }) => (rowData.props && rowData.props.key) ? rowData.props.key : rowIndex };
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather not put a fallback here. rowIndex is wrong, and I'd rather have a React warning about a missing key, so that the issue is not silently covered.

@martinpitt martinpitt merged commit 11bd2c0 into cockpit-project:master Feb 5, 2020
martinpitt pushed a commit that referenced this pull request Feb 5, 2020
…gTable

A consumer of ListingTable component can now pass a unique key to the `props`
object of each row, which will be then internally used by React as the
row's key.
Start using this property for the Tables in Hardware Info page, so that
we can drop the workaround for wrong key assignment in the ListingTable
implementation.

Closes #13488
@KKoukiou KKoukiou deleted the fix-table-keys branch February 6, 2020 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker Targetted for next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants