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

DOP-3903: API Changelog Support to omit entries #919

Merged
merged 21 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
8 changes: 6 additions & 2 deletions plugins/utils/openapi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const { hideChanges, hideDiffChanges } = require('../../src/components/OpenAPIChangelog/utils/filterHiddenChanges');

const atlasAdminProdChangelogS3Prefix = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog';
const atlasAdminDevChangelogS3Prefix = 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/changelog';

const fetchChangelogData = async (runId, versions, s3Prefix) => {
try {
/* Using metadata runId, fetch OpenAPI Changelog full change list */
const changelogResp = await fetch(`${s3Prefix}/${runId}/changelog.json`);
const changelog = await changelogResp.json();
const unfilteredChangelog = await changelogResp.json();
const changelog = hideChanges(unfilteredChangelog);

/* Aggregate all Resources in changelog for frontend filter */
const resourcesListSet = new Set();
Expand All @@ -18,7 +21,8 @@ const fetchChangelogData = async (runId, versions, s3Prefix) => {
const mostRecentResourceVersions = versions.slice(-2);
const mostRecentDiffLabel = mostRecentResourceVersions.join('_');
const mostRecentDiffResp = await fetch(`${s3Prefix}/${runId}/${mostRecentDiffLabel}.json`);
const mostRecentDiffData = await mostRecentDiffResp.json();
const mostRecentUnfilteredDiffData = await mostRecentDiffResp.json();
const mostRecentDiffData = hideDiffChanges(mostRecentUnfilteredDiffData);

return {
changelog,
Expand Down
1 change: 1 addition & 0 deletions src/components/OpenAPIChangelog/OpenAPIChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const StyledLoadingSkeleton = styled.div`
const OpenAPIChangelog = () => {
const { snootyEnv } = useSiteMetadata();
const { index = {}, changelog = [], changelogResourcesList = [] } = useChangelogData();

const resourceVersions = index.versions?.length ? index.versions.slice().reverse() : [];
const downloadChangelogUrl = useMemo(() => getDownloadChangelogUrl(index.runId, snootyEnv), [index, snootyEnv]);

Expand Down
46 changes: 46 additions & 0 deletions src/components/OpenAPIChangelog/utils/filterHiddenChanges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//nested filtering out all changes with hideFromChangelog
//hides changes on all versions changelog
const hideChanges = (changelog) => {
const versionUpdate = (version) => {
const updatedVersion = { ...version };
if (version?.changes) {
updatedVersion.changes = version.changes.filter((change) => !change.hideFromChangelog);
}
return updatedVersion;
};

//pathUpdate takes the array of versions from the specific path passed in and takes each version and runs versionUpdate on it
const pathUpdate = (path) => {
const updatedPath = { ...path, versions: path.versions.map(versionUpdate) };
updatedPath.versions = updatedPath.versions.filter((version) => version.changes?.length);
return updatedPath;
};

//dateUpdate takes the array of paths from the specific date section passed in and takes each path and runs pathUpdate on it
const dateUpdate = (dateSection) => {
const updatedDateSection = { ...dateSection, paths: dateSection.paths.map(pathUpdate) };
updatedDateSection.paths = updatedDateSection.paths.filter((path) => path.versions?.length);
return updatedDateSection;
};

//changelog is the json file with everything in it. Map at this level takes each date section and runs dateUpdate on it
const updatedChangelog = changelog.map(dateUpdate);
return updatedChangelog.filter((dateSection) => dateSection.paths?.length);
};

//nested filtering out all changes with hideFromChangelog
//hides changes on diffs
const hideDiffChanges = (diffData) => {
const pathUpdate = (path) => {
const updatedPath = { ...path };
if (path?.changes) {
updatedPath.changes = path.changes.filter((change) => !change.hideFromChangelog);
}
return updatedPath;
};

const updatedDiffData = diffData.map(pathUpdate);
return updatedDiffData.filter((path) => path.changes?.length);
};

module.exports = { hideChanges, hideDiffChanges };
4 changes: 3 additions & 1 deletion src/components/OpenAPIChangelog/utils/useFetchDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { fetchOADiff } from '../../../utils/realm';
import useChangelogData from '../../../utils/use-changelog-data';
import { getDiffRequestFormat } from './getDiffRequestFormat';
import { hideDiffChanges } from './filterHiddenChanges';

export const useFetchDiff = (resourceVersionOne, resourceVersionTwo, setIsLoading, setToastOpen, snootyEnv) => {
const { index = {}, mostRecentDiff = {} } = useChangelogData();
Expand All @@ -20,7 +21,8 @@ export const useFetchDiff = (resourceVersionOne, resourceVersionTwo, setIsLoadin
setIsLoading(true);
fetchOADiff(index.runId, fromAndToDiffLabel, snootyEnv)
.then((response) => {
setDiff(response);
const filteredDiff = hideDiffChanges(response);
setDiff(filteredDiff);
setIsLoading(false);
})
.catch((err) => {
Expand Down
157 changes: 141 additions & 16 deletions tests/unit/__snapshots__/ChangeList.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
line-height: 28px;
}

.emotion-35 {
.emotion-54 {
font-family: Euclid Circular A,‘Helvetica Neue’,Helvetica,Arial,sans-serif;
display: -webkit-inline-box;
display: -webkit-inline-flex;
Expand All @@ -183,11 +183,11 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
color: #00684A;
}

.emotion-40 {
.emotion-59 {
position: relative;
}

.emotion-41 {
.emotion-60 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -200,7 +200,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
margin-right: 5px;
}

.emotion-43 {
.emotion-62 {
color: #DB3030;
}

Expand Down Expand Up @@ -254,6 +254,53 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
</ul>
</div>
</section>
<section
class="emotion-2 emotion-3"
>
<h2
class="emotion-4"
>
01 February 2024 Release
</h2>
<div
class="emotion-5 emotion-6"
data-testid="resource-changes-block"
>
<div
class="emotion-7 emotion-8"
>
<a
class="lg-ui-0001 emotion-9"
href="//0/#tag/Alert-Configurations/operation/updateAlertConfiguration"
target="_self"
>
<span
class="emotion-10"
>
<h6
class="emotion-11 emotion-12 emotion-13"
>
PUT /api/atlas/v2/groups/{groupId}/alertConfigs/{alertConfigId}
</h6>
</span>
</a>
<div
class="emotion-14 emotion-15 emotion-16"
>
Removed
</div>
</div>
<ul
class="emotion-17 emotion-18"
>
<li
class="emotion-19 emotion-20"
>
This change should really definitely be hidden
</li>
</ul>
</div>
</section>
<section
class="emotion-2 emotion-3"
>
Expand Down Expand Up @@ -285,7 +332,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
</span>
</a>
<div
class="emotion-14 emotion-15 emotion-35"
class="emotion-14 emotion-15 emotion-54"
>
Released
</div>
Expand All @@ -297,11 +344,11 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
class="emotion-19 emotion-20"
>
<div
class="emotion-40 emotion-41 emotion-42"
class="emotion-59 emotion-60 emotion-61"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-43"
class="emotion-62"
fill="none"
height="16"
role="img"
Expand Down Expand Up @@ -344,7 +391,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
</span>
</a>
<div
class="emotion-14 emotion-15 emotion-35"
class="emotion-14 emotion-15 emotion-54"
>
Released
</div>
Expand All @@ -356,11 +403,37 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
class="emotion-19 emotion-20"
>
<div
class="emotion-40 emotion-41 emotion-42"
class="emotion-59 emotion-60 emotion-61"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-62"
fill="none"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14ZM7 4.5a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4Zm2 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</div>
This change should be hidden
</li>
<li
class="emotion-19 emotion-20"
>
<div
class="emotion-59 emotion-60 emotion-61"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-43"
class="emotion-62"
fill="none"
height="16"
role="img"
Expand All @@ -382,11 +455,11 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
class="emotion-19 emotion-20"
>
<div
class="emotion-40 emotion-41 emotion-42"
class="emotion-59 emotion-60 emotion-61"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-43"
class="emotion-62"
fill="none"
height="16"
role="img"
Expand All @@ -413,11 +486,11 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
class="emotion-19 emotion-20"
>
<div
class="emotion-40 emotion-41 emotion-42"
class="emotion-59 emotion-60 emotion-61"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-43"
class="emotion-62"
fill="none"
height="16"
role="img"
Expand Down Expand Up @@ -460,7 +533,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
</span>
</a>
<div
class="emotion-14 emotion-15 emotion-35"
class="emotion-14 emotion-15 emotion-54"
>
Updated
</div>
Expand Down Expand Up @@ -512,7 +585,7 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders all version changelog co
</span>
</a>
<div
class="emotion-14 emotion-15 emotion-35"
class="emotion-14 emotion-15 emotion-54"
>
Updated
</div>
Expand Down Expand Up @@ -696,6 +769,32 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders diff changelog correctly
<ul
class="emotion-11 emotion-12"
>
<li
class="emotion-13 emotion-14"
>
<div
class="emotion-15 emotion-16 emotion-17"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-18"
fill="none"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14ZM7 4.5a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4Zm2 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</div>
A change
</li>
<li
class="emotion-13 emotion-14"
>
Expand Down Expand Up @@ -812,6 +911,32 @@ exports[`OpenAPIChangelog ChangeList ChangeList renders diff changelog correctly
</div>
Removed the required property 'name' from the response with the '200' status.
</li>
<li
class="emotion-13 emotion-14"
>
<div
class="emotion-15 emotion-16 emotion-17"
>
<svg
aria-label="Important With Circle Icon"
class="emotion-18"
fill="none"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14ZM7 4.5a1 1 0 0 1 2 0v4a1 1 0 0 1-2 0v-4Zm2 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</div>
Removed the required property 'name' from the response with the '200' status.
</li>
</ul>
</div>
</div>
Expand Down
Loading
Loading