@redocly/theme 0.61.0-next.2 → 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/Menu/variables.js +1 -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/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/use-color-switcher.js +7 -8
- package/lib/core/hooks/use-page-actions.js +37 -6
- 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/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/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 +4 -4
- 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/Menu/variables.ts +1 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/core/constants/catalog.ts +2 -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/use-color-switcher.ts +13 -10
- package/src/core/hooks/use-page-actions.ts +63 -6
- package/src/core/hooks/use-telemetry-fallback.ts +2 -0
- package/src/core/types/catalog.ts +38 -10
- 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/transform-revisions-to-version-history.ts +163 -0
- package/src/icons/NavaidMilitaryIcon/NavaidMilitaryIcon.tsx +43 -0
- package/src/index.ts +2 -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';
|