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

fix(Collection): Clean up auto-scroll and add back selected item styling #7747

Merged
merged 1 commit into from
Jul 22, 2024
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
4 changes: 0 additions & 4 deletions packages/insomnia/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,6 @@ async function renderApp() {
path: 'toggle-expand-all',
action: async (...args) => (await import('./routes/actions')).toggleExpandAllRequestGroupsAction(...args),
},
{
path: 'expand-all-for-request',
action: async (...args) => (await import('./routes/actions')).expandAllForRequest(...args),
},
],
},
{
Expand Down
29 changes: 1 addition & 28 deletions packages/insomnia/src/ui/routes/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import { database as db } from '../../common/database';
import { importResourcesToWorkspace, scanResources } from '../../common/import';
import { generateId } from '../../common/misc';
import * as models from '../../models';
import type { GrpcRequest } from '../../models/grpc-request';
import { getById, update } from '../../models/helpers/request-operations';
import type { MockServer } from '../../models/mock-server';
import { isRemoteProject } from '../../models/project';
import { isRequest, type Request } from '../../models/request';
import { isRequestGroup, isRequestGroupId, type RequestGroup } from '../../models/request-group';
import { isRequestGroup, isRequestGroupId } from '../../models/request-group';
import { isRequestGroupMeta } from '../../models/request-group-meta';
import type { UnitTest } from '../../models/unit-test';
import type { UnitTestSuite } from '../../models/unit-test-suite';
import type { WebSocketRequest } from '../../models/websocket-request';
import { isCollection, isEnvironment, scopeToActivity, type Workspace } from '../../models/workspace';
import type { WorkspaceMeta } from '../../models/workspace-meta';
import { getSendRequestCallback } from '../../network/unit-test-feature';
Expand Down Expand Up @@ -1399,28 +1397,3 @@ export const toggleExpandAllRequestGroupsAction: ActionFunction = async ({ param
}));
return null;
};

export const expandAllForRequest: ActionFunction = async ({ params, request }) => {
const { workspaceId } = params;
invariant(typeof workspaceId === 'string', 'Workspace ID is required');
const data = await request.json() as {
requestId: string;
};
const activeRequest = await getById(data.requestId);
invariant(request, 'Request not found');

const ancestors = await database.withAncestors<RequestGroup | Request | WebSocketRequest | GrpcRequest>(activeRequest, [models.requestGroup.type]);

const requestGroups = ancestors.filter(isRequestGroup);

await Promise.all(requestGroups.map(async requestGroup => {
const requestGroupMeta = await models.requestGroupMeta.getByParentId(requestGroup._id);

if (requestGroupMeta) {
return models.requestGroupMeta.update(requestGroupMeta, { collapsed: false });
}
return models.requestGroupMeta.create({ parentId: requestGroup._id, collapsed: false });
}));

return { success: true };
};
22 changes: 8 additions & 14 deletions packages/insomnia/src/ui/routes/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,6 @@ export const Debug: FC = () => {
key={sortOrder}
dragAndDropHooks={sortOrder === 'type-manual' ? collectionDragAndDrop.dragAndDropHooks : undefined}
onAction={key => {
console.log(key);
const id = key.toString();
if (isRequestGroupId(id)) {
const item = collection.find(i => i.doc._id === id);
Expand Down Expand Up @@ -1101,17 +1100,7 @@ export const Debug: FC = () => {
</div>
</Panel>
<PanelResizeHandle className='h-full w-[1px] bg-[--hl-md]' />
<Panel
onFocus={() => {
requestId && expandAllForRequestFetcher.submit({
requestId,
}, {
action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/expand-all-for-request`,
method: 'POST',
encType: 'application/json',
});
}}
>
<Panel>
<PanelGroup autoSaveId="insomnia-panels" direction={direction}>
<Panel id="pane-one" className='pane-one theme--pane'>
{workspaceId ? (
Expand Down Expand Up @@ -1211,6 +1200,10 @@ const CollectionGridListItem = ({

const name = patchFetcher?.json && typeof patchFetcher.json === 'object' && 'name' in patchFetcher.json && typeof patchFetcher.json.name === 'string' ? patchFetcher.json.name : item.doc.name;

const params = useParams() as { requestId?: string; requestGroupId?: string };

const isSelected = item.doc._id === params.requestId || item.doc._id === params.requestGroupId;

return (
<GridListItem
id={item.doc._id}
Expand All @@ -1225,12 +1218,13 @@ const CollectionGridListItem = ({
setIsContextMenuOpen(true);
}}
onDoubleClick={() => setIsEditable(true)}
className="flex select-none outline-none group-aria-selected:text-[--color-font] relative group-hover:bg-[--hl-xs] group-focus:bg-[--hl-sm] transition-colors gap-2 px-4 items-center h-[--line-height-xs] w-full overflow-hidden text-[--hl]"
data-selected={isSelected}
className="flex select-none outline-none data-[selected=true]:text-[--color-font] relative group-hover:bg-[--hl-xs] group-focus:bg-[--hl-sm] transition-colors gap-2 px-4 items-center h-[--line-height-xs] w-full overflow-hidden text-[--hl]"
style={{
paddingLeft: `${item.level + 1}rem`,
}}
>
<span className="group-aria-selected:bg-[--color-surprise] transition-colors top-0 left-0 absolute h-full w-[2px] bg-transparent" />
<span data-selected={isSelected} className="data-[selected=true]:bg-[--color-surprise] transition-colors top-0 left-0 absolute h-full w-[2px] bg-transparent" />
<Button slot="drag" className="hidden" />
{isRequest(item.doc) && (
<span
Expand Down
Loading