Skip to content

Commit 3ccb69a

Browse files
Adding context field to widgets. (#23218)
* Adding context field to widgets. * Updating snapshots.
1 parent f9794ac commit 3ccb69a

File tree

10 files changed

+114
-14
lines changed

10 files changed

+114
-14
lines changed

graylog2-server/src/main/java/org/graylog/plugins/views/search/views/WidgetDTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public abstract class WidgetDTO implements ContentPackable<WidgetEntity>, UsesSe
5757
public static final String FIELD_STREAMS = "streams";
5858
public static final String FIELD_STREAM_CATEGORIES = "stream_categories";
5959
public static final String FIELD_DESCRIPTION = "description";
60+
public static final String FIELD_CONTEXT = "context";
6061

6162
@JsonProperty(FIELD_ID)
6263
public abstract String id();
@@ -92,6 +93,10 @@ public abstract class WidgetDTO implements ContentPackable<WidgetEntity>, UsesSe
9293
@Nullable
9394
public abstract String description();
9495

96+
@JsonProperty(FIELD_CONTEXT)
97+
@Nullable
98+
public abstract String context();
99+
95100
public static Builder builder() {
96101
return Builder.builder();
97102
}
@@ -136,6 +141,9 @@ public static abstract class Builder {
136141
@JsonProperty(FIELD_DESCRIPTION)
137142
public abstract Builder description(@Nullable String description);
138143

144+
@JsonProperty(FIELD_CONTEXT)
145+
public abstract Builder context(@Nullable String context);
146+
139147
public abstract WidgetDTO build();
140148

141149
@JsonCreator
@@ -157,6 +165,7 @@ public WidgetEntity toContentPackEntity(EntityDescriptorIds entityDescriptorIds)
157165
final WidgetEntity.Builder builder = WidgetEntity.builder()
158166
.id(this.id())
159167
.description(this.description())
168+
.context(this.context())
160169
.config(this.config())
161170
.filter(this.filter())
162171
.filters(filters().stream().map(filter -> filter.toContentPackEntity(entityDescriptorIds)).toList())

graylog2-server/src/main/java/org/graylog2/contentpacks/model/entities/WidgetEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public abstract class WidgetEntity implements NativeEntityConverter<WidgetDTO> {
8080
public static final String FIELD_STREAMS = "streams";
8181
public static final String FIELD_STREAM_CATEGORIES = "stream_categories";
8282
public static final String FIELD_DESCRIPTION = "description";
83+
public static final String FIELD_CONTEXT = "context";
8384

8485
@JsonProperty(FIELD_ID)
8586
public abstract String id();
@@ -113,6 +114,10 @@ public abstract class WidgetEntity implements NativeEntityConverter<WidgetDTO> {
113114
@Nullable
114115
public abstract String description();
115116

117+
@JsonProperty(FIELD_CONTEXT)
118+
@Nullable
119+
public abstract String context();
120+
116121
public static Builder builder() {
117122
return Builder.builder();
118123
}
@@ -154,6 +159,9 @@ public static abstract class Builder {
154159
@JsonProperty(FIELD_DESCRIPTION)
155160
public abstract Builder description(@Nullable String description);
156161

162+
@JsonProperty(FIELD_CONTEXT)
163+
public abstract Builder context(@Nullable String context);
164+
157165
public abstract WidgetEntity build();
158166

159167
@JsonCreator
@@ -169,6 +177,7 @@ static Builder builder() {
169177
public WidgetDTO toNativeEntity(Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
170178
final WidgetDTO.Builder widgetBuilder = WidgetDTO.builder()
171179
.description(this.description())
180+
.context(this.context())
172181
.config(this.config())
173182
.filter(this.filter())
174183
.filters(filters().stream().map(filter -> filter.toNativeEntity(parameters, nativeEntities)).toList())

graylog2-web-interface/src/views/logic/aggregationbuilder/AggregationWidget.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@ import type { TimeRange } from 'views/logic/queries/Query';
2222
import type { FiltersType } from 'views/types';
2323
import type { QueryString } from 'views/logic/queries/types';
2424

25+
import type { AggregationWidgetConfigJson } from './AggregationWidgetConfig';
2526
import AggregationWidgetConfig from './AggregationWidgetConfig';
2627

2728
import Widget, { widgetAttributesForComparison } from '../widgets/Widget';
2829

30+
type AggregationWidgetJson = {
31+
id: string;
32+
config: AggregationWidgetConfigJson;
33+
filter?: string;
34+
timerange?: TimeRange;
35+
query?: QueryString;
36+
streams?: Array<string>;
37+
stream_categories?: Array<string>;
38+
filters?: FiltersType;
39+
description?: string;
40+
context?: string;
41+
};
2942
export default class AggregationWidget extends Widget {
3043
constructor(
3144
id: string,
@@ -37,6 +50,7 @@ export default class AggregationWidget extends Widget {
3750
streamCategories?: Array<string>,
3851
filters?: FiltersType,
3952
description?: string,
53+
context?: string,
4054
) {
4155
super(
4256
id,
@@ -49,15 +63,16 @@ export default class AggregationWidget extends Widget {
4963
streamCategories,
5064
filters,
5165
description,
66+
context,
5267
);
5368
}
5469

5570
static type = 'AGGREGATION';
5671

5772
static defaultTitle = 'Untitled Aggregation';
5873

59-
static fromJSON(value) {
60-
const { id, config, filter, timerange, query, streams, stream_categories, filters, description } = value;
74+
static fromJSON(value: AggregationWidgetJson) {
75+
const { id, config, filter, timerange, query, streams, stream_categories, filters, description, context } = value;
6176

6277
return new AggregationWidget(
6378
id,
@@ -69,14 +84,18 @@ export default class AggregationWidget extends Widget {
6984
stream_categories,
7085
filters,
7186
description,
87+
context,
7288
);
7389
}
7490

7591
toBuilder() {
76-
const { id, config, filter, timerange, query, streams, stream_categories, filters, description } = this._value;
92+
const { id, config, filter, timerange, query, streams, stream_categories, filters, description, context } =
93+
this._value;
7794

7895
// eslint-disable-next-line @typescript-eslint/no-use-before-define
79-
return new Builder(Map({ id, config, filter, timerange, query, streams, stream_categories, filters, description }));
96+
return new Builder(
97+
Map({ id, config, filter, timerange, query, streams, stream_categories, filters, description, context }),
98+
);
8099
}
81100

82101
static builder() {
@@ -86,7 +105,9 @@ export default class AggregationWidget extends Widget {
86105

87106
equals(other: any) {
88107
if (other instanceof AggregationWidget) {
89-
return widgetAttributesForComparison.every((key) => isDeepEqual(this[key], other[key]));
108+
return [...widgetAttributesForComparison, 'description', 'context'].every((key) =>
109+
isDeepEqual(this[key], other[key]),
110+
);
90111
}
91112

92113
return false;
@@ -103,7 +124,7 @@ export default class AggregationWidget extends Widget {
103124

104125
class Builder extends Widget.Builder {
105126
build() {
106-
const { id, config, filter, timerange, query, streams, stream_categories, filters, description } =
127+
const { id, config, filter, timerange, query, streams, stream_categories, filters, description, context } =
107128
this.value.toObject();
108129

109130
return new AggregationWidget(
@@ -116,6 +137,7 @@ class Builder extends Widget.Builder {
116137
stream_categories,
117138
filters,
118139
description,
140+
context,
119141
);
120142
}
121143
}

graylog2-web-interface/src/views/logic/aggregationbuilder/AggregationWidgetConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type InternalState = {
4848
units: UnitsConfig;
4949
};
5050

51-
type AggregationWidgetConfigJson = {
51+
export type AggregationWidgetConfigJson = {
5252
column_pivots: Array<PivotJson>;
5353
formatting_settings: WidgetFormattingSettingsJSON;
5454
rollup: boolean;

graylog2-web-interface/src/views/logic/views/__snapshots__/CopyPageToDashboard.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ exports[`copyPageToDashboard should copy a page to a dashboard 1`] = `
7373
"visualization": "bar",
7474
"visualization_config": null,
7575
},
76+
"context": undefined,
7677
"description": undefined,
7778
"filter": undefined,
7879
"filters": Immutable.List [],

graylog2-web-interface/src/views/logic/views/__snapshots__/CopyWidgetToDashboard.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ exports[`copyWidgetToDashboard should copy a widget to a dashboard 1`] = `
9696
"visualization": "bar",
9797
"visualization_config": null,
9898
},
99+
"context": undefined,
99100
"description": undefined,
100101
"filter": undefined,
101102
"filters": Immutable.List [],
@@ -125,6 +126,7 @@ exports[`copyWidgetToDashboard should copy a widget to a dashboard 1`] = `
125126
"sort": [],
126127
"visualization": "numeric",
127128
},
129+
"context": undefined,
128130
"description": undefined,
129131
"filter": undefined,
130132
"filters": Immutable.List [],

graylog2-web-interface/src/views/logic/views/__snapshots__/MoveWidgetToTab.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ exports[`MoveWidgetToTab should copy a Widget to a dashboard 1`] = `
5050
"sort": [],
5151
"visualization": "numeric",
5252
},
53+
"context": undefined,
5354
"description": undefined,
5455
"filter": undefined,
5556
"filters": Immutable.List [],
@@ -103,6 +104,7 @@ exports[`MoveWidgetToTab should copy a Widget to a dashboard 1`] = `
103104
"sort": [],
104105
"visualization": "numeric",
105106
},
107+
"context": undefined,
106108
"description": undefined,
107109
"filter": undefined,
108110
"filters": Immutable.List [],
@@ -184,6 +186,7 @@ exports[`MoveWidgetToTab should move a Widget to a dashboard 1`] = `
184186
"sort": [],
185187
"visualization": "numeric",
186188
},
189+
"context": undefined,
187190
"description": undefined,
188191
"filter": undefined,
189192
"filters": Immutable.List [],
@@ -258,6 +261,7 @@ exports[`MoveWidgetToTab should provide a default position in case the widgets p
258261
"sort": [],
259262
"visualization": "numeric",
260263
},
264+
"context": undefined,
261265
"description": undefined,
262266
"filter": undefined,
263267
"filters": Immutable.List [],
@@ -333,6 +337,7 @@ exports[`MoveWidgetToTab should work when titles are empty 1`] = `
333337
"sort": [],
334338
"visualization": "numeric",
335339
},
340+
"context": undefined,
336341
"description": undefined,
337342
"filter": undefined,
338343
"filters": Immutable.List [],

graylog2-web-interface/src/views/logic/views/__snapshots__/UpdateSearchForWidgets.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
145145
"visualization": "bar",
146146
"visualization_config": null,
147147
},
148+
"context": undefined,
148149
"description": undefined,
149150
"filter": undefined,
150151
"filters": Immutable.List [],
@@ -172,6 +173,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
172173
"visualization": "numeric",
173174
"visualization_config": null,
174175
},
176+
"context": undefined,
175177
"description": undefined,
176178
"filter": undefined,
177179
"filters": Immutable.List [],
@@ -218,6 +220,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
218220
"visualization": "bar",
219221
"visualization_config": null,
220222
},
223+
"context": undefined,
221224
"description": undefined,
222225
"filter": undefined,
223226
"filters": Immutable.List [],
@@ -245,6 +248,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
245248
"visualization": "numeric",
246249
"visualization_config": null,
247250
},
251+
"context": undefined,
248252
"description": undefined,
249253
"filter": undefined,
250254
"filters": Immutable.List [],
@@ -298,6 +302,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
298302
"visualization": "bar",
299303
"visualization_config": null,
300304
},
305+
"context": undefined,
301306
"description": undefined,
302307
"filter": undefined,
303308
"filters": Immutable.List [],
@@ -336,6 +341,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
336341
"visualization": "bar",
337342
"visualization_config": null,
338343
},
344+
"context": undefined,
339345
"description": undefined,
340346
"filter": undefined,
341347
"filters": Immutable.List [],
@@ -363,6 +369,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
363369
"visualization": "numeric",
364370
"visualization_config": null,
365371
},
372+
"context": undefined,
366373
"description": undefined,
367374
"filter": undefined,
368375
"filters": Immutable.List [],
@@ -383,6 +390,7 @@ exports[`UpdateSearchForWidgets should generate a new search for the view 1`] =
383390
],
384391
"show_message_row": true,
385392
},
393+
"context": undefined,
386394
"description": undefined,
387395
"filter": undefined,
388396
"filters": Immutable.List [],

graylog2-web-interface/src/views/logic/views/__snapshots__/ViewTransformer.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ exports[`ViewTransformer transform with all attributes should transform a view w
123123
],
124124
"show_message_row": true,
125125
},
126+
"context": undefined,
126127
"description": undefined,
127128
"filter": undefined,
128129
"filters": Immutable.List [],
@@ -169,6 +170,7 @@ exports[`ViewTransformer transform with all attributes should transform a view w
169170
"visualization": "bar",
170171
"visualization_config": null,
171172
},
173+
"context": undefined,
172174
"description": undefined,
173175
"filter": undefined,
174176
"filters": Immutable.List [],

0 commit comments

Comments
 (0)