Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back and forward support for app actions #294

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/Explore/GroupBySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export function GroupBySelector({ options, radioAttributes, value, onChange, sho
value={value && getModifiedSelectOptions(otherAttrOptions).some((x) => x.value === value) ? value : null} // remove value from select when radio button clicked
placeholder={'Other attributes'}
options={getModifiedSelectOptions(otherAttrOptions)}
onChange={(selected) => onChange(selected?.value ?? defaultOnChangeValue)}
onChange={(selected) => {
const newSelected = selected?.value ?? defaultOnChangeValue;
onChange(newSelected);
}}
className={styles.select}
isClearable
onInputChange={(value: string, { action }: InputActionMeta) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface TraceSceneState extends SceneObjectState {
}

export class TracesByServiceScene extends SceneObjectBase<TraceSceneState> {
protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['actionView', 'selection'] });
public _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['actionView', 'selection', 'metric'] });

public constructor(state: MakeOptional<TraceSceneState, 'body'>) {
super({
Expand All @@ -76,6 +76,7 @@ export class TracesByServiceScene extends SceneObjectBase<TraceSceneState> {
this._subs.add(
metricVariable.subscribeToState((newState, prevState) => {
if (newState.value !== prevState.value) {
this.setState({ metric: newState.value as MetricFunction });
const selection = getDefaultSelectionForMetric(newState.value as MetricFunction);
if (selection) {
this.setState({ selection });
Expand Down Expand Up @@ -155,6 +156,7 @@ export class TracesByServiceScene extends SceneObjectBase<TraceSceneState> {
getUrlState() {
return {
actionView: this.state.actionView,
metric: this.state.metric,
selection: this.state.selection ? JSON.stringify(this.state.selection) : undefined,
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Explore/panels/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export function getHistogramVizPanel(scene: SceneObject, yBuckets: number[]) {
const yTo = yBucketToDuration(args[0].y?.to || 0, yBuckets);
newSelection.duration = { from: yFrom, to: yTo };

parent.setState({ selection: newSelection });
parent._urlSync.performBrowserHistoryAction(() => {
parent.setState({ selection: newSelection });
});
if (!shouldShowSelection(parent.state.actionView)) {
parent.setActionView('comparison');
}
Expand Down
12 changes: 9 additions & 3 deletions src/pages/Explore/TraceExploration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
VAR_LATENCY_THRESHOLD,
VAR_METRIC,
} from '../../utils/shared';
import { getTraceExplorationScene, getFilterSignature, getFiltersVariable } from '../../utils/utils';
import { getTraceExplorationScene, getFilterSignature, getFiltersVariable, getTraceByServiceSceneAsDescendent } from '../../utils/utils';
import { DetailsScene } from '../../components/Explore/TracesByService/DetailsScene';
import { FilterByVariable } from 'components/Explore/filters/FilterByVariable';
import { getSignalForKey, primarySignalOptions } from './primary-signals';
Expand Down Expand Up @@ -189,15 +189,21 @@ export class TraceExploration extends SceneObjectBase<TraceExplorationState> {
if (!signal || this.state.primarySignal === signal) {
return;
}
this.setState({ primarySignal: signal });

this._urlSync.performBrowserHistoryAction(() => {
this.setState({ primarySignal: signal });
});
};

public onChangeMetricFunction = (metric: string) => {
const variable = this.getMetricVariable();
if (!metric || variable.getValue() === metric) {
return;
}
variable.changeValueTo(metric);

getTraceByServiceSceneAsDescendent(this)._urlSync.performBrowserHistoryAction(() => {
variable.changeValueTo(metric);
});
};

public getMetricFunction() {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Explore/TraceExplorationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function TraceExplorationView({ exploration }: { exploration: TraceExplor
}

return (
<UrlSyncContextProvider scene={exploration} updateUrlOnInit={true} createBrowserHistorySteps={false}>
<UrlSyncContextProvider scene={exploration} updateUrlOnInit={true} createBrowserHistorySteps={true}>
<exploration.Component model={exploration} />
</UrlSyncContextProvider>
);
Expand Down
10 changes: 10 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
return sceneGraph.getAncestor(model, TracesByServiceScene);
}

export function getTraceByServiceSceneAsDescendent(model: SceneObject): TracesByServiceScene {
const scenes = sceneGraph.findDescendents(model, TracesByServiceScene);

if (!scenes || scenes.length < 1 || !(scenes[0] instanceof TracesByServiceScene)) {
throw new Error('TracesByServiceScene not found');
}

return scenes[0];
}

export function newTracesExploration(
locationService: LocationService,
initialDS?: string,
Expand All @@ -61,7 +71,7 @@
}

export function getErrorMessage(data: SceneDataState) {
return data?.data?.error?.message ?? 'There are no Tempo data sources';

Check warning on line 74 in src/utils/utils.ts

View workflow job for this annotation

GitHub Actions / build

'error' is deprecated. use errors instead -- will be removed in Grafana 10+
}

export function getNoDataMessage(context: string) {
Expand Down
Loading