Skip to content
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

KOGITO-10018: SWF Editor - Integrate SWF diagram editor theme API with VsCode and Combined Editor #2164

Merged
merged 24 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2330af9
Remove extra space at the bottom of the canvas
handreyrc Jan 31, 2024
d436372
Add theme support to stunner
handreyrc Jan 31, 2024
196e28b
Fix import order
handreyrc Feb 1, 2024
e1b8d40
Expose setTheme method in js
handreyrc Feb 1, 2024
414af6f
SWF Theme support
handreyrc Feb 1, 2024
452ebf1
Stunner alert's dark mode
handreyrc Feb 2, 2024
9a344af
Fix setTheme nullpointer
handreyrc Feb 6, 2024
8da1293
Remove extra space
handreyrc Feb 6, 2024
42a4d39
Do not set same theme
handreyrc Feb 6, 2024
6d71b32
Fix conflicting method names
handreyrc Feb 27, 2024
63236f9
Add GWT setTheme->applyTheme call
handreyrc Feb 27, 2024
8a184f8
Add dark theme to keyboard shortcuts icon
handreyrc Feb 27, 2024
40dc370
Do not apply theme if there are errors in the diagram, do it when it …
handreyrc Feb 28, 2024
f356821
Apply dark theme to zoombar combobox
handreyrc Mar 6, 2024
2b5c198
Fix zoombar combobox arrow and hover border colors
handreyrc Mar 6, 2024
7be0768
Apply Error Page Dark Theme
handreyrc Mar 6, 2024
caa3059
Fix shortcut modal and icon theme
handreyrc Mar 7, 2024
6580afc
Listen theme changes and apply theme
handreyrc Mar 7, 2024
6b47724
Fix CI failing test
handreyrc Mar 11, 2024
b6abe84
Make keyboard icon lighter in dark mode
handreyrc Mar 12, 2024
bd79282
Adjust shortcuts modal color pattern
handreyrc Mar 13, 2024
d0a6262
Fix Error page and new diagram theme issue
handreyrc Mar 14, 2024
fd6f534
Use themes only if themes are supported by the editor
handreyrc Mar 19, 2024
1ac02a7
Fix keyboard shortcuts icon on text editor
handreyrc Mar 25, 2024
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
2 changes: 2 additions & 0 deletions packages/editor/src/api/KogitoEditorEnvelopeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { KogitoEditorChannelApi } from "./KogitoEditorChannelApi";
import { I18nService } from "@kie-tools-core/i18n/dist/envelope";
import { OperatingSystem } from "@kie-tools-core/operating-system";
import { KeyboardShortcutsService } from "@kie-tools-core/keyboard-shortcuts/dist/envelope/KeyboardShortcutsService";
import { EditorTheme } from "./EditorTheme";

export interface KogitoEditorEnvelopeContextType<
ChannelApi extends KogitoEditorChannelApi & ApiDefinition<ChannelApi>
Expand All @@ -34,6 +35,7 @@ export interface KogitoEditorEnvelopeContextType<
keyboardShortcuts: KeyboardShortcutsService;
i18n: I18nService;
};
supportedThemes: EditorTheme[];
}

export const KogitoEditorEnvelopeContext = React.createContext<KogitoEditorEnvelopeContextType<any>>({} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import { Modal } from "@patternfly/react-core/dist/js/components/Modal";
import { KeyboardIcon } from "@patternfly/react-icons/dist/js/icons/keyboard-icon";
import { OperatingSystem } from "@kie-tools-core/operating-system";
import { useKogitoEditorEnvelopeContext } from "../../api";
import { EditorTheme, useKogitoEditorEnvelopeContext } from "../../api";
import { useEditorEnvelopeI18nContext } from "../i18n";
import { useSharedValue } from "@kie-tools-core/envelope-bus/dist/hooks";

export function KeyBindingsHelpOverlay() {
const [showing, setShowing] = useState(false);
const envelopeContext = useKogitoEditorEnvelopeContext();
const { i18n } = useEditorEnvelopeI18nContext();
const [theme] = useSharedValue(envelopeContext.channelApi?.shared.kogitoEditor_theme);

const toggle = useCallback(() => {
setShowing(!showing);
Expand All @@ -61,7 +63,7 @@
}
return lhs;
}, new Map<string, Set<{ label: string; combination: string }>>());
}, [envelopeContext.services.keyboardShortcuts.registered()]);

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest)

