diff --git a/src/github-apps/scripts/sync.js b/src/github-apps/scripts/sync.js index f229a70701..b1bdf46b60 100755 --- a/src/github-apps/scripts/sync.js +++ b/src/github-apps/scripts/sync.js @@ -7,7 +7,6 @@ import path from 'path' import { slug } from 'github-slugger' import yaml from 'js-yaml' -import { getOverrideCategory } from '../../rest/scripts/utils/operation.js' import { getContents } from '../../../script/helpers/git-utils.js' import permissionSchema from './permission-list-schema.js' import enabledSchema from './enabled-list-schema.js' @@ -39,7 +38,7 @@ export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAcces const isUserAccessToken = progAccessData[operation.operationId].userToServerRest const isFineGrainedPat = isUserAccessToken && !progAccessData[operation.operationId].disabledForPatV2 - const { category, subcategory } = getCategory(operation) + const { category, subcategory } = operation['x-github'] const appDataOperation = { slug: slug(operation.summary), subcategory, @@ -232,12 +231,6 @@ function sortObjectByTitle(obj) { }, {}) } -function getCategory(operation) { - const schemaCategory = operation['x-github'].category - const schemaSubcategory = operation['x-github'].subcategory - return getOverrideCategory(operation.operationId, schemaCategory, schemaSubcategory) -} - function getDisplayTitle(title, resourceGroup) { if (!title) { console.warn(`No title found for title ${title} resource group ${resourceGroup}`) diff --git a/src/landings/components/SidebarProduct.tsx b/src/landings/components/SidebarProduct.tsx index 65143f4bc7..92a15bfddd 100644 --- a/src/landings/components/SidebarProduct.tsx +++ b/src/landings/components/SidebarProduct.tsx @@ -168,7 +168,6 @@ export const SidebarProduct = () => { {restPages.map((childPage, i) => { - const isStandaloneCategory = childPage.documentType === 'article' const childTitle = childPage.shortTitle || childPage.title return ( @@ -177,7 +176,6 @@ export const SidebarProduct = () => { routePath={routePath} title={childTitle} page={childPage} - isStandaloneCategory={isStandaloneCategory} /> ) })} diff --git a/src/rest/components/RestCollapsibleSection.tsx b/src/rest/components/RestCollapsibleSection.tsx index 26ff7b7385..66c84c0e8d 100644 --- a/src/rest/components/RestCollapsibleSection.tsx +++ b/src/rest/components/RestCollapsibleSection.tsx @@ -17,16 +17,14 @@ type SectionProps = { routePath: string page: ProductTreeNode title: string - isStandaloneCategory: boolean } export const RestCollapsibleSection = (props: SectionProps) => { const router = useRouter() - const { routePath, title, page, isStandaloneCategory } = props + const { routePath, title, page } = props const [currentAnchor, setCurrentAnchor] = useState('') const [visibleAnchor, setVisibleAnchor] = useState('') const isActive = routePath.includes(page.href + '/') || routePath === page.href - const [standAloneExpanded, setStandAloneExpanded] = useState(isActive) const [mapTopicExpanded, setMapTopicExpanded] = useState(isActive) const miniTocItems = @@ -125,114 +123,85 @@ export const RestCollapsibleSection = (props: SectionProps) => { return ( // This is where a category has no subcategory
- {isStandaloneCategory ? ( - { - router.push(page.href) - e?.stopPropagation() - setStandAloneExpanded(!standAloneExpanded) - }} - > - {title} - - {miniTocItems.length > 0 && ( - <> - {miniTocItems.map((item) => { - return renderRestAnchorLink(item) - })} - - )} - - - ) : ( - // This is where a category has a subcategory - - {title} - - {page.childPages.map((childPage, i) => { - const childTitle = childPage.shortTitle || childPage.title - const childActive = - routePath.includes(childPage.href + '/') || routePath === childPage.href - const childCurrent = routePath === childPage.href - return ( -
- setMapTopicExpanded(childCurrent && mapTopicExpanded)} - defaultExpanded={childActive} - // We need the subcategory level to router.push so that we can get the operations - // We also want it to open/close on click without doing router.push when toggling - onSelect={(e) => { - e.preventDefault() - const currentTarget = e.target - if ( - childPage.href.split('/').pop() === router.query.subcategory && - mapTopicExpanded - ) { - prevTarget = currentTarget - } - - if (prevTarget && prevTarget === currentTarget) { - setMapTopicExpanded(!mapTopicExpanded) - } else { - sendEvent({ - type: EventType.navigate, - navigate_label: `rest page navigate to: ${childPage.href}`, - }) - } - - if ( - e.nativeEvent instanceof KeyboardEvent && - e.nativeEvent.code === 'Enter' - ) { - document.getElementById(childPage.href)?.click() - e?.stopPropagation() - } - + + {title} + + {page.childPages.map((childPage, i) => { + const childTitle = childPage.shortTitle || childPage.title + const childActive = + routePath.includes(childPage.href + '/') || routePath === childPage.href + const childCurrent = routePath === childPage.href + return ( +
+ setMapTopicExpanded(childCurrent && mapTopicExpanded)} + defaultExpanded={childActive} + // We need the subcategory level to router.push so that we can get the operations + // We also want it to open/close on click without doing router.push when toggling + onSelect={(e) => { + e.preventDefault() + const currentTarget = e.target + if ( + childPage.href.split('/').pop() === router.query.subcategory && + mapTopicExpanded + ) { prevTarget = currentTarget - }} - > - - {childTitle} - + } - - {/* At this point we have the mini-toc data for the current page - so we render this list of operation links. */} - {routePath === childPage.href ? ( - <> - {miniTocItems.length > 0 && ( - <> - {miniTocItems.map((item) => { - return renderRestAnchorLink(item) - })} - - )} - - ) : ( -
- )} -
-
-
- ) - })} -
-
- )} + if (prevTarget && prevTarget === currentTarget) { + setMapTopicExpanded(!mapTopicExpanded) + } else { + sendEvent({ + type: EventType.navigate, + navigate_label: `rest page navigate to: ${childPage.href}`, + }) + } + + if (e.nativeEvent instanceof KeyboardEvent && e.nativeEvent.code === 'Enter') { + document.getElementById(childPage.href)?.click() + e?.stopPropagation() + } + + prevTarget = currentTarget + }} + > + + {childTitle} + + + + {/* At this point we have the mini-toc data for the current page + so we render this list of operation links. */} + {routePath === childPage.href ? ( + <> + {miniTocItems.length > 0 && ( + <> + {miniTocItems.map((item) => { + return renderRestAnchorLink(item) + })} + + )} + + ) : ( +
+ )} +
+
+
+ ) + })} +
+
) } diff --git a/src/rest/scripts/utils/operation.js b/src/rest/scripts/utils/operation.js index 9996beabc7..91f4001093 100644 --- a/src/rest/scripts/utils/operation.js +++ b/src/rest/scripts/utils/operation.js @@ -1,9 +1,7 @@ #!/usr/bin/env node import httpStatusCodes from 'http-status-code' -import { readFile } from 'fs/promises' import { get, isPlainObject } from 'lodash-es' import { parseTemplate } from 'url-template' -import path from 'path' import mergeAllOf from 'json-schema-merge-allof' import { renderContent } from '#src/content-render/index.js' @@ -12,10 +10,6 @@ import operationSchema from './operation-schema.js' import { validateData } from './validate-data.js' import { getBodyParams } from './get-body-params.js' -const { operationUrls } = JSON.parse( - await readFile(path.join('src/rest/lib/rest-api-overrides.json'), 'utf8') -) - export default class Operation { #operation constructor(verb, requestPath, operation, globalServers) { @@ -47,25 +41,14 @@ export default class Operation { this.verb = verb this.requestPath = requestPath this.title = operation.summary - this.setCategories() + this.category = operation['x-github'].category + this.subcategory = operation['x-github'].subcategory this.parameters = operation.parameters || [] this.bodyParameters = [] this.enabledForGitHubApps = operation['x-github'].enabledForGitHubApps return this } - setCategories() { - const operationId = this.#operation.operationId - const xGithub = this.#operation['x-github'] - const { category, subcategory } = getOverrideCategory( - operationId, - xGithub.category, - xGithub.subcategory - ) - this.category = category - this.subcategory = subcategory - } - async process() { await Promise.all([ this.codeExamples(), @@ -79,10 +62,6 @@ export default class Operation { validateData(this, operationSchema) } - getExternalDocs() { - return this.#operation.externalDocs - } - async renderDescription() { this.descriptionHTML = await renderContent(this.#operation.description) return this @@ -169,18 +148,3 @@ export default class Operation { ) } } - -// This is a temporary method of overriding the category and subcategory -// of an operation to allow redirecting. We only need to do this until -// we update the urls in the OpenAPI to reflect the current location on -// docs.github.com. Once we've done that, we can remove this functionality. -export function getOverrideCategory(operationId, category, subcategory) { - const newCategory = operationUrls[operationId] ? operationUrls[operationId].category : category - - const isSubcategoryOverride = operationUrls[operationId] && operationUrls[operationId].subcategory - const newSubcategory = isSubcategoryOverride - ? operationUrls[operationId].subcategory - : subcategory || category - - return { category: newCategory, subcategory: newSubcategory } -} diff --git a/tests/rendering-fixtures/playwright-rendering.spec.ts b/tests/rendering-fixtures/playwright-rendering.spec.ts index 2dfcb948b4..54940d5bcd 100644 --- a/tests/rendering-fixtures/playwright-rendering.spec.ts +++ b/tests/rendering-fixtures/playwright-rendering.spec.ts @@ -429,14 +429,6 @@ test.describe('survey', () => { }) test.describe('rest API reference pages', () => { - test('REST code-scanning', async ({ page }) => { - await page.goto('/rest') - await page.getByRole('treeitem', { name: 'Code Scanning' }).locator('svg').click() - await page.getByText('Code Scanning').click() - await page.getByTestId('sidebar').getByRole('link', { name: 'About code scanning' }).click() - await expect(page).toHaveURL(/\/en\/rest\/code-scanning\?apiVersion=/) - await expect(page).toHaveTitle(/Code Scanning - GitHub Docs/) - }) test('REST actions', async ({ page }) => { await page.goto('/rest') await page.getByTestId('sidebar').getByText('Actions').click()