@redocly/theme 0.61.0-next.1 → 0.61.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Catalog/CatalogEntity/CatalogEntity.js +5 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsGraph.js +9 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistoryButton.d.ts +6 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistoryButton.js +144 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar.d.ts +8 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar.js +161 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityRevisionItem.d.ts +8 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityRevisionItem.js +67 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityVersionItem.d.ts +9 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityVersionItem.js +212 -0
- package/lib/components/Catalog/CatalogEntity/CatalogEntityMetadata.js +2 -25
- package/lib/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityRelations.js +12 -1
- package/lib/components/Catalog/CatalogEntity/ShowMoreButton.d.ts +8 -0
- package/lib/components/Catalog/CatalogEntity/ShowMoreButton.js +35 -0
- package/lib/components/Catalog/CatalogTableView/CatalogTableViewRow.d.ts +2 -0
- package/lib/components/Catalog/CatalogTableView/CatalogTableViewRow.js +4 -1
- package/lib/components/Catalog/variables.js +112 -0
- package/lib/components/ColorModeSwitcher/ColorModeIcon.d.ts +2 -1
- package/lib/components/ColorModeSwitcher/ColorModeIcon.js +3 -2
- package/lib/components/ColorModeSwitcher/ColorModeSwitcher.js +1 -4
- package/lib/components/Menu/variables.js +1 -0
- package/lib/components/Product/utils.d.ts +1 -0
- package/lib/components/Product/utils.js +10 -0
- package/lib/components/Tooltip/Tooltip.js +2 -0
- package/lib/core/constants/catalog.d.ts +1 -0
- package/lib/core/constants/catalog.js +2 -1
- package/lib/core/constants/common.d.ts +4 -0
- package/lib/core/constants/common.js +5 -1
- package/lib/core/hooks/catalog/use-catalog-entity-details.d.ts +3 -1
- package/lib/core/hooks/catalog/use-catalog-entity-details.js +12 -5
- package/lib/core/hooks/index.d.ts +1 -0
- package/lib/core/hooks/index.js +1 -0
- package/lib/core/hooks/search/use-recent-searches.js +14 -41
- package/lib/core/hooks/use-color-switcher.d.ts +0 -1
- package/lib/core/hooks/use-color-switcher.js +19 -13
- package/lib/core/hooks/use-page-actions.js +37 -6
- package/lib/core/hooks/use-product-picker.js +12 -2
- package/lib/core/hooks/use-store.d.ts +17 -0
- package/lib/core/hooks/use-store.js +64 -0
- package/lib/core/hooks/use-telemetry-fallback.d.ts +2 -0
- package/lib/core/hooks/use-telemetry-fallback.js +2 -0
- package/lib/core/types/catalog.d.ts +33 -4
- package/lib/core/types/common.d.ts +2 -0
- package/lib/core/types/hooks.d.ts +14 -3
- package/lib/core/types/l10n.d.ts +1 -1
- package/lib/core/utils/build-revision-url.d.ts +1 -0
- package/lib/core/utils/build-revision-url.js +15 -0
- package/lib/core/utils/date.d.ts +14 -0
- package/lib/core/utils/date.js +39 -0
- package/lib/core/utils/index.d.ts +2 -0
- package/lib/core/utils/index.js +2 -0
- package/lib/core/utils/load-and-navigate.js +7 -2
- package/lib/core/utils/transform-revisions-to-version-history.d.ts +8 -0
- package/lib/core/utils/transform-revisions-to-version-history.js +110 -0
- package/lib/icons/NavaidMilitaryIcon/NavaidMilitaryIcon.d.ts +9 -0
- package/lib/icons/NavaidMilitaryIcon/NavaidMilitaryIcon.js +26 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/package.json +5 -5
- package/src/components/Catalog/CatalogEntity/CatalogEntity.tsx +7 -1
- package/src/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsGraph.tsx +12 -0
- package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistoryButton.tsx +147 -0
- package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar.tsx +180 -0
- package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityRevisionItem.tsx +93 -0
- package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityVersionItem.tsx +284 -0
- package/src/components/Catalog/CatalogEntity/CatalogEntityMetadata.tsx +3 -25
- package/src/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityRelations.tsx +15 -2
- package/src/components/Catalog/CatalogEntity/ShowMoreButton.tsx +47 -0
- package/src/components/Catalog/CatalogTableView/CatalogTableViewRow.tsx +6 -1
- package/src/components/Catalog/variables.ts +112 -0
- package/src/components/ColorModeSwitcher/ColorModeIcon.tsx +5 -3
- package/src/components/ColorModeSwitcher/ColorModeSwitcher.tsx +2 -7
- package/src/components/Menu/variables.ts +1 -0
- package/src/components/Product/utils.ts +6 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/core/constants/catalog.ts +2 -0
- package/src/core/constants/common.ts +5 -0
- package/src/core/hooks/__mocks__/use-theme-hooks.ts +1 -0
- package/src/core/hooks/catalog/use-catalog-entity-details.ts +22 -6
- package/src/core/hooks/index.ts +1 -0
- package/src/core/hooks/search/use-recent-searches.ts +38 -65
- package/src/core/hooks/use-color-switcher.ts +29 -15
- package/src/core/hooks/use-page-actions.ts +63 -6
- package/src/core/hooks/use-product-picker.ts +12 -0
- package/src/core/hooks/use-store.ts +95 -0
- package/src/core/hooks/use-telemetry-fallback.ts +2 -0
- package/src/core/types/catalog.ts +38 -10
- package/src/core/types/common.ts +4 -0
- package/src/core/types/hooks.ts +23 -4
- package/src/core/types/l10n.ts +10 -0
- package/src/core/utils/build-revision-url.ts +16 -0
- package/src/core/utils/date.ts +33 -0
- package/src/core/utils/index.ts +2 -0
- package/src/core/utils/load-and-navigate.ts +6 -1
- package/src/core/utils/transform-revisions-to-version-history.ts +163 -0
- package/src/icons/NavaidMilitaryIcon/NavaidMilitaryIcon.tsx +43 -0
- package/src/index.ts +2 -0
|
@@ -40,16 +40,6 @@ export type UseCatalogResponse = {
|
|
|
40
40
|
collapsedSidebar: boolean;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export type UseCatalogFetchCatalogEntities = (
|
|
44
|
-
params: CatalogApiParams,
|
|
45
|
-
initialData?: BffCatalogEntityList,
|
|
46
|
-
) => CatalogApiResults<BffCatalogEntity>;
|
|
47
|
-
|
|
48
|
-
export type UseCatalogFetchCatalogEntitiesRelations = (
|
|
49
|
-
params: CatalogApiParams & { entityKey: string },
|
|
50
|
-
initialData?: BffCatalogRelatedEntityList,
|
|
51
|
-
) => CatalogApiResults<BffCatalogRelatedEntity>;
|
|
52
|
-
|
|
53
43
|
export type UseCatalogSortResponse = {
|
|
54
44
|
sortOption: SortOption | null;
|
|
55
45
|
setSortOption: (option: SortOption | null) => void;
|
|
@@ -128,6 +118,7 @@ export type CatalogApiParams = {
|
|
|
128
118
|
filter?: string;
|
|
129
119
|
sort?: string;
|
|
130
120
|
search?: string;
|
|
121
|
+
entityVersion?: string | null;
|
|
131
122
|
};
|
|
132
123
|
|
|
133
124
|
export type UseCatalogEntitiesProps = {
|
|
@@ -170,6 +161,7 @@ export type BffCatalogRelatedEntity = {
|
|
|
170
161
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
171
162
|
metadata?: Record<string, any>;
|
|
172
163
|
version?: string | null;
|
|
164
|
+
revision?: string | null;
|
|
173
165
|
readonly createdAt: string | null;
|
|
174
166
|
readonly updatedAt: string | null;
|
|
175
167
|
};
|
|
@@ -207,6 +199,7 @@ export type BffCatalogEntity = {
|
|
|
207
199
|
readonly revision: string;
|
|
208
200
|
readonly isCurrent?: boolean | null;
|
|
209
201
|
readonly isDefaultVersion?: boolean | null;
|
|
202
|
+
readonly isDeleted?: boolean | null;
|
|
210
203
|
readonly createdAt: string;
|
|
211
204
|
readonly updatedAt: string;
|
|
212
205
|
};
|
|
@@ -229,6 +222,41 @@ export type Page = {
|
|
|
229
222
|
total: number;
|
|
230
223
|
};
|
|
231
224
|
|
|
225
|
+
export type BffCatalogEntityRevision = {
|
|
226
|
+
readonly version: string | null;
|
|
227
|
+
readonly revision: string | null;
|
|
228
|
+
readonly isCurrent: boolean | null;
|
|
229
|
+
readonly isDefaultVersion: boolean | null;
|
|
230
|
+
readonly createdAt: string | null;
|
|
231
|
+
readonly updatedAt: string | null;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export type BffCatalogEntityRevisionList = BffCatalogList<BffCatalogEntityRevision>;
|
|
235
|
+
|
|
232
236
|
export type EntityRelationType = (typeof ENTITY_RELATION_TYPES)[number];
|
|
233
237
|
|
|
234
238
|
export type ListType = 'default' | 'team' | 'api-operation' | 'data-schema';
|
|
239
|
+
|
|
240
|
+
export type CatalogEntityRevision = {
|
|
241
|
+
name: string;
|
|
242
|
+
date: string;
|
|
243
|
+
revisionDate: string | null;
|
|
244
|
+
isActive?: boolean;
|
|
245
|
+
isCurrent?: boolean;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export type CatalogEntityVersionHistoryGroup = {
|
|
249
|
+
version: string;
|
|
250
|
+
date: string;
|
|
251
|
+
isCurrent?: boolean;
|
|
252
|
+
isExpanded?: boolean;
|
|
253
|
+
revisions?: CatalogEntityRevision[];
|
|
254
|
+
singleRevisionDate?: string | null;
|
|
255
|
+
hasCurrentRevisionFromBackend?: boolean;
|
|
256
|
+
isDefaultVersion?: boolean;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export type SidebarConnectedEntity = {
|
|
260
|
+
key: string;
|
|
261
|
+
version?: string;
|
|
262
|
+
};
|
package/src/core/types/common.ts
CHANGED
package/src/core/types/hooks.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
import type { ShikiTransformer } from '@shikijs/types';
|
|
10
10
|
import type { Callback, TFunction as TFunc } from 'i18next';
|
|
11
11
|
import type { To, Location, NavigateFunction } from 'react-router-dom';
|
|
12
|
+
import type { UseQueryResult } from '@tanstack/react-query';
|
|
12
13
|
import type { CatalogConfig, ProductUiConfig } from '@redocly/theme/config';
|
|
13
14
|
import type {
|
|
14
15
|
UseCatalogResponse,
|
|
@@ -16,8 +17,8 @@ import type {
|
|
|
16
17
|
UseCatalogSortResponse,
|
|
17
18
|
UseCatalogSearchResponse,
|
|
18
19
|
UseCatalogProps,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
CatalogApiParams,
|
|
21
|
+
CatalogApiResults,
|
|
21
22
|
} from './catalog';
|
|
22
23
|
import type { UserMenuData } from './user-menu';
|
|
23
24
|
import type { ItemState } from './sidebar';
|
|
@@ -33,6 +34,14 @@ import type { TFunction } from './l10n';
|
|
|
33
34
|
import type { BreadcrumbItem } from './breadcrumb';
|
|
34
35
|
import type { DrilldownMenuItemDetails } from './sidebar';
|
|
35
36
|
|
|
37
|
+
import {
|
|
38
|
+
BffCatalogEntity,
|
|
39
|
+
BffCatalogEntityList,
|
|
40
|
+
BffCatalogRelatedEntity,
|
|
41
|
+
BffCatalogRelatedEntityList,
|
|
42
|
+
BffCatalogEntityRevision,
|
|
43
|
+
BffCatalogEntityRevisionList,
|
|
44
|
+
} from './catalog';
|
|
36
45
|
import { AiSearchError } from '../constants/search';
|
|
37
46
|
|
|
38
47
|
export type ThemeHooks = {
|
|
@@ -147,8 +156,18 @@ export type ThemeHooks = {
|
|
|
147
156
|
useCatalog: (props?: UseCatalogProps) => UseCatalogResponse;
|
|
148
157
|
useCatalogSort: () => UseCatalogSortResponse;
|
|
149
158
|
useCatalogSearch: () => UseCatalogSearchResponse;
|
|
150
|
-
useFetchCatalogEntities:
|
|
151
|
-
|
|
159
|
+
useFetchCatalogEntities: (
|
|
160
|
+
params: CatalogApiParams,
|
|
161
|
+
initialData?: BffCatalogEntityList,
|
|
162
|
+
) => CatalogApiResults<BffCatalogEntity>;
|
|
163
|
+
useFetchCatalogEntitiesRelations: (
|
|
164
|
+
params: CatalogApiParams & { entityKey: string },
|
|
165
|
+
initialData?: BffCatalogRelatedEntityList,
|
|
166
|
+
) => CatalogApiResults<BffCatalogRelatedEntity>;
|
|
167
|
+
useFetchCatalogEntityRevisions: (params: { entityKey: string; version?: string | null }) => {
|
|
168
|
+
query: UseQueryResult<BffCatalogEntityRevisionList, Error>;
|
|
169
|
+
items: BffCatalogEntityRevision[];
|
|
170
|
+
};
|
|
152
171
|
useCatalogClassic: (config: CatalogConfig) => FilteredCatalog;
|
|
153
172
|
useTelemetry: () => Omit<
|
|
154
173
|
AsyncApiRealmUI.Telemetry,
|
package/src/core/types/l10n.ts
CHANGED
|
@@ -170,6 +170,16 @@ export type TranslationKey =
|
|
|
170
170
|
| 'catalog.links.label'
|
|
171
171
|
| 'catalog.metadata.domains'
|
|
172
172
|
| 'catalog.metadata.owners'
|
|
173
|
+
| 'catalog.history.button.label'
|
|
174
|
+
| 'catalog.history.sidebar.title'
|
|
175
|
+
| 'catalog.history.sidebar.close'
|
|
176
|
+
| 'catalog.history.version.label'
|
|
177
|
+
| 'catalog.history.version.notSpecified'
|
|
178
|
+
| 'catalog.history.version.default'
|
|
179
|
+
| 'catalog.history.revisions.limitMessage'
|
|
180
|
+
| 'catalog.history.revision.current'
|
|
181
|
+
| 'catalog.history.revisions.showLess'
|
|
182
|
+
| 'catalog.history.revisions.showMore'
|
|
173
183
|
| 'sidebar.menu.backLabel'
|
|
174
184
|
| 'sidebar.menu.backToLabel'
|
|
175
185
|
| 'sidebar.actions.show'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function buildRevisionUrl(
|
|
2
|
+
basePath: string,
|
|
3
|
+
revisionDate: string | null | undefined,
|
|
4
|
+
version?: string | null,
|
|
5
|
+
): string | undefined {
|
|
6
|
+
if (!revisionDate) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const params = new URLSearchParams();
|
|
11
|
+
params.set('revision', revisionDate);
|
|
12
|
+
if (version) {
|
|
13
|
+
params.set('version', version);
|
|
14
|
+
}
|
|
15
|
+
return `${basePath}?${params.toString()}`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a date string to localized short date format (e.g., "Dec 12, 2025")
|
|
3
|
+
* @param dateString - ISO date string or null
|
|
4
|
+
* @param locale - Locale string (e.g., "en-US")
|
|
5
|
+
* @returns Formatted date string or empty string if dateString is null
|
|
6
|
+
*/
|
|
7
|
+
export function toLocalizedShortDate(dateString: string | null, locale: string): string {
|
|
8
|
+
if (!dateString) return '';
|
|
9
|
+
const date = new Date(dateString);
|
|
10
|
+
return date.toLocaleDateString(locale, {
|
|
11
|
+
month: 'short',
|
|
12
|
+
day: 'numeric',
|
|
13
|
+
year: 'numeric',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Formats a date string to localized short date-time format (e.g., "Dec 12, 3:45 PM")
|
|
19
|
+
* @param dateString - ISO date string or null
|
|
20
|
+
* @param locale - Locale string (e.g., "en-US")
|
|
21
|
+
* @returns Formatted date-time string or empty string if dateString is null
|
|
22
|
+
*/
|
|
23
|
+
export function toLocalizedShortDateTime(dateString: string | null, locale: string): string {
|
|
24
|
+
if (!dateString) return '';
|
|
25
|
+
const date = new Date(dateString);
|
|
26
|
+
return date.toLocaleString(locale, {
|
|
27
|
+
month: 'short',
|
|
28
|
+
day: 'numeric',
|
|
29
|
+
hour: 'numeric',
|
|
30
|
+
minute: '2-digit',
|
|
31
|
+
hour12: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
package/src/core/utils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NavigateFunction, NavigateOptions } from 'react-router-dom';
|
|
2
2
|
|
|
3
|
+
import { getNavbarElement } from './get-navbar-element';
|
|
3
4
|
import { withLoadProgress } from './with-load-progress';
|
|
4
5
|
|
|
5
6
|
export type HistoryOrigin = 'pm' | 'browser';
|
|
@@ -45,7 +46,11 @@ export async function loadAndNavigate({
|
|
|
45
46
|
if (hash) {
|
|
46
47
|
const el = document.getElementById(hash.slice(1));
|
|
47
48
|
if (el) {
|
|
48
|
-
|
|
49
|
+
const navbar = getNavbarElement();
|
|
50
|
+
const navbarHeight = navbar?.offsetHeight ?? 0;
|
|
51
|
+
const elementTop = el.getBoundingClientRect().top + window.scrollY;
|
|
52
|
+
const scrollPosition = elementTop - navbarHeight;
|
|
53
|
+
window.scrollTo({ top: scrollPosition, behavior: 'smooth' });
|
|
49
54
|
}
|
|
50
55
|
} else {
|
|
51
56
|
window.scrollTo(0, 0);
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BffCatalogEntityRevision,
|
|
3
|
+
CatalogEntityRevision,
|
|
4
|
+
CatalogEntityVersionHistoryGroup,
|
|
5
|
+
} from '@redocly/theme/core/types';
|
|
6
|
+
|
|
7
|
+
import { VERSION_NOT_SPECIFIED } from '@redocly/theme/core/constants';
|
|
8
|
+
|
|
9
|
+
import { toLocalizedShortDate, toLocalizedShortDateTime } from './date';
|
|
10
|
+
|
|
11
|
+
function compareVersionsDescending(versionA: string, versionB: string): number {
|
|
12
|
+
return versionB.localeCompare(versionA, undefined, { numeric: true });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function extractGroupComparisonData(group: CatalogEntityVersionHistoryGroup): {
|
|
16
|
+
version: string;
|
|
17
|
+
isNotSpecified: boolean;
|
|
18
|
+
time: number;
|
|
19
|
+
hasCurrent: boolean;
|
|
20
|
+
} {
|
|
21
|
+
const version = group.version;
|
|
22
|
+
const isNotSpecified = version === VERSION_NOT_SPECIFIED;
|
|
23
|
+
|
|
24
|
+
// Get version dates (oldest revision date for each group - the version's creation date)
|
|
25
|
+
// This ensures versions stay in their original order even when new revisions are added
|
|
26
|
+
const date =
|
|
27
|
+
group.singleRevisionDate ||
|
|
28
|
+
(group.revisions && group.revisions.length > 0
|
|
29
|
+
? group.revisions[group.revisions.length - 1]?.revisionDate
|
|
30
|
+
: undefined) ||
|
|
31
|
+
'';
|
|
32
|
+
const time = date ? new Date(date).getTime() : 0;
|
|
33
|
+
|
|
34
|
+
const hasCurrent = group.hasCurrentRevisionFromBackend ?? false;
|
|
35
|
+
|
|
36
|
+
return { version, isNotSpecified, time, hasCurrent };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function compareVersionGroupsDescending(
|
|
40
|
+
groupA: CatalogEntityVersionHistoryGroup,
|
|
41
|
+
groupB: CatalogEntityVersionHistoryGroup,
|
|
42
|
+
): number {
|
|
43
|
+
const {
|
|
44
|
+
version: versionA,
|
|
45
|
+
isNotSpecified: isNotSpecifiedA,
|
|
46
|
+
time: timeA,
|
|
47
|
+
hasCurrent: hasCurrentA,
|
|
48
|
+
} = extractGroupComparisonData(groupA);
|
|
49
|
+
const {
|
|
50
|
+
version: versionB,
|
|
51
|
+
isNotSpecified: isNotSpecifiedB,
|
|
52
|
+
time: timeB,
|
|
53
|
+
hasCurrent: hasCurrentB,
|
|
54
|
+
} = extractGroupComparisonData(groupB);
|
|
55
|
+
|
|
56
|
+
// First, compare by version date (oldest first, so most recent versions come first)
|
|
57
|
+
const dateComparison = timeB - timeA;
|
|
58
|
+
if (dateComparison !== 0) {
|
|
59
|
+
return dateComparison;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If dates are equal, prioritize the one with isCurrent from backend
|
|
63
|
+
if (hasCurrentA !== hasCurrentB) {
|
|
64
|
+
return hasCurrentB ? 1 : -1; // hasCurrentB comes first if true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If both have same isCurrent status, compare by version
|
|
68
|
+
// If both are unknown or both are real versions, compare by version
|
|
69
|
+
if (isNotSpecifiedA === isNotSpecifiedB) {
|
|
70
|
+
return compareVersionsDescending(versionA, versionB);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If one is unknown and one is a real version, unknown comes last
|
|
74
|
+
return isNotSpecifiedA ? 1 : -1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type TransformRevisionsToVersionHistoryParams = {
|
|
78
|
+
revisions: BffCatalogEntityRevision[];
|
|
79
|
+
currentRevisionDate?: string;
|
|
80
|
+
currentVersion?: string | null;
|
|
81
|
+
locale?: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export function transformRevisionsToVersionHistory({
|
|
85
|
+
revisions,
|
|
86
|
+
currentRevisionDate,
|
|
87
|
+
currentVersion,
|
|
88
|
+
locale = typeof navigator !== 'undefined' ? navigator.language : 'en-US',
|
|
89
|
+
}: TransformRevisionsToVersionHistoryParams): CatalogEntityVersionHistoryGroup[] {
|
|
90
|
+
const normalizedCurrentVersion = currentVersion === null ? VERSION_NOT_SPECIFIED : currentVersion;
|
|
91
|
+
|
|
92
|
+
const versionMap = new Map<string, BffCatalogEntityRevision[]>();
|
|
93
|
+
revisions.forEach((revision) => {
|
|
94
|
+
const version = revision.version || VERSION_NOT_SPECIFIED;
|
|
95
|
+
const versionRevisions = versionMap.get(version) || [];
|
|
96
|
+
versionRevisions.push(revision);
|
|
97
|
+
if (!versionMap.has(version)) {
|
|
98
|
+
versionMap.set(version, versionRevisions);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const versionGroups = Array.from(versionMap.entries()).map(([version, versionRevisions]) => {
|
|
103
|
+
const sortedRevisions = [...versionRevisions].sort((a, b) => {
|
|
104
|
+
const dateA = a.revision ? new Date(a.revision).getTime() : 0;
|
|
105
|
+
const dateB = b.revision ? new Date(b.revision).getTime() : 0;
|
|
106
|
+
return dateB - dateA;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const latestRevision = sortedRevisions[0];
|
|
110
|
+
|
|
111
|
+
const versionMatches =
|
|
112
|
+
normalizedCurrentVersion === undefined || normalizedCurrentVersion === version;
|
|
113
|
+
|
|
114
|
+
let isCurrent: boolean;
|
|
115
|
+
if (currentRevisionDate !== undefined) {
|
|
116
|
+
// Check if revision matches AND version matches
|
|
117
|
+
const revisionMatches = sortedRevisions.some((rev) => rev.revision === currentRevisionDate);
|
|
118
|
+
isCurrent = revisionMatches && versionMatches;
|
|
119
|
+
} else {
|
|
120
|
+
// When no revision is specified, use isCurrent flag from the latest revision
|
|
121
|
+
// but only if version also matches (or no version filter is applied)
|
|
122
|
+
isCurrent = (latestRevision?.isCurrent ?? false) && versionMatches;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check if any revision in this version group is the default version
|
|
126
|
+
const isDefaultVersion = sortedRevisions.some((rev) => rev.isDefaultVersion === true);
|
|
127
|
+
|
|
128
|
+
const revisions =
|
|
129
|
+
sortedRevisions.length > 1
|
|
130
|
+
? sortedRevisions.map((rev, index): CatalogEntityRevision => {
|
|
131
|
+
const revisionMatches = currentRevisionDate
|
|
132
|
+
? rev.revision === currentRevisionDate
|
|
133
|
+
: false;
|
|
134
|
+
const isActiveRevision = revisionMatches && versionMatches;
|
|
135
|
+
const isCurrentByDefault =
|
|
136
|
+
!currentRevisionDate &&
|
|
137
|
+
normalizedCurrentVersion === undefined &&
|
|
138
|
+
index === 0 &&
|
|
139
|
+
isCurrent;
|
|
140
|
+
return {
|
|
141
|
+
name: `r.${sortedRevisions.length - index}`,
|
|
142
|
+
date: toLocalizedShortDateTime(rev.revision, locale),
|
|
143
|
+
revisionDate: rev.revision,
|
|
144
|
+
isActive: isActiveRevision || isCurrentByDefault,
|
|
145
|
+
isCurrent: rev.isCurrent ?? false,
|
|
146
|
+
};
|
|
147
|
+
})
|
|
148
|
+
: undefined;
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
version,
|
|
152
|
+
date: toLocalizedShortDate(latestRevision?.revision || null, locale),
|
|
153
|
+
isCurrent,
|
|
154
|
+
isExpanded: isCurrent,
|
|
155
|
+
hasCurrentRevisionFromBackend: latestRevision?.isCurrent ?? false,
|
|
156
|
+
isDefaultVersion,
|
|
157
|
+
revisions,
|
|
158
|
+
singleRevisionDate: sortedRevisions.length === 1 ? sortedRevisions[0]?.revision : undefined,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return versionGroups.sort(compareVersionGroupsDescending);
|
|
163
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { IconProps } from '@redocly/theme/icons/types';
|
|
5
|
+
|
|
6
|
+
import { getCssColorVariable } from '@redocly/theme/core/utils';
|
|
7
|
+
|
|
8
|
+
const Icon = (props: IconProps) => {
|
|
9
|
+
return (
|
|
10
|
+
<svg
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
width="16"
|
|
13
|
+
height="16"
|
|
14
|
+
viewBox="0 0 16 16"
|
|
15
|
+
fill="none"
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
<path
|
|
19
|
+
d="M8 15C6.61553 15 5.26216 14.5895 4.11101 13.8203C2.95987 13.0511 2.06266 11.9579 1.53285 10.6788C1.00303 9.3997 0.86441 7.99224 1.13451 6.63437C1.4046 5.2765 2.07129 4.02922 3.05026 3.05026C4.02922 2.07129 5.2765 1.4046 6.63437 1.13451C7.99224 0.86441 9.3997 1.00303 10.6788 1.53285C11.9579 2.06266 13.0511 2.95987 13.8203 4.11101C14.5895 5.26216 15 6.61553 15 8C14.9979 9.85588 14.2597 11.6351 12.9474 12.9474C11.6351 14.2597 9.85588 14.9979 8 15ZM8 2C6.81332 2 5.65328 2.3519 4.66658 3.01119C3.67989 3.67047 2.91085 4.60755 2.45673 5.7039C2.0026 6.80026 1.88378 8.00666 2.11529 9.17054C2.3468 10.3344 2.91825 11.4035 3.75736 12.2426C4.59648 13.0818 5.66558 13.6532 6.82946 13.8847C7.99335 14.1162 9.19975 13.9974 10.2961 13.5433C11.3925 13.0892 12.3295 12.3201 12.9888 11.3334C13.6481 10.3467 14 9.18669 14 8C13.9982 6.40926 13.3655 4.88419 12.2406 3.75936C11.1158 2.63454 9.59075 2.00182 8 2Z"
|
|
20
|
+
fill="#1A1C21"
|
|
21
|
+
/>
|
|
22
|
+
<path
|
|
23
|
+
d="M8 12C7.20888 12 6.43552 11.7654 5.77772 11.3259C5.11993 10.8864 4.60724 10.2616 4.30449 9.53074C4.00173 8.79983 3.92252 7.99557 4.07686 7.21964C4.2312 6.44372 4.61217 5.73099 5.17158 5.17158C5.73099 4.61217 6.44372 4.2312 7.21964 4.07686C7.99557 3.92252 8.79983 4.00173 9.53074 4.30449C10.2616 4.60724 10.8864 5.11993 11.3259 5.77772C11.7654 6.43552 12 7.20888 12 8C11.9988 9.0605 11.577 10.0772 10.8271 10.8271C10.0772 11.577 9.0605 11.9988 8 12ZM8 5C7.40666 5 6.82664 5.17595 6.33329 5.50559C5.83994 5.83524 5.45543 6.30377 5.22836 6.85195C5.0013 7.40013 4.94189 8.00333 5.05765 8.58527C5.1734 9.16722 5.45913 9.70177 5.87868 10.1213C6.29824 10.5409 6.83279 10.8266 7.41473 10.9424C7.99668 11.0581 8.59988 10.9987 9.14805 10.7716C9.69623 10.5446 10.1648 10.1601 10.4944 9.66671C10.8241 9.17337 11 8.59335 11 8C10.9991 7.20463 10.6828 6.44208 10.1203 5.87966C9.55793 5.31725 8.79538 5.00089 8 5Z"
|
|
24
|
+
fill="#1A1C21"
|
|
25
|
+
/>
|
|
26
|
+
<path
|
|
27
|
+
d="M8 9C8.55229 9 9 8.55229 9 8C9 7.44772 8.55229 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55229 7.44772 9 8 9Z"
|
|
28
|
+
fill="#1A1C21"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const NavaidMilitaryIcon = styled(Icon).attrs(() => ({
|
|
35
|
+
'data-component-name': 'icons/NavaidMilitaryIcon/NavaidMilitaryIcon',
|
|
36
|
+
}))<IconProps>`
|
|
37
|
+
path {
|
|
38
|
+
fill: ${({ color }) => getCssColorVariable(color)};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
height: ${({ size }) => size || '16px'};
|
|
42
|
+
width: ${({ size }) => size || '16px'};
|
|
43
|
+
`;
|
package/src/index.ts
CHANGED
|
@@ -136,6 +136,8 @@ export * from '@redocly/theme/components/Catalog/CatalogSelector';
|
|
|
136
136
|
export * from '@redocly/theme/components/Catalog/CatalogSortButton';
|
|
137
137
|
export * from '@redocly/theme/components/Catalog/CatalogTagsWithTooltip';
|
|
138
138
|
export * from '@redocly/theme/components/Catalog/CatalogViewModeToggle';
|
|
139
|
+
export * from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistoryButton';
|
|
140
|
+
export * from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar';
|
|
139
141
|
export * from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityRelations';
|
|
140
142
|
export * from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityTeamRelations';
|
|
141
143
|
export * from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityRelations/CatalogEntityDefaultRelations';
|