Skip to content

Commit

Permalink
Fix ListView bug in Navigations
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrozadotdev committed Dec 3, 2023
1 parent 433b663 commit d92be35
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 31 deletions.
3 changes: 1 addition & 2 deletions client/packages/openblocks/src/appView/AppViewInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export class AppViewInstance<I = any, O = any> {

if (!appDsl) {
if (!axiosIns && window.setupProxy) {
axiosIns = axios.create({ baseURL: baseUrl, withCredentials: true });
window.setupProxy(axiosIns, message);
axiosIns = window.setupProxy(axiosIns, message);
}
const data: ApplicationResp = await axiosIns
.get(`/api/v1/applications/${this.appId}/view`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { manualOptionsControl } from "comps/controls/optionsControl";
import { BoolCodeControl, StringControl } from "comps/controls/codeControl";
import { IconControl } from "comps/controls/iconControl";
import styled from "styled-components";
import React, { Suspense, useContext, useState } from "react";
import React, { Suspense, useContext, useRef, useState } from "react";
import { registerLayoutMap } from "comps/comps/uiComp";
import { AppSelectComp } from "comps/comps/layout/appSelectComp";
import { NameAndExposingInfo } from "comps/utils/exposingTypes";
Expand All @@ -21,6 +21,8 @@ import RootWrapper from "components/RootWrapper"
import { useSelector } from "react-redux";
import { getBrandingConfig } from "redux/selectors/configSelectors";

import { AppViewInstance, OpenblocksAppView } from "index.sdk"

const TabBar = React.lazy(() => import("antd-mobile/es/components/tab-bar"));
const TabBarItem = React.lazy(() =>
import("antd-mobile/es/components/tab-bar/tab-bar").then((module) => ({
Expand Down Expand Up @@ -151,6 +153,20 @@ let MobileTabLayoutTmp = (function () {
.build();
})();

function View(appId: string) {
const ref = useRef<AppViewInstance | null>(null);
if (!appId) {
return null;
}
return (
<OpenblocksAppView
ref={ref}
appId={appId}
baseUrl={window.location.origin}
/>
)
}

MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
const [tabIndex, setTabIndex] = useState(0);
const { readOnly } = useContext(ExternalEditorContext);
Expand All @@ -160,34 +176,35 @@ MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
>
).filter((tab) => !tab.children.hidden.getView());
const currentTab = tabViews[tabIndex];
// const appView = (currentTab &&
// currentTab.children.app.getAppId() &&
// currentTab.children.app.getView()) || (
// <EmptyContent
// text={readOnly ? "" : trans("aggregation.emptyTabTooltip")}
// style={{ height: "100%", backgroundColor: "white" }}
// />
// );
// Workaround until fix ListView bug
const appView = currentTab && currentTab.children.app.getAppId() ? (
<iframe
title={currentTab.children.app.getAppId()}
src={`${window.location.origin}/apps/${currentTab.children.app.getAppId()}?template=true`}
style={{
height: "100%",
width: "100%",
overflow: "hidden",
border: "none",
display: "block"
}}
>
</iframe>
) : (
const appView = (currentTab &&
currentTab.children.app.getAppId() &&
View(currentTab.children.app.getAppId())) || (
<EmptyContent
text={readOnly ? "" : trans("aggregation.emptyTabTooltip")}
style={{ height: "100%", backgroundColor: "white" }}
/>
)
);

// Workaround until fix ListView bug
// const appView = currentTab && currentTab.children.app.getAppId() ? (
// <iframe
// title={currentTab.children.app.getAppId()}
// src={`${window.location.origin}/apps/${currentTab.children.app.getAppId()}?template=true`}
// style={{
// height: "100%",
// width: "100%",
// overflow: "hidden",
// border: "none",
// display: "block"
// }}
// >
// </iframe>
// ) : (
// <EmptyContent
// text={readOnly ? "" : trans("aggregation.emptyTabTooltip")}
// style={{ height: "100%", backgroundColor: "white" }}
// />
// )

const tabBarView = (
<TabBarView
Expand Down
21 changes: 19 additions & 2 deletions client/packages/openblocks/src/comps/comps/layout/navLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { TopHeaderHeight } from "constants/style";
import { Section } from "openblocks-design";
import { trans } from "i18n";
import { EditorContainer, EmptyContent } from "pages/common/styledComponent";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import styled from "styled-components";
import { isUserViewMode, useAppPathParam, useAppPageId } from "util/hooks";
import RootWrapper from "components/RootWrapper"
import { useSelector } from "react-redux";
import { getBrandingConfig } from "redux/selectors/configSelectors";
import { AppViewInstance, OpenblocksAppView } from "index.sdk";

const StyledSide = styled(Layout.Sider)`
max-height: calc(100vh - ${TopHeaderHeight});
Expand Down Expand Up @@ -62,6 +63,20 @@ let NavTmpLayout = (function () {
.build();
})();

function View(appId: string) {
const ref = useRef<AppViewInstance | null>(null);
if (!appId) {
return null;
}
return (
<OpenblocksAppView
ref={ref}
appId={appId}
baseUrl={window.location.origin}
/>
)
}

NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
const pathParam = useAppPathParam();
const [appPageId, updateHash] = useAppPageId();
Expand Down Expand Up @@ -170,6 +185,7 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
selectedKey = firstItem[0];
}
}
console.log(selectedKey)
setSelectedKey(selectedKey);
}, [appPageId]);

Expand All @@ -178,7 +194,8 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
let pageView = <EmptyContent text="" style={{ height: "100%" }} />;
const selectedItem = itemKeyRecord[selectedKey];
if (selectedItem && !selectedItem.children.hidden.getView()) {
const compView = selectedItem.children.action.getView();
//@ts-ignore
const compView = View(selectedItem.toJsonValue().action.comp.app.appId);
if (compView) {
pageView = compView;
}
Expand Down
2 changes: 1 addition & 1 deletion client/packages/openblocks/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ declare global {
interface Window {
printPerf: () => void;
__OPENBLOCKS_DEV__?: {};
setupProxy?: (axiosIns: AxiosInstance, message: unknown) => void;
setupProxy?: (axiosIns: AxiosInstance, message: unknown) => AxiosInstance;
}
}
3 changes: 3 additions & 0 deletions proxy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ initI18n().then(() => {
});

let mockIns: MockAdapter;
let axiosInstance: AxiosInstance;

window.setupProxy = (axiosIns: AxiosInstance, messageIns: unknown) => {
if (!mockIns) {
Expand All @@ -32,5 +33,7 @@ window.setupProxy = (axiosIns: AxiosInstance, messageIns: unknown) => {
});
console.warn("[PROXY]: Mock applied!");
}
axiosInstance = axiosIns;
}
return axiosInstance;
};
2 changes: 1 addition & 1 deletion proxy/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ declare global {
interface Window {
sdk: unknown;
uploadAvatar: (config: UploadRequestOption) => void;
setupProxy: (axiosIns: AxiosInstance, messageIns: unknown) => void;
setupProxy: (axiosIns: AxiosInstance, messageIns: unknown) => AxiosInstance;
}
}

0 comments on commit d92be35

Please sign in to comment.