diff --git a/__tests__/Snapshottest/UIOutputComparisonTests.tsx b/__tests__/Snapshottest/UIOutputComparisonTests.tsx index 819928ff..30ba43c2 100644 --- a/__tests__/Snapshottest/UIOutputComparisonTests.tsx +++ b/__tests__/Snapshottest/UIOutputComparisonTests.tsx @@ -19,10 +19,11 @@ describe("LibraryContainer", function () { let data = createLibraryItem(ItemData); // Create "LibraryContainer" to pass as an argument for creation of "LibraryItem" - const libContainer = LibraryEntryPoint.CreateLibraryController(); + let libcontroller = LibraryEntryPoint.CreateLibraryController() + let libContainer = mount(libcontroller.createLibraryContainer()) // Creation of LibraryItem component - const libraryItemComponent = ; + const libraryItemComponent = ; it("Test UI rendering of single component of Library Item", function () { // "LibraryItem" with Shallow rendering to testing component as a unit. diff --git a/__tests__/Snapshottest/__snapshots__/UIOutputComparisonTests.tsx.snap b/__tests__/Snapshottest/__snapshots__/UIOutputComparisonTests.tsx.snap index d2b1ee9b..770efc91 100644 --- a/__tests__/Snapshottest/__snapshots__/UIOutputComparisonTests.tsx.snap +++ b/__tests__/Snapshottest/__snapshots__/UIOutputComparisonTests.tsx.snap @@ -12,6 +12,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components "contextData": "", "description": "", "expanded": false, + "hiddenInWorkspaceContext": false, "iconUrl": "", "itemType": "category", "keywords": [ @@ -29,6 +30,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components "contextData": "", "description": "", "expanded": false, + "hiddenInWorkspaceContext": false, "iconUrl": "", "itemType": "category", "keywords": [ @@ -45,6 +47,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components "contextData": "", "description": "", "expanded": false, + "hiddenInWorkspaceContext": false, "iconUrl": "", "itemType": "none", "keywords": [ @@ -59,35 +62,47 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components } } libraryContainer={ - LibraryController { - "DefaultSectionName": "default", - "FilterCategoryEventName": "filterCategoryChange", - "ItemClickedEventName": "itemClicked", - "ItemMouseEnterEventName": "itemMouseEnter", - "ItemMouseLeaveEventName": "itemMouseLeave", - "ItemSummaryExpandedEventName": "itemSummaryExpanded", - "MiscSectionName": "Miscellaneous", - "RefreshLibraryViewRequestName": "refreshLibraryView", - "SearchTextUpdatedEventName": "searchTextUpdated", - "SectionIconClickedEventName": "sectionIconClicked", - "createLibraryByElementId": [Function], - "createLibraryContainer": [Function], - "on": [Function], - "raiseEvent": [Function], - "reactor": Reactor { - "events": [], - }, - "refreshLibraryView": [Function], - "refreshLibraryViewHandler": null, - "registerRequestHandler": [Function], - "request": [Function], - "requestHandler": {}, - "searchLibraryItemsHandler": null, - "setLayoutSpecsJson": [Function], - "setLayoutSpecsJsonHandler": null, - "setLoadedTypesJson": [Function], - "setLoadedTypesJsonHandler": null, - } + +
+ This is LibraryContainer +
+
} showItemSummary={false} > diff --git a/__tests__/UITests.tsx b/__tests__/UITests.tsx index 758ed900..bd3e1d71 100644 --- a/__tests__/UITests.tsx +++ b/__tests__/UITests.tsx @@ -106,6 +106,7 @@ describe("LibraryContainer UI", function () { }; libController = LibraryEntryPoint.CreateLibraryController(); + libContainer = mount(libController.createLibraryContainer()) }); it("should recognize mouse click event and change expand state", function () { @@ -117,7 +118,7 @@ describe("LibraryContainer UI", function () { // If you are testing full React components, // mount is used to do rendering and test actions are simulated on mounted html - let libraryItem = mount(); + let libraryItem = mount(); expect(libraryItem).to.have.lengthOf(1); expect(libraryItem.props().data.childItems).to.have.lengthOf(2); @@ -137,7 +138,7 @@ describe("LibraryContainer UI", function () { let data = createLibraryItem(ItemData); //pass a callback which if called will end the test - let libraryItem = mount( { done() }} />); + let libraryItem = mount( { done() }} />); let header = libraryItem.find(('div.LibraryItemHeader')).at(0);// the state of LibraryItem is changed when clicking on header expect(header).to.have.lengthOf(1); // verify that there is a header diff --git a/docs/RawTypeData.json b/docs/RawTypeData.json index 892eb277..52d0f7f0 100644 --- a/docs/RawTypeData.json +++ b/docs/RawTypeData.json @@ -18,7 +18,8 @@ "itemType": "action", "keywords": "Dynamo.Nodes.Symbol, Input, variable, argument, parameter", "weight": 0, - "description": "A function parameter, use with custom nodes.\n\nYou can specify the type and default value for parameter. E.g.,\n\ninput : var[]..[]\nvalue : bool = false" + "description": "A function parameter, use with custom nodes.\n\nYou can specify the type and default value for parameter. E.g.,\n\ninput : var[]..[]\nvalue : bool = false", + "hiddenInWorkspaceContext":true }, { "fullyQualifiedName": "Core.Input.Output", @@ -28,7 +29,8 @@ "itemType": "action", "keywords": "Dynamo.Nodes.Output, Output", "weight": 0, - "description": "A function output, use with custom nodes" + "description": "A function output, use with custom nodes", + "hiddenInWorkspaceContext":true }, { "fullyQualifiedName": "Core.Units.Convert Between Units", diff --git a/src/LibraryUtilities.ts b/src/LibraryUtilities.ts index 29fb3e3e..53d6b989 100644 --- a/src/LibraryUtilities.ts +++ b/src/LibraryUtilities.ts @@ -17,6 +17,7 @@ export class TypeListNode { description: string = ""; processed: boolean = false; weight: number = 0; + hiddenInWorkspaceContext:boolean constructor(data: any) { this.fullyQualifiedName = data.fullyQualifiedName; @@ -27,6 +28,7 @@ export class TypeListNode { this.parameters = data.parameters; this.description = data.description; this.weight = data.weight; + this.hiddenInWorkspaceContext = data.hiddenInWorkspaceContext; } } @@ -34,6 +36,7 @@ export interface IncludeInfo { path: string; iconUrl?: string; inclusive?: boolean; + hiddenInWorkspaceContext?:boolean } export class IncludeItemPair { @@ -91,6 +94,7 @@ export class ItemData { childItems: ItemData[] = []; pathToItem: ItemData[] = []; weight: number = 0; + hiddenInWorkspaceContext:boolean = false constructor(public text: string) { this.keywords.push(text ? text.toLowerCase() : text); @@ -118,6 +122,7 @@ export class ItemData { this.keywords.push(keyword.toLowerCase().replace(/ /g, '')); }); this.keywords.push(typeListNode.fullyQualifiedName.toLowerCase().replace(/ /g, '')); + this.hiddenInWorkspaceContext = typeListNode.hiddenInWorkspaceContext; } appendChild(childItem: ItemData) { diff --git a/src/SharedTypes.ts b/src/SharedTypes.ts new file mode 100644 index 00000000..c744cb9e --- /dev/null +++ b/src/SharedTypes.ts @@ -0,0 +1,7 @@ + +/** + * Hosting contexts for the library. These represent + * Dynamo home and custom workspaces, none is the default. + */ +export enum HostingContextType { home ="home", custom = "custom", none = "none"} + diff --git a/src/components/LibraryContainer.tsx b/src/components/LibraryContainer.tsx index 7c7272e8..83029e8b 100644 --- a/src/components/LibraryContainer.tsx +++ b/src/components/LibraryContainer.tsx @@ -10,6 +10,7 @@ import { Searcher } from "../Searcher"; import { SearchBar, CategoryData } from "./SearchBar"; import { SearchResultItem } from "./SearchResultItem"; import * as ReactDOM from "react-dom"; +import { HostingContextType } from "../SharedTypes"; declare global { interface Window { setTooltipText: any; } @@ -41,6 +42,16 @@ export interface LibraryContainerStates { action: string; query: string; } + /** + * context that the library is currently displayed in, currently used to hide + * some loadedtypes in certain contexts. + */ + hostingContext:HostingContextType + /** + * used to control legacy props overriding state behavior. (see UNSAFE_componentWillMount) + * TODO (get rid of this and the unsafe lifecycle hook while retaining behavior.) + */ + shouldOverrideExpandedState:boolean } export class LibraryContainer extends React.Component { @@ -72,12 +83,13 @@ export class LibraryContainer extends React.Component 0 && !currentlyExpanded && this.props.onItemWillExpand) { this.props.onItemWillExpand(ReactDOM.findDOMNode(this)); } - this.setState({ expanded: !currentlyExpanded }); - //auto expand the coregroup elements //commenting as part of the task : https://jira.autodesk.com/browse/QNTM-2975 // if(this.props.data.itemType === "category" ) { @@ -415,6 +416,10 @@ export class LibraryItem extends React.Component void; @@ -46,8 +47,12 @@ export class SearchResultItem extends React.Component void) | null = null; // This is to make it possible to set an external search handler. // Given a search text, it will call the callback function with search result. @@ -60,6 +62,7 @@ export class LibraryController { this.setLoadedTypesJson = this.setLoadedTypesJson.bind(this); this.setLayoutSpecsJson = this.setLayoutSpecsJson.bind(this); this.refreshLibraryView = this.refreshLibraryView.bind(this); + this.setHostContext = this.setHostContext.bind(this); this.reactor = new Reactor(); } @@ -166,4 +169,16 @@ export class LibraryController { this.refreshLibraryViewHandler(); } } + /** + * Set the host context that the library is being displayed in. + * Some loadedTypes will not be displayed in the home context. + * @param context current host context. + * @returns void + */ + setHostContext(context:HostingContextType):void{ + if(this.setHostContextHandler){ + console.log("set context to",context) + return this.setHostContextHandler(context); + } + } }