Skip to content

Commit

Permalink
allow deselecting proto file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-willis committed Jan 16, 2025
1 parent 78a97f4 commit a2dd84a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const GrpcMethodDropdown: FunctionComponent<Props> = ({
}));
const selectedPath = selectedMethod?.fullPath;

console.log(methods, disabled);
return (
<Select
aria-label="Select gRPC method"
Expand Down
15 changes: 7 additions & 8 deletions packages/insomnia/src/ui/components/modals/proto-files-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export interface Props {
reloadRequests: (requestIds: string[]) => void;
}

export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave, reloadRequests }) => {
export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave }) => {
const modalRef = useRef<ModalHandle>(null);
const { workspaceId } = useParams() as { workspaceId: string };
const { workspaceId } = useParams() as { workspaceId: string; requestId: string };

const [selectedId, setSelectedId] = useState(defaultId);
const [protoDirectories, setProtoDirectories] = useState<ExpandedProtoDirectory[]>([]);
Expand Down Expand Up @@ -205,7 +205,7 @@ export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave, reloadRe
if (!filePath) {
return;
}
if (!await isProtofileValid(filePath)) {
if (!(await isProtofileValid(filePath))) {
return;
}
const contents = await fs.promises.readFile(filePath, 'utf-8');
Expand All @@ -216,8 +216,7 @@ export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave, reloadRe
const impacted = await models.grpcRequest.findByProtoFileId(updatedFile._id);
const requestIds = impacted.map(g => g._id);
if (requestIds?.length) {
requestIds.forEach(requestId => window.main.grpc.cancel(requestId));
reloadRequests(requestIds);
requestIds.forEach(async requestId => window.main.grpc.cancel(requestId));
}
};

Expand Down Expand Up @@ -294,6 +293,7 @@ export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave, reloadRe
protoDirectories={protoDirectories}
selectedId={selectedId}
handleSelect={id => setSelectedId(id)}
handleUnselect={() => setSelectedId('')}
handleUpdate={handleUpdate}
handleDelete={handleDeleteFile}
handleDeleteDirectory={handleDeleteDirectory}
Expand All @@ -305,11 +305,10 @@ export const ProtoFilesModal: FC<Props> = ({ defaultId, onHide, onSave, reloadRe
className="btn"
onClick={event => {
event.preventDefault();
if (typeof onSave === 'function' && selectedId) {
onSave(selectedId);
if (typeof onSave === 'function') {
onSave(selectedId || '');
}
}}
disabled={!selectedId}
>
Save
</button>
Expand Down
16 changes: 9 additions & 7 deletions packages/insomnia/src/ui/components/panes/grpc-request-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const GrpcRequestPane: FunctionComponent<Props> = ({
reloadRequests,
}) => {
const { activeRequest } = useRouteLoaderData('request/:requestId') as GrpcRequestLoaderData;
const {
activeEnvironment,
} = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData;
const environmentId = activeEnvironment._id;
const { settings } = useRootLoaderData();
const [isProtoModalOpen, setIsProtoModalOpen] = useState(false);
const { requestMessages, running, methods } = grpcState;
Expand Down Expand Up @@ -86,10 +90,6 @@ export const GrpcRequestPane: FunctionComponent<Props> = ({
const activeRequestSyncVersion = useActiveRequestSyncVCSVersion();
const { workspaceId, requestId } = useParams() as { workspaceId: string; requestId: string };
const patchRequest = useRequestPatcher();
const {
activeEnvironment,
} = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData;
const environmentId = activeEnvironment._id;
// Reset the response pane state when we switch requests, the environment gets modified, or the (Git|Sync)VCS version changes
const uniquenessKey = `${activeEnvironment.modified}::${requestId}::${gitVersion}::${activeRequestSyncVersion}`;
const method = methods.find(c => c.fullPath === activeRequest.protoMethodName);
Expand Down Expand Up @@ -381,7 +381,11 @@ export const GrpcRequestPane: FunctionComponent<Props> = ({
defaultId={activeRequest.protoFileId}
onHide={() => setIsProtoModalOpen(false)}
onSave={async (protoFileId: string) => {
if (activeRequest.protoFileId !== protoFileId) {
if (!protoFileId) {
patchRequest(requestId, { protoFileId: '', protoMethodName: '' });
setGrpcState({ ...grpcState, methods: [] });
setIsProtoModalOpen(false);
} else {
try {
const methods = await window.main.grpc.loadMethods(protoFileId);
patchRequest(requestId, { protoFileId, protoMethodName: '' });
Expand All @@ -394,8 +398,6 @@ export const GrpcRequestPane: FunctionComponent<Props> = ({
error,
});
}
} else {
setIsProtoModalOpen(false);
}
}}
/>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Props {
protoDirectories: ExpandedProtoDirectory[];
selectedId?: string;
handleSelect: SelectProtoFileHandler;
handleUnselect: SelectProtoFileHandler;
handleDelete: DeleteProtoFileHandler;
handleUpdate: UpdateProtoFileHandler;
handleDeleteDirectory: DeleteProtoDirectoryHandler;
Expand All @@ -29,6 +30,7 @@ const recursiveRender = (
indent: number,
{ dir, files, subDirs }: ExpandedProtoDirectory,
handleSelect: SelectProtoFileHandler,
handleUnselect: SelectProtoFileHandler,
handleUpdate: UpdateProtoFileHandler,
handleDelete: DeleteProtoFileHandler,
handleDeleteDirectory: DeleteProtoDirectoryHandler,
Expand Down Expand Up @@ -69,7 +71,17 @@ const recursiveRender = (
onClick={() => handleSelect(f._id)}
>
<>
<Checkbox className="py-0" isSelected={f._id === selectedId} onChange={isSelected => isSelected && handleSelect(f._id)}>
<Checkbox
className="py-0"
isSelected={f._id === selectedId}
onChange={isSelected => {
if (isSelected) {
handleSelect(f._id);
} else {
handleUnselect(f._id);
}
}}
>
{({ isSelected }) => {
return <>
{isSelected ?
Expand Down Expand Up @@ -115,6 +127,7 @@ const recursiveRender = (
indent + 1,
sd,
handleSelect,
handleUnselect,
handleUpdate,
handleDelete,
handleDeleteDirectory,
Expand All @@ -133,6 +146,7 @@ export const ProtoFileList: FunctionComponent<Props> = props => (
0,
dir,
props.handleSelect,
props.handleUnselect,
props.handleUpdate,
props.handleDelete,
props.handleDeleteDirectory,
Expand Down

0 comments on commit a2dd84a

Please sign in to comment.