Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 874cb7a

Browse files
Added team filter support (#195)
1 parent 9f51b61 commit 874cb7a

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

‎public/app/core/reducers/fn-slice.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export interface FnGlobalState {
1515
queryParams: AnyObject;
1616
hiddenVariables: readonly string[];
1717
fnGlobalTimeRange: TimeRange | null;
18+
metadata: {
19+
teams: string[];
20+
};
1821
}
1922

2023
export type UpdateFNGlobalStateAction = PayloadAction<Partial<FnGlobalState>>;
@@ -57,6 +60,9 @@ export const INITIAL_FN_STATE: FnGlobalState = {
5760
queryParams: {},
5861
hiddenVariables: [],
5962
fnGlobalTimeRange: null,
63+
metadata: {
64+
teams: [],
65+
},
6066
} as const;
6167

6268
const reducers: SliceCaseReducers<FnGlobalState> = {

‎public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@ export const optionPickerFactory = <Model extends VariableWithOptions | Variable
5353
};
5454
}
5555

56+
const isMfeTeamFilter = state.fnGlobalState.FNDashboard && state.fnGlobalState.metadata.teams.length;
57+
58+
const teamFilter = isMfeTeamFilter
59+
? state.fnGlobalState.metadata.teams.map((t) => ({
60+
text: t,
61+
value: t,
62+
selected: false,
63+
}))
64+
: [];
65+
66+
const p = getVariablesState(rootStateKey, state).optionsPicker;
67+
5668
return {
57-
picker: getVariablesState(rootStateKey, state).optionsPicker,
69+
picker: { ...p, ...(teamFilter.length && { options: [...p.options, ...teamFilter] }) },
70+
mfeState: state.fnGlobalState,
5871
};
5972
};
6073

@@ -149,7 +162,9 @@ export const optionPickerFactory = <Model extends VariableWithOptions | Variable
149162
<VariableInput
150163
id={VARIABLE_PREFIX + id}
151164
value={picker.queryValue}
152-
onChange={this.onFilterOrSearchOptions}
165+
onChange={(value) => {
166+
this.onFilterOrSearchOptions(value);
167+
}}
153168
onNavigate={this.onNavigate}
154169
aria-expanded={true}
155170
aria-controls={`options-${id}`}

‎public/app/fn-app/create-mfe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class createMfe {
204204

205205
const initialState: FnGlobalState = {
206206
...INITIAL_FN_STATE,
207-
FNDashboard: true,
208207
...pick(props, ...fnStateProps),
208+
FNDashboard: true,
209209
};
210210

211211
createMfe.logger.info('[FN Grafana] Dispatching initial state.', { initialState });
@@ -280,6 +280,7 @@ class createMfe {
280280
version: other.version,
281281
queryParams: other.queryParams,
282282
controlsContainer: other.controlsContainer,
283+
metadata: other.metadata,
283284
})
284285
);
285286
}

‎public/app/fn-app/fn-dashboard-page/render-fn-dashboard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DashboardRoutes, StoreState, useSelector } from 'app/types';
77

88
import { FNDashboardProps } from '../types';
99

10-
const locationService = locationSrv as HistoryWrapper;
10+
exportconst mfeLocationService = locationSrv as HistoryWrapper;
1111

1212
const DEFAULT_DASHBOARD_PAGE_PROPS: Pick<DashboardPageProps, 'history' | 'route'> & {
1313
match: Pick<DashboardPageProps['match'], 'isExact' | 'path' | 'url'>;
@@ -17,7 +17,7 @@ const DEFAULT_DASHBOARD_PAGE_PROPS: Pick<DashboardPageProps, 'history' | 'route'
1717
path: '/d/:uid/:slug?',
1818
url: '',
1919
},
20-
history: {}asDashboardPageProps['history'],
20+
history: mfeLocationService.getHistory(),
2121
route: {
2222
routeName: DashboardRoutes.Normal,
2323
path: '/d/:uid/:slug?',
@@ -50,7 +50,7 @@ export const RenderFNDashboard: FC<FNDashboardProps> = (props) => {
5050
}, [firstError, setErrors]);
5151

5252
useEffect(() => {
53-
locationService.fnPathnameChange(window.location.pathname, queryParams);
53+
mfeLocationService.fnPathnameChange(window.location.pathname, queryParams);
5454
}, [queryParams]);
5555

5656
const dashboardPageProps: DashboardPageProps = useMemo(
@@ -62,7 +62,7 @@ export const RenderFNDashboard: FC<FNDashboardProps> = (props) => {
6262
...props,
6363
},
6464
},
65-
location: locationService.getLocation(),
65+
location: mfeLocationService.getLocation(),
6666
queryParams,
6767
hiddenVariables,
6868
controlsContainer,

‎public/app/fn-app/types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactNode } from 'react';
22

3-
import { GrafanaThemeType } from '@grafana/data';
3+
import { FnGlobalState } from 'app/core/reducers/fn-slice';
44

55
export type FailedToMountGrafanaErrorName = 'FailedToMountGrafana';
66

@@ -16,17 +16,9 @@ export type GrafanaMicroFrontendActions = {
1616
export type AnyObject<K extends string | number | symbol = string, V = any> = {
1717
[key in K]: V;
1818
};
19-
20-
export interface FNDashboardProps {
19+
export interface FNDashboardProps extends FnGlobalState {
2120
name: string;
22-
uid: string;
23-
slug: string;
24-
version: number;
25-
mode: GrafanaThemeType.Dark | GrafanaThemeType.Light;
26-
queryParams: Record<string, string>;
2721
fnError?: ReactNode;
28-
pageTitle?: string;
29-
controlsContainer: string | null;
3022
isLoading: (isLoading: boolean) => void;
3123
setErrors: (errors?: { [K: number | string]: string }) => void;
3224
hiddenVariables: readonly string[];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /