|
1 | | -import appStore, { ContribPoint } from "../store/appStore"; |
2 | | -import fetchApiResult from "../utils/fetchApiResult"; |
3 | | -import { fetchComponentModel } from "../api"; |
4 | | -import { updateContributionState } from "./updateContributionState"; |
| 1 | +import { setComponentVisibility } from "./setComponentVisibility"; |
5 | 2 |
|
6 | 3 | export function showPanel(panelIndex: number) { |
7 | | - const contribPoint = "panels"; |
8 | | - const getState = appStore.getState; |
9 | | - const panelStates = getState().contributionStatesRecord[contribPoint]; |
10 | | - const panelState = panelStates[panelIndex]; |
11 | | - if (panelState.visible) { |
12 | | - return; // nothing to do |
13 | | - } |
14 | | - if (panelState.componentModelResult.status) { |
15 | | - // If we have some status, the component is loaded or is being loaded |
16 | | - updateContributionState(contribPoint, panelIndex, { visible: true }); |
17 | | - } else { |
18 | | - // No status yet, so we must load the component |
19 | | - updateContributionState(contribPoint, panelIndex, { |
20 | | - visible: true, |
21 | | - componentModelResult: { status: "pending" }, |
22 | | - }); |
23 | | - const inputValues = getLayoutInputValues(contribPoint, panelIndex); |
24 | | - fetchApiResult( |
25 | | - fetchComponentModel, |
26 | | - contribPoint, |
27 | | - panelIndex, |
28 | | - inputValues, |
29 | | - ).then((componentModelResult) => { |
30 | | - updateContributionState(contribPoint, panelIndex, { |
31 | | - componentModelResult, |
32 | | - }); |
33 | | - }); |
34 | | - } |
35 | | -} |
36 | | - |
37 | | -function getLayoutInputValues( |
38 | | - contribPoint: ContribPoint, |
39 | | - contribIndex: number, |
40 | | -): unknown[] { |
41 | | - const contributionModels = |
42 | | - appStore.getState().contributionsRecordResult.data![contribPoint]; |
43 | | - const contributionModel = contributionModels[contribIndex]; |
44 | | - const inputs = contributionModel.layout!.inputs; |
45 | | - if (inputs && inputs.length > 0) { |
46 | | - // TODO: get inputValue from sources specified by input.kind. |
47 | | - // For time being we use null as it is JSON-serializable |
48 | | - return inputs.map((input) => { |
49 | | - console.warn(`layout input not supported yet`, input); |
50 | | - return null; |
51 | | - }); |
52 | | - } else { |
53 | | - return []; |
54 | | - } |
| 4 | + setComponentVisibility("panels", panelIndex, true); |
55 | 5 | } |
0 commit comments