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

Update Code Editor #67

Merged
merged 4 commits into from
Oct 3, 2024
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
6 changes: 6 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 3.3.0 (2024-10-02)

### Features / Enhancements

- Update Code Editor toolbar (#67)

## 3.2.0 (2024-09-20)

### Features / Enhancements
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@
"typecheck": "tsc --emitDeclarationOnly false --noEmit"
},
"types": "dist/index.d.ts",
"version": "3.2.0"
"version": "3.3.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,15 @@ describe('AutosizeCodeEditor', () => {
expect(onEditorDidMount).toHaveBeenCalledTimes(4);
});

it('Should render mini map button and show/hide map', async () => {
it('Should render mini map button and show/hide map if value more or equal 100 characters', async () => {
const onChange = jest.fn();
const onEditorDidMount = jest.fn();

render(getComponent({ onEditorDidMount, onChange }));
const valueIn1000Rows = Array.from(new Array(1000))
.map((value, index) => index)
.join('\n');

render(getComponent({ value: valueIn1000Rows, onEditorDidMount, onChange }));

/**
* Check paste button
Expand Down Expand Up @@ -289,6 +293,23 @@ describe('AutosizeCodeEditor', () => {
expect(onEditorDidMount).toHaveBeenCalledTimes(4);
});

it('Should not render mini map button if value less than 100 characters', async () => {
const onChange = jest.fn();
const onEditorDidMount = jest.fn();

/**
* 99 characters
*/
const value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore';

render(getComponent({ value: value, onEditorDidMount, onChange }));

/**
* Check paste button
*/
expect(selectors.miniMapButton(true)).not.toBeInTheDocument();
});

it('Should open/close modal on toolbar button', async () => {
const onChange = jest.fn();
const onEditorDidMount = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { Toolbar } from './Toolbar';
type Props = React.ComponentProps<typeof CodeEditor> & {
minHeight?: number;
maxHeight?: number;
modalTitle: string;
modalButtonTooltip: string;
};

/**
Expand Down Expand Up @@ -52,8 +50,6 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
minHeight,
maxHeight,
height: staticHeight,
modalTitle,
modalButtonTooltip,
onEditorDidMount,
monacoOptions,
showMiniMap,
Expand Down Expand Up @@ -133,7 +129,6 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
monacoEditor={monacoEditor}
isShowMiniMap={isShowMiniMap}
setIsShowMiniMap={setIsShowMiniMap}
modalButtonTooltip={modalButtonTooltip}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
/>
Expand All @@ -151,7 +146,7 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
/>

<Modal
title={modalTitle}
title="Code editor"
isOpen={isOpen}
onDismiss={() => setIsOpen(false)}
className={styles.modal}
Expand All @@ -167,7 +162,6 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
isShowMiniMap={isShowMiniMap}
monacoEditor={monacoEditorModal}
setIsShowMiniMap={setIsShowMiniMap}
modalButtonTooltip={modalButtonTooltip}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
/>
Expand Down
32 changes: 13 additions & 19 deletions packages/components/src/components/AutosizeCodeEditor/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ type Props = {
*/
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;

/**
* Modal Button tooltip
*
* @type {string}
*/
modalButtonTooltip: string;

/**
* Value
*
Expand Down Expand Up @@ -86,7 +79,6 @@ type Props = {
export const Toolbar: React.FC<Props> = ({
monacoEditor,
setIsOpen,
modalButtonTooltip,
editorValue,
isModal = false,
setCurrentMonacoOptions,
Expand Down Expand Up @@ -123,7 +115,7 @@ export const Toolbar: React.FC<Props> = ({
leftItems={[
<ToolbarButton
key="code-editor-button-modal"
tooltip={modalButtonTooltip}
tooltip={isModal ? 'Collapse code editor' : 'Expand code editor'}
icon={isModal ? 'compress-arrows' : 'expand-arrows-alt'}
iconSize="lg"
onClick={() => setIsOpen(isModal ? false : true)}
Expand Down Expand Up @@ -205,16 +197,18 @@ export const Toolbar: React.FC<Props> = ({
}}
{...TEST_IDS.codeEditor.wrapButton.apply()}
/>
<ToolbarButton
tooltip={isShowMiniMap ? 'Hide mini map' : 'Show mini map'}
icon="gf-movepane-right"
iconSize="lg"
variant={isShowMiniMap ? 'active' : 'default'}
onClick={() => {
setIsShowMiniMap((prev) => !prev);
}}
{...TEST_IDS.codeEditor.miniMapButton.apply()}
/>
{editorValue && editorValue.length > 100 && (
<ToolbarButton
tooltip={isShowMiniMap ? 'Hide mini map' : 'Show mini map'}
icon="gf-movepane-right"
iconSize="lg"
variant={isShowMiniMap ? 'active' : 'default'}
onClick={() => {
setIsShowMiniMap((prev) => !prev);
}}
{...TEST_IDS.codeEditor.miniMapButton.apply()}
/>
)}
</PageToolbar>
);
};
Loading