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 Autosize Code Editor toolbar #78

Merged
merged 3 commits into from
Jan 20, 2025
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
33 changes: 26 additions & 7 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log

## 4.1.0 (2025-01-17)

### Features / Enhancements

- Updated AutosizeCodeEditor (#78)

## 4.0.0 (2024-01-10)

### Features / Enhancements

- Added useSavedState hook (#77)
- Added useLocalStorage hook (#77)

## 3.9.0 (2024-01-09)

### Features / Enhancements

- Added Alert with details component (#76)

## 3.8.0 (2024-12-12)

### Features / Enhancements
Expand All @@ -10,32 +29,32 @@

### Features / Enhancements

- Add DatasourceEditor and DatasourcePayloadEditor (#73)
- Added DatasourceEditor and DatasourcePayloadEditor (#73)

## 3.6.0 (2024-11-29)

### Features / Enhancements

- Update AutosizeCodeEditor (#70)
- Update onBlur behavior for code editor (#71)
- Updated AutosizeCodeEditor (#70)
- Updated onBlur behavior for code editor (#71)

## 3.5.0 (2024-10-23)

### Features / Enhancements

- Add useDatasourceRequest hooks (#69)
- Added useDatasourceRequest hooks (#69)

## 3.4.1 (2024-10-22)

### Features / Enhancements

- Add useDashboardVariables and useDashboardRefresh hooks (#68)
- Added useDashboardVariables and useDashboardRefresh hooks (#68)

## 3.3.0 (2024-10-02)

### Features / Enhancements

- Update Code Editor toolbar (#67)
- Updated Code Editor toolbar (#67)

## 3.2.0 (2024-09-20)

Expand All @@ -60,7 +79,7 @@

### Features / Enhancements

- Update @testing-library/react to 16 (#60)
- Updated @testing-library/react to 16 (#60)

## 2.9.0 (2024-09-02)

Expand Down
2 changes: 1 addition & 1 deletion packages/components/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023-2024 Volkov Labs
Copyright 2023-2025 Volkov Labs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@
"typecheck": "tsc --emitDeclarationOnly false --noEmit"
},
"types": "dist/index.d.ts",
"version": "4.0.0"
"version": "4.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,5 +512,25 @@ describe('AutosizeCodeEditor', () => {
*/
expect(selectors.copyPasteText()).toHaveTextContent('');
});

it('Should disable paste button for read-only mode', async () => {
const onChange = jest.fn();
const onEditorDidMount = jest.fn();

render(getComponent({ onChange, onEditorDidMount, value: 'test code', readOnly: true }));

expect(selectors.pasteButton()).toBeInTheDocument();

/**
* Click on paste button
*/
await act(() => fireEvent.click(selectors.pasteButton()));

/**
* Should display pasted text
*/
expect(selectors.pasteButton()).toBeInTheDocument();
expect(selectors.pasteButton()).toBeDisabled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
setIsShowMiniMap={setIsShowMiniMap}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
readOnly={restProps.readOnly}
/>
<CodeEditor
value={isEscaping ? value.replaceAll('\\n', '\n') : value}
Expand Down Expand Up @@ -214,6 +215,7 @@ export const AutosizeCodeEditor: React.FC<Props> = ({
setIsShowMiniMap={setIsShowMiniMap}
currentMonacoOptions={currentMonacoOptions}
setCurrentMonacoOptions={setCurrentMonacoOptions}
readOnly={restProps.readOnly}
/>
<CodeEditor
value={isEscaping ? value.replaceAll('\\n', '\n') : value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ type Props = {
* @type {React.Dispatch<React.SetStateAction<boolean | undefined>>}
*/
setIsShowMiniMap: React.Dispatch<React.SetStateAction<boolean | undefined>>;

/**
* Is read only mode
*
* @type {boolean}
*/
readOnly?: boolean;
};

/**
Expand All @@ -85,6 +92,7 @@ export const Toolbar: React.FC<Props> = ({
currentMonacoOptions,
isShowMiniMap,
setIsShowMiniMap,
readOnly,
}) => {
/**
* Styles and Theme
Expand Down Expand Up @@ -137,8 +145,9 @@ export const Toolbar: React.FC<Props> = ({
{...TEST_IDS.codeEditor.copyButton.apply()}
/>
<ToolbarButton
disabled={readOnly}
className={styles.copyPasteIcon}
tooltip="Paste code"
tooltip={readOnly ? `Cannot edit in read-only mode` : `Paste code`}
icon="file-alt"
iconSize="lg"
onClick={async () => {
Expand Down
Loading