Skip to content

Commit

Permalink
Merge pull request #732 from nisan-abeywickrama/fix-document-order
Browse files Browse the repository at this point in the history
Add default sorting order for Api document types in devportal
  • Loading branch information
tgtshanika authored Sep 5, 2024
2 parents 9335757 + 1ad03c3 commit 98e4176
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions portals/devportal/src/main/webapp/site/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@
"Apis.Details.Documents.Documentation.title": "API Documentation",
"Apis.Details.Documents.Documentation.type.api.msg.format": "API_MESSAGE_FORMAT",
"Apis.Details.Documents.Documentation.type.how.to": "HOWTO",
"Apis.Details.Documents.Documentation.type.other": "Other",
"Apis.Details.Documents.Documentation.type.other": "OTHER",
"Apis.Details.Documents.Documentation.type.public.forum": "PUBLIC_FORUM",
"Apis.Details.Documents.Documentation.type.samples": "Samples",
"Apis.Details.Documents.Documentation.type.samples": "SAMPLES",
"Apis.Details.Documents.Documentation.type.support.forum": "SUPPORT_FORUM",
"Apis.Details.Documents.Documentation.type.swagger.doc": "SWAGGER_DOC",
"Apis.Details.Documents.View.btn.download": "Download",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,17 @@ function DocList(props) {
const {
documentList, apiId, selectedDoc, setbreadcrumbDocument, intl,
} = props;

const documentTypeOrder = ['HOWTO', 'SAMPLES', 'PUBLIC_FORUM', 'SUPPORT_FORUM', 'OTHER'];

const documentTypes = {
HOWTO: intl.formatMessage({
id: 'Apis.Details.Documents.Documentation.type.how.to',
defaultMessage: 'HOWTO',
}),
SAMPLES: intl.formatMessage({
id: 'Apis.Details.Documents.Documentation.type.samples',
defaultMessage: 'Samples',
defaultMessage: 'SAMPLES',
}),
PUBLIC_FORUM: intl.formatMessage({
id: 'Apis.Details.Documents.Documentation.type.public.forum',
Expand All @@ -261,7 +264,7 @@ function DocList(props) {
}),
OTHER: intl.formatMessage({
id: 'Apis.Details.Documents.Documentation.type.other',
defaultMessage: 'Other',
defaultMessage: 'OTHER',
}),
};

Expand Down Expand Up @@ -289,7 +292,13 @@ function DocList(props) {
value={selectedDoc}
id='document-autocomplete'
className={classes.autocomplete}
options={documentList.sort((a, b) => -b.type.localeCompare(a.type))}
options={documentList.sort((a, b) => {
const getOrder = (type) => {
const order = documentTypeOrder.indexOf(type);
return order === -1 ? -1 : order;
};
return getOrder(a.type) - getOrder(b.type);
})}
groupBy={(document) => {
if (document.type in documentTypes) {
return documentTypes[document.type];
Expand Down

0 comments on commit 98e4176

Please sign in to comment.