Browse Source

fix: chat UI baseline fixes: a lone severity mark in inline code outside a code block shows as the severity chip; an update's Details drops facts whose label is also a change, so a changed field is not listed twice; the entity details page follows the chat's changes to the open record (reloads when not editing, keeps the edits with the Reload notice when editing); the colour question's custom colour opens the system picker (a hidden input type=color under the eyedropper, as in the design repo) instead of the color picker panel

pull/16859/head
Igor Kulikov 3 days ago
parent
commit
86e4ca14d3
  1. 6
      ui-ngx/src/app/modules/home/components/ai/ai-action-line.component.ts
  2. 12
      ui-ngx/src/app/modules/home/components/ai/ai-color-field.component.html
  3. 41
      ui-ngx/src/app/modules/home/components/ai/ai-color-field.component.ts
  4. 7
      ui-ngx/src/app/modules/home/components/ai/ai-references.ts
  5. 14
      ui-ngx/src/app/modules/home/components/entity/entity-details-page.component.ts
  6. 17
      ui-ngx/src/theme/ai-theme.scss

6
ui-ngx/src/app/modules/home/components/ai/ai-action-line.component.ts

@ -183,8 +183,12 @@ export class AiActionLineComponent {
const facts = this.facts();
const stages = this.action().stages ?? [];
const done = this.action().status === 'SUCCESS' && this.action().progress ? [...stages, this.action().progress] : stages;
const labelOf = (fact: AiDetailFact) => (fact.raw ? fact.label : this.translate.instant(fact.label) as string).trim().toLowerCase();
const changed = new Set(facts.filter(fact => fact.change).map(labelOf));
const own = changed.size ? view.blocks.map(block => block.type === 'facts' ? {...block, rows: block.rows.filter(fact => !changed.has(labelOf(fact)))} : block)
.filter(block => block.type !== 'facts' || block.rows.length) : view.blocks;
const blocks = [...(done.length ? [{type: 'list' as const, label: {key: 'ai-assistant.detail.stages'}, rows: done}] : []),
...view.blocks, ...(facts.length ? [{type: 'facts' as const, rows: facts}] : [])];
...own, ...(facts.length ? [{type: 'facts' as const, rows: facts}] : [])];
return {...view, blocks};
});

12
ui-ngx/src/app/modules/home/components/ai/ai-color-field.component.html

