Skip to content

Commit

Permalink
Fix Revert button to be active when unstaged changes exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonni committed Nov 2, 2023
1 parent 1462129 commit 7645256
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/renderer/src/components/Card/ActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import type {MouseEvent} from 'react';
import {useState} from 'react';

export type Action = {
/** Icon displayed on this action. */
icon: JSX.Element;
/** Title displayed on this action. */
name: string;
/** Optional tooltip message displayed on this action. */
tooltip?: string;
/** If `true`, the action is disabled. */
disabled?: boolean;
/** Click event handler for this action. */
onClick: () => void;
};

Expand Down
13 changes: 7 additions & 6 deletions packages/renderer/src/components/Card/BaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Merge,
PlaylistAdd,
PlaylistRemove,
ReplyAll,
Save,
Undo,
} from '@mui/icons-material';
import {styled} from '@mui/material';
import type {UUID} from '@syn-types/app';
Expand Down Expand Up @@ -55,6 +55,7 @@ import {fileSaveDialog} from '../Dialogs';
import {GitCommit} from '../GitIcons';
import Content from './Content';
import MenuBar from './MenuBar';
import type {Action} from './ActionsMenu';

const BaseCard = forwardRef<HTMLDivElement, PropsWithChildren<Props>>(
({id, children, ...props}, ref) => {
Expand Down Expand Up @@ -89,7 +90,7 @@ const BaseCard = forwardRef<HTMLDivElement, PropsWithChildren<Props>>(
branch.status !== 'uncommitted';
const dispatch = useAppDispatch();

const actions = [
const actions: Action[] = [
{
icon: <Save />,
name: 'Save',
Expand All @@ -102,13 +103,13 @@ const BaseCard = forwardRef<HTMLDivElement, PropsWithChildren<Props>>(
: null,
},
{
icon: <Undo />,
name: 'Undo',
tooltip: 'Undo changes made to the file content to match the current filesystem version',
icon: <ReplyAll />,
name: 'Revert',
tooltip: 'Undo changes that have not been commited to the version control system',
disabled:
metafile?.handler !== 'Editor' ||
!isVersionedMetafile(metafile) ||
metafile.status === 'unmodified',
!['*modified', '*added', '*deleted'].includes(metafile.status),
onClick: () => {
if (isVersionedMetafile(metafile)) dispatch(revertChanges(metafile));
},
Expand Down

0 comments on commit 7645256

Please sign in to comment.