Skip to content

Add conceptset preview#2792

Merged
chrisknoll merged 6 commits intomasterfrom
add_conceptset_preview
Jan 27, 2023
Merged

Add conceptset preview#2792
chrisknoll merged 6 commits intomasterfrom
add_conceptset_preview

Conversation

@anton-abushkevich
Copy link
Contributor

Resolves #2791

Copy link
Collaborator

@chrisknoll chrisknoll left a comment

Choose a reason for hiding this comment

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

When I bring up the preview, and change some of the existing elements in the preview, but then click 'cancel', the existing elements that I changed remain changed.

Should the preview use a 'copy' of the concept set expression for preview, and then 'apply' copies the copy into the final concept set expression?

@anton-abushkevich
Copy link
Contributor Author

@chrisknoll
You are absolutely right. Please review the last commit - I added copying of existing CS items, instead of including them into the preview by reference.

Please note the ConceptSetItem.js changes. It turns out, that when creating a new object on the basis of existing one, the observable fields isExcluded, includeDescendants and includeMapped were always true, because for example data.isExcluded is a reference to a function, and in the expression data.isExcluded || false interpreted as true, so the result was always true. I fixed it by adding a call to extract the values from there observables, like data.isExcluded && data.isExcluded() || false.

Comment on lines +8 to +10
self.isExcluded = ko.observable(data.isExcluded && data.isExcluded() || false);
self.includeDescendants = ko.observable(data.includeDescendants && data.includeDescendants() || false);
self.includeMapped = ko.observable(data.includeMapped && data.includeMapped() || false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't do this, data should never come in as an observable to the constructor.

If you want to make a 'copy' and re-observe it, take the origional, do a ko.toJS() on the object, then re-instantiate.

ie:

var origional; // this is the existing thing to clone

var clone = new ConceptSetItem(ko.toJS(origional))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, reverted

Comment on lines +540 to +543
const existingConceptsCopy = this.conceptSetStore.current()
? this.conceptSetStore.current().expression.items().map(item => new ConceptSetItem(item))
: [];
this.previewConcepts(itemsToAdd.concat(existingConceptsCopy));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, you would just say:

const existingConceptsCopy = new ConceptSet(ko.toJS(this.conceptSetStore.current()));

Although what i'm suggesting above assumed that the ConceptSetPreview would be working off of a ConceptSet and not an array of ConceptSetItems...which is fine but in that case, I should say that the change is:

const existingConceptsCopy = this.conceptSetStore.current()
				? this.conceptSetStore.current().expression.items().map(item => new ConceptSetItem(ko.toJS(item)))
				: [];

And then, when the 'Apply' button is clicked in the preview editor, that will overwrite this.conceptSetStore.current() with the new state of the ConceptSetItems.

But, overall, you have the right approach: you need to clone the existing concept set for the user to modify, and only 'commit' the change when they click 'Apply' and discard those changes (ie: do nothing) if they cancel.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note, that last part (where when the click is made, the finalized change is saved back to the current concept set...if we're working off a clone, doesn't the changes made to the clone need to propagate tack to the object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.
Cloned concepts are concatenated with selected in the search results. They all stored in this.previewConcepts() and passed to current concept set in the addPreviewConcepts() method.

@chrisknoll
Copy link
Collaborator

chrisknoll commented Dec 22, 2022

The onPreview param is only being set in search.js but if you use the preview button within a concept set editor, you get an error.

My concern here is that the preview behavior seems to be standard across any context (show a modal with the concept set editor with the clone) so could this behavior be embedded inside the ConceptAddBox component?

If it makes sense to have the component hosting the ConceptAddBox component provide their own impelementation of 'onPreview' then what you have works, but I was just curious if there will be a need to have context-specific implementations. Your implementation does provide that flexiblity, but it does mean we need to make sure that search, included concept, source concept tabs all provide a handler for onPreview param.

@anton-abushkevich
Copy link
Contributor Author

@chrisknoll
Do you think we need the preview in places other than the Search page? If yes, than sure - I can move preview handling into the ConceptAddBox or make some wrapper around it and move preview functionality there. For now I added a check - the Preview button is hidden if no preview handler provided.

Also I fixed multiple CS stores behavior - please review.

@anthonysena
Copy link
Collaborator

@anton-abushkevich from discussion today on the Atlas WG, we feel that having such a concept set preview would be useful wherever we work with Concept Sets in the user interface. So if we could modify this PR to have this capability, that would be a great addition to this enhancement.

@chrisknoll chrisknoll merged commit 582571e into master Jan 27, 2023
@delete-merged-branch delete-merged-branch bot deleted the add_conceptset_preview branch January 27, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Concept Set preview

3 participants