<commit_before>﻿
import * as React from 'react'
import { Dic } from '@framework/Globals'
import { TypeContext, StyleOptions, EntityFrame } from '@framework/TypeContext'
import { TypeInfo, getTypeInfo, parseId, GraphExplorer, PropertyRoute, ReadonlyBinding } from '@framework/Reflection'
import * as Navigator from '@framework/Navigator'
import * as Finder from '@framework/Finder'
import * as Operations from '@framework/Operations'
import { EntityPack, Entity, Lite, JavascriptMessage, entityInfo, getToString } from '@framework/Signum.Entities'
import { renderWidgets, renderEmbeddedWidgets, WidgetContext } from '@framework/Frames/Widgets'
import ValidationErrors from '@framework/Frames/ValidationErrors'
import ButtonBar from '@framework/Frames/ButtonBar'
import { CaseActivityEntity, WorkflowEntity, ICaseMainEntity, CaseActivityOperation, CaseActivityQuery, WorkflowMainEntityStrategy } from '../Signum.Entities.Workflow'
import * as WorkflowClient from '../WorkflowClient'

import { UncontrolledDropdown, DropdownItem, DropdownToggle, DropdownMenu, LinkContainer } from '@framework/Components'

export default class WorkflowDropdown extends React.Component<{}, { starts: Array<WorkflowEntity> }>
{
    constructor(props: any) {
        super(props);
        this.state = { starts: [] };
    } 

    componentWillMount() {
        WorkflowClient.API.starts()
            .then(starts => this.setState({ starts }))
            .done();
    }

    static getInboxUrl(): string {
        return WorkflowClient.getDefaultInboxUrl();
    }

    render() {

        return (
            <UncontrolledDropdown className="sf-workflow" id="workflowDropdown" nav inNavbar>
                <DropdownToggle nav caret>
                    {WorkflowEntity.nicePluralName()}
                </DropdownToggle>
                <DropdownMenu style={{ minWidth: "200px" }}>
                    <LinkContainer exact to={WorkflowDropdown.getInboxUrl()}><DropdownItem>{CaseActivityQuery.Inbox.niceName()}</DropdownItem></LinkContainer>
                    {this.state.starts.length > 0 && <DropdownItem divider />}
                    {this.state.starts.length > 0 && <DropdownItem disabled>{JavascriptMessage.create.niceToString()}</DropdownItem>}
                    {this.getStarts().flatMap((kvp, i) => [
                        (kvp.elements.length > 1 && <DropdownItem key={i} disabled>{kvp.elements[0].typeInfo.niceName}</DropdownItem>),
                        ...kvp.elements.map((val, j) =>
                            <LinkContainer key={i + "-" + j} to={`~/workflow/new/${val.workflow.id}/${val.mainEntityStrategy}`}>
                                <DropdownItem>{val.workflow.toStr}{val.mainEntityStrategy == "SelectByUser" ? `(${WorkflowMainEntityStrategy.niceToString(val.mainEntityStrategy)})` : ""}</DropdownItem>
                            </LinkContainer>)
                    ])}
                </DropdownMenu>
            </UncontrolledDropdown>
        );
            }
        
