Skip to content

Take the latest changes from Raheel #534

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

Merged
merged 12 commits into from
Nov 29, 2023
Merged
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
9 changes: 6 additions & 3 deletions client/packages/lowcoder/src/appView/AppViewInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AppView } from "./AppView";
import { API_STATUS_CODES } from "constants/apiConstants";
import { AUTH_LOGIN_URL } from "constants/routesURL";
import { AuthSearchParams } from "constants/authConstants";
import { saveAuthSearchParams } from "@lowcoder-ee/pages/userAuth/authUtils";

export type OutputChangeHandler<O> = (output: O) => void;
export type EventTriggerHandler = (eventName: string) => void;
Expand Down Expand Up @@ -71,9 +72,11 @@ export class AppViewInstance<I = any, O = any> {
.then((i) => i.data)
.catch((e) => {
if (e.response?.status === API_STATUS_CODES.REQUEST_NOT_AUTHORISED) {
window.location.href = `${webUrl}${AUTH_LOGIN_URL}?${
AuthSearchParams.redirectUrl
}=${encodeURIComponent(window.location.href)}`;
saveAuthSearchParams({
[AuthSearchParams.redirectUrl]: encodeURIComponent(window.location.href),
[AuthSearchParams.loginType]: null,
})
window.location.href = `${webUrl}${AUTH_LOGIN_URL}`;
}
});

Expand Down
2 changes: 2 additions & 0 deletions client/packages/lowcoder/src/comps/hooks/hookComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ThemeComp } from "./themeComp";
import UrlParamsHookComp from "./UrlParamsHookComp";
import { UtilsComp } from "./utilsComp";
import { VideoMeetingControllerComp } from "../comps/meetingComp/videoMeetingControllerComp";
import { ScreenInfoHookComp } from "./screenInfoComp";

window._ = _;
window.dayjs = dayjs;
Expand Down Expand Up @@ -97,6 +98,7 @@ const HookMap: HookCompMapRawType = {
modal: ModalComp,
meeting: VideoMeetingControllerComp,
currentUser: CurrentUserHookComp,
screenInfo: ScreenInfoHookComp,
urlParams: UrlParamsHookComp,
drawer: DrawerComp,
theme: ThemeComp,
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/comps/hooks/hookCompTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const AllHookComp = [
"message",
"localStorage",
"currentUser",
"screenInfo",
"urlParams",
"theme",
] as const;
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/comps/hooks/hookListComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const defaultHookListValue = [
{ compType: "message", name: "message" },
{ compType: "localStorage", name: "localStorage" },
{ compType: "currentUser", name: "currentUser" },
{ compType: "screenInfo", name: "screenInfo" },
{ compType: "theme", name: "theme" },
] as const;

Expand Down
65 changes: 65 additions & 0 deletions client/packages/lowcoder/src/comps/hooks/screenInfoComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useCallback, useEffect, useState } from "react";
import { hookToStateComp } from "../generators/hookToComp";

enum ScreenTypes {
Mobile = 'mobile',
Tablet = 'tablet',
Desktop = 'desktop',
}

type ScreenType = typeof ScreenTypes[keyof typeof ScreenTypes]

type ScreenInfo = {
width?: number;
height?: number;
deviceType?: ScreenType;
isDesktop?: boolean;
isTablet?: boolean;
isMobile?: boolean;
}

function useScreenInfo() {
const getDeviceType = () => {
if (window.screen.width < 768) return ScreenTypes.Mobile;
if (window.screen.width < 889) return ScreenTypes.Tablet;
return ScreenTypes.Desktop;
}
const getFlagsByDeviceType = (deviceType: ScreenType) => {
const flags = {
isMobile: false,
isTablet: false,
isDesktop: false,
};
if(deviceType === ScreenTypes.Mobile) {
return { ...flags, isMobile: true };
}
if(deviceType === ScreenTypes.Tablet) {
return { ...flags, Tablet: true };
}
return { ...flags, isDesktop: true };
}

const getScreenInfo = useCallback(() => {
const { width, height } = window.screen;
const deviceType = getDeviceType();
const flags = getFlagsByDeviceType(deviceType);

return { width, height, deviceType, ...flags };
}, [])

const [screenInfo, setScreenInfo] = useState<ScreenInfo>({});

const updateScreenInfo = useCallback(() => {
setScreenInfo(getScreenInfo());
}, [getScreenInfo])

useEffect(() => {
window.addEventListener('resize', updateScreenInfo);
updateScreenInfo();
return () => window.removeEventListener('resize', updateScreenInfo);
}, [ updateScreenInfo ])

return screenInfo;
}

