Skip to content

Commit

Permalink
fix: should not refetch as much [INS-3817] (#7377)
Browse files Browse the repository at this point in the history
* should not refetch a much

* remove graphql revalidate

* drill prop
  • Loading branch information
jackkav authored May 6, 2024
1 parent bcf5504 commit 5f08604
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FC, useEffect } from 'react';
import { useFetcher, useParams } from 'react-router-dom';
import React, { FC } from 'react';
import { useParams } from 'react-router-dom';
import styled from 'styled-components';

import { getAccountId } from '../../../account/session';
import { getAppWebsiteBaseURL } from '../../../common/constants';
import { isOwnerOfOrganization } from '../../../models/organization';
import { OrganizationFeatureLoaderData, useOrganizationLoaderData } from '../../../ui/routes/organization';
import { useOrganizationLoaderData } from '../../../ui/routes/organization';
import { useRootLoaderData } from '../../routes/root';
import { showModal } from '../modals';
import { AlertModal } from '../modals/alert-modal';
Expand Down Expand Up @@ -77,28 +77,15 @@ interface Props {
createMockServer: () => void;
importFrom: () => void;
cloneFromGit: () => void;
isGitSyncEnabled: boolean;
}

export const EmptyStatePane: FC<Props> = ({ createRequestCollection, createDesignDocument, createMockServer, importFrom, cloneFromGit }) => {
export const EmptyStatePane: FC<Props> = ({ createRequestCollection, createDesignDocument, createMockServer, importFrom, cloneFromGit, isGitSyncEnabled }) => {
const { organizationId } = useParams<{ organizationId: string }>();
const { organizations } = useOrganizationLoaderData();
const { userSession } = useRootLoaderData();
const currentOrg = organizations.find(organization => (organization.id === organizationId));
const permissionsFetcher = useFetcher<OrganizationFeatureLoaderData>({ key: `permissions:${organizationId}` });

useEffect(() => {
const isIdleAndUninitialized = permissionsFetcher.state === 'idle' && !permissionsFetcher.data;
if (isIdleAndUninitialized) {
permissionsFetcher.load(`/organization/${organizationId}/permissions`);
}
}, [organizationId, permissionsFetcher]);

const { features } = permissionsFetcher.data || {
features: {
gitSync: { enabled: false, reason: 'Insomnia API unreachable' },
},
};
const isGitSyncEnabled = features.gitSync.enabled;
const accountId = getAccountId();

const showUpgradePlanModal = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ async function renderApp() {
(
await import('./routes/organization')
).organizationPermissionsLoader(...args),
shouldRevalidate: data => data.currentParams.organizationId !== data.nextParams.organizationId,
},
{
path: 'sync-projects',
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/ui/routes/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ const ProjectRoute: FC = () => {
createMockServer={createNewMockServer}
importFrom={() => setImportModalType('file')}
cloneFromGit={importFromGit}
isGitSyncEnabled={isGitSyncEnabled}
/>
);
}}
Expand Down

0 comments on commit 5f08604

Please sign in to comment.