React Hook useMemo has missing dependencies: 'envelopeContext.operatingSystem' and 'envelopeContext.services.keyboardShortcuts'. Either include them or remove the dependency array

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest)

React Hook useMemo has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (macos-latest)

React Hook useMemo has missing dependencies: 'envelopeContext.operatingSystem' and 'envelopeContext.services.keyboardShortcuts'. Either include them or remove the dependency array

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (macos-latest)

React Hook useMemo has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (windows-latest)

React Hook useMemo has missing dependencies: 'envelopeContext.operatingSystem' and 'envelopeContext.services.keyboardShortcuts'. Either include them or remove the dependency array

Check warning on line 66 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (windows-latest)

React Hook useMemo has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked

useEffect(() => {
const id = envelopeContext.services.keyboardShortcuts.registerKeyPress(
Expand All @@ -71,7 +73,7 @@
{ element: window }
);
return () => envelopeContext.services.keyboardShortcuts.deregister(id);
}, [i18n]);

Check warning on line 76 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

Check warning on line 76 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (macos-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

Check warning on line 76 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (windows-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

useEffect(() => {
if (showing) {
Expand All @@ -80,13 +82,15 @@
});
return () => envelopeContext.services.keyboardShortcuts.deregister(id);
}
}, [showing]);

Check warning on line 85 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (ubuntu-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

Check warning on line 85 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (macos-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

Check warning on line 85 in packages/editor/src/envelope/KeyBindingsHelpOverlay/KeyBindingsHelpOverlay.tsx

View workflow job for this annotation

GitHub Actions / run (windows-latest)

React Hook useEffect has a missing dependency: 'envelopeContext.services.keyboardShortcuts'. Either include it or remove the dependency array

const themeCss = getCssThemeModifier(envelopeContext.supportedThemes, theme!);

return (
<>
<div
onClick={() => setShowing(!showing)}
className={"kie-tools--keyboard-shortcuts kie-tools--keyboard-shortcuts-icon"}
className={"kie-tools--keyboard-shortcuts kie-tools--keyboard-shortcuts-icon" + themeCss}
data-ouia-component-id="keyboard-shortcuts-icon"
data-testid={"keyboard-shortcuts-help-overlay-icon"}
>
Expand All @@ -100,7 +104,7 @@
width={"60%"}
onClose={toggle}
data-testid={"keyboard-shortcuts-help-overlay"}
className={"kie-tools--keyboard-shortcuts"}
className={"kie-tools--keyboard-shortcuts" + themeCss}
>
<TextContent>
<TextList component={TextListVariants.dl}>
Expand All @@ -124,6 +128,21 @@
);
}

function getCssThemeModifier(supportedThemes: EditorTheme[], theme: EditorTheme) {
if (supportedThemes.includes(theme)) {
switch (theme) {
case EditorTheme.DARK: {
return " dark";
}
default: {
return "";
}
}
}

return "";
}

function handleMacOsCombination(combination: string, os?: OperatingSystem) {
if (os === OperatingSystem.MACOS) {
return combination.replace("ctrl", "cmd");
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/envelope/KogitoEditorEnvelope.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class KogitoEditorEnvelope<
keyboardShortcuts: keyboardShortcutsService,
i18n: i18nService,
},
supportedThemes: [],
}
) {}

Expand Down
8 changes: 8 additions & 0 deletions packages/editor/src/envelope/KogitoEditorEnvelopeApiImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EditorContent,
EditorFactory,
EditorInitArgs,
EditorTheme,
KogitoEditorChannelApi,
KogitoEditorEnvelopeApi,
KogitoEditorEnvelopeContextType,
Expand Down Expand Up @@ -84,6 +85,13 @@ export class KogitoEditorEnvelopeApiImpl<

