Skip to content

Commit

Permalink
Update wrap button to indicate state and add button for the map (#64)
Browse files Browse the repository at this point in the history
* Code editor updated

* Updates

---------

Co-authored-by: Mikhail Volkov <[email protected]>
  • Loading branch information
vitPinchuk and mikhail-vl authored Sep 13, 2024
1 parent ccdde92 commit 28e7261
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 14 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NPM packages
# Business packages

Packages to use across projects.
NPM packages for the Business Suite for Grafana.

## Install all packages

Expand All @@ -10,10 +10,27 @@ Run the command in the root folder to install all packages
npm install
```

## Add npm package
## Install a specific package

Install npm or local package for the workspace

```
npm i [package] -w [local-package]
```

## Business Suite for Grafana

The Business Suite is a collection of open source plugins created and actively maintained by Volkov Labs.

The collection aims to solve the most frequent business tasks by providing an intuitive interface with detailed written documentation, examples, and video tutorials.

[![Business Suite for Grafana](https://raw.githubusercontent.com/VolkovLabs/.github/main/business.png)](https://volkovlabs.io/plugins/)

## Feedback

We're looking forward to hearing from you. You can use different ways to get in touch with us.

- Ask a question, request a new feature, or report an issue at [GitHub issues](https://github.com/volkovlabs/business-packages/issues).
- Subscribe to our [YouTube Channel](https://www.youtube.com/@volkovlabs) and leave your comments.
- Sponsor our open-source plugins for Grafana at [GitHub Sponsor](https://github.com/sponsors/VolkovLabs).
- Support our project by starring the repository.
7 changes: 7 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 3.1.0 (2024-09-13)

### Features / Enhancements

- Updated wrap button to indicate state (#64)
- Added button for the mini map (#64)

## 3.0.0 (2024-09-11)

### 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.0.0"
"version": "3.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,49 @@ describe('AutosizeCodeEditor', () => {
expect(onEditorDidMount).toHaveBeenCalledTimes(4);
});

it('Should render mini map button and show/hide map', async () => {
const onChange = jest.fn();
const onEditorDidMount = jest.fn();

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

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

/**
* Check tooltip via aria-label
*/
expect(selectors.miniMapButton()).toHaveAttribute('aria-label', 'Show mini map');

expect(onEditorDidMount).toHaveBeenCalledTimes(2);

act(() => fireEvent.click(selectors.miniMapButton()));

/**
* Call onEditorDidMount after set state
*/
expect(onEditorDidMount).toHaveBeenCalledTimes(3);

/**
* Check tooltip via aria-label
*/
expect(selectors.miniMapButton()).toHaveAttribute('aria-label', 'Hide mini map');

act(() => fireEvent.click(selectors.miniMapButton()));

/**
* Check tooltip via aria-label
*/
expect(selectors.miniMapButton()).toHaveAttribute('aria-label', 'Show mini map');

/**
* Call onEditorDidMount after set state
*/
expect(onEditorDidMount).toHaveBeenCalledTimes(4);
});

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 @@ -56,6 +56,7 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
modalButtonTooltip,
onEditorDidMount,
monacoOptions,
showMiniMap,
...restProps
}) => {
/**
Expand All @@ -67,9 +68,11 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
* State
*/
const [isOpen, setIsOpen] = useState(false);
const [isShowMiniMap, setIsShowMiniMap] = useState(showMiniMap);
const [currentMonacoOptions, setCurrentMonacoOptions] = useState(monacoOptions);
const [monacoEditor, setMonacoEditor] = useState<monacoType.editor.IStandaloneCodeEditor | null>(null);
const [monacoEditorModal, setMonacoEditorModal] = useState<monacoType.editor.IStandaloneCodeEditor | null>(null);
const [currentMonacoOptions, setCurrentMonacoOptions] = useState(monacoOptions);

/**
* Height
*/
Expand Down Expand Up @@ -125,22 +128,25 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
return (
<>
<Toolbar
editorValue={value}
setIsOpen={setIsOpen}
monacoEditor={monacoEditor}
editorValue={value}
isShowMiniMap={isShowMiniMap}
setIsShowMiniMap={setIsShowMiniMap}
modalButtonTooltip={modalButtonTooltip}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
/>
<CodeEditor
value={value}
showMiniMap={isShowMiniMap}
height={staticHeight ?? height}
monacoOptions={currentMonacoOptions}
onEditorDidMount={onEditorDidMountMain}
onChange={(value) => {
onChange?.(value);
setHeight(getHeightByValue(value, minHeight, maxHeight));
}}
height={staticHeight ?? height}
onEditorDidMount={onEditorDidMountMain}
monacoOptions={currentMonacoOptions}
{...restProps}
/>

Expand All @@ -156,23 +162,25 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
<div className={styles.content} {...TEST_IDS.codeEditor.modal.apply()}>
<Toolbar
isModal
editorValue={value}
setIsOpen={setIsOpen}
isShowMiniMap={isShowMiniMap}
monacoEditor={monacoEditorModal}
editorValue={value}
setIsShowMiniMap={setIsShowMiniMap}
modalButtonTooltip={modalButtonTooltip}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
/>
<CodeEditor
showMiniMap
value={value}
showMiniMap={isShowMiniMap}
containerStyles={styles.modalEditor}
monacoOptions={currentMonacoOptions}
onEditorDidMount={modalEditorDidMount}
onChange={(value) => {
onChange?.(value);
setHeight(getHeightByValue(value, minHeight, maxHeight));
}}
containerStyles={styles.modalEditor}
onEditorDidMount={modalEditorDidMount}
monacoOptions={currentMonacoOptions}
{...restProps}
/>
</div>
Expand Down
27 changes: 27 additions & 0 deletions packages/components/src/components/AutosizeCodeEditor/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ type Props = {
* @type {React.Dispatch<React.SetStateAction<CodeEditorMonacoOptions | undefined>>}
*/
setCurrentMonacoOptions: React.Dispatch<React.SetStateAction<CodeEditorMonacoOptions | undefined>>;

/**
* Show mini map
*
* @type {boolean}
*/
isShowMiniMap?: boolean;

/**
* Set show mini map
*
* @type {React.Dispatch<React.SetStateAction<boolean | undefined>>}
*/
setIsShowMiniMap: React.Dispatch<React.SetStateAction<boolean | undefined>>;
};

/**
Expand All @@ -77,6 +91,8 @@ export const Toolbar: React.FC<Props> = ({
isModal = false,
setCurrentMonacoOptions,
currentMonacoOptions,
isShowMiniMap,
setIsShowMiniMap,
}) => {
/**
* Styles and Theme
Expand Down Expand Up @@ -179,6 +195,7 @@ export const Toolbar: React.FC<Props> = ({
tooltip="Wrap code on new lines"
icon="wrap-text"
iconSize="lg"
variant={currentMonacoOptions?.wordWrap === 'on' ? 'active' : 'default'}
onClick={() => {
const wrapCode = currentMonacoOptions?.wordWrap === 'on' ? 'off' : 'on';
setCurrentMonacoOptions({
Expand All @@ -188,6 +205,16 @@ 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()}
/>
</PageToolbar>
);
};
1 change: 1 addition & 0 deletions packages/components/src/constants/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const TEST_IDS = {
copyButton: createSelector(() => `data-testid code-editor copy-button`),
copyPasteText: createSelector(() => `data-testid code-editor copy-paste-text`),
modal: createSelector(() => `data-testid code-editor modal-window`),
miniMapButton: createSelector(() => `data-testid code-editor mini-map-button`),
modalButton: createSelector((name: unknown) => `data-testid code-editor modal-button-${name}`),
pasteButton: createSelector(() => `data-testid code-editor paste-button`),
wrapButton: createSelector(() => `data-testid code-editor wrap-button`),
Expand Down

0 comments on commit 28e7261

Please sign in to comment.