Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
add files to code studio
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Jan 16, 2024
1 parent 593e6ba commit f823cfa
Show file tree
Hide file tree
Showing 63 changed files with 5,146 additions and 192 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function App() {
const handleKeyEvent = useCallback((e: KeyboardEvent) => {
if (
(e.key === '=' || e.key === '-' || e.key === '0') &&
(e.metaKey || e.ctrlKey)
(e.metaKey || e.ctrlKey) &&
!e.shiftKey
) {
const root = document.querySelector(':root');
if (!root) {
Expand Down
8 changes: 7 additions & 1 deletion client/src/CommandBar/Body/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ const CommandBarItem = ({
onClick();
if (closeOnClick) {
setIsVisible(false);
setChosenStep({ id: CommandBarStepEnum.INITIAL });
}
} else {
setChosenStep({ id: id as CommandBarStepEnum });
setChosenStep({
id: id as Exclude<
CommandBarStepEnum,
CommandBarStepEnum.ADD_FILE_TO_STUDIO
>,
});
}
updateArrayInStorage(RECENT_COMMANDS_KEY, itemKey);
}, [id, onClick, closeOnClick, itemKey]);
Expand Down
3 changes: 3 additions & 0 deletions client/src/CommandBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ManageRepos from './steps/ManageRepos';
import AddNewRepo from './steps/AddNewRepo';
import ToggleTheme from './steps/ToggleTheme';
import SearchFiles from './steps/SeachFiles';
import AddFileToStudio from './steps/AddFileToStudio';

type Props = {};

Expand Down Expand Up @@ -78,6 +79,8 @@ const CommandBar = ({}: Props) => {
<ToggleTheme />
) : chosenStep.id === CommandBarStepEnum.SEARCH_FILES ? (
<SearchFiles />
) : chosenStep.id === CommandBarStepEnum.ADD_FILE_TO_STUDIO ? (
<AddFileToStudio {...chosenStep.data} />
) : null}
</Modal>
);
Expand Down
161 changes: 161 additions & 0 deletions client/src/CommandBar/steps/AddFileToStudio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import {
ChangeEvent,
memo,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import {
AddFileToStudioDataType,
CommandBarItemGeneralType,
CommandBarSectionType,
CommandBarStepEnum,
TabTypesEnum,
} from '../../types/general';
import { CodeStudioIcon, PlusSignIcon } from '../../icons';
import Header from '../Header';
import Body from '../Body';
import Footer from '../Footer';
import { CommandBarContext } from '../../context/commandBarContext';
import { ProjectContext } from '../../context/projectContext';
import { TabsContext } from '../../context/tabsContext';
import { postCodeStudio } from '../../services/api';

type Props = AddFileToStudioDataType & {};

const AddFileToStudio = ({ path, repoRef, branch }: Props) => {
const { t } = useTranslation();
const { setChosenStep } = useContext(CommandBarContext.Handlers);
const { project, refreshCurrentProjectStudios } = useContext(
ProjectContext.Current,
);
const { openNewTab } = useContext(TabsContext.Handlers);
const [inputValue, setInputValue] = useState('');
const [sectionsToShow, setSectionsToShow] = useState<CommandBarSectionType[]>(
[],
);

const handleChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
}, []);

const handleBack = useCallback(() => {
setChosenStep({ id: CommandBarStepEnum.INITIAL });
}, []);

const handleNewCodeStudio = useCallback(async () => {
if (project?.id) {
const newId = await postCodeStudio(project.id);
refreshCurrentProjectStudios();
openNewTab({
type: TabTypesEnum.FILE,
studioId: newId,
path,
repoRef,
branch,
});
}
}, [project?.id, path, repoRef, branch]);

const initialSections = useMemo(() => {
return [
{
items: [
{
label: t('New studio conversation'),
Icon: PlusSignIcon,
id: 'new_code_studio',
key: 'new_code_studio',
onClick: handleNewCodeStudio,
closeOnClick: true,
footerHint: '',
footerBtns: [{ label: t('Create new'), shortcut: ['entr'] }],
},
],
itemsOffset: 0,
key: 'new-items',
},
{
items: (project?.studios || []).map((s) => ({
label: s.name,
Icon: CodeStudioIcon,
id: s.id,
key: s.id,
onClick: () =>
openNewTab({
type: TabTypesEnum.FILE,
studioId: s.id,
path,
repoRef,
branch,
}),
closeOnClick: true,
// footerHint: t('{{count}} context files used', {
// count: s.token_counts?.per_file.filter((f) => !!f).length,
// }),
footerHint: '',
footerBtns: [{ label: t('Add to existing'), shortcut: ['entr'] }],
})),
label: t('Existing studio conversations'),
itemsOffset: 1,
key: 'studio-items',
},
];
}, [
t,
project?.studios,
handleNewCodeStudio,
openNewTab,
path,
repoRef,
branch,
]);

useEffect(() => {
if (!inputValue) {
setSectionsToShow(initialSections);
return;
}
const newSectionsToShow: CommandBarSectionType[] = [];
initialSections.forEach((s) => {
const items = (s.items as CommandBarItemGeneralType[]).filter((item) => {
return item.label.toLowerCase().includes(inputValue.toLowerCase());
});

if (items.length) {
newSectionsToShow.push({
...s,
items,
itemsOffset: newSectionsToShow[newSectionsToShow.length - 1]
? newSectionsToShow[newSectionsToShow.length - 1].itemsOffset +
newSectionsToShow[newSectionsToShow.length - 1].items.length
: 0,
});
}
});
setSectionsToShow(newSectionsToShow);
}, [initialSections, inputValue]);

const breadcrumbs = useMemo(() => {
return [t('Add file to studio')];
}, []);

return (
<div className="w-full flex flex-col h-[28.875rem] max-w-[40rem] overflow-auto">
<Header
value={inputValue}
onChange={handleChange}
breadcrumbs={breadcrumbs}
handleBack={handleBack}
placeholder={t('Search studio conversations...')}
/>
<Body sections={sectionsToShow} />
<Footer />
</div>
);
};

export default memo(AddFileToStudio);
32 changes: 25 additions & 7 deletions client/src/Project/CurrentTabContent/FileTab/ActionsDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
import { memo, useMemo } from 'react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import DropdownSection from '../../../components/Dropdown/Section';
import SectionItem from '../../../components/Dropdown/Section/SectionItem';
import { SplitViewIcon, FileWithSparksIcon } from '../../../icons';
import {
SplitViewIcon,
FileWithSparksIcon,
StudioPlusSignIcon,
} from '../../../icons';
import { openInSplitViewShortcut } from '../../../consts/commandBar';
import { explainFileShortcut } from './index';
import {
addFileToStudioShortcut,
explainFileShortcut,
} from '../../../consts/shortcuts';

type Props = {
handleExplain: () => void;
handleMoveToAnotherSide: () => void;
handleAddToStudio: () => void;
};

const ActionsDropdown = ({ handleExplain, handleMoveToAnotherSide }: Props) => {
const ActionsDropdown = ({
handleExplain,
handleMoveToAnotherSide,
handleAddToStudio,
}: Props) => {
const { t } = useTranslation();

return (
<div>
<DropdownSection>
<DropdownSection borderBottom>
<SectionItem
label={t('Explain file')}
onClick={handleExplain}
// isFocused
shortcut={explainFileShortcut}
icon={<FileWithSparksIcon sizeClassName="w-4 h-4" />}
/>
<SectionItem
label={t('Add to studio')}
onClick={handleAddToStudio}
shortcut={addFileToStudioShortcut}
icon={<StudioPlusSignIcon sizeClassName="w-4 h-4" />}
/>
</DropdownSection>
<DropdownSection>
<SectionItem
label={t('Open in split view')}
shortcut={openInSplitViewShortcut}
onClick={handleMoveToAnotherSide}
// isFocused
icon={<SplitViewIcon sizeClassName="w-4 h-4" />}
/>
</DropdownSection>
Expand Down
Loading

0 comments on commit f823cfa

Please sign in to comment.