    getStarts() {
        return this.state.starts.flatMap(w => {
            const typeInfo = getTypeInfo(w.mainEntityType!.cleanName);

            if (w.mainEntityStrategy != "Both")
                return [({ workflow: w, typeInfo, mainEntityStrategy: w.mainEntityStrategy! })]
            else
                return [({ workflow: w, typeInfo, mainEntityStrategy: ("CreateNew" as WorkflowMainEntityStrategy) })]
                    .concat([({ workflow: w, typeInfo, mainEntityStrategy: ("SelectByUser" as WorkflowMainEntityStrategy) })]);
        }).groupBy(kvp => kvp.typeInfo.name);
    }
}
<commit_msg>fix when dynamic does not compile and we have workflow based dynamic entities<commit_after>﻿
import * as React from 'react'
import { Dic } from '@framework/Globals'
import { TypeContext, StyleOptions, EntityFrame } from '@framework/TypeContext'
import { TypeInfo, getTypeInfo, parseId, GraphExplorer, PropertyRoute, ReadonlyBinding } from '@framework/Reflection'
import * as Navigator from '@framework/Navigator'
import * as Finder from '@framework/Finder'
import * as Operations from '@framework/Operations'
import { EntityPack, Entity, Lite, JavascriptMessage, entityInfo, getToString } from '@framework/Signum.Entities'
import { renderWidgets, renderEmbeddedWidgets, WidgetContext } from '@framework/Frames/Widgets'
import ValidationErrors from '@framework/Frames/ValidationErrors'
import ButtonBar from '@framework/Frames/ButtonBar'
import { CaseActivityEntity, WorkflowEntity, ICaseMainEntity, CaseActivityOperation, CaseActivityQuery, WorkflowMainEntityStrategy } from '../Signum.Entities.Workflow'
import * as WorkflowClient from '../WorkflowClient'

import { UncontrolledDropdown, DropdownItem, DropdownToggle, DropdownMenu, LinkContainer } from '@framework/Components'

export default class WorkflowDropdown extends React.Component<{}, { starts: Array<WorkflowEntity> }>
{
    constructor(props: any) {
        super(props);
        this.state = { starts: [] };
    } 

    componentWillMount() {
        WorkflowClient.API.starts()
            .then(starts => this.setState({ starts }))
            .done();
    }

    static getInboxUrl(): string {
        return WorkflowClient.getDefaultInboxUrl();
    }

    render() {

        return (
            <UncontrolledDropdown className="sf-workflow" id="workflowDropdown" nav inNavbar>
                <DropdownToggle nav caret>
                    {WorkflowEntity.nicePluralName()}
                </DropdownToggle>
                <DropdownMenu style={{ minWidth: "200px" }}>
                    <LinkContainer exact to={WorkflowDropdown.getInboxUrl()}><DropdownItem>{CaseActivityQuery.Inbox.niceName()}</DropdownItem></LinkContainer>
                    {this.state.starts.length > 0 && <DropdownItem divider />}
                    {this.state.starts.length > 0 && <DropdownItem disabled>{JavascriptMessage.create.niceToString()}</DropdownItem>}
                    {this.state.starts.length > 0 && this.getStarts().flatMap((kvp, i) => [
                        (kvp.elements.length > 1 && <DropdownItem key={i} disabled>{kvp.elements[0].typeInfo.niceName}</DropdownItem>),
                        ...kvp.elements.map((val, j) =>
                            <LinkContainer key={i + "-" + j} to={`~/workflow/new/${val.workflow.id}/${val.mainEntityStrategy}`}>
                                <DropdownItem>{val.workflow.toStr}{val.mainEntityStrategy == "SelectByUser" ? `(${WorkflowMainEntityStrategy.niceToString(val.mainEntityStrategy)})` : ""}</DropdownItem>
                            </LinkContainer>)
                    ])}
                </DropdownMenu>
            </UncontrolledDropdown>
        );
            }
        
    getStarts() {
        return this.state.starts.flatMap(w => {
            const typeInfo = getTypeInfo(w.mainEntityType!.cleanName);

            if (w.mainEntityStrategy != "Both")
                return [({ workflow: w, typeInfo, mainEntityStrategy: w.mainEntityStrategy! })]
            else
                return [({ workflow: w, typeInfo, mainEntityStrategy: ("CreateNew" as WorkflowMainEntityStrategy) })]
                    .concat([({ workflow: w, typeInfo, mainEntityStrategy: ("SelectByUser" as WorkflowMainEntityStrategy) })]);
        }).filter(kvp => !!kvp.typeInfo)
            .groupBy(kvp => kvp.typeInfo.name);
    }
}

{'fraction_non_alphanumeric': 0.12563019484943452, 'fraction_numerical': 0.0020438751873552256, 'mean_word_length': 2.853018372703412, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3954858', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1960, 'n_words': 396}