Skip to content

Commit ae65f49

Browse files
Googlercopybara-github
authored andcommitted
Support setting the node state icon and background colors.
PiperOrigin-RevId: 833773611
1 parent 96b4b12 commit ae65f49

4 files changed

Lines changed: 91 additions & 3 deletions

File tree

src/app/node.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,62 @@ describe('DAG Node', () => {
141141
expect(createGroup).not.toThrow();
142142
});
143143

144+
it('Allows overriding the background color for a node state badge',
145+
fakeAsync(async () => {
146+
const customBgColor = 'rgb(128, 0, 128)';
147+
const node = new DagNode('c', 'execution', 'FAILED', {
148+
stateBgColor: customBgColor,
149+
});
150+
fixture.componentInstance.fakeNode = node;
151+
152+
const stateElement = await harness.nodeStateElement();
153+
const style = await stateElement.getAttribute('style');
154+
expect(style).toContain(`background: ${customBgColor}`);
155+
}));
156+
157+
it('Allows overriding the background color for a group state badge',
158+
fakeAsync(async () => {
159+
const customBgColor = 'rgb(128, 0, 128)';
160+
const group = new DagGroup('group-id', [], [], [], 'FAILED', {
161+
stateBgColor: customBgColor,
162+
hasControlNode: true,
163+
});
164+
fixture.componentInstance.fakeNode = group.generateControlNode()!;
165+
fixture.detectChanges();
166+
167+
const stateElement = await harness.nodeStateElement();
168+
const style = await stateElement.getAttribute('style');
169+
expect(style).toContain(`background: ${customBgColor}`);
170+
}));
171+
172+
it('Allows overriding the state icon color for a node',
173+
fakeAsync(async () => {
174+
const customStateIconColor = 'rgb(128, 0, 128)';
175+
const node = new DagNode('c', 'execution', 'FAILED', {
176+
stateIconColor: customStateIconColor,
177+
});
178+
fixture.componentInstance.fakeNode = node;
179+
180+
const stateElement = await harness.nodeStateElement();
181+
const style = await stateElement.getAttribute('style');
182+
expect(style).toContain(`color: ${customStateIconColor}`);
183+
}));
184+
185+
it('Allows overriding the state icon color for a group',
186+
fakeAsync(async () => {
187+
const customStateIconColor = 'rgb(128, 0, 128)';
188+
const group = new DagGroup('group-id', [], [], [], 'FAILED', {
189+
stateIconColor: customStateIconColor,
190+
hasControlNode: true,
191+
});
192+
fixture.componentInstance.fakeNode = group.generateControlNode()!;
193+
fixture.detectChanges();
194+
195+
const stateElement = await harness.nodeStateElement();
196+
const style = await stateElement.getAttribute('style');
197+
expect(style).toContain(`color: ${customStateIconColor}`);
198+
}));
199+
144200
});
145201

