-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget-builder): Add helper to convert widget to builder state
This lets us put the widget builder state into the URL so it can be parsed by the hook when the builder mounts.
- Loading branch information
1 parent
8e45680
commit 7fba528
Showing
5 changed files
with
68 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
static/app/views/dashboards/widgetBuilder/utils/convertWidgetToBuilderStateParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {DisplayType, type Widget, WidgetType} from 'sentry/views/dashboards/types'; | ||
|
||
type StringifiedWidgetBuilderState = { | ||
dataset?: WidgetType; | ||
description?: string; | ||
displayType?: DisplayType; | ||
fields?: string[]; | ||
title?: string; | ||
yAxis?: string[]; | ||
}; | ||
|
||
/** | ||
* Converts a widget to a set of query params that can be used to | ||
* restore the widget builder state. | ||
*/ | ||
export function convertWidgetToBuilderStateParams( | ||
widget: Widget | ||
): StringifiedWidgetBuilderState { | ||
const yAxis = widget.queries.flatMap(q => q.aggregates); | ||
const fields = widget.queries.flatMap(q => q.fields ?? []); | ||
return { | ||
title: widget.title, | ||
description: widget.description ?? '', | ||
dataset: widget.widgetType ?? WidgetType.ERRORS, | ||
displayType: widget.displayType ?? DisplayType.TABLE, | ||
fields, | ||
yAxis, | ||
}; | ||
} |