Skip to content

Commit

Permalink
fix: added support to add menu entries
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed Nov 27, 2024
1 parent 7d2389b commit 152b38e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/designer/src/Components/Drawers/NavDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useQuickFormDefinition } from "../../Contexts/QuickFormDefContext";
import SlideTreeItem from "./SlideTreeItem";
import QuestionTreeItem from "./QuestionTreeItem";
import { CodeIcon } from "../Icons/CodeIcon";
import { getOrCreateQuickFormViewContainer } from "../Views/DesignerViews";

type NavDrawerProps = {
isOpen: boolean;
Expand All @@ -28,6 +29,8 @@ export const NavDrawer = ({ setIsOpen, isOpen, newSlideNodes }: NavDrawerProps)
const { setView, view, setActiveSlide, activeSlide, quickformpayload, updateQuickFormPayload, setActiveQuestion, activeQuestion, designerLocale } = useQuickFormDefinition();
const { actions: { history, deserialize } } = useEditorChanges();

const views = getOrCreateQuickFormViewContainer();

return (
<Drawer
type="inline"
Expand Down Expand Up @@ -77,6 +80,7 @@ export const NavDrawer = ({ setIsOpen, isOpen, newSlideNodes }: NavDrawerProps)
<ViewTreeItem title="Ending" icon={<EndingViewIcon />} setView={setView} selectedView={view} viewName="ending" />
<ViewTreeItem title="Settings" icon={<SettingsViewIcon />} setView={setView} selectedView={view} viewName="settings" />
<ViewTreeItem title="Source view" icon={<CodeIcon />} setView={setView} selectedView={view} viewName="sourceView" />
{Object.entries(views).map(([key, _view]) => <ViewTreeItem childName={quickformpayload['__designer'][`active${_view.navKey}`]} key={key} title={_view.title} icon={_view.icon} setView={setView} selectedView={view} viewName={key} children={_view.nav && <_view.nav />} />)}
</Tree>
</DrawerBody>
</Drawer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useMemo } from "react";
import { QuestionJsonModel } from "@eavfw/quickform-core/src/model/json-definitions/JsonDataModels";
import { CaretUpFilled, CaretDownFilled } from "@fluentui/react-icons"

const useNavDrawerStyles = makeStyles({
export const useNavDrawerStyles = makeStyles({
actions: {
backgroundColor: tokens.colorNeutralBackground1Hover,
position: "absolute",
Expand Down
41 changes: 41 additions & 0 deletions packages/designer/src/Components/Views/DesignerViews.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { ReactNode } from "react"
import { useQuickFormDefinition } from "../../Contexts/QuickFormDefContext"
import { ViewNames } from "../../Types/ViewNames"
import { QuickFormEndingSettingsView } from "./QuickFormEndingSettingsView"
Expand All @@ -7,11 +8,51 @@ import { QuickFormQuestionsView } from "./QuickFormQuestionsView"
import { QuickFormSettingsView } from "./QuickFormSettingsView"
import { QuickFormSourceView } from "./QuickFormSourceView"
import { QuickFormSubmitSettingsView } from "./QuickFormSubmitSettingsView"
import { TreeItemLayoutProps } from "@fluentui/react-components"


export type QuickFormView = {

view: React.FC;
nav?: React.FC;
title: string;
navKey: string;
icon: TreeItemLayoutProps["iconBefore"]
}

export type QuickFormViews = {

[key: string]: QuickFormView;

}

declare global {
var __eav_qf_views: QuickFormViews | undefined;
}

export function getOrCreateQuickFormViewContainer(): QuickFormViews {
if (!globalThis.__eav_qf_views) {

globalThis.__eav_qf_views = {};
;
}
return globalThis.__eav_qf_views;
}

export function registerQuickformView<Key extends keyof QuickFormViews>(name: Key, instance: (QuickFormViews)[Key]) {
let services = getOrCreateQuickFormViewContainer();
services[name] = instance;
}

export const DesignerViews = () => {

const { updateQuickFormPayload, quickformpayload, activeQuestion, activeSlide, view } = useQuickFormDefinition();
const views = getOrCreateQuickFormViewContainer();
if (view in views) {

const View = views[view]?.view;
return <View />
}

return <>
{view === "settings" && <QuickFormSettingsView />}
Expand Down
3 changes: 2 additions & 1 deletion packages/designer/src/Components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

export { registerInputControlDesignerField } from "./Views/QuickFormQuestionsView";
export { registerInputControlDesignerField } from "./Views/QuickFormQuestionsView";
export * from "./Views/DesignerViews";
4 changes: 3 additions & 1 deletion packages/designer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
export * from "./Components";
import "./Designer";
export * from "./QuickFormDesigner";
export * from "./Contexts/QuickFormDefContext";
export * from "./Contexts/QuickFormDefContext";
export * from "./Utils/makeid";
export * from "./Types/QuickFormDefinition";

0 comments on commit 152b38e

Please sign in to comment.