@vtex/faststore-plugin-buyer-portal 2.0.48 → 2.0.50
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/package.json +1 -1
- package/public/buyer-portal-icons.svg +9 -0
- package/src/features/accounting-fields/hooks/useListAccountingFields.ts +2 -1
- package/src/features/addresses/components/AddressLine/AddressLine.tsx +3 -6
- package/src/features/budgets/layouts/BudgetsDetailsLayout/BudgetsDetailsLayout.tsx +4 -9
- package/src/features/budgets/layouts/BudgetsLayout/BudgetsLayout.tsx +2 -9
- package/src/features/buying-policies/layouts/BuyingPoliciesLayout/BuyingPoliciesLayout.tsx +14 -31
- package/src/features/contracts/components/ContractListItem/ContractListItem.tsx +0 -5
- package/src/features/contracts/components/index.ts +0 -2
- package/src/features/contracts/hooks/useSwitchContract.ts +13 -5
- package/src/features/contracts/layouts/ContractListingLayout/ContractListingLayout.tsx +8 -1
- package/src/features/contracts/layouts/ContractListingLayout/ContractSettingsNav.tsx +39 -63
- package/src/features/contracts/layouts/ContractListingLayout/__tests__/utils.test.ts +51 -0
- package/src/features/contracts/layouts/ContractListingLayout/contract-listing-layout.scss +36 -10
- package/src/features/contracts/layouts/ContractListingLayout/utils.ts +53 -0
- package/src/features/org-units/components/CreateOrgUnitDrawer/CreateOrgUnitDrawer.tsx +4 -2
- package/src/features/org-units/components/DeleteOrgUnitDrawer/DeleteOrgUnitDrawer.tsx +6 -2
- package/src/features/org-units/components/OrgUnitBreadcrumb/OrgUnitBreadcrumbLink.tsx +3 -4
- package/src/features/org-units/components/OrgUnitDetailsNavbar/OrgUnitDetailsNavbar.tsx +86 -4
- package/src/features/org-units/components/OrgUnitHeaderNav/OrgUnitHeaderNav.tsx +13 -2
- package/src/features/org-units/components/OrgUnitsHierarchyTree/OrgUnitsHierarchyTree.tsx +18 -10
- package/src/features/org-units/components/UpdateOrgUnitDrawer/UpdateOrgUnitDrawer.tsx +4 -2
- package/src/features/org-units/hooks/useOrgUnitByUser.ts +2 -0
- package/src/features/org-units/layouts/OrgUnitsLayout/OrgUnitsLayout.tsx +2 -9
- package/src/features/roles/layout/RolesLayout/RolesLayout.tsx +2 -9
- package/src/features/shared/components/BasicCard/BasicCard.tsx +6 -3
- package/src/features/shared/components/BasicCard/BasicCardLine.tsx +3 -5
- package/src/features/shared/components/BasicDrawer/BasicDrawer.tsx +3 -2
- package/src/features/shared/components/BasicDrawer/BasicDrawerHeading.tsx +4 -1
- package/src/features/shared/components/BuyerPortalProvider/BuyerPortalProvider.tsx +2 -0
- package/src/features/shared/components/HeaderInside/HeaderInside.tsx +2 -5
- package/src/features/shared/components/InternalTopbar/InternalTopbar.tsx +3 -4
- package/src/features/shared/components/PageLoadingIndicator/PageLoadingIndicator.tsx +129 -0
- package/src/features/shared/components/PageLoadingIndicator/page-loading-indicator.scss +49 -0
- package/src/features/shared/components/Table/TableRow/TableRow.tsx +2 -5
- package/src/features/shared/components/VerticalNav/VerticalNavLink.tsx +11 -10
- package/src/features/shared/hooks/index.ts +3 -0
- package/src/features/shared/hooks/useDisplayedOrgUnitName.ts +12 -0
- package/src/features/shared/hooks/useDrawerProps.ts +17 -4
- package/src/features/shared/hooks/usePageItems.ts +7 -1
- package/src/features/shared/hooks/usePageLoading.ts +11 -0
- package/src/features/shared/hooks/useQuery.ts +62 -20
- package/src/features/shared/hooks/useShellScrollReset.ts +27 -0
- package/src/features/shared/layouts/ContractTabsLayout/ContractTabsLayout.tsx +26 -65
- package/src/features/shared/layouts/FinanceTabsLayout/FinanceTabsLayout.tsx +4 -41
- package/src/features/shared/layouts/GlobalLayout/global-layout.scss +1 -0
- package/src/features/shared/layouts/LoadingTabsLayout/LoadingTabsLayout.tsx +5 -2
- package/src/features/shared/layouts/OrgUnitTabsLayout/OrgUnitTabLayout.tsx +4 -39
- package/src/features/shared/layouts/SumaPageLayout/SumaPageLayout.tsx +11 -5
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebar.tsx +17 -8
- package/src/features/shared/layouts/SumaPageLayout/SumaSidebarDrawer.tsx +44 -2
- package/src/features/shared/layouts/SumaPageLayout/suma-sidebar-drawer.scss +147 -5
- package/src/features/shared/localization/__tests__/page-loader-entries.test.ts +2 -2
- package/src/features/shared/utils/__tests__/getRouteKey.test.ts +29 -0
- package/src/features/shared/utils/__tests__/getSumaListingSidebarLinks.test.ts +30 -0
- package/src/features/shared/utils/__tests__/routeLayoutMapping.test.ts +21 -1
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/shared/utils/getRouteKey.ts +4 -0
- package/src/features/shared/utils/getSumaListingSidebarLinks.ts +8 -1
- package/src/features/shared/utils/pageLoading/__tests__/keptSidebarDrawer.test.ts +170 -0
- package/src/features/shared/utils/pageLoading/__tests__/navigationLevel.test.ts +107 -0
- package/src/features/shared/utils/pageLoading/__tests__/orgUnitNames.test.ts +60 -0
- package/src/features/shared/utils/pageLoading/__tests__/pageLoadingStore.test.ts +266 -0
- package/src/features/shared/utils/pageLoading/keptSidebarDrawer.ts +133 -0
- package/src/features/shared/utils/pageLoading/navigationLevel.ts +89 -0
- package/src/features/shared/utils/pageLoading/orgUnitNames.ts +49 -0
- package/src/features/shared/utils/pageLoading/pageLoadingStore.ts +277 -0
- package/src/features/shared/utils/routeLayoutMapping.ts +17 -4
- package/src/features/shared/utils/withProviders.tsx +5 -1
- package/src/features/shared/utils/withRouteKey.ts +23 -0
- package/src/features/users/layouts/UsersLayout/UsersLayout.tsx +2 -9
- package/src/pages/contract-information.tsx +1 -1
- package/src/pages/contracts.tsx +30 -45
- package/src/pages/home.tsx +17 -25
- package/src/pages/org-unit-details.tsx +15 -102
- package/src/features/contracts/components/ContractSwitchOverlay/ContractSwitchOverlay.tsx +0 -47
- package/src/features/contracts/components/ContractSwitchOverlay/contract-switch-overlay.scss +0 -7
|
@@ -7,6 +7,7 @@ import { buyerPortalRoutes } from "../../utils/buyerPortalRoutes";
|
|
|
7
7
|
import { getSumaListingSidebarLinks } from "../../utils/getSumaListingSidebarLinks";
|
|
8
8
|
|
|
9
9
|
import { FullSidebarNav } from "./FullSidebarNav";
|
|
10
|
+
import { resolveOrgLinkContractId } from "./resolveOrgLinkContractId";
|
|
10
11
|
import { getSumaSidebarConfig } from "./sumaSidebarConfig";
|
|
11
12
|
|
|
12
13
|
import type { SumaSidebarVariant } from "./sumaSidebarConfig";
|
|
@@ -41,7 +42,7 @@ export const SumaSidebar = ({
|
|
|
41
42
|
data-fs-bp-contract-listing-sidebar
|
|
42
43
|
data-fs-bp-suma-sidebar-variant={variant}
|
|
43
44
|
>
|
|
44
|
-
{
|
|
45
|
+
{config.showBackLink && (
|
|
45
46
|
<Link
|
|
46
47
|
href={contractsUrl}
|
|
47
48
|
data-fs-bp-contract-listing-back-link
|
|
@@ -72,13 +73,21 @@ export const SumaSidebar = ({
|
|
|
72
73
|
|
|
73
74
|
{config.sections === null ? (
|
|
74
75
|
<VerticalNav.Menu>
|
|
75
|
-
{getSumaListingSidebarLinks(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
{getSumaListingSidebarLinks(
|
|
77
|
+
{
|
|
78
|
+
orgUnitId,
|
|
79
|
+
contractId,
|
|
80
|
+
organizationContractId: resolveOrgLinkContractId(
|
|
81
|
+
featureFlags?.suma,
|
|
82
|
+
contractId
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
t
|
|
86
|
+
).map((item) => (
|
|
87
|
+
<VerticalNav.Link key={item.link} link={item.link}>
|
|
88
|
+
{item.name}
|
|
89
|
+
</VerticalNav.Link>
|
|
90
|
+
))}
|
|
82
91
|
</VerticalNav.Menu>
|
|
83
92
|
) : (
|
|
84
93
|
<FullSidebarNav
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { MouseEvent, TransitionEvent } from "react";
|
|
2
|
+
|
|
1
3
|
import storeConfig from "discovery.config";
|
|
2
4
|
|
|
3
5
|
import Link from "next/link";
|
|
4
6
|
|
|
5
|
-
import { BasicDrawer, type BasicDrawerProps } from "../../components";
|
|
7
|
+
import { BasicDrawer, Icon, type BasicDrawerProps } from "../../components";
|
|
8
|
+
import { useBuyerPortal } from "../../hooks";
|
|
6
9
|
|
|
7
10
|
import { SumaSidebar, type SumaSidebarProps } from "./SumaSidebar";
|
|
8
11
|
|
|
@@ -17,13 +20,40 @@ export const SumaSidebarDrawer = ({
|
|
|
17
20
|
variant,
|
|
18
21
|
showBackLink,
|
|
19
22
|
close,
|
|
23
|
+
onTransitionEnd,
|
|
20
24
|
...props
|
|
21
25
|
}: SumaSidebarDrawerProps) => {
|
|
26
|
+
const { currentOrgUnit } = useBuyerPortal();
|
|
27
|
+
|
|
28
|
+
// Only the drawer's own slide may unmount it. Transitions inside it, like
|
|
29
|
+
// the close button's hover, end first and would cut the slide short.
|
|
30
|
+
const handleTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {
|
|
31
|
+
if (event.target === event.currentTarget) {
|
|
32
|
+
onTransitionEnd(event);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// A link closes the drawer on the click, while the next page loads behind
|
|
37
|
+
// it. Clicks that open a new tab keep it open.
|
|
38
|
+
const closeOnLinkClick = (event: MouseEvent) => {
|
|
39
|
+
const isPlainClick =
|
|
40
|
+
event.button === 0 &&
|
|
41
|
+
!event.metaKey &&
|
|
42
|
+
!event.ctrlKey &&
|
|
43
|
+
!event.shiftKey &&
|
|
44
|
+
!event.altKey;
|
|
45
|
+
|
|
46
|
+
if (isPlainClick && (event.target as Element).closest("a[href]")) {
|
|
47
|
+
close();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
22
51
|
return (
|
|
23
52
|
<BasicDrawer
|
|
24
53
|
data-fs-bp-suma-sidebar-drawer
|
|
25
54
|
close={close}
|
|
26
55
|
{...props}
|
|
56
|
+
onTransitionEnd={handleTransitionEnd}
|
|
27
57
|
data-fs-slide-over-direction="leftSide"
|
|
28
58
|
data-fs-slide-over-sidebar
|
|
29
59
|
>
|
|
@@ -34,8 +64,20 @@ export const SumaSidebarDrawer = ({
|
|
|
34
64
|
</Link>
|
|
35
65
|
}
|
|
36
66
|
onClose={close}
|
|
67
|
+
closeIcon={<Icon name="CloseSymbol" width={20} height={20} />}
|
|
37
68
|
/>
|
|
38
|
-
<BasicDrawer.Body
|
|
69
|
+
<BasicDrawer.Body
|
|
70
|
+
data-fs-bp-suma-sidebar-drawer-body
|
|
71
|
+
onClick={closeOnLinkClick}
|
|
72
|
+
>
|
|
73
|
+
{currentOrgUnit?.name && (
|
|
74
|
+
<div data-fs-bp-suma-sidebar-drawer-unit>
|
|
75
|
+
<Icon name="FilledFolder" width={20} height={20} />
|
|
76
|
+
<span data-fs-bp-suma-sidebar-drawer-unit-name>
|
|
77
|
+
{currentOrgUnit.name}
|
|
78
|
+
</span>
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
39
81
|
<SumaSidebar
|
|
40
82
|
orgUnitId={orgUnitId}
|
|
41
83
|
contractId={contractId}
|
|
@@ -1,17 +1,81 @@
|
|
|
1
1
|
@use "~@faststore/ui/src/styles/base/utilities" as u;
|
|
2
|
+
|
|
3
|
+
// Google Docs' side menu curve, with its 250ms made 30% longer for this wider
|
|
4
|
+
// drawer, as Material does for tablets. There are no motion tokens for it
|
|
5
|
+
// (`--fs-transition-timing` is 0.2s).
|
|
6
|
+
$suma-sidebar-drawer-duration: 325ms;
|
|
7
|
+
$suma-sidebar-drawer-easing: cubic-bezier(0.4, 0, 0.2, 1);
|
|
8
|
+
|
|
9
|
+
@keyframes suma-sidebar-drawer-in {
|
|
10
|
+
from {
|
|
11
|
+
transform: translateX(-100%);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The overlay's color fades with the drawer instead of popping in and out.
|
|
16
|
+
// The theme sets that color with `!important` inside this layer, so these
|
|
17
|
+
// rules join it with a higher specificity; transitions still run over
|
|
18
|
+
// `!important` values.
|
|
19
|
+
@layer theme {
|
|
20
|
+
[data-fs-overlay]:has([data-fs-bp-suma-sidebar-drawer][data-fs-slide-over]) {
|
|
21
|
+
transition: background-color $suma-sidebar-drawer-duration
|
|
22
|
+
$suma-sidebar-drawer-easing;
|
|
23
|
+
|
|
24
|
+
@starting-style {
|
|
25
|
+
background-color: transparent !important;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&:has([data-fs-slide-over-state="out"]) {
|
|
29
|
+
background-color: transparent !important;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@media (prefers-reduced-motion: reduce) {
|
|
33
|
+
transition: none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
2
38
|
[data-fs-bp-suma-sidebar-drawer] {
|
|
3
39
|
@import "../../components/BasicDrawer/basic-drawer.scss";
|
|
4
40
|
|
|
41
|
+
// Same height as the header that opens it; the padding stays at phone size
|
|
42
|
+
// because the drawer keeps its width at every breakpoint.
|
|
43
|
+
&[data-fs-bp-basic-drawer] [data-fs-bp-basic-drawer-heading] {
|
|
44
|
+
gap: var(--fs-bp-gap-1);
|
|
45
|
+
min-height: var(--fs-bp-spacing-12);
|
|
46
|
+
padding: var(--fs-bp-padding-0) var(--fs-bp-padding-5);
|
|
47
|
+
border-bottom-color: var(--fs-bp-color-neutral-2);
|
|
48
|
+
|
|
49
|
+
[data-fs-bp-basic-drawer-heading-title] {
|
|
50
|
+
&,
|
|
51
|
+
&:first-child {
|
|
52
|
+
padding-left: var(--fs-bp-padding-0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Same box and states as the header's menu button.
|
|
57
|
+
[data-fs-bp-basic-drawer-heading-close-button] {
|
|
58
|
+
--fs-button-height: var(--fs-bp-spacing-9);
|
|
59
|
+
--fs-button-border-radius: var(--fs-bp-border-radius-full);
|
|
60
|
+
--fs-button-tertiary-text-color: var(--fs-bp-color-neutral-8);
|
|
61
|
+
--fs-button-tertiary-text-color-active: var(--fs-bp-color-neutral-8);
|
|
62
|
+
--fs-button-tertiary-bkg-color-hover: var(--fs-bp-color-transparent-0);
|
|
63
|
+
--fs-button-tertiary-bkg-color-active: var(--fs-bp-color-transparent-1);
|
|
64
|
+
|
|
65
|
+
svg {
|
|
66
|
+
color: var(--fs-bp-color-neutral-8);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
5
71
|
[data-fs-bp-org-unit-details-navbar-link] {
|
|
6
|
-
@include text-style('display-
|
|
72
|
+
@include text-style('display-6');
|
|
7
73
|
font-weight: var(--fs-bp-weight-bold);
|
|
74
|
+
letter-spacing: var(--fs-bp-letter-spacing-3);
|
|
8
75
|
color: var(--fs-bp-color-brand);
|
|
9
76
|
text-decoration: none;
|
|
77
|
+
// Lines the logo up with the menu items' text
|
|
10
78
|
margin-left: var(--fs-bp-margin-5);
|
|
11
|
-
|
|
12
|
-
@include u.media(">=tablet") {
|
|
13
|
-
margin: var(--fs-bp-margin-0);
|
|
14
|
-
}
|
|
15
79
|
}
|
|
16
80
|
|
|
17
81
|
&[data-fs-bp-basic-drawer][data-fs-slide-over-size] {
|
|
@@ -27,6 +91,70 @@
|
|
|
27
91
|
}
|
|
28
92
|
}
|
|
29
93
|
|
|
94
|
+
// The drawer mounts already "in", so it slides in with an animation and
|
|
95
|
+
// slides out with a transition, both with the same curve. The shadow
|
|
96
|
+
// separates it from the page and goes away as soon as it starts closing.
|
|
97
|
+
&[data-fs-bp-basic-drawer][data-fs-slide-over] {
|
|
98
|
+
--fs-slide-over-transition-timing: #{$suma-sidebar-drawer-duration};
|
|
99
|
+
|
|
100
|
+
box-shadow: 0 0 var(--fs-bp-spacing-4) var(--fs-bp-color-transparent-1);
|
|
101
|
+
animation: suma-sidebar-drawer-in var(--fs-slide-over-transition-timing)
|
|
102
|
+
$suma-sidebar-drawer-easing;
|
|
103
|
+
|
|
104
|
+
&[data-fs-slide-over-state="out"] {
|
|
105
|
+
box-shadow: none;
|
|
106
|
+
animation: none;
|
|
107
|
+
transform: translateX(-100%);
|
|
108
|
+
transition: transform var(--fs-slide-over-transition-timing)
|
|
109
|
+
$suma-sidebar-drawer-easing;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The exit still needs a transition: its end unmounts the drawer.
|
|
113
|
+
@media (prefers-reduced-motion: reduce) {
|
|
114
|
+
--fs-slide-over-transition-timing: 1ms;
|
|
115
|
+
|
|
116
|
+
animation: none;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Same padding as the desktop sidebar at every width, instead of the
|
|
121
|
+
// drawer body's form spacing.
|
|
122
|
+
&[data-fs-bp-basic-drawer]
|
|
123
|
+
[data-fs-bp-suma-sidebar-drawer-body]
|
|
124
|
+
[data-fs-bp-basic-drawer-body-wrapper] {
|
|
125
|
+
padding: var(--fs-bp-padding-5);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Mirrors the header's unit control, which the drawer covers.
|
|
129
|
+
[data-fs-bp-suma-sidebar-drawer-unit] {
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: center;
|
|
132
|
+
gap: var(--fs-bp-gap-2);
|
|
133
|
+
min-height: var(--fs-bp-spacing-9);
|
|
134
|
+
padding: var(--fs-bp-padding-0) var(--fs-bp-padding-5);
|
|
135
|
+
margin-bottom: var(--fs-bp-margin-5);
|
|
136
|
+
|
|
137
|
+
svg {
|
|
138
|
+
flex-shrink: 0;
|
|
139
|
+
color: var(--fs-bp-color-brand);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
[data-fs-bp-suma-sidebar-drawer-unit-name] {
|
|
144
|
+
@include text-style('action');
|
|
145
|
+
min-width: 0;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
font-weight: var(--fs-bp-weight-medium);
|
|
148
|
+
color: var(--fs-bp-color-neutral-8);
|
|
149
|
+
text-overflow: ellipsis;
|
|
150
|
+
white-space: nowrap;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Phones need the vertical space; the contract name alone identifies it.
|
|
154
|
+
[data-fs-bp-suma-sidebar-identity] [data-fs-bp-letter-highlight] {
|
|
155
|
+
display: none;
|
|
156
|
+
}
|
|
157
|
+
|
|
30
158
|
// The sidebar is hidden below "notebook" so it can be toggled from the
|
|
31
159
|
// navbar; force it visible here since the drawer is only rendered while open.
|
|
32
160
|
[data-fs-bp-contract-listing-sidebar] {
|
|
@@ -35,3 +163,17 @@
|
|
|
35
163
|
padding: var(--fs-bp-padding-0);
|
|
36
164
|
}
|
|
37
165
|
}
|
|
166
|
+
|
|
167
|
+
// A drawer kept open across a page load shows as it was, without the entry
|
|
168
|
+
// motion or the overlay fading in again.
|
|
169
|
+
[data-fs-bp-suma-sidebar-drawer][data-fs-bp-suma-sidebar-drawer-kept][data-fs-bp-basic-drawer][data-fs-slide-over] {
|
|
170
|
+
animation: none;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@layer theme {
|
|
174
|
+
[data-fs-overlay]:has([data-fs-bp-suma-sidebar-drawer][data-fs-bp-suma-sidebar-drawer-kept][data-fs-slide-over]) {
|
|
175
|
+
@starting-style {
|
|
176
|
+
background-color: var(--fs-bp-color-transparent-overlay) !important;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -31,13 +31,13 @@ const getRequestedEntries = (page: string): LocalizationFeature[] => {
|
|
|
31
31
|
// Components rendered by a page resolve `t("<feature>.…")` keys from the entries
|
|
32
32
|
// its loader requests. A shared component whose entry is not requested renders
|
|
33
33
|
// the raw key (B2BTEAM-4276, B2BTEAM-4277).
|
|
34
|
+
// `/org-unit/[orgUnitId]` only redirects to the contracts listing and renders
|
|
35
|
+
// nothing, so it no longer requests `users`. See specs/sidebar-unification.md.
|
|
34
36
|
const REQUIRED_ENTRIES: Record<string, LocalizationFeature[]> = {
|
|
35
37
|
// Sidebar → AccountingFieldDropdown, CreateAccountingFieldDrawer
|
|
36
38
|
profile: ["accountingFields"],
|
|
37
39
|
// OrgUnitsDropdownMenu → CreateUserDrawerSelector → CreateUserDrawer*
|
|
38
40
|
"org-units": ["users"],
|
|
39
|
-
// AddAllToOrgUnitDropdown → CreateUserDrawerSelector → CreateUserDrawer*
|
|
40
|
-
"org-unit-details": ["users"],
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
describe("page loaders request the localization entries their components use", () => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { getRouteKey } from "../getRouteKey";
|
|
4
|
+
|
|
5
|
+
describe("getRouteKey", () => {
|
|
6
|
+
it("keeps the path", () => {
|
|
7
|
+
expect(getRouteKey("/pvt/organization-account/users/unit-a")).toBe(
|
|
8
|
+
"/pvt/organization-account/users/unit-a"
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("drops the query string", () => {
|
|
13
|
+
expect(
|
|
14
|
+
getRouteKey("/pvt/organization-account/users/unit-a?contractId=c&page=2")
|
|
15
|
+
).toBe("/pvt/organization-account/users/unit-a");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("drops the hash", () => {
|
|
19
|
+
expect(getRouteKey("/pvt/organization-account/roles/unit-a#top")).toBe(
|
|
20
|
+
"/pvt/organization-account/roles/unit-a"
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("tells apart two units of the same page", () => {
|
|
25
|
+
expect(getRouteKey("/pvt/organization-account/users/unit-a")).not.toBe(
|
|
26
|
+
getRouteKey("/pvt/organization-account/users/unit-b")
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -41,3 +41,33 @@ describe("getSumaListingSidebarLinks (unit view)", () => {
|
|
|
41
41
|
).toBe("/pvt/organization-account/budgets/unit-1/contract-1");
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe("getSumaListingSidebarLinks (organizationContractId)", () => {
|
|
46
|
+
const links = getSumaListingSidebarLinks(
|
|
47
|
+
{
|
|
48
|
+
orgUnitId: "unit-1",
|
|
49
|
+
contractId: "contract-1",
|
|
50
|
+
organizationContractId: "contract-1",
|
|
51
|
+
},
|
|
52
|
+
t
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
it("adds the contractId to organization links when given", () => {
|
|
56
|
+
expect(links.find((l) => l.name === "layouts.navigation.users")?.link).toBe(
|
|
57
|
+
"/pvt/organization-account/users/unit-1?contractId=contract-1"
|
|
58
|
+
);
|
|
59
|
+
expect(
|
|
60
|
+
links.find((l) => l.name === "layouts.navigation.roles")?.link
|
|
61
|
+
).toContain("contractId=contract-1");
|
|
62
|
+
expect(
|
|
63
|
+
links.find((l) => l.name === "layouts.navigation.organizationalUnits")
|
|
64
|
+
?.link
|
|
65
|
+
).toContain("contractId=contract-1");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("keeps the Contracts link unit-scoped", () => {
|
|
69
|
+
expect(
|
|
70
|
+
links.find((l) => l.name === "layouts.navigation.contracts")?.link
|
|
71
|
+
).toBe("/pvt/organization-account/contracts/unit-1");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../routeLayoutMapping";
|
|
7
7
|
|
|
8
8
|
describe("routeLayoutMapping", () => {
|
|
9
|
-
it("maps the
|
|
9
|
+
it("maps the contracts listing to its own loading layout", () => {
|
|
10
10
|
const config = getTabsLayoutConfigFromRoute(
|
|
11
11
|
"/pvt/organization-account/contracts/unit-1?removed=2"
|
|
12
12
|
);
|
|
@@ -17,6 +17,13 @@ describe("routeLayoutMapping", () => {
|
|
|
17
17
|
).toEqual({ orgUnitId: "unit-1" });
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
it("shows the contracts listing skeleton for a unit's home redirect", () => {
|
|
21
|
+
expect(
|
|
22
|
+
getTabsLayoutConfigFromRoute("/pvt/organization-account/org-unit/unit-1")
|
|
23
|
+
?.layout
|
|
24
|
+
).toBe("ContractListingLayout");
|
|
25
|
+
});
|
|
26
|
+
|
|
20
27
|
it("keeps contract pages on the contract tabs layout", () => {
|
|
21
28
|
expect(
|
|
22
29
|
getTabsLayoutConfigFromRoute(
|
|
@@ -25,6 +32,19 @@ describe("routeLayoutMapping", () => {
|
|
|
25
32
|
).toBe("ContractTabsLayout");
|
|
26
33
|
});
|
|
27
34
|
|
|
35
|
+
it.each([
|
|
36
|
+
["users/unit-1", "OrgUnitTabsLayout"],
|
|
37
|
+
["user/unit-1/user-1", "OrgUnitTabsLayout"],
|
|
38
|
+
["roles/unit-1/role-1", "OrgUnitTabsLayout"],
|
|
39
|
+
["budgets/unit-1/contract-1", "FinanceTabsLayout"],
|
|
40
|
+
["budgets/unit-1/contract-1/budget-1", "FinanceTabsLayout"],
|
|
41
|
+
["buying-policy/unit-1/contract-1/policy-1", "FinanceTabsLayout"],
|
|
42
|
+
])("keeps the unit page %s on a unit view layout", (path, layout) => {
|
|
43
|
+
expect(
|
|
44
|
+
getTabsLayoutConfigFromRoute(`/pvt/organization-account/${path}`)?.layout
|
|
45
|
+
).toBe(layout);
|
|
46
|
+
});
|
|
47
|
+
|
|
28
48
|
it("returns null for unmapped routes", () => {
|
|
29
49
|
expect(
|
|
30
50
|
getTabsLayoutConfigFromRoute("/pvt/organization-account/unknown")
|
|
@@ -8,9 +8,12 @@ export const getSumaListingSidebarLinks = (
|
|
|
8
8
|
{
|
|
9
9
|
orgUnitId,
|
|
10
10
|
contractId,
|
|
11
|
+
organizationContractId,
|
|
11
12
|
}: {
|
|
12
13
|
orgUnitId: string;
|
|
13
14
|
contractId: string;
|
|
15
|
+
/** `contractId` for the Organization links; omitted under SUMA. */
|
|
16
|
+
organizationContractId?: string;
|
|
14
17
|
},
|
|
15
18
|
t: LocalizeFn
|
|
16
19
|
) => [
|
|
@@ -18,6 +21,10 @@ export const getSumaListingSidebarLinks = (
|
|
|
18
21
|
name: t("layouts.navigation.contracts"),
|
|
19
22
|
link: buyerPortalRoutes.contracts({ orgUnitId }),
|
|
20
23
|
},
|
|
21
|
-
...getOrganizationSettingsLinks({
|
|
24
|
+
...getOrganizationSettingsLinks({
|
|
25
|
+
orgUnitId,
|
|
26
|
+
contractId: organizationContractId,
|
|
27
|
+
t,
|
|
28
|
+
}),
|
|
22
29
|
...getFinanceSettingsLinks({ orgUnitId, contractId }, t),
|
|
23
30
|
];
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
KEPT_SIDEBAR_DRAWER_MAX_AGE,
|
|
5
|
+
KEPT_SIDEBAR_DRAWER_STORAGE_KEY,
|
|
6
|
+
forgetSidebarDrawerKeptAcrossLoad,
|
|
7
|
+
isFullLoadEnd,
|
|
8
|
+
isNavigationStart,
|
|
9
|
+
isSidebarDrawerKept,
|
|
10
|
+
keepSidebarDrawer,
|
|
11
|
+
releaseSidebarDrawer,
|
|
12
|
+
takeSidebarDrawerKeptAcrossLoad,
|
|
13
|
+
} from "../keptSidebarDrawer";
|
|
14
|
+
|
|
15
|
+
const BASE = "/pvt/organization-account";
|
|
16
|
+
const PROFILE = `${BASE}/profile/u1/c1`;
|
|
17
|
+
const idle = { phase: "idle", targetPath: null, fullLoad: false } as const;
|
|
18
|
+
const toRoles = {
|
|
19
|
+
phase: "navigating",
|
|
20
|
+
targetPath: `${BASE}/roles/u1`,
|
|
21
|
+
fullLoad: false,
|
|
22
|
+
} as const;
|
|
23
|
+
const toUsers = {
|
|
24
|
+
phase: "navigating",
|
|
25
|
+
targetPath: `${BASE}/users/u1`,
|
|
26
|
+
fullLoad: false,
|
|
27
|
+
} as const;
|
|
28
|
+
const toProfile = {
|
|
29
|
+
phase: "navigating",
|
|
30
|
+
targetPath: PROFILE,
|
|
31
|
+
fullLoad: true,
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
const createStorage = () => {
|
|
35
|
+
const items = new Map<string, string>();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
getItem: (key: string) => items.get(key) ?? null,
|
|
39
|
+
setItem: (key: string, value: string) => void items.set(key, value),
|
|
40
|
+
removeItem: (key: string) => void items.delete(key),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe("keptSidebarDrawer", () => {
|
|
45
|
+
let storage: ReturnType<typeof createStorage>;
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
storage = createStorage();
|
|
49
|
+
vi.stubGlobal("window", { sessionStorage: storage });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
releaseSidebarDrawer();
|
|
54
|
+
vi.unstubAllGlobals();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("keeps the drawer from when it's opened until it's released", () => {
|
|
58
|
+
expect(isSidebarDrawerKept()).toBe(false);
|
|
59
|
+
|
|
60
|
+
keepSidebarDrawer();
|
|
61
|
+
expect(isSidebarDrawerKept()).toBe(true);
|
|
62
|
+
|
|
63
|
+
releaseSidebarDrawer();
|
|
64
|
+
expect(isSidebarDrawerKept()).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("keeps a drawer opened during a full load for the page it opens", () => {
|
|
68
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
69
|
+
|
|
70
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000)).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("compares the page without its locale or query", () => {
|
|
74
|
+
keepSidebarDrawer({ ...toProfile, targetPath: `${PROFILE}?tab=1` }, 1000);
|
|
75
|
+
|
|
76
|
+
expect(takeSidebarDrawerKeptAcrossLoad(`/it-IT${PROFILE}`, 2000)).toBe(
|
|
77
|
+
true
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("restores it once: reloading the page doesn't", () => {
|
|
82
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
83
|
+
takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000);
|
|
84
|
+
|
|
85
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 3000)).toBe(false);
|
|
86
|
+
expect(storage.getItem(KEPT_SIDEBAR_DRAWER_STORAGE_KEY)).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("doesn't keep it across loads outside a full load", () => {
|
|
90
|
+
keepSidebarDrawer(undefined, 1000);
|
|
91
|
+
keepSidebarDrawer(idle, 1000);
|
|
92
|
+
keepSidebarDrawer(toRoles, 1000);
|
|
93
|
+
keepSidebarDrawer({ ...toProfile, phase: "mounting" }, 1000);
|
|
94
|
+
|
|
95
|
+
expect(storage.getItem(KEPT_SIDEBAR_DRAWER_STORAGE_KEY)).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("doesn't restore it on another page or after too long", () => {
|
|
99
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
100
|
+
expect(takeSidebarDrawerKeptAcrossLoad(`${BASE}/roles/u1`, 2000)).toBe(
|
|
101
|
+
false
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
105
|
+
expect(
|
|
106
|
+
takeSidebarDrawerKeptAcrossLoad(
|
|
107
|
+
PROFILE,
|
|
108
|
+
1000 + KEPT_SIDEBAR_DRAWER_MAX_AGE + 1
|
|
109
|
+
)
|
|
110
|
+
).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("forgets it when the buyer closes it or a navigation starts", () => {
|
|
114
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
115
|
+
releaseSidebarDrawer();
|
|
116
|
+
|
|
117
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000)).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("forgets it for the next page only when the full load ends", () => {
|
|
121
|
+
keepSidebarDrawer(toProfile, 1000);
|
|
122
|
+
forgetSidebarDrawerKeptAcrossLoad();
|
|
123
|
+
|
|
124
|
+
expect(isSidebarDrawerKept()).toBe(true);
|
|
125
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("ignores a broken or missing storage", () => {
|
|
129
|
+
storage.setItem(KEPT_SIDEBAR_DRAWER_STORAGE_KEY, "{");
|
|
130
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000)).toBe(false);
|
|
131
|
+
|
|
132
|
+
vi.stubGlobal("window", {
|
|
133
|
+
get sessionStorage() {
|
|
134
|
+
throw new Error("blocked");
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
expect(() => keepSidebarDrawer(toProfile, 1000)).not.toThrow();
|
|
138
|
+
expect(takeSidebarDrawerKeptAcrossLoad(PROFILE, 2000)).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("isNavigationStart", () => {
|
|
143
|
+
it("is a start when a navigation begins or changes its destination", () => {
|
|
144
|
+
expect(isNavigationStart(idle, toRoles)).toBe(true);
|
|
145
|
+
expect(isNavigationStart({ ...toRoles, phase: "mounting" }, toUsers)).toBe(
|
|
146
|
+
true
|
|
147
|
+
);
|
|
148
|
+
expect(isNavigationStart(toRoles, toUsers)).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("isn't a start while the same page loads or shows", () => {
|
|
152
|
+
expect(isNavigationStart(toRoles, toRoles)).toBe(false);
|
|
153
|
+
expect(isNavigationStart(toRoles, { ...toRoles, phase: "mounting" })).toBe(
|
|
154
|
+
false
|
|
155
|
+
);
|
|
156
|
+
expect(isNavigationStart(toRoles, idle)).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("isFullLoadEnd", () => {
|
|
161
|
+
it("is an end when a full load goes back to idle on the same page", () => {
|
|
162
|
+
expect(isFullLoadEnd(toProfile, idle)).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("isn't an end for other navigations or while loading", () => {
|
|
166
|
+
expect(isFullLoadEnd(toRoles, idle)).toBe(false);
|
|
167
|
+
expect(isFullLoadEnd(toProfile, toProfile)).toBe(false);
|
|
168
|
+
expect(isFullLoadEnd(idle, idle)).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
});
|