export const ScreenInfoHookComp = hookToStateComp(useScreenInfo);
11 changes: 8 additions & 3 deletions client/packages/lowcoder/src/constants/authConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import {
export type AuthInviteInfo = InviteInfo & { invitationId: string };
export type AuthLocationState = { inviteInfo?: AuthInviteInfo; thirdPartyAuthError?: boolean };

export const AuthSearchParams = {
loginType: "loginType",
redirectUrl: "redirectUrl",
export enum AuthSearchParams {
loginType = "loginType",
redirectUrl = "redirectUrl",
};

export type AuthSearchParamsType = {
loginType: string | null,
redirectUrl: string | null,
};

export type OauthRequestParam = {
Expand Down
1 change: 0 additions & 1 deletion client/packages/lowcoder/src/constants/routesURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const QR_CODE_OAUTH_URL = `${USER_AUTH_URL}/oauth/qrcode`;
export const OAUTH_REDIRECT = `${USER_AUTH_URL}/oauth/redirect`;
export const CAS_AUTH_REDIRECT = `${USER_AUTH_URL}/cas/redirect`;
export const LDAP_AUTH_LOGIN_URL = `${USER_AUTH_URL}/ldap/login`;
export const USER_INFO_COMPLETION = `${USER_AUTH_URL}/completion`;
export const INVITE_LANDING_URL = "/invite/:invitationId";
export const ORG_AUTH_LOGIN_URL = `/org/:orgId/auth/login`;
export const ORG_AUTH_REGISTER_URL = `/org/:orgId/auth/register`;
Expand Down
109 changes: 75 additions & 34 deletions client/packages/lowcoder/src/pages/editor/right/uiCompPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import { draggingUtils } from "layout";
import { isEmpty } from "lodash";
import { language } from "i18n";
import {
ComListTitle,
CompIconDiv,
EmptyCompContent,
RightPanelContentWrapper,
} from "pages/editor/right/styledComponent";
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
import React, { useContext, useMemo } from "react";
import React, { useContext, useMemo, useState } from "react";
import styled from "styled-components";
import { labelCss } from "lowcoder-design";
import {
BaseSection,
PropertySectionContext,
PropertySectionContextType,
PropertySectionState,
labelCss,
} from "lowcoder-design";
import { TransparentImg } from "../../../util/commonUtils";
import { RightContext } from "./rightContext";

const GrayLabel = (props: { label: string }) => {
const { label } = props;
return <ComListTitle>{label}</ComListTitle>;
};

const CompDiv = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -80,16 +80,25 @@ const InsertContain = styled.div`
gap: 8px;
`;

const CategoryLabel = styled(GrayLabel)`
margin: 0;
`;

const SectionWrapper = styled.div`
margin-bottom: 16px;
.section-header {
margin-left: 0;
}
&:not(:last-child){
border-bottom: 1px solid #e1e3eb;
}
`;

const stateCompName = 'UICompSections';
const initialState: PropertySectionState = { [stateCompName]: {}};
Object.keys(uiCompCategoryNames).forEach((cat) => {
const key = uiCompCategoryNames[cat as UICompCategory];
initialState[stateCompName][key] = key === uiCompCategoryNames.common
})

export const UICompPanel = () => {
const { onDrag, searchValue } = useContext(RightContext);
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);

const categories = useMemo(() => {
const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
Expand All @@ -103,6 +112,22 @@ export const UICompPanel = () => {
return cats;
}, []);

const propertySectionContextValue = useMemo<PropertySectionContextType>(() => {
return {
compName: stateCompName,
state: propertySectionState,
toggle: (compName: string, sectionName: string) => {
setPropertySectionState((oldState) => {
const nextSectionState: PropertySectionState = { ...oldState };
const compState = nextSectionState[compName] || {};
compState[sectionName] = compState[sectionName] === false;
nextSectionState[compName] = compState;
return nextSectionState;
});
},
};
}, [propertySectionState]);

const compList = useMemo(
() =>
Object.entries(categories)
Expand All @@ -122,36 +147,52 @@ export const UICompPanel = () => {

return (
<SectionWrapper key={index}>
<CategoryLabel label={uiCompCategoryNames[key as UICompCategory]} />
<InsertContain>
{infos.map((info) => (
<CompDiv key={info[0]} className={info[0] === "table" ? tableDragClassName : ""}>
<HovDiv
draggable
onDragStart={(e) => {
e.dataTransfer.setData("compType", info[0]);
e.dataTransfer.setDragImage(TransparentImg, 0, 0);
draggingUtils.setData("compType", info[0]);
onDrag(info[0]);
}}
>
<IconContain Icon={info[1].icon}></IconContain>
</HovDiv>
<CompNameLabel>{info[1].name}</CompNameLabel>
{language !== "en" && <CompEnNameLabel>{info[1].enName}</CompEnNameLabel>}
</CompDiv>
))}
</InsertContain>
<BaseSection
noMargin
width={288}
name={uiCompCategoryNames[key as UICompCategory]}
>
<InsertContain>
{infos.map((info) => (
<CompDiv key={info[0]} className={info[0] === "table" ? tableDragClassName : ""}>
<HovDiv
draggable
onDragStart={(e) => {
e.dataTransfer.setData("compType", info[0]);
e.dataTransfer.setDragImage(TransparentImg, 0, 0);
draggingUtils.setData("compType", info[0]);
onDrag(info[0]);
}}
>
<IconContain Icon={info[1].icon}></IconContain>
</HovDiv>
<CompNameLabel>{info[1].name}</CompNameLabel>
{language !== "en" && <CompEnNameLabel>{info[1].enName}</CompEnNameLabel>}
</CompDiv>
))}
</InsertContain>
</BaseSection>
</SectionWrapper>
);
})
.filter((t) => t != null),
[categories, searchValue, onDrag]
);

if(!compList.length) return (
<RightPanelContentWrapper>
<EmptyCompContent />
</RightPanelContentWrapper>
)

return (
<RightPanelContentWrapper>
{compList.length > 0 ? compList : <EmptyCompContent />}
{/* {compList.length > 0 ? compList : <EmptyCompContent />} */}
<PropertySectionContext.Provider
value={propertySectionContextValue}
>
{compList}
</PropertySectionContext.Provider>
</RightPanelContentWrapper>
);
};
27 changes: 20 additions & 7 deletions client/packages/lowcoder/src/pages/userAuth/authUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
BASE_URL,
CAS_AUTH_REDIRECT,
OAUTH_REDIRECT,
USER_INFO_COMPLETION,
} from "constants/routesURL";
import { AxiosPromise, AxiosResponse } from "axios";
import { ApiResponse } from "api/apiResponses";
Expand All @@ -16,6 +15,7 @@ import { createContext, useState } from "react";
import { SystemConfig } from "constants/configConstants";
import {
AuthInviteInfo,
AuthSearchParamsType,
AuthSessionStoreParams,
ThirdPartyAuthGoal,
ThirdPartyAuthType,
Expand Down Expand Up @@ -79,12 +79,7 @@ export function authRespValidate(
) {
let replaceUrl = redirectUrl || BASE_URL;
const baseUrl = `${window.location.protocol}//${window.location.host}`;
if (infoCompleteCheck) {
// need complete info
replaceUrl = redirectUrl
? `${USER_INFO_COMPLETION}?redirectUrl=${redirectUrl}`
: USER_INFO_COMPLETION;
}

if (doValidResponse(resp)) {
onAuthSuccess?.();
history.replace(replaceUrl.replace(baseUrl, ''));
Expand Down Expand Up @@ -185,3 +180,21 @@ export const getRedirectUrl = (authType: ThirdPartyAuthType) => {
`${window.location.origin}${authType === "CAS" ? CAS_AUTH_REDIRECT : OAUTH_REDIRECT}`
);
};

const AuthSearchParamStorageKey = "_temp_auth_search_params_";

export const saveAuthSearchParams = (
authSearchParams: AuthSearchParamsType
) => {
sessionStorage.setItem(AuthSearchParamStorageKey, JSON.stringify(authSearchParams));
}

export const loadAuthSearchParams = ():AuthSearchParamsType | null => {
const authParams = sessionStorage.getItem(AuthSearchParamStorageKey);
if (!authParams) return null;
return JSON.parse(authParams);
}

export const clearAuthSearchParams = () => {
sessionStorage.removeItem(AuthSearchParamStorageKey);
}
3 changes: 2 additions & 1 deletion client/packages/lowcoder/src/pages/userAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Redirect, Route, Switch, useLocation, useParams } from "react-router-do
import React, { useEffect, useMemo } from "react";
import { useSelector, useDispatch } from "react-redux";
import { selectSystemConfig } from "redux/selectors/configSelectors";
import { AuthContext } from "pages/userAuth/authUtils";
import { AuthContext, clearAuthSearchParams } from "pages/userAuth/authUtils";
import { AuthRoutes } from "@lowcoder-ee/constants/authConstants";
import { AuthLocationState } from "constants/authConstants";
import { ProductLoading } from "components/ProductLoading";
Expand Down Expand Up @@ -37,6 +37,7 @@ export default function UserAuth() {

const fetchUserAfterAuthSuccess = () => {
dispatch(fetchUserAction());
clearAuthSearchParams();
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class AbstractAuthenticator {
authRespValidate(
resp,
this.needInfoCheck(this.authParams.sourceType),
this.authParams.afterLoginRedirect,
getSafeAuthRedirectURL(this.authParams.afterLoginRedirect),
onAuthSuccess,
);
})
Expand Down
Loading