@ -30,10 +30,14 @@
[value]="digits()" [disabled]="disabled()" [attr.aria-invalid]="wrong() || null"
[attr.aria-label]="'ai-assistant.question.hex-label' | translate: {question: question().question, label: ('ai-assistant.question.other-color-short' | translate)}"
(input)="typeHex(hexInput)" (blur)="checkHex(hexInput)" (keydown.enter)="hexEnter($event, hexInput)">
<button mat-icon-button type="button" [disabled]="disabled()"
[matTooltip]="'ai-assistant.question.pick-color' | translate" matTooltipPosition="above"
[attr.aria-label]="'ai-assistant.question.pick-color' | translate"
(click)="openPicker($any($event.currentTarget), hexInput)"><mat-icon>colorize</mat-icon></button>
<span class="k-hexf-pick">
<button mat-icon-button type="button" [disabled]="disabled()"
[matTooltip]="'ai-assistant.question.pick-color' | translate" matTooltipPosition="above"
[attr.aria-label]="'ai-assistant.question.pick-color' | translate"
(click)="openPicker(picker, hexInput)"><mat-icon>colorize</mat-icon></button>
<input #picker type="color" tabindex="-1" aria-hidden="true" [value]="hex() ?? '#000000'"
(input)="pickColor(picker, hexInput)">
</span>
</span>
</div>
@if (wrong()) {

41
ui-ngx/src/app/modules/home/components/ai/ai-color-field.component.ts

@ -1,10 +1,7 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, ElementRef, inject, input, model, output, Renderer2, signal, ViewContainerRef } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, ElementRef, inject, input, model, output, signal } from '@angular/core';
import { AiQuestion } from '@shared/models/solution-creator.models';
import { TbPopoverService } from '@shared/components/popover.service';
import { ColorPickerPanelComponent } from '@shared/components/color-picker/color-picker-panel.component';
import tinycolor from 'tinycolor2';
import { aiColorOf, aiHexOf, aiIsFree } from '@home/components/ai/ai-question.models';
export function aiColorReady(question: AiQuestion, value: string): boolean {
@ -29,9 +26,6 @@ export class AiColorFieldComponent {
enter = output<Event>();
private elementRef: ElementRef<HTMLElement> = inject(ElementRef);
private popoverService = inject(TbPopoverService);
private renderer = inject(Renderer2);
private viewContainerRef = inject(ViewContainerRef);
readonly colorOf = aiColorOf;
readonly wrong = signal(false);
@ -81,31 +75,20 @@ export class AiColorFieldComponent {
}
}
openPicker(trigger: HTMLElement, field: HTMLInputElement): void {
openPicker(picker: HTMLInputElement, field: HTMLInputElement): void {
if (this.disabled()) {
return;
}
if (this.popoverService.hasPopover(trigger)) {
this.popoverService.hidePopover(trigger);
return;
picker.value = aiHexOf(field.value) ?? '#000000';
try {
picker.showPicker();
} catch {
picker.click();
}
const popover = this.popoverService.displayPopover({
trigger,
renderer: this.renderer,
hostView: this.viewContainerRef,
componentType: ColorPickerPanelComponent,
preferredPlacement: ['bottomLeft', 'bottom', 'topLeft', 'top'],
context: {color: this.hex() ?? '#305680', disableAlpha: true, colorCancelButton: true},
showCloseButton: false,
popoverContentStyle: {padding: '12px 4px 12px 12px'},
isModal: true
});
popover.tbComponentRef.instance.popover = popover;
popover.tbComponentRef.instance.colorSelected.subscribe((color: string) => {
popover.hide();
field.value = tinycolor(color).toHex().toUpperCase();
this.typeHex(field);
});
popover.tbComponentRef.instance.colorCancelDialog.subscribe(() => popover.hide());
}
pickColor(picker: HTMLInputElement, field: HTMLInputElement): void {
field.value = picker.value.slice(1).toUpperCase();
this.typeHex(field);
}
}

7
ui-ngx/src/app/modules/home/components/ai/ai-references.ts

@ -236,6 +236,13 @@ function replaceMatches(node: Text, pattern: RegExp, chip: (match: RegExpExecArr
export function decorateSeverities(root: HTMLElement, severities: string[] | undefined, label: (severity: string) => string): void {
if (aiHasSeverityMarks(root.textContent ?? '')) {
const lone = new RegExp('^\\s*' + SEVERITY_MARK.source + '\\s*$');
root.querySelectorAll('code').forEach(code => {
const match = !code.closest('pre') ? lone.exec(code.textContent ?? '') : null;
if (match) {
code.replaceWith(severityChip(match[1], label));
}
});
textNodes(root, MARK_SKIP).forEach(node => replaceMatches(node, SEVERITY_MARK, match => severityChip(match[1], label)));
decorateAlarmTables(root);
return;

14
ui-ngx/src/app/modules/home/components/entity/entity-details-page.component.ts

@ -97,6 +97,20 @@ export class EntityDetailsPageComponent extends EntityDetailsPanelComponent impl
this.reload();
}
}));
this.subscriptions.push(this.panelService.updatedData$.subscribe(affected => {
const id = this.currentEntityId?.id;
if (!id || !affected.some(entityId => entityId.id === id)) {
return;
}
if (this.isEdit) {
this.panelService.keepEdits('entity', () => {
this.onToggleDetailsEditMode();
this.reload();
});
} else {
this.reload();
}
}));
this.subscriptions.push(this.route.paramMap.subscribe( paramMap => {
if (this.entitiesTableConfig) {
const entityType = this.entitiesTableConfig.entityType;

17
ui-ngx/src/theme/ai-theme.scss

@ -4727,6 +4727,23 @@ cursor: pointer;
}
}
.k-ask .k-hexf-pick {
position: relative;
display: inline-flex;
> input[type="color"] {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
opacity: 0;
pointer-events: none;
}
}
.k-ask .k-hexf-hash {
font-family: var(--tb-mono);
font-size: var(--chat-code);

Loading…
Cancel
Save