Skip to content

Commit

Permalink
Docge: Add basic handling for the @SInCE tag (#43550)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo authored Aug 24, 2022
1 parent a498e31 commit d012e2a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ _Returns_

- `EntityRecordResolution< RecordType >`: Entity record data.

_Changelog_

`6.1.0` Introduced in WordPress core.

### useEntityRecords

Resolves the specified entity records.
Expand Down Expand Up @@ -875,6 +879,10 @@ _Returns_

- `EntityRecordsResolution< RecordType >`: Entity records data.

_Changelog_

`6.1.0` Introduced in WordPress core.

### useResourcePermissions

Resolves resource permissions.
Expand Down Expand Up @@ -941,6 +949,10 @@ _Returns_

- `ResourcePermissionsResolution< IdType >`: Entity records data.

_Changelog_

`6.1.0` Introduced in WordPress core.

<!-- END TOKEN(Autogenerated hooks|src/hooks/index.ts) -->

## Contributing to this package
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/src/hooks/use-entity-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export interface Options {
/**
* Resolves the specified entity record.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
* @param recordId ID of the requested entity record.
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/src/hooks/use-entity-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const EMPTY_ARRAY = [];
/**
* Resolves the specified entity records.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
* @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
Expand Down
5 changes: 4 additions & 1 deletion packages/core-data/src/hooks/use-query-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ interface QuerySelectResponse< Data > {
* Like useSelect, but the selectors return objects containing
* both the original data AND the resolution info.
*
* @since 6.1.0 Introduced in WordPress core.
* @private
*
* @param {Function} mapQuerySelect see useSelect
* @param {Array} deps see useSelect
*
Expand Down Expand Up @@ -71,7 +74,7 @@ interface QuerySelectResponse< Data > {
*
* @return {QuerySelectResponse} Queried data.
*/
export default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {
export default function useQuerySelect( mapQuerySelect, deps ) {
return useSelect( ( select, registry ) => {
const resolve = ( store ) => enrichSelectors( select( store ) );
return mapQuerySelect( resolve, registry );
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/src/hooks/use-resource-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type ResourcePermissionsResolution< IdType > = [
/**
* Resolves resource permissions.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param resource The resource in question, e.g. media.
* @param id ID of a specific resource entry, if needed, e.g. 10.
*
Expand Down
19 changes: 19 additions & 0 deletions packages/docgen/lib/markdown/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ const formatExamples = ( tags, docs ) => {
}
};

const formatSince = ( tags, docs ) => {
if ( tags && tags.length > 0 ) {
docs.push( '\n' );
docs.push( '\n' );
docs.push( '*Changelog*' );
docs.push( '\n' );
docs.push( '\n' );
docs.push(
...tags.map(
( tag ) =>
`\n${ cleanSpaces(
`\`${ tag.name }\` ${ tag.description }`
) }`
)
);
}
};

const formatDeprecated = ( tags, docs ) => {
if ( tags && tags.length > 0 ) {
docs.push( '\n' );
Expand Down Expand Up @@ -187,6 +205,7 @@ module.exports = (
},
docs
);
formatSince( getSymbolTagsByName( symbol, 'since' ), docs );
docs.push( '\n' );
docs.push( '\n' );
} );
Expand Down
3 changes: 2 additions & 1 deletion packages/docgen/test/get-jsdoc-from-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe( 'JSDoc', () => {
getJSDocFromToken( {
leadingComments: [
{
value: '*\n * A function that adds two parameters.\n *\n * @deprecated Use native addition instead.\n * @since v2\n *\n * @see addition\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators\n *\n * @param {number} firstParam The first param to add.\n * @param {number} secondParam The second param to add.\n *\n * @example\n *\n * ```js\n * const addResult = sum( 1, 3 );\n * console.log( addResult ); // will yield 4\n * ```\n *\n * @return {number} The result of adding the two params.\n ',
value: '*\n * A function that adds two parameters.\n *\n * @deprecated Use native addition instead.\n * @since v2 Introduced.\n *\n * @see addition\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators\n *\n * @param {number} firstParam The first param to add.\n * @param {number} secondParam The second param to add.\n *\n * @example\n *\n * ```js\n * const addResult = sum( 1, 3 );\n * console.log( addResult ); // will yield 4\n * ```\n *\n * @return {number} The result of adding the two params.\n ',
},
],
} )
Expand All @@ -24,6 +24,7 @@ describe( 'JSDoc', () => {
{
tag: 'since',
name: 'v2',
description: 'Introduced.\n',
},
{
tag: 'see',
Expand Down

0 comments on commit d012e2a

Please sign in to comment.