Skip to content

Commit db9dfb5

Browse files
[customized views] remove UIs related to managing them when irrelevant
In the Theia trace extension, the functionality to create custom views has not been implemented. However the UI element , a plus sign button added after the "views" entry of the "configurator" element, used to trigger creating custom views, is always present, even when not supported (no callback provided that create the custom views). This commit removes that button when not relevant. There's also the UI element added to remove previously created custom views (the "x" button), that does work in the Theia extension. For consistency, this commit also removes this button. Another tweak done when customization is not supported is to filter root "configurator" nodes from the nodes list early, so they are not displayed in the views list. If they have children , from previously configured output descriptors (from the vscode trace extension), then the children will be displayed as before but as root nodes instead of children of their "configurator" node. The filtering of "configurator" node is overridable, by creating a class that extends ReactAvailableViewsWidget and overrides method : "protected doFilterList(list: OutputDescriptor[]): OutputDescriptor[]", e.g. to return the original, unfiltered list. Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
1 parent 9ac37ba commit db9dfb5

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

react-components/src/trace-explorer/trace-explorer-views-widget.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
181181
const lookup: { [key: string]: TreeNode } = {};
182182
const idStringToNodeId: { [key: string]: number } = {};
183183

184+
// By default, when customization is not supported,
185+
// replace useless root "configurator" nodes with their
186+
// children, if any.
187+
list = this.filterList(list);
184188
// Fill-in the lookup table
185189
list.forEach((output, index) => {
186190
const node: TreeNode = this.entryToTreeNode(output, idStringToNodeId);
@@ -210,6 +214,25 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
210214
return rootNodes;
211215
}
212216

217+
private filterList(list: OutputDescriptor[]): OutputDescriptor[] {
218+
return this.doFilterList(list);
219+
}
220+
221+
/**
222+
* Overridable function that permits to remove output descriptors for the list obtained from
223+
* the trace server. The default implementation removes "configurator" nodes when customization
224+
* is not possible. The code that processes the list afterward to create nodes from them, will
225+
* promote children of removed nodes to root nodes, when the parent is not found.
226+
* @param list list of output descriptors
227+
* @returns filtered list
228+
*/
229+
protected doFilterList(list: OutputDescriptor[]): OutputDescriptor[] {
230+
if (!this.isCustomizationSupported()) {
231+
return list.filter(output => !this.isOutputCustomizable(output));
232+
}
233+
return list;
234+
}
235+
213236
private entryToTreeNode(entry: OutputDescriptor, idStringToNodeId: { [key: string]: number }): TreeNode {
214237
const id = idStringToNodeId[entry.id] ?? (idStringToNodeId[entry.id] = this._idGenerator++);
215238

@@ -233,11 +256,8 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
233256
}
234257

235258
private createEnrichedContent(entry: OutputDescriptor): (() => JSX.Element) | undefined {
236-
const isCustomizable = entry.capabilities?.canCreate === true;
237-
const isDeletable = entry.capabilities?.canDelete === true;
238-
239-
// Return undefined if no relevant capabilities
240-
if (!isCustomizable && !isDeletable) {
259+
// Return undefined if no relevant capabilities or if customization is not supported
260+
if ((!this.isOutputCustomizable(entry) && !this.isOutputDeletable(entry)) || !this.isCustomizationSupported()) {
241261
return undefined;
242262
}
243263

@@ -249,7 +269,7 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
249269
flexShrink: 1
250270
};
251271

252-
const useCustomizableUI = isCustomizable;
272+
const useCustomizableUI = this.isOutputCustomizable(entry);
253273

254274
const EnrichedContent = (): JSX.Element => {
255275
const displayName = useCustomizableUI ? entry.name : entry.configuration?.name;
@@ -297,4 +317,18 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
297317
this.updateAvailableViews();
298318
}
299319
};
320+
321+
private isOutputCustomizable(od: OutputDescriptor): boolean {
322+
return !!od.capabilities?.canCreate;
323+
}
324+
325+
private isOutputDeletable(od: OutputDescriptor): boolean {
326+
return !!od.capabilities?.canDelete;
327+
}
328+
329+
private isCustomizationSupported(): boolean {
330+
// If the app using this library has not provided a callback to create
331+
// customized views, we can consider customizing views is not supported
332+
return !!this.props.onCustomizationClick;
333+
}
300334
}

0 commit comments

Comments
 (0)