@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const useProject: () => {
|
|
3
|
+
defaultProjectId: string;
|
|
4
|
+
projectName: string;
|
|
5
|
+
};
|
|
6
|
+
type ProjectProviderProps = {
|
|
7
|
+
defaultProjectId: string;
|
|
8
|
+
projectName: string;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A Provider to sync project id across micro-frontends. Used by useNavigateParams to ensure project id is always present in the url.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ProjectProvider: ({ defaultProjectId, projectName, children, }: ProjectProviderProps) => React.JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -196,10 +196,42 @@ var AuditInfo = function AuditInfo(_ref) {
|
|
|
196
196
|
}));
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
var ProjectContext = /*#__PURE__*/React.createContext(undefined);
|
|
200
|
+
var useProject = function useProject() {
|
|
201
|
+
var context = React.useContext(ProjectContext);
|
|
202
|
+
if (!context) {
|
|
203
|
+
throw new Error("Must be used within a ProjectProvider");
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
defaultProjectId: context.defaultProjectId,
|
|
207
|
+
projectName: context.projectName
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* A Provider to sync project id across micro-frontends. Used by useNavigateParams to ensure project id is always present in the url.
|
|
212
|
+
*/
|
|
213
|
+
var ProjectProvider = function ProjectProvider(_ref) {
|
|
214
|
+
var defaultProjectId = _ref.defaultProjectId,
|
|
215
|
+
projectName = _ref.projectName,
|
|
216
|
+
children = _ref.children;
|
|
217
|
+
return React.createElement(ProjectContext.Provider, {
|
|
218
|
+
value: {
|
|
219
|
+
defaultProjectId: defaultProjectId,
|
|
220
|
+
projectName: projectName
|
|
221
|
+
}
|
|
222
|
+
}, children);
|
|
223
|
+
};
|
|
224
|
+
|
|
199
225
|
var Breadcrumbs = function Breadcrumbs(_ref) {
|
|
200
226
|
var prependBreadcrumbItem = _ref.prependBreadcrumbItem,
|
|
201
227
|
pathname = _ref.pathname,
|
|
202
228
|
onBreadcrumbLookup = _ref.onBreadcrumbLookup;
|
|
229
|
+
var _useProject = useProject(),
|
|
230
|
+
projectName = _useProject.projectName,
|
|
231
|
+
defaultProjectId = _useProject.defaultProjectId;
|
|
232
|
+
var _useSearchParams = reactRouterDom.useSearchParams(),
|
|
233
|
+
searchParams = _useSearchParams[0];
|
|
234
|
+
var projectValue = searchParams.get(projectName);
|
|
203
235
|
var paths = util.splitUrlPath(pathname);
|
|
204
236
|
var breadcrumbs = paths.map(function (path) {
|
|
205
237
|
return {
|
|
@@ -220,10 +252,13 @@ var Breadcrumbs = function Breadcrumbs(_ref) {
|
|
|
220
252
|
as: "span"
|
|
221
253
|
}, title);
|
|
222
254
|
}
|
|
255
|
+
if (!projectValue) {
|
|
256
|
+
searchParams.set(projectName, defaultProjectId);
|
|
257
|
+
}
|
|
223
258
|
return React.createElement(menu.BreadcrumbItem, {
|
|
224
259
|
key: path,
|
|
225
260
|
as: reactRouterDom.Link,
|
|
226
|
-
to: path
|
|
261
|
+
to: path + "?" + searchParams.toString()
|
|
227
262
|
}, title);
|
|
228
263
|
});
|
|
229
264
|
if (prependBreadcrumbItem) {
|
|
@@ -1106,6 +1141,37 @@ function useEventListener(eventName, handler, element) {
|
|
|
1106
1141
|
}, [eventName, element]);
|
|
1107
1142
|
}
|
|
1108
1143
|
|
|
1144
|
+
/**
|
|
1145
|
+
* A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State
|
|
1146
|
+
*
|
|
1147
|
+
* @param to can be a string path, a To object, or a number (delta)
|
|
1148
|
+
* @param options contains options for modifying the navigation
|
|
1149
|
+
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
1150
|
+
*/
|
|
1151
|
+
function useNavigateParams() {
|
|
1152
|
+
var _useProject = useProject(),
|
|
1153
|
+
projectName = _useProject.projectName,
|
|
1154
|
+
defaultProjectId = _useProject.defaultProjectId;
|
|
1155
|
+
var navigate = reactRouterDom.useNavigate();
|
|
1156
|
+
var _useSearchParams = reactRouterDom.useSearchParams(),
|
|
1157
|
+
searchParams = _useSearchParams[0];
|
|
1158
|
+
var projectValue = searchParams.get(projectName);
|
|
1159
|
+
var navigateParam = function navigateParam(to, options) {
|
|
1160
|
+
if (options === void 0) {
|
|
1161
|
+
options = {};
|
|
1162
|
+
}
|
|
1163
|
+
if (projectValue == null) {
|
|
1164
|
+
searchParams.set(projectName, defaultProjectId);
|
|
1165
|
+
}
|
|
1166
|
+
if (typeof to === "number") {
|
|
1167
|
+
navigate(to + "?" + searchParams.toString(), options);
|
|
1168
|
+
} else {
|
|
1169
|
+
navigate(to + "?" + searchParams.toString(), options);
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
return navigateParam;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1109
1175
|
exports.ActionBar = ActionBar;
|
|
1110
1176
|
exports.ActionBarLeft = ActionBarLeft;
|
|
1111
1177
|
exports.ActionBarRight = ActionBarRight;
|
|
@@ -1130,6 +1196,7 @@ exports.OrganisationDropDown = OrganisationDropDown;
|
|
|
1130
1196
|
exports.PageTitle = PageTitle;
|
|
1131
1197
|
exports.Pager = Pager;
|
|
1132
1198
|
exports.PermissionCheck = PermissionCheck;
|
|
1199
|
+
exports.ProjectProvider = ProjectProvider;
|
|
1133
1200
|
exports.RouteLeavingGuard = RouteLeavingGuard;
|
|
1134
1201
|
exports.Stack = Stack;
|
|
1135
1202
|
exports.StatusLabel = StatusLabel;
|
|
@@ -1143,4 +1210,6 @@ exports.responsiveProp = responsiveProp;
|
|
|
1143
1210
|
exports.useDocumentTitle = useDocumentTitle;
|
|
1144
1211
|
exports.useEventListener = useEventListener;
|
|
1145
1212
|
exports.useFeatureToggle = useFeatureToggle;
|
|
1213
|
+
exports.useNavigateParams = useNavigateParams;
|
|
1214
|
+
exports.useProject = useProject;
|
|
1146
1215
|
//# sourceMappingURL=common.cjs.development.js.map
|