this.editor = await this.editorFactory.createEditor(this.args.envelopeContext, initArgs);

// "Permanent" theme subscription, destroyed along editor's iFrame
if (this.args.envelopeContext.supportedThemes.length > 1) {
this.args.envelopeContext.channelApi.shared.kogitoEditor_theme.subscribe((theme: EditorTheme) => {
this.editor.setTheme(theme);
});
}

await this.view().setEditor(this.editor);

this.editor.af_onStartup?.();
Expand Down
32 changes: 32 additions & 0 deletions packages/editor/src/envelope/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@
color: var(--pf-global--Color--dark-100);
}

.kie-tools--keyboard-shortcuts.kie-tools--keyboard-shortcuts-icon.dark {
color: #979797;
}

.pf-c-modal-box.kie-tools--keyboard-shortcuts.dark {
background-color: #313131;
.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
.dt,
.dd,
h1,
h2,
h3,
h4,
h5,
h6,
dt,
dd {
color: #cccccc;
}
.pf-c-button.pf-m-plain {
color: #cccccc;
}
.pf-c-button.pf-m-plain:hover {
color: #000;
}
}

body {
color: var(--pf-global--Color-dark--100);
}
Expand Down
21 changes: 19 additions & 2 deletions packages/editor/tests/envelope/EditorEnvelopeView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,33 @@ import * as React from "react";
import { cleanup, fireEvent, getByTestId, render, act } from "@testing-library/react";
import { EditorEnvelopeView, EditorEnvelopeViewApi } from "@kie-tools-core/editor/dist/envelope/EditorEnvelopeView";
import { DummyEditor } from "./DummyEditor";
import { usingEditorEnvelopeI18nContext, usingEnvelopeContext } from "./utils";
import { DEFAULT_TESTING_ENVELOPE_CONTEXT, usingEditorEnvelopeI18nContext, usingEnvelopeContext } from "./utils";
import { Editor } from "@kie-tools-core/editor/dist/api";

