-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathnavigation-actions.ts
58 lines (53 loc) · 1.91 KB
/
navigation-actions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
//
// SPDX-License-Identifier: Apache-2.0
import { EMPTY_DISPLAY_PACKAGE_INFO } from '../../../shared-constants';
import { getParents } from '../../helpers/get-parents';
import {
getPackageInfoOfSelectedAttribution,
getTargetSelectedAttributionId,
getTargetSelectedResourceId,
} from '../../selectors/resource-selectors';
import { AppThunkAction } from '../../types';
import { setTemporaryDisplayPackageInfo } from './all-views-simple-actions';
import {
setExpandedIds,
setSelectedAttributionId,
setSelectedResourceId,
setTargetSelectedAttributionId,
setTargetSelectedResourceId,
} from './audit-view-simple-actions';
export function resetTemporaryDisplayPackageInfo(): AppThunkAction {
return (dispatch, getState) => {
dispatch(
setTemporaryDisplayPackageInfo(
getPackageInfoOfSelectedAttribution(getState()) ||
EMPTY_DISPLAY_PACKAGE_INFO,
),
);
};
}
export function setSelectedResourceOrAttributionIdToTargetValue(): AppThunkAction {
return (dispatch, getState) => {
const targetSelectedResourceId = getTargetSelectedResourceId(getState());
const targetSelectedAttributionId =
getTargetSelectedAttributionId(getState());
if (targetSelectedResourceId !== null) {
dispatch(setSelectedResourceId(targetSelectedResourceId));
dispatch(setTargetSelectedResourceId(null));
}
if (targetSelectedAttributionId !== null) {
dispatch(setSelectedAttributionId(targetSelectedAttributionId));
dispatch(setTargetSelectedAttributionId(null));
}
};
}
export function openResourceInResourceBrowser(
resourceId: string,
): AppThunkAction {
return (dispatch) => {
dispatch(setExpandedIds(getParents(resourceId).concat([resourceId])));
dispatch(setSelectedResourceId(resourceId));
};
}