Skip to content

Commit

Permalink
👉 **added**: ability to not activate NoInput and NoMatch connector if…
Browse files Browse the repository at this point in the history
… commands inside cds-action-replyv2 not contains buttons
  • Loading branch information
Gabriele Panico committed Jun 12, 2024
1 parent c895144 commit a120e38
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
[idAction] = "idAction"
[action] = "action"
[previewMode] = "previewMode"
[handleActionChanges]="eventActionChanges.asObservable()"
(updateAndSaveAction) = onUpdateAndSaveAction($event)
(changeActionReply) = onChangeActionReply($event)
(onConnectorChange)= onConnectorChangeReply($event)>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IntentService } from '../../../../../../services/intent.service';
import { ConnectorService } from '../../../../../../services/connector.service';
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
import { Subject } from 'rxjs';


@Component({
Expand All @@ -27,6 +28,8 @@ export class CdsActionReplyV2Component implements OnInit {
@Output() updateAndSaveAction = new EventEmitter();
@Output() onConnectorChange = new EventEmitter<{type: 'create' | 'delete', fromId: string, toId: string}>()

eventActionChanges: Subject<ActionReplyV2> = new Subject<ActionReplyV2>();

// idIntentSelected: string;
idAction: string;

Expand Down Expand Up @@ -346,7 +349,8 @@ export class CdsActionReplyV2Component implements OnInit {
event.buttons.splice(event.index, 1);
var intentId = this.idAction.substring(0, this.idAction.indexOf('/'));
this.connectorService.deleteConnectorFromAction(intentId, button.__idConnector);
this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.ACTION, element: this.action});
const element = {type: TYPE_UPDATE_ACTION.ACTION, element: this.action};
this.onUpdateAndSaveAction(element);
}


Expand All @@ -358,6 +362,7 @@ export class CdsActionReplyV2Component implements OnInit {
public async onUpdateAndSaveAction(element) {
this.logger.log('[cds-action-reply] onUpdateAndSaveAction:::: ', this.action, element);
// this.connectorService.updateConnector(this.intentSelected.intent_id);
this.eventActionChanges.next(this.action)
this.updateAndSaveAction.emit(this.action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<cds-connector class="button-connector"
[idConnector] = "idConnectorNoInput"
[idConnection] = "idConnectionNoInput"
[isConnected] = "isConnectedNoInput">
[isConnected] = "isConnectedNoInput"
[isDisabled] = "isConnectorInputDisabled">
</cds-connector>
</div>

Expand All @@ -36,7 +37,8 @@
<cds-connector class="button-connector"
[idConnector] = "idConnectorNoMatch"
[idConnection] = "idConnectionNoMatch"
[isConnected] = "isConnectedNoMatch">
[isConnected] = "isConnectedNoMatch"
[isDisabled] = "isConnectorMatchDisabled">
</cds-connector>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Subscription } from 'rxjs/internal/Subscription';
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
import { secondsToDhms } from 'src/app/utils/util';
import { Observable } from 'rxjs';

@Component({
selector: 'cds-action-reply-settings',
Expand All @@ -27,6 +28,7 @@ export class CdsActionReplySettingsComponent implements OnInit {
@Input() action: ActionReplyV2;
@Input() index: number;
@Input() previewMode: boolean = true;
@Input() handleActionChanges: Observable<ActionReplyV2>
@Output() onConnectorChange = new EventEmitter<{type: 'create' | 'delete', fromId: string, toId: string}>()

listOfIntents: Array<{name: string, value: string, icon?:string}>;
Expand All @@ -39,6 +41,8 @@ export class CdsActionReplySettingsComponent implements OnInit {
idConnectionNoInput: string;
isConnectedNoMatch: boolean = false;
isConnectedNoInput: boolean = false;
isConnectorInputDisabled: boolean = false;
isConnectorMatchDisabled: boolean = false;
connector: any;
private subscriptionChangedConnector: Subscription;

Expand All @@ -61,6 +65,12 @@ export class CdsActionReplySettingsComponent implements OnInit {
}
});
this.initializeConnector();

this.handleActionChanges.subscribe(()=> this.checkButtonsInCommands())
}

ngOnChanges() {
this.logger.debug("[ACTION REPLY SETTINGS] onChangessss: ", this.action);
}

/** */
Expand All @@ -80,6 +90,7 @@ export class CdsActionReplySettingsComponent implements OnInit {
this.idConnectorNoMatch = this.idAction + '/noMatch';
this.listOfIntents = this.intentService.getListOfIntents();
this.checkConnectionStatus();
this.checkButtonsInCommands();
}

private updateConnector(){
Expand Down Expand Up @@ -172,7 +183,25 @@ export class CdsActionReplySettingsComponent implements OnInit {
}

// PRIVATE FUNCTIONS //

private checkButtonsInCommands(){
let commands = this.action.attributes.commands
if(commands && commands.length > 0){
let messages = commands.filter(command => command.type === TYPE_COMMAND.MESSAGE)
messages.forEach(el => {
if(el.message.attributes.attachment && el.message.attributes.attachment.buttons && el.message.attributes.attachment.buttons.length > 0){
this.isConnectorInputDisabled = false;
this.isConnectorMatchDisabled = false;
return;

}else{
//CASE: no buttons in message element
this.isConnectorInputDisabled = true;
this.isConnectorMatchDisabled = true;
return;
}
})
}
}

// EVENT FUNCTIONS //

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="block-line">
<!-- <svg shape-rendering="geometricPrecision" class="pre-line"><path d="M 0 4 L 13 4" class="sc-eGiIjr kEjIty sc-bTQVhO kjXfPj"></path></svg> -->
</div>
<div class="block-connector">
<div class="block-connector" [attr.disabled]="isDisabled">
<div connector *ngIf="!isConnected" [id]="idConnector" class="point-connector-empty tds_connectable"></div>
<div connector *ngIf="isConnected" [id]="idConnector" [attr.idConnection]="idConnection" class="point-connector"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
align-items: center;
-webkit-box-pack: center;
justify-content: center;

&[disabled = "true"]{
cursor: not-allowed !important;
opacity: 0.6;

.point-connector,
.point-connector-empty,
.point-connector-empty:hover{
cursor: not-allowed !important;
pointer-events:none;
}

}
// cursor: copy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class CdsConnectorComponent implements OnInit {
@Input() idConnector: string;
@Input() idConnection: string;
@Input() isConnected: boolean;
@Input() isDisabled: boolean;

constructor() { }

Expand Down

0 comments on commit a120e38

Please sign in to comment.