146202
describe('Internals', () => {

src/app/node.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ export class DagNodeEl implements OnInit, OnDestroy {
214214

215215
getNodeStateColor(node: DagNode) {
216216
const {state, icon} = node;
217-
return isNoState(state) ?
218-
icon!.color :
217+
if (isNoState(state)) {
218+
return icon!.color;
219+
}
220+
return node.stateIconColor ||
219221
this.fetchIcon(this.iconForState(state), 'color');
220222
}
221223

@@ -227,7 +229,8 @@ export class DagNodeEl implements OnInit, OnDestroy {
227229
icon ? fetchIcon(icon, key) : '';
228230

229231
isNoState = isNoState;
230-
bgForState = (state: NodeState) => bgForState(state, this.theme);
232+
bgForState = (state: NodeState) =>
233+
this.node?.stateBgColor || bgForState(state, this.theme);
231234
iconForState = (state: NodeState) => iconForState(state, this.theme);
232235
isTextIcon = isTextIcon;
233236
convertStateToRuntime = convertStateToRuntime;

src/app/node_spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ export class DagGroup implements
267267
conditionalQuery = '';
268268
callout: NodeCallout = '';
269269
modifiers = new Set<NodeModifier>();
270+
stateBgColor = '';
271+
stateIconColor = '';
270272
stateTooltip = '';
271273
iconTooltip = '';
272274
subType?: unknown;
@@ -296,6 +298,8 @@ export class DagGroup implements
296298
hideControlNodeShadow = false,
297299
customControlNode = undefined,
298300
expanded = false,
301+
stateBgColor = '',
302+
stateIconColor = '',
299303
stateTooltip = '',
300304
iconTooltip = '',
301305
treatAsLoop = false,
@@ -323,6 +327,8 @@ export class DagGroup implements
323327
hideControlNodeShadow,
324328
customControlNode,
325329
expanded,
330+
stateBgColor,
331+
stateIconColor,
326332
stateTooltip,
327333
iconTooltip,
328334
subType,
@@ -504,6 +510,8 @@ export interface GraphSpec {
504510
export interface DagNodeMeta {
505511
displayName?: string;
506512
state?: NodeState;
513+
stateBgColor?: string;
514+
stateIconColor?: string;
507515
stateTooltip?: string;
508516
iconTooltip?: string;
509517
/**
@@ -633,6 +641,8 @@ export class DagNode implements
633641
type: NodeType = 'execution';
634642
subType: unknown;
635643
state: NodeState = 'NO_STATE_STATIC';
644+
stateBgColor: string = '';
645+
stateIconColor: string = '';
636646
stateTooltip: string = '';
637647
iconTooltip: string = '';
638648
conditionalQuery = '';
@@ -663,6 +673,8 @@ export class DagNode implements
663673
conditionalQuery = '',
664674
modifiers = new Set<NodeModifier>(),
665675
callout = '',
676+
stateBgColor = '',
677+
stateIconColor = '',
666678
stateTooltip = '',
667679
iconTooltip = '',
668680
subType = undefined,
@@ -673,6 +685,8 @@ export class DagNode implements
673685
id,
674686
type,
675687
state,
688+
stateBgColor,
689+
stateIconColor,
676690
stateTooltip,
677691
iconTooltip,
678692
icon: icon ? {...icon} : icon,
@@ -775,6 +789,8 @@ export class DagNode implements
775789
displayName,
776790
icon,
777791
state,
792+
stateBgColor,
793+
stateIconColor,
778794
stateTooltip,
779795
iconTooltip,
780796
options,
@@ -804,6 +820,8 @@ export class DagNode implements
804820
conditionalQuery,
805821
modifiers,
806822
callout,
823+
stateBgColor,
824+
stateIconColor,
807825
stateTooltip,
808826
iconTooltip,
809827
subType,
@@ -840,6 +858,8 @@ export class DagNode implements
840858
expanded,
841859
displayName,
842860
groupLabel,
861+
stateBgColor,
862+
stateIconColor,
843863
stateTooltip,
844864
iconTooltip,
845865
subType,
@@ -866,6 +886,8 @@ export class DagNode implements
866886
callout,
867887
displayName,
868888
groupLabel,
889+
stateBgColor,
890+
stateIconColor,
869891
stateTooltip,
870892
iconTooltip,
871893
subType,

src/app/test_resources/node_harness.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export class DagNodeElHarness extends ComponentHarness {
4747
MatIconHarness.with({selector: '.icon-space .icon.right .mat-icon'}))();
4848
}
4949

50+
/**
51+
* Returns the `<div>` element for the node state.
52+
*/
53+
async nodeStateElement(): Promise<TestElement> {
54+
return this.locatorFor('.icon-space.state')();
55+
}
56+
5057
/** Is the icon for the current node Text instead of SVG */
5158
async hasTextIcon() {
5259
const element =

0 commit comments

Comments
 (0)