Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/yellow-socks-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/mongo-nav': minor
---

Add `loadData` prop to `MongoNav`
1 change: 1 addition & 0 deletions packages/mongo-nav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| `activeOrgId` | `string` | ID for active organization, will cause a POST request to cloud to update current active organization. | |
| `activeProjectId` | `string` | ID for active project, will cause a POST request to cloud to update current active project. |
| `className` | `string` | Applies a className to the root element |
| `loadData` | `boolean` | Determines whether or not the component will fetch data from cloud | `true` |

_Any other properties will be spread on the root element_

Expand Down
31 changes: 31 additions & 0 deletions packages/mongo-nav/src/MongoNav.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,35 @@ describe('packages/mongo-nav', () => {
);
});
});

describe('when loadData is set to false', () => {
beforeEach(() =>
renderComponent({
mode: 'dev',
loadData: false,
}),
);

test('the user name is not displayed', () => {
expect(expectedElements.userMenu?.innerHTML.includes('DevMode')).toBe(
false,
);
});

test('the current project name is not displayed', () => {
expect(
expectedElements.currentProject?.innerHTML.includes(
dataFixtures!.currentProject!.projectName,
),
).toBe(false);
});

test('the current organization name is not displayed', () => {
expect(
expectedElements.currentOrg?.innerHTML.includes(
dataFixtures!.currentOrganization!.orgName,
),
).toBe(false);
});
});
});
1 change: 1 addition & 0 deletions packages/mongo-nav/src/MongoNav.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ storiesOf('MongoNav', module).add('Default', () => (
version: '4.4.0',
enabled: boolean('enabled', false),
}}
loadData={boolean('loadData', true)}
/>
</div>
</LeafygreenProvider>
Expand Down
13 changes: 11 additions & 2 deletions packages/mongo-nav/src/MongoNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ interface MongoNavInterface {
* Applies a className to the root element
*/
className?: string;

/**
* Determines whether or not the component will fetch data from cloud
*/
loadData?: boolean;
}

/**
Expand Down Expand Up @@ -157,13 +162,15 @@ interface MongoNavInterface {
* @param props.activeOrgId ID for active organization, will cause a POST request to cloud to update current active organization.
* @param props.activeProjectId ID for active project, will cause a POST request to cloud to update current active project.
* @param props.className Applies a className to the root element
* @param props.loadData Determines whether or not the component will fetch data from cloud
*/
function MongoNav({
activeProduct,
activeNav,
onOrganizationChange,
onProjectChange,
mode = Mode.Production,
loadData = true,
showProjNav = true,
admin = false,
hosts: hostsProp,
Expand Down Expand Up @@ -224,7 +231,9 @@ function MongoNav({
}

useEffect(() => {
if (mode === Mode.Dev) {
if (!loadData) {
setData(undefined);
} else if (mode === Mode.Dev) {
getDataFixtures().then(data => setData(data as DataInterface));
} else {
const body =
Expand All @@ -236,7 +245,7 @@ function MongoNav({
.then(handleResponse)
.catch(console.error);
}
}, [mode, endpointURI, activeOrgId, activeProjectId]);
}, [mode, endpointURI, activeOrgId, activeProjectId, loadData]);

const defaultURLS: Required<URLSInterface> = {
userMenu: {
Expand Down