Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
computed: {
...mapGetters(['clipboardRootId']),
...mapState('clipboard', ['initializing', 'clipboardNodesMap']),
...mapState('contentNode', ['contentNodesMap']),
...mapGetters('clipboard', [
'channels',
'selectedNodeIds',
Expand Down Expand Up @@ -248,13 +249,19 @@
topicAndResourceCount() {
let topicCount = 0;
let resourceCount = 0;
const contentNodesValues = Object.values(this.contentNodesMap);
this.selectedNodeIds.forEach(id => {
const kind = this.clipboardNodesMap[id]?.kind;
if (kind === 'topic' || !kind) {
// Increment topicCount if kind is "topic" or not set
const node = this.clipboardNodesMap[id];
let kind = node?.kind;
// Check contentNodesMap for node kind if missing in clipboardNodesMap
if (!kind && node?.source_node_id) {
const contentNode = contentNodesValues.find(n => n.node_id === node.source_node_id);
kind = contentNode?.kind;
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking question: did you find that the ?. was necessary here because kind and/or source_node_id was missing on some contents or was it to just avoid unhandled errors just in case?

I ask because if we should expect kind on every contentNode (which I think we should?) then using the ?. might result in hard-to-debug issues when it isn't because it'll just count broken nodes as "resources" in any case here.

It's not crucial here, but in the if/else below it might be worth making the second condition like this (shortened for GH formatting).

if(kind === 'topic) { topicCount++  }
else if (kind) { resourceCount++ }  // it's not undefined or null, so we know it's a non-topic resource
else { console.error("`kind` missing from content...")  }

But, again, this only really matters if we should be able to expect kind to always be defined in this context -- which may not be the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we should be able to expect kind on every contentNode, the ? is in place to avoid any potential errors, but you are right about potential difficulties with debugging so I will make this change.

}
if (kind === 'topic') {
topicCount++;
} else {
// Increment resourceCount for any other kind
resourceCount++;
}
});
Expand Down