function renderEditorEnvelopeView(): EditorEnvelopeViewApi<Editor> {
const editorEnvelopeRef = React.createRef<EditorEnvelopeViewApi<Editor>>();
const setLocale = jest.fn();
const kogitoEditor_theme = jest.fn() as any;
const subscribe = jest.fn() as any;
const unsubscribe = jest.fn() as any;

render(
usingEditorEnvelopeI18nContext(
usingEnvelopeContext(
<EditorEnvelopeView ref={editorEnvelopeRef} setLocale={setLocale} showKeyBindingsOverlay={true} />
<EditorEnvelopeView ref={editorEnvelopeRef} setLocale={setLocale} showKeyBindingsOverlay={true} />,
{
channelApi: {
...DEFAULT_TESTING_ENVELOPE_CONTEXT.channelApi,
shared: {
...DEFAULT_TESTING_ENVELOPE_CONTEXT.channelApi.shared,
kogitoEditor_theme: {
...kogitoEditor_theme,
subscribe: subscribe,
unsubscribe: unsubscribe,
},
},
},
}
).wrapper
).wrapper
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe("KeyBindingsHelpOverlay", () => {
test("minimal setup", async () => {
const keyboardShortcutsService = new DefaultKeyboardShortcutsService({ os: OperatingSystem.WINDOWS });
keyboardShortcutsService.registerKeyPress("ctrl+c", "Copy", () => Promise.resolve(), {});
const kogitoEditor_theme = jest.fn() as any;
const subscribe = jest.fn() as any;
const unsubscribe = jest.fn() as any;

const component = render(
usingEditorEnvelopeI18nContext(
Expand All @@ -37,6 +40,17 @@ describe("KeyBindingsHelpOverlay", () => {
...DEFAULT_TESTING_ENVELOPE_CONTEXT.services,
keyboardShortcuts: keyboardShortcutsService,
},
channelApi: {
...DEFAULT_TESTING_ENVELOPE_CONTEXT.channelApi,
shared: {
...DEFAULT_TESTING_ENVELOPE_CONTEXT.channelApi.shared,
kogitoEditor_theme: {
...kogitoEditor_theme,
subscribe: subscribe,
unsubscribe: unsubscribe,
},
},
},
}).wrapper
).wrapper
);
Expand Down
1 change: 1 addition & 0 deletions packages/editor/tests/envelope/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const DEFAULT_TESTING_ENVELOPE_CONTEXT: KogitoEditorEnvelopeContextType<K
keyboardShortcuts: new DefaultKeyboardShortcutsService({} as any),
i18n: new I18nService(),
},
supportedThemes: [],
};

export function usingEnvelopeContext(
Expand Down
6 changes: 6 additions & 0 deletions packages/kie-bc-editors/src/bpmn/envelope/BpmnEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { GwtEditorWrapper } from "../../common";
import { CanvasConsumedInteropApi } from "../../canvas/CanvasConsumedInteropApi";
import { EditorTheme } from "@kie-tools-core/editor/dist/api";

interface CustomWindow extends Window {
canvas: CanvasConsumedInteropApi;
Expand Down Expand Up @@ -74,4 +75,9 @@ export class BpmnEditorImpl extends GwtEditorWrapper implements BpmnEditor {
public centerNode(uuid: string) {
window.canvas.centerNode(uuid);
}

public setTheme(theme: EditorTheme) {
// Themes are not supported by BPMN Editor
return Promise.resolve();
}
}
14 changes: 12 additions & 2 deletions packages/kie-bc-editors/src/common/GwtEditorWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,18 @@ export class GwtEditorWrapper implements Editor {
}

public setTheme(theme: EditorTheme): Promise<void> {
// Only default theme is supported
return Promise.resolve();
if (!theme) {
Promise.resolve();
}

switch (theme) {
case EditorTheme.DARK: {
return Promise.resolve(this.gwtEditor.applyTheme("dark"));
}
default: {
return Promise.resolve(this.gwtEditor.applyTheme("light"));
}
}
}

private removeBusinessCentralHeaderPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface GwtEditor {
getPreview(): Promise<string | undefined>;
validate(): Promise<Notification[]>;
selectStateByName(name: string | null): Promise<void>;
applyTheme(name: string | null): Promise<void>;
}

export class GwtAppFormerConsumedInteropApi {
Expand Down
6 changes: 6 additions & 0 deletions packages/kie-bc-editors/src/dmn/envelope/DmnEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { GwtEditorWrapper } from "../../common";
import { CanvasConsumedInteropApi } from "../../canvas/CanvasConsumedInteropApi";
import { EditorTheme } from "@kie-tools-core/editor/dist/api";

interface CustomWindow extends Window {
canvas: CanvasConsumedInteropApi;
Expand Down Expand Up @@ -74,4 +75,9 @@ export class DmnEditorImpl extends GwtEditorWrapper implements DmnEditor {
public centerNode(uuid: string) {
window.canvas.centerNode(uuid);
}

public setTheme(theme: EditorTheme) {
// Themes are not supported by DMN Editor
return Promise.resolve();
}
}
6 changes: 6 additions & 0 deletions packages/kie-bc-editors/src/scesim/envelope/SceSimEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { GwtEditorWrapper } from "../../common";
import { EditorTheme } from "@kie-tools-core/editor/dist/api";

export interface SceSimEditor extends GwtEditorWrapper {
mySceSimMethod(): string;
Expand All @@ -27,4 +28,9 @@ export class SceSimEditorImpl extends GwtEditorWrapper implements SceSimEditor {
public mySceSimMethod() {
return "scesim-specific--configured";
}

public setTheme(theme: EditorTheme) {
// Themes are not supported by SceSim Editor
return Promise.resolve();
}
}
6 changes: 5 additions & 1 deletion packages/kie-bc-editors/tests/DummyEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class DummyEditor implements Editor, GwtEditor {
return Promise.resolve([]);
}

public setTheme(theme: EditorTheme): Promise<void> {
public setTheme(_theme: EditorTheme): Promise<void> {
return Promise.resolve();
}

public applyTheme(_name: string | null): Promise<void> {
return Promise.resolve();
}

Expand Down
13 changes: 12 additions & 1 deletion packages/kie-bc-editors/tests/GwtEditorWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { GwtEditorWrapper } from "@kie-tools/kie-bc-editors/dist/common/GwtEditorWrapper";
import { GwtStateControlService } from "@kie-tools/kie-bc-editors/dist/common/gwtStateControl";
import { KogitoEditorChannelApi } from "@kie-tools-core/editor/dist/api";
import { EditorTheme, KogitoEditorChannelApi } from "@kie-tools-core/editor/dist/api";
import { messageBusClientApiMock } from "@kie-tools-core/envelope-bus/dist-tests/common";
import { I18n } from "@kie-tools-core/i18n/dist/core";
import { kieBcEditorsI18nDefaults, kieBcEditorsI18nDictionaries } from "@kie-tools/kie-bc-editors/dist/common/i18n";
Expand All @@ -33,6 +33,7 @@ const MockEditor = jest.fn(() => ({
getPreview: jest.fn(),
validate: jest.fn(),
selectStateByName: jest.fn(() => Promise.resolve()),
applyTheme: jest.fn(() => Promise.resolve()),
}));

const mockEditor = new MockEditor();
Expand Down Expand Up @@ -66,6 +67,16 @@ describe("GwtEditorWrapper", () => {
expect(mockEditor.selectStateByName).toHaveBeenCalledWith("stateName");
});

test("setTheme", async () => {
await wrapper.setTheme(EditorTheme.DARK);
expect(mockEditor.applyTheme).toHaveBeenCalledWith("dark");
});

test("setTheme", async () => {
await wrapper.setTheme(EditorTheme.LIGHT);
expect(mockEditor.applyTheme).toHaveBeenCalledWith("light");
});

test("af_onOpen removes header", () => {
const parent = document.createElement("div");
const workbenchHeaderPanel = document.createElement("div");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe("GwtEditorWrapperFactory", () => {
keyboardShortcuts: {} as any,
i18n: new I18nService(),
},
supportedThemes: [],
},
{
resourcesPathPrefix: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const envelopeContext: KogitoEditorEnvelopeContextType<KogitoEditorChannelApi> =
keyboardShortcuts: new DefaultKeyboardShortcutsService({ os: OperatingSystem.LINUX }),
i18n: new I18nService(),
},
supportedThemes: [],
};

describe("PMMLEditorFactory", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const envelopeContext: KogitoEditorEnvelopeContextType<KogitoEditorChannelApi> =
keyboardShortcuts: new DefaultKeyboardShortcutsService({ os: OperatingSystem.LINUX }),
i18n: new I18nService(),
},
supportedThemes: [],
};

const editorInterface: PMMLEditorInterface = new PMMLEditorInterface(envelopeContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/

import { EditorFactory, EditorInitArgs, KogitoEditorEnvelopeContextType } from "@kie-tools-core/editor/dist/api";
import {
EditorFactory,
EditorInitArgs,
KogitoEditorEnvelopeContextType,
EditorTheme,
} from "@kie-tools-core/editor/dist/api";
import { GwtEditorWrapperFactory } from "@kie-tools/kie-bc-editors/dist/common";
import { getServerlessWorkflowLanguageData, ServerlessWorkflowDiagramEditorChannelApi } from "../api";
import { DiagramExposedInteropApi } from "../api/DiagramExposedInteropApi";
Expand Down Expand Up @@ -63,6 +68,9 @@ export class ServerlessWorkflowDiagramEditorFactory
this.gwtEditorEnvelopeConfig
);

// Initialize swf supported themes
ctx.supportedThemes = [EditorTheme.LIGHT, EditorTheme.DARK];

return factory.createEditor(ctx, initArgs);
}
}
Loading
Loading