@backstage/core-components 0.10.0-next.2 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @backstage/core-components
2
2
 
3
+ ## 0.10.0-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7f5e79961d: Fix relative `sub-paths` by concatenating the app's base path with them.
8
+ - a70869e775: Updated dependency `msw` to `^0.43.0`.
9
+ - 693990d4fe: Updated dependency `@react-hookz/web` to `^15.0.0`.
10
+ - Updated dependencies
11
+ - @backstage/core-plugin-api@1.0.4-next.0
12
+
3
13
  ## 0.10.0-next.2
4
14
 
5
15
  ### Minor Changes
package/dist/index.esm.js CHANGED
@@ -3,14 +3,15 @@ import Snackbar from '@material-ui/core/Snackbar';
3
3
  import IconButton from '@material-ui/core/IconButton';
4
4
  import CloseIcon from '@material-ui/icons/Close';
5
5
  import { Alert } from '@material-ui/lab';
6
- import { useApi, alertApiRef, useAnalytics, errorApiRef, storageApiRef, useApp, oauthRequestApiRef, useApiHolder, configApiRef, useElementFilter, attachComponentData, discoveryApiRef } from '@backstage/core-plugin-api';
6
+ import { useApi, alertApiRef, useAnalytics, configApiRef, errorApiRef, storageApiRef, useApp, oauthRequestApiRef, useApiHolder, useElementFilter, attachComponentData, discoveryApiRef } from '@backstage/core-plugin-api';
7
7
  import pluralize from 'pluralize';
8
8
  import { makeStyles, createStyles, useTheme, darken, lighten, withStyles, styled, ThemeProvider } from '@material-ui/core/styles';
9
9
  import MaterialAvatar from '@material-ui/core/Avatar';
10
10
  import Button$1 from '@material-ui/core/Button';
11
11
  import classNames from 'classnames';
12
12
  import Link$1 from '@material-ui/core/Link';
13
- import { Link as Link$2, useSearchParams, useLocation, useResolvedPath, resolvePath } from 'react-router-dom';
13
+ import { Link as Link$2, useSearchParams, useLocation, useResolvedPath as useResolvedPath$1, resolvePath } from 'react-router-dom';
14
+ import { trimEnd, isEqual, orderBy, isMatch, transform } from 'lodash';
14
15
  import Tooltip from '@material-ui/core/Tooltip';
15
16
  import CopyIcon from '@material-ui/icons/FileCopy';
16
17
  import useCopyToClipboard from 'react-use/lib/useCopyToClipboard';
@@ -86,7 +87,6 @@ import TableCell from '@material-ui/core/TableCell';
86
87
  import TableRow from '@material-ui/core/TableRow';
87
88
  import ListItemIcon from '@material-ui/core/ListItemIcon';
88
89
  import Popover from '@material-ui/core/Popover';
89
- import { isEqual, orderBy, isMatch, transform } from 'lodash';
90
90
  import qs from 'qs';
91
91
  import MuiBrokenImageIcon from '@material-ui/icons/BrokenImage';
92
92
  import { Helmet } from 'react-helmet';
@@ -224,6 +224,31 @@ const useStyles$R = makeStyles({
224
224
  }
225
225
  }, { name: "Link" });
226
226
  const isExternalUri = (uri) => /^([a-z+.-]+):/.test(uri);
227
+ const useBaseUrl = () => {
228
+ try {
229
+ const config = useApi(configApiRef);
230
+ return config.getOptionalString("app.baseUrl");
231
+ } catch {
232
+ return void 0;
233
+ }
234
+ };
235
+ const useBasePath = () => {
236
+ var _a;
237
+ const base = "http://dummy.dev";
238
+ const url = (_a = useBaseUrl()) != null ? _a : "/";
239
+ const { pathname } = new URL(url, base);
240
+ return trimEnd(pathname, "/");
241
+ };
242
+ const useResolvedPath = (uri) => {
243
+ let resolvedPath = String(uri);
244
+ const basePath = useBasePath();
245
+ const external = isExternalUri(resolvedPath);
246
+ const startsWithBasePath = resolvedPath.startsWith(basePath);
247
+ if (!external && !startsWithBasePath) {
248
+ resolvedPath = basePath.concat(resolvedPath);
249
+ }
250
+ return resolvedPath;
251
+ };
227
252
  const getNodeText = (node) => {
228
253
  var _a;
229
254
  if (node instanceof Array) {
@@ -240,7 +265,7 @@ const getNodeText = (node) => {
240
265
  const Link = React.forwardRef(({ onClick, noTrack, ...props }, ref) => {
241
266
  const classes = useStyles$R();
242
267
  const analytics = useAnalytics();
243
- const to = String(props.to);
268
+ const to = useResolvedPath(props.to);
244
269
  const linkText = getNodeText(props.children) || to;
245
270
  const external = isExternalUri(to);
246
271
  const newWindow = external && !!/^https?:/.exec(to);
@@ -251,19 +276,20 @@ const Link = React.forwardRef(({ onClick, noTrack, ...props }, ref) => {
251
276
  }
252
277
  };
253
278
  return external ? /* @__PURE__ */ React.createElement(Link$1, {
279
+ ...newWindow ? { target: "_blank", rel: "noopener" } : {},
280
+ ...props,
254
281
  ref,
255
282
  href: to,
256
283
  onClick: handleClick,
257
- ...newWindow ? { target: "_blank", rel: "noopener" } : {},
258
- ...props,
259
284
  className: classNames(classes.externalLink, props.className)
260
285
  }, props.children, /* @__PURE__ */ React.createElement("span", {
261
286
  className: classes.visuallyHidden
262
287
  }, ", Opens in a new window")) : /* @__PURE__ */ React.createElement(Link$1, {
288
+ ...props,
263
289
  ref,
264
290
  component: Link$2,
265
- onClick: handleClick,
266
- ...props
291
+ to,
292
+ onClick: handleClick
267
293
  });
268
294
  });
269
295
 
@@ -3596,7 +3622,7 @@ const SidebarSubmenuItem = (props) => {
3596
3622
  const closeSubmenu = () => {
3597
3623
  setIsHoveredOn(false);
3598
3624
  };
3599
- const toLocation = useResolvedPath(to != null ? to : "");
3625
+ const toLocation = useResolvedPath$1(to != null ? to : "");
3600
3626
  const currentLocation = useLocation();
3601
3627
  let isActive = isLocationMatch(currentLocation, toLocation);
3602
3628
  const [showDropDown, setShowDropDown] = useState(false);
@@ -3946,7 +3972,7 @@ const WorkaroundNavLink = React.forwardRef(function WorkaroundNavLinkWithRef({
3946
3972
  ...rest
3947
3973
  }, ref) {
3948
3974
  let { pathname: locationPathname } = useLocation();
3949
- let { pathname: toPathname } = useResolvedPath(to);
3975
+ let { pathname: toPathname } = useResolvedPath$1(to);
3950
3976
  if (!caseSensitive) {
3951
3977
  locationPathname = locationPathname.toLocaleLowerCase("en-US");
3952
3978
  toPathname = toPathname.toLocaleLowerCase("en-US");