@entur-partner/common 10.0.1 → 10.0.2-alpha.0
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/dist/ProjectProvider.d.ts +15 -0
- package/dist/common.cjs.development.js +70 -1
- package/dist/common.cjs.development.js.map +1 -1
- package/dist/common.cjs.production.min.js +1 -1
- package/dist/common.cjs.production.min.js.map +1 -1
- package/dist/common.esm.js +69 -3
- package/dist/common.esm.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/styles.css +46 -46
- package/dist/useNavigateParams.d.ts +9 -0
- package/package.json +4 -4
package/dist/common.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import React, { Children, Component, useState, useEffect, useRef } from 'react';
|
|
|
2
2
|
import { localeDate, localeDateTime, isDate, isDateString, splitUrlPath, isString, isFunction, assertIsDefined, hasAllPermissions, hasOneOfPermissions } from '@entur-partner/util';
|
|
3
3
|
import cx from 'classnames';
|
|
4
4
|
import { BreadcrumbItem, BreadcrumbNavigation, Pagination } from '@entur/menu';
|
|
5
|
-
import { Link as Link$1, useInRouterContext, useBlocker, useNavigate } from 'react-router-dom';
|
|
5
|
+
import { useSearchParams, Link as Link$1, useInRouterContext, useBlocker, useNavigate } from 'react-router-dom';
|
|
6
6
|
import { ButtonGroup, SecondaryButton, PrimaryButton, Button } from '@entur/button';
|
|
7
7
|
import { Modal } from '@entur/modal';
|
|
8
8
|
import { Paragraph, Link as Link$2, Heading6 } from '@entur/typography';
|
|
@@ -192,10 +192,42 @@ var AuditInfo = function AuditInfo(_ref) {
|
|
|
192
192
|
}));
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
var ProjectContext = /*#__PURE__*/React.createContext(undefined);
|
|
196
|
+
var useProject = function useProject() {
|
|
197
|
+
var context = React.useContext(ProjectContext);
|
|
198
|
+
if (!context) {
|
|
199
|
+
throw new Error("Must be used within a ProjectProvider");
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
defaultProjectId: context.defaultProjectId,
|
|
203
|
+
projectName: context.projectName
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* A Provider to sync project id across micro-frontends. Used by useNavigateParams to ensure project id is always present in the url.
|
|
208
|
+
*/
|
|
209
|
+
var ProjectProvider = function ProjectProvider(_ref) {
|
|
210
|
+
var defaultProjectId = _ref.defaultProjectId,
|
|
211
|
+
projectName = _ref.projectName,
|
|
212
|
+
children = _ref.children;
|
|
213
|
+
return React.createElement(ProjectContext.Provider, {
|
|
214
|
+
value: {
|
|
215
|
+
defaultProjectId: defaultProjectId,
|
|
216
|
+
projectName: projectName
|
|
217
|
+
}
|
|
218
|
+
}, children);
|
|
219
|
+
};
|
|
220
|
+
|
|
195
221
|
var Breadcrumbs = function Breadcrumbs(_ref) {
|
|
196
222
|
var prependBreadcrumbItem = _ref.prependBreadcrumbItem,
|
|
197
223
|
pathname = _ref.pathname,
|
|
198
224
|
onBreadcrumbLookup = _ref.onBreadcrumbLookup;
|
|
225
|
+
var _useProject = useProject(),
|
|
226
|
+
projectName = _useProject.projectName,
|
|
227
|
+
defaultProjectId = _useProject.defaultProjectId;
|
|
228
|
+
var _useSearchParams = useSearchParams(),
|
|
229
|
+
searchParams = _useSearchParams[0];
|
|
230
|
+
var projectValue = searchParams.get(projectName);
|
|
199
231
|
var paths = splitUrlPath(pathname);
|
|
200
232
|
var breadcrumbs = paths.map(function (path) {
|
|
201
233
|
return {
|
|
@@ -216,10 +248,13 @@ var Breadcrumbs = function Breadcrumbs(_ref) {
|
|
|
216
248
|
as: "span"
|
|
217
249
|
}, title);
|
|
218
250
|
}
|
|
251
|
+
if (!projectValue) {
|
|
252
|
+
searchParams.set(projectName, defaultProjectId);
|
|
253
|
+
}
|
|
219
254
|
return React.createElement(BreadcrumbItem, {
|
|
220
255
|
key: path,
|
|
221
256
|
as: Link$1,
|
|
222
|
-
to: path
|
|
257
|
+
to: path + "?" + searchParams.toString()
|
|
223
258
|
}, title);
|
|
224
259
|
});
|
|
225
260
|
if (prependBreadcrumbItem) {
|
|
@@ -1102,5 +1137,36 @@ function useEventListener(eventName, handler, element) {
|
|
|
1102
1137
|
}, [eventName, element]);
|
|
1103
1138
|
}
|
|
1104
1139
|
|
|
1105
|
-
|
|
1140
|
+
/**
|
|
1141
|
+
* A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State
|
|
1142
|
+
*
|
|
1143
|
+
* @param to can be a string path, a To object, or a number (delta)
|
|
1144
|
+
* @param options contains options for modifying the navigation
|
|
1145
|
+
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
1146
|
+
*/
|
|
1147
|
+
function useNavigateParams() {
|
|
1148
|
+
var _useProject = useProject(),
|
|
1149
|
+
projectName = _useProject.projectName,
|
|
1150
|
+
defaultProjectId = _useProject.defaultProjectId;
|
|
1151
|
+
var navigate = useNavigate();
|
|
1152
|
+
var _useSearchParams = useSearchParams(),
|
|
1153
|
+
searchParams = _useSearchParams[0];
|
|
1154
|
+
var projectValue = searchParams.get(projectName);
|
|
1155
|
+
var navigateParam = function navigateParam(to, options) {
|
|
1156
|
+
if (options === void 0) {
|
|
1157
|
+
options = {};
|
|
1158
|
+
}
|
|
1159
|
+
if (projectValue == null) {
|
|
1160
|
+
searchParams.set(projectName, defaultProjectId);
|
|
1161
|
+
}
|
|
1162
|
+
if (typeof to === "number") {
|
|
1163
|
+
navigate(to + "?" + searchParams.toString(), options);
|
|
1164
|
+
} else {
|
|
1165
|
+
navigate(to + "?" + searchParams.toString(), options);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
return navigateParam;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
export { ActionBar, ActionBarLeft, ActionBarRight, AuditInfo, Box, Breadcrumbs, ConfirmModal, Content, EnturPartnerLogo, EnturPartnerLogoSvg, Environment, ErrorBoundary, ExpandableMultiLanguageInput, FeatureToggle, FormatCurrencyAmount, FormatDateTime, LanguageSelect, Link, LinkButton, Menu, MultiLanguageInput, OrganisationDropDown, PageTitle, Pager, PermissionCheck, ProjectProvider, RouteLeavingGuard, Stack, StatusLabel, Text, Unbutton, UserMenu, featureFlag, getColorForEnvironment, getHumanReadableEnvironment, responsiveProp, useDocumentTitle, useEventListener, useFeatureToggle, useNavigateParams, useProject };
|
|
1106
1172
|
//# sourceMappingURL=common.esm.js.map
|