Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorting to workflow next states (comma-list, menu) #2983

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -106,7 +106,7 @@ <h2 *ngIf="workflow">
<div class="inner-table">
<div *ngIf="!state.next_states.length">-</div>
<div *ngIf="state.next_states.length">
<os-comma-separated-listing [list]="state.next_states">
<os-comma-separated-listing [list]="sortedNextStates(state)">
Copy link
Member

@bastianjoel bastianjoel Nov 10, 2023

Choose a reason for hiding this comment

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

This can cause performance issues because this gets calculated on every change detection cycle and the underlying method performs a sort.

However, because the next states might be quite small in most cases I approve.

<ng-template let-next>{{ next.name }}</ng-template>
</os-comma-separated-listing>
</div>
Expand Down Expand Up @@ -217,7 +217,7 @@ <h1 mat-dialog-title>
<!-- select next states menu -->
<mat-menu matMenuContent #nextStatesMenu="matMenu">
<ng-template let-state="state" matMenuContent>
<div *ngFor="let nextState of workflow.states">
<div *ngFor="let nextState of getWorkflowStates()">
<button mat-menu-item *ngIf="nextState.name !== state.name" (click)="onSetNextState(nextState, state)">
<mat-icon *ngIf="state.next_state_ids?.includes(nextState.id)">check</mat-icon>
<span>{{ nextState.name }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ Note: Does not affect the visibility of change recommendations.`
return (<any>state)[perm.selector];
}

public sortedNextStates(state: ViewMotionState): ViewMotionState[] {
return state.next_states.sort((a, b) => a.weight - b.weight);
}

private async deleteWorkflowState(state: ViewMotionState): Promise<void> {
const title = this.translate.instant(`Are you sure you want to delete this state?`);
const content = `${state.name}`;
Expand Down