Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat(code-editor): Update icon when editor is dirty
Browse files Browse the repository at this point in the history
Currently, when the source code is changed through the source code
editor, the sync button is always green, being the only feedback that
it was changed the top banner.

This commit updates the icon from the green check to an orange sync icon
whenever the code editor is dirty. It also changes the tooltip text from
"Sync your code" to "Code is synced"

fixes: #2185
  • Loading branch information
lordrip committed Jul 31, 2023
1 parent cc3d0e9 commit b527903
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { StepErrorBoundary } from './StepErrorBoundary';
import { fetchIntegrationJson, RequestService } from '@kaoto/api';
import { StepErrorBoundary } from '../StepErrorBoundary';
import { SyncButton } from './SyncButton';
import { RequestService, fetchIntegrationJson } from '@kaoto/api';
import { useFlowsStore, useIntegrationSourceStore, useSettingsStore } from '@kaoto/store';
import { CodeEditorMode } from '@kaoto/types';
import { CodeEditor, CodeEditorControl, Language } from '@patternfly/react-code-editor';
import { Alert } from '@patternfly/react-core';
import { CheckCircleIcon, EraserIcon, RedoIcon, UndoIcon } from '@patternfly/react-icons';
import { EraserIcon, RedoIcon, UndoIcon } from '@patternfly/react-icons';
import { setDiagnosticsOptions } from 'monaco-yaml';
import { useEffect, useRef } from 'react';
import { useEffect, useRef, useState } from 'react';
import { EditorDidMount } from 'react-monaco-editor';
import { useDebouncedCallback } from 'use-debounce';
import { shallow } from 'zustand/shallow';
Expand Down Expand Up @@ -39,6 +40,13 @@ export const SourceCodeEditor = (props: ISourceCodeEditor) => {
);

const setFlowsWrapper = useFlowsStore((state) => state.setFlowsWrapper, shallow);
const [isDirty, setIsDirty] = useState(false);
const [isUpdateButtonVisible, setIsUpdateButtonVisible] = useState(false);

useEffect(() => {
setIsDirty(sourceCode !== syncedSourceCode);
setIsUpdateButtonVisible(sourceCode !== '' && props.mode === CodeEditorMode.FREE_EDIT);
}, [props.mode, sourceCode, syncedSourceCode]);

useEffect(() => {
setDiagnosticsOptions({
Expand Down Expand Up @@ -155,14 +163,10 @@ export const SourceCodeEditor = (props: ISourceCodeEditor) => {
);

const UpdateButton = (
<CodeEditorControl
key="updateButton"
icon={<CheckCircleIcon color={'green'} />}
aria-label="Apply the code"
data-testid={'sourceCode--applyButton'}
<SyncButton
isDirty={isDirty}
isVisible={isUpdateButtonVisible}
onClick={updateModelFromTheEditor}
tooltipProps={{ content: 'Sync your code', position: 'top' }}
isVisible={sourceCode !== '' && props.mode === CodeEditorMode.FREE_EDIT}
/>
);

Expand Down
7 changes: 7 additions & 0 deletions packages/kaoto-ui/src/components/SourceCode/SyncButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.icon-warning {
color: var(--pf-global--warning-color--100);
}

.icon-success {
color: var(--pf-global--success-color--100);
}
39 changes: 39 additions & 0 deletions packages/kaoto-ui/src/components/SourceCode/SyncButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import './SyncButton.css';
import { CodeEditorControl } from '@patternfly/react-code-editor';
import { CheckCircleIcon, SyncAltIcon } from '@patternfly/react-icons';
import { FunctionComponent, useEffect, useState } from 'react';

interface ISyncIcon {
isDirty: boolean;
isVisible: boolean;
onClick: () => void;
}

export const SyncButton: FunctionComponent<ISyncIcon> = (props) => {
const [tooltipProps, setTooltipProps] = useState({ content: 'Sync your code', position: 'top' });

useEffect(() => {
setTooltipProps({
content: props.isDirty ? 'Sync your code' : 'Code is synced',
position: 'top',
});
}, [props.isDirty]);

return (
<CodeEditorControl
key="updateButton"
icon={
props.isDirty ? (
<SyncAltIcon className="icon-warning" />
) : (
<CheckCircleIcon className="icon-success" />
)
}
aria-label="Apply the code"
data-testid="sourceCode--applyButton"
onClick={props.onClick}
tooltipProps={tooltipProps}
isVisible={props.isVisible}
/>
);
};
32 changes: 0 additions & 32 deletions packages/kaoto-ui/src/components/SourceCodeEditorModal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kaoto-ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export * from './KaotoToolbar';
export * from './PlusButtonEdge';
export * from './MiniCatalog';
export * from './SettingsModal';
export * from './SourceCodeEditor';
export * from './SourceCode/SourceCodeEditor';
export * from './StepErrorBoundary';
export * from './ThemeSwitcher';
export * from './VisualizationControls';
Expand Down

0 comments on commit b527903

Please sign in to comment.