@backstage/plugin-catalog-react 0.0.0-nightly-20260723031410 → 0.0.0-nightly-20260724031548
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 +6 -5
- package/dist/components/EntityOwnerPicker/EntityOwnerPicker.esm.js +20 -2
- package/dist/components/EntityOwnerPicker/EntityOwnerPicker.esm.js.map +1 -1
- package/dist/components/EntityOwnerPicker/VirtualizedListbox.esm.js +44 -0
- package/dist/components/EntityOwnerPicker/VirtualizedListbox.esm.js.map +1 -0
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20260724031548
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- ed462ad: Fixed `EntityOwnerPicker` in `owners-only` mode to display human-readable entity titles (from `metadata.title` or `spec.profile.displayName`) instead of opaque internal names, both in the dropdown list and in the selected owner chips. The owner list is now virtualized, keeping the picker responsive for catalogs with large numbers of owner entities.
|
|
7
8
|
- Updated dependencies
|
|
8
|
-
- @backstage/core-components@0.0.0-nightly-
|
|
9
|
-
- @backstage/ui@0.0.0-nightly-
|
|
9
|
+
- @backstage/core-components@0.0.0-nightly-20260724031548
|
|
10
|
+
- @backstage/ui@0.0.0-nightly-20260724031548
|
|
10
11
|
- @backstage/integration-react@1.2.20
|
|
11
|
-
- @backstage/
|
|
12
|
-
- @backstage/
|
|
12
|
+
- @backstage/core-compat-api@0.0.0-nightly-20260724031548
|
|
13
|
+
- @backstage/frontend-test-utils@0.0.0-nightly-20260724031548
|
|
13
14
|
- @backstage/core-plugin-api@1.12.8
|
|
14
15
|
- @backstage/frontend-plugin-api@0.17.3
|
|
15
16
|
- @backstage/plugin-permission-react@0.5.3
|
|
@@ -21,6 +21,7 @@ import { useEntityPresentation } from '../../apis/EntityPresentationApi/useEntit
|
|
|
21
21
|
import '../../apis/StarredEntitiesApi/StarredEntitiesApi.esm.js';
|
|
22
22
|
import 'zen-observable';
|
|
23
23
|
import { useFetchEntities } from './useFetchEntities.esm.js';
|
|
24
|
+
import { VirtualizedListbox } from './VirtualizedListbox.esm.js';
|
|
24
25
|
import { catalogReactTranslationRef } from '../../translation.esm.js';
|
|
25
26
|
import { useApiHolder } from '@backstage/core-plugin-api';
|
|
26
27
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
@@ -56,7 +57,8 @@ const checkedIcon = /* @__PURE__ */ jsx(CheckBoxIcon, { fontSize: "small" });
|
|
|
56
57
|
function RenderOptionLabel(props) {
|
|
57
58
|
const classes = useStyles();
|
|
58
59
|
const isGroup = props.entity.kind.toLocaleLowerCase("en-US") === "group";
|
|
59
|
-
const
|
|
60
|
+
const entityOrRef = props.mode === "owners-only" ? stringifyEntityRef(props.entity) : props.entity;
|
|
61
|
+
const { primaryTitle: title } = useEntityPresentation(entityOrRef);
|
|
60
62
|
return /* @__PURE__ */ jsx(Box, { className: classes.fullWidth, children: /* @__PURE__ */ jsx(
|
|
61
63
|
FixedWidthFormControlLabel,
|
|
62
64
|
{
|
|
@@ -139,6 +141,14 @@ const EntityOwnerPicker = (props) => {
|
|
|
139
141
|
return o === v;
|
|
140
142
|
},
|
|
141
143
|
getOptionLabel: (o) => {
|
|
144
|
+
if (mode === "owners-only") {
|
|
145
|
+
const ref = typeof o === "string" ? o : stringifyEntityRef(o);
|
|
146
|
+
return entityPresentationSnapshot(
|
|
147
|
+
ref,
|
|
148
|
+
void 0,
|
|
149
|
+
entityPresentationApi
|
|
150
|
+
).primaryTitle;
|
|
151
|
+
}
|
|
142
152
|
const entity = typeof o === "string" ? cache.getEntity(o) || parseEntityRef(o, {
|
|
143
153
|
defaultKind: "group",
|
|
144
154
|
defaultNamespace: "default"
|
|
@@ -163,12 +173,20 @@ const EntityOwnerPicker = (props) => {
|
|
|
163
173
|
},
|
|
164
174
|
filterOptions: (x) => x,
|
|
165
175
|
renderOption: (entity, { selected }) => {
|
|
166
|
-
return /* @__PURE__ */ jsx(
|
|
176
|
+
return /* @__PURE__ */ jsx(
|
|
177
|
+
RenderOptionLabel,
|
|
178
|
+
{
|
|
179
|
+
entity,
|
|
180
|
+
isSelected: selected,
|
|
181
|
+
mode
|
|
182
|
+
}
|
|
183
|
+
);
|
|
167
184
|
},
|
|
168
185
|
name: "owner-picker",
|
|
169
186
|
onInputChange: (_e, inputValue) => {
|
|
170
187
|
setText(inputValue);
|
|
171
188
|
},
|
|
189
|
+
ListboxComponent: VirtualizedListbox,
|
|
172
190
|
ListboxProps: {
|
|
173
191
|
onScroll: (e) => {
|
|
174
192
|
const element = e.currentTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOwnerPicker.esm.js","sources":["../../../src/components/EntityOwnerPicker/EntityOwnerPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport Box from '@material-ui/core/Box';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport Typography from '@material-ui/core/Typography';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport CheckBoxIcon from '@material-ui/icons/CheckBox';\nimport CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';\nimport { MouseEvent, useEffect, useMemo, useState } from 'react';\nimport { useEntityList } from '../../hooks/useEntityListProvider';\nimport { EntityOwnerFilter } from '../../filters';\nimport { useDebouncedEffect } from '@react-hookz/web';\nimport PersonIcon from '@material-ui/icons/Person';\nimport GroupIcon from '@material-ui/icons/Group';\nimport {\n entityPresentationApiRef,\n entityPresentationSnapshot,\n} from '../../apis';\nimport { useFetchEntities } from './useFetchEntities';\nimport { withStyles } from '@material-ui/core/styles';\nimport { useEntityPresentation } from '../../apis';\nimport { catalogReactTranslationRef } from '../../translation';\nimport { useApiHolder } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { CatalogAutocomplete } from '../CatalogAutocomplete';\n\n/** @public */\nexport type CatalogReactEntityOwnerPickerClassKey = 'input';\n\nconst useStyles = makeStyles(\n {\n root: {},\n label: {},\n input: {},\n fullWidth: { width: '100%' },\n boxLabel: {\n width: '100%',\n textOverflow: 'ellipsis',\n overflow: 'hidden',\n },\n },\n { name: 'CatalogReactEntityOwnerPicker' },\n);\n\n/** @public */\nexport type FixedWidthFormControlLabelClassKey = 'label' | 'root';\n\nconst FixedWidthFormControlLabel = withStyles(\n _theme => ({\n label: {\n width: '100%',\n },\n root: {\n width: '90%',\n },\n }),\n { name: 'FixedWidthFormControlLabel' },\n)(FormControlLabel);\n\nconst icon = <CheckBoxOutlineBlankIcon fontSize=\"small\" />;\nconst checkedIcon = <CheckBoxIcon fontSize=\"small\" />;\n\n/**\n * @public\n */\nexport type EntityOwnerPickerProps = {\n mode?: 'owners-only' | 'all';\n};\n\nfunction RenderOptionLabel(props: { entity: Entity; isSelected: boolean }) {\n const classes = useStyles();\n const isGroup = props.entity.kind.toLocaleLowerCase('en-US') === 'group';\n const { primaryTitle: title } = useEntityPresentation(props.entity);\n return (\n <Box className={classes.fullWidth}>\n <FixedWidthFormControlLabel\n className={classes.fullWidth}\n control={\n <Checkbox\n icon={icon}\n checkedIcon={checkedIcon}\n checked={props.isSelected}\n />\n }\n onClick={event => event.preventDefault()}\n label={\n <Tooltip title={title}>\n <Box display=\"flex\" alignItems=\"center\">\n {isGroup ? (\n <GroupIcon fontSize=\"small\" />\n ) : (\n <PersonIcon fontSize=\"small\" />\n )}\n \n <Box className={classes.boxLabel}>\n <Typography noWrap>{title}</Typography>\n </Box>\n </Box>\n </Tooltip>\n }\n />\n </Box>\n );\n}\n\n/** @public */\nexport const EntityOwnerPicker = (props?: EntityOwnerPickerProps) => {\n const classes = useStyles();\n const { mode = 'owners-only' } = props || {};\n const apis = useApiHolder();\n const entityPresentationApi = apis.get(entityPresentationApiRef);\n const {\n updateFilters,\n filters,\n queryParameters: { owners: ownersParameter },\n } = useEntityList();\n\n const [text, setText] = useState('');\n const { t } = useTranslationRef(catalogReactTranslationRef);\n\n const queryParamOwners = useMemo(\n () => [ownersParameter].flat().filter(Boolean) as string[],\n [ownersParameter],\n );\n\n const [selectedOwners, setSelectedOwners] = useState<string[]>(\n queryParamOwners.length ? queryParamOwners : filters.owners?.values ?? [],\n );\n\n const [{ value, loading }, handleFetch, cache] = useFetchEntities({\n mode,\n initialSelectedOwnersRefs: selectedOwners,\n });\n useDebouncedEffect(\n () => handleFetch({ text: text.toLocaleLowerCase('en-US') }),\n [text, handleFetch],\n 250,\n );\n\n const availableOwners = value?.items || [];\n\n // Set selected owners on query parameter updates; this happens at initial page load and from\n // external updates to the page location.\n useEffect(() => {\n if (queryParamOwners.length) {\n const filter = new EntityOwnerFilter(queryParamOwners);\n setSelectedOwners(filter.values);\n }\n }, [queryParamOwners]);\n\n useEffect(() => {\n updateFilters({\n owners: selectedOwners.length\n ? new EntityOwnerFilter(selectedOwners)\n : undefined,\n });\n }, [selectedOwners, updateFilters]);\n\n if (\n ['user', 'group'].includes(\n filters.kind?.value.toLocaleLowerCase('en-US') || '',\n )\n ) {\n return null;\n }\n\n return (\n <Box className={classes.root} pb={1} pt={1}>\n <CatalogAutocomplete<Entity, true>\n label={t('entityOwnerPicker.title')}\n multiple\n disableCloseOnSelect\n loading={loading}\n options={availableOwners}\n value={selectedOwners as unknown as Entity[]}\n getOptionSelected={(o, v) => {\n if (typeof v === 'string') {\n return stringifyEntityRef(o) === v;\n }\n return o === v;\n }}\n getOptionLabel={o => {\n const entity =\n typeof o === 'string'\n ? cache.getEntity(o) ||\n parseEntityRef(o, {\n defaultKind: 'group',\n defaultNamespace: 'default',\n })\n : o;\n return entityPresentationSnapshot(\n entity,\n undefined,\n entityPresentationApi,\n ).primaryTitle;\n }}\n onChange={(_: object, owners) => {\n setText('');\n setSelectedOwners(\n owners.map(e => {\n const entityRef =\n typeof e === 'string' ? e : stringifyEntityRef(e);\n\n if (typeof e !== 'string') {\n cache.setEntity(e);\n }\n return entityRef;\n }),\n );\n }}\n filterOptions={x => x}\n renderOption={(entity, { selected }) => {\n return <RenderOptionLabel entity={entity} isSelected={selected} />;\n }}\n name=\"owner-picker\"\n onInputChange={(_e, inputValue) => {\n setText(inputValue);\n }}\n ListboxProps={{\n onScroll: (e: MouseEvent) => {\n const element = e.currentTarget;\n const hasReachedEnd =\n Math.abs(\n element.scrollHeight - element.clientHeight - element.scrollTop,\n ) < 1;\n\n if (hasReachedEnd && value?.cursor) {\n handleFetch({ items: value.items, cursor: value.cursor });\n }\n },\n 'data-testid': 'owner-picker-listbox',\n }}\n LabelProps={{ className: classes.label }}\n TextFieldProps={{ className: classes.input }}\n />\n </Box>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,SAAA,GAAY,UAAA;AAAA,EAChB;AAAA,IACE,MAAM,EAAC;AAAA,IACP,OAAO,EAAC;AAAA,IACR,OAAO,EAAC;AAAA,IACR,SAAA,EAAW,EAAE,KAAA,EAAO,MAAA,EAAO;AAAA,IAC3B,QAAA,EAAU;AAAA,MACR,KAAA,EAAO,MAAA;AAAA,MACP,YAAA,EAAc,UAAA;AAAA,MACd,QAAA,EAAU;AAAA;AACZ,GACF;AAAA,EACA,EAAE,MAAM,+BAAA;AACV,CAAA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AAA,EAAY,QAAA,EAAU,CAAA;AAAA,MAClE,CAAA;AAAA,MACA,IAAA,EAAK,cAAA;AAAA,MACL,aAAA,EAAe,CAAC,EAAA,EAAI,UAAA,KAAe;AACjC,QAAA,OAAA,CAAQ,UAAU,CAAA;AAAA,MACpB,CAAA;AAAA,MACA,YAAA,EAAc;AAAA,QACZ,QAAA,EAAU,CAAC,CAAA,KAAkB;AAC3B,UAAA,MAAM,UAAU,CAAA,CAAE,aAAA;AAClB,UAAA,MAAM,gBACJ,IAAA,CAAK,GAAA;AAAA,YACH,OAAA,CAAQ,YAAA,GAAe,OAAA,CAAQ,YAAA,GAAe,OAAA,CAAQ;AAAA,WACxD,GAAI,CAAA;AAEN,UAAA,IAAI,aAAA,IAAiB,OAAO,MAAA,EAAQ;AAClC,YAAA,WAAA,CAAY,EAAE,KAAA,EAAO,KAAA,CAAM,OAAO,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AAAA,UAC1D;AAAA,QACF,CAAA;AAAA,QACA,aAAA,EAAe;AAAA,OACjB;AAAA,MACA,UAAA,EAAY,EAAE,SAAA,EAAW,OAAA,CAAQ,KAAA,EAAM;AAAA,MACvC,cAAA,EAAgB,EAAE,SAAA,EAAW,OAAA,CAAQ,KAAA;AAAM;AAAA,GAC7C,EACF,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"EntityOwnerPicker.esm.js","sources":["../../../src/components/EntityOwnerPicker/EntityOwnerPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport Box from '@material-ui/core/Box';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport Typography from '@material-ui/core/Typography';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { makeStyles } from '@material-ui/core/styles';\nimport CheckBoxIcon from '@material-ui/icons/CheckBox';\nimport CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';\nimport { MouseEvent, useEffect, useMemo, useState } from 'react';\nimport { useEntityList } from '../../hooks/useEntityListProvider';\nimport { EntityOwnerFilter } from '../../filters';\nimport { useDebouncedEffect } from '@react-hookz/web';\nimport PersonIcon from '@material-ui/icons/Person';\nimport GroupIcon from '@material-ui/icons/Group';\nimport {\n entityPresentationApiRef,\n entityPresentationSnapshot,\n} from '../../apis';\nimport { useFetchEntities } from './useFetchEntities';\nimport { VirtualizedListbox } from './VirtualizedListbox';\nimport { withStyles } from '@material-ui/core/styles';\nimport { useEntityPresentation } from '../../apis';\nimport { catalogReactTranslationRef } from '../../translation';\nimport { useApiHolder } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { CatalogAutocomplete } from '../CatalogAutocomplete';\n\n/** @public */\nexport type CatalogReactEntityOwnerPickerClassKey = 'input';\n\nconst useStyles = makeStyles(\n {\n root: {},\n label: {},\n input: {},\n fullWidth: { width: '100%' },\n boxLabel: {\n width: '100%',\n textOverflow: 'ellipsis',\n overflow: 'hidden',\n },\n },\n { name: 'CatalogReactEntityOwnerPicker' },\n);\n\n/** @public */\nexport type FixedWidthFormControlLabelClassKey = 'label' | 'root';\n\nconst FixedWidthFormControlLabel = withStyles(\n _theme => ({\n label: {\n width: '100%',\n },\n root: {\n width: '90%',\n },\n }),\n { name: 'FixedWidthFormControlLabel' },\n)(FormControlLabel);\n\nconst icon = <CheckBoxOutlineBlankIcon fontSize=\"small\" />;\nconst checkedIcon = <CheckBoxIcon fontSize=\"small\" />;\n\n/**\n * @public\n */\nexport type EntityOwnerPickerProps = {\n mode?: 'owners-only' | 'all';\n};\n\nfunction RenderOptionLabel(props: {\n entity: Entity;\n isSelected: boolean;\n mode: 'owners-only' | 'all';\n}) {\n const classes = useStyles();\n const isGroup = props.entity.kind.toLocaleLowerCase('en-US') === 'group';\n // owners-only stubs lack title/displayName; pass ref string so the presentation API fetches the full entity.\n const entityOrRef: Entity | string =\n props.mode === 'owners-only'\n ? stringifyEntityRef(props.entity)\n : props.entity;\n const { primaryTitle: title } = useEntityPresentation(entityOrRef);\n return (\n <Box className={classes.fullWidth}>\n <FixedWidthFormControlLabel\n className={classes.fullWidth}\n control={\n <Checkbox\n icon={icon}\n checkedIcon={checkedIcon}\n checked={props.isSelected}\n />\n }\n onClick={event => event.preventDefault()}\n label={\n <Tooltip title={title}>\n <Box display=\"flex\" alignItems=\"center\">\n {isGroup ? (\n <GroupIcon fontSize=\"small\" />\n ) : (\n <PersonIcon fontSize=\"small\" />\n )}\n \n <Box className={classes.boxLabel}>\n <Typography noWrap>{title}</Typography>\n </Box>\n </Box>\n </Tooltip>\n }\n />\n </Box>\n );\n}\n\n/** @public */\nexport const EntityOwnerPicker = (props?: EntityOwnerPickerProps) => {\n const classes = useStyles();\n const { mode = 'owners-only' } = props || {};\n const apis = useApiHolder();\n const entityPresentationApi = apis.get(entityPresentationApiRef);\n const {\n updateFilters,\n filters,\n queryParameters: { owners: ownersParameter },\n } = useEntityList();\n\n const [text, setText] = useState('');\n const { t } = useTranslationRef(catalogReactTranslationRef);\n\n const queryParamOwners = useMemo(\n () => [ownersParameter].flat().filter(Boolean) as string[],\n [ownersParameter],\n );\n\n const [selectedOwners, setSelectedOwners] = useState<string[]>(\n queryParamOwners.length ? queryParamOwners : filters.owners?.values ?? [],\n );\n\n const [{ value, loading }, handleFetch, cache] = useFetchEntities({\n mode,\n initialSelectedOwnersRefs: selectedOwners,\n });\n useDebouncedEffect(\n () => handleFetch({ text: text.toLocaleLowerCase('en-US') }),\n [text, handleFetch],\n 250,\n );\n\n const availableOwners = value?.items || [];\n\n // Set selected owners on query parameter updates; this happens at initial page load and from\n // external updates to the page location.\n useEffect(() => {\n if (queryParamOwners.length) {\n const filter = new EntityOwnerFilter(queryParamOwners);\n setSelectedOwners(filter.values);\n }\n }, [queryParamOwners]);\n\n useEffect(() => {\n updateFilters({\n owners: selectedOwners.length\n ? new EntityOwnerFilter(selectedOwners)\n : undefined,\n });\n }, [selectedOwners, updateFilters]);\n\n if (\n ['user', 'group'].includes(\n filters.kind?.value.toLocaleLowerCase('en-US') || '',\n )\n ) {\n return null;\n }\n\n return (\n <Box className={classes.root} pb={1} pt={1}>\n <CatalogAutocomplete<Entity, true>\n label={t('entityOwnerPicker.title')}\n multiple\n disableCloseOnSelect\n loading={loading}\n options={availableOwners}\n value={selectedOwners as unknown as Entity[]}\n getOptionSelected={(o, v) => {\n if (typeof v === 'string') {\n return stringifyEntityRef(o) === v;\n }\n return o === v;\n }}\n getOptionLabel={o => {\n if (mode === 'owners-only') {\n // Stubs have no title; use string ref so entityPresentationSnapshot hits the API cache.\n const ref = typeof o === 'string' ? o : stringifyEntityRef(o);\n return entityPresentationSnapshot(\n ref,\n undefined,\n entityPresentationApi,\n ).primaryTitle;\n }\n const entity =\n typeof o === 'string'\n ? cache.getEntity(o) ||\n parseEntityRef(o, {\n defaultKind: 'group',\n defaultNamespace: 'default',\n })\n : o;\n return entityPresentationSnapshot(\n entity,\n undefined,\n entityPresentationApi,\n ).primaryTitle;\n }}\n onChange={(_: object, owners) => {\n setText('');\n setSelectedOwners(\n owners.map(e => {\n const entityRef =\n typeof e === 'string' ? e : stringifyEntityRef(e);\n\n if (typeof e !== 'string') {\n cache.setEntity(e);\n }\n return entityRef;\n }),\n );\n }}\n filterOptions={x => x}\n renderOption={(entity, { selected }) => {\n return (\n <RenderOptionLabel\n entity={entity}\n isSelected={selected}\n mode={mode}\n />\n );\n }}\n name=\"owner-picker\"\n onInputChange={(_e, inputValue) => {\n setText(inputValue);\n }}\n ListboxComponent={VirtualizedListbox}\n ListboxProps={{\n onScroll: (e: MouseEvent) => {\n const element = e.currentTarget;\n const hasReachedEnd =\n Math.abs(\n element.scrollHeight - element.clientHeight - element.scrollTop,\n ) < 1;\n\n if (hasReachedEnd && value?.cursor) {\n handleFetch({ items: value.items, cursor: value.cursor });\n }\n },\n 'data-testid': 'owner-picker-listbox',\n }}\n LabelProps={{ className: classes.label }}\n TextFieldProps={{ className: classes.input }}\n />\n </Box>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,SAAA,GAAY,UAAA;AAAA,EAChB;AAAA,IACE,MAAM,EAAC;AAAA,IACP,OAAO,EAAC;AAAA,IACR,OAAO,EAAC;AAAA,IACR,SAAA,EAAW,EAAE,KAAA,EAAO,MAAA,EAAO;AAAA,IAC3B,QAAA,EAAU;AAAA,MACR,KAAA,EAAO,MAAA;AAAA,MACP,YAAA,EAAc,UAAA;AAAA,MACd,QAAA,EAAU;AAAA;AACZ,GACF;AAAA,EACA,EAAE,MAAM,+BAAA;AACV,CAAA;AAKA,MAAM,0BAAA,GAA6B,UAAA;AAAA,EACjC,CAAA,MAAA,MAAW;AAAA,IACT,KAAA,EAAO;AAAA,MACL,KAAA,EAAO;AAAA,KACT;AAAA,IACA,IAAA,EAAM;AAAA,MACJ,KAAA,EAAO;AAAA;AACT,GACF,CAAA;AAAA,EACA,EAAE,MAAM,4BAAA;AACV,CAAA,CAAE,gBAAgB,CAAA;AAElB,MAAM,IAAA,mBAAO,GAAA,CAAC,wBAAA,EAAA,EAAyB,QAAA,EAAS,OAAA,EAAQ,CAAA;AACxD,MAAM,WAAA,mBAAc,GAAA,CAAC,YAAA,EAAA,EAAa,QAAA,EAAS,OAAA,EAAQ,CAAA;AASnD,SAAS,kBAAkB,KAAA,EAIxB;AACD,EAAA,MAAM,UAAU,SAAA,EAAU;AAC1B,EAAA,MAAM,UAAU,KAAA,CA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;AAAA,MACpB,CAAA;AAAA,MACA,gBAAA,EAAkB,kBAAA;AAAA,MAClB,YAAA,EAAc;AAAA,QACZ,QAAA,EAAU,CAAC,CAAA,KAAkB;AAC3B,UAAA,MAAM,UAAU,CAAA,CAAE,aAAA;AAClB,UAAA,MAAM,gBACJ,IAAA,CAAK,GAAA;AAAA,YACH,OAAA,CAAQ,YAAA,GAAe,OAAA,CAAQ,YAAA,GAAe,OAAA,CAAQ;AAAA,WACxD,GAAI,CAAA;AAEN,UAAA,IAAI,aAAA,IAAiB,OAAO,MAAA,EAAQ;AAClC,YAAA,WAAA,CAAY,EAAE,KAAA,EAAO,KAAA,CAAM,OAAO,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AAAA,UAC1D;AAAA,QACF,CAAA;AAAA,QACA,aAAA,EAAe;AAAA,OACjB;AAAA,MACA,UAAA,EAAY,EAAE,SAAA,EAAW,OAAA,CAAQ,KAAA,EAAM;AAAA,MACvC,cAAA,EAAgB,EAAE,SAAA,EAAW,OAAA,CAAQ,KAAA;AAAM;AAAA,GAC7C,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { createContext, forwardRef, useContext, Children, cloneElement } from 'react';
|
|
3
|
+
import { FixedSizeList } from 'react-window';
|
|
4
|
+
|
|
5
|
+
const ITEM_SIZE = 36;
|
|
6
|
+
const renderRow = (props) => {
|
|
7
|
+
const { data, index, style } = props;
|
|
8
|
+
return cloneElement(data[index], { style });
|
|
9
|
+
};
|
|
10
|
+
const OuterElementContext = createContext({});
|
|
11
|
+
const OuterElementType = forwardRef(
|
|
12
|
+
({ onScroll: rrOnScroll, ...props }, ref) => {
|
|
13
|
+
const { onScroll: outerOnScroll, ...outerProps } = useContext(OuterElementContext);
|
|
14
|
+
const handleScroll = (e) => {
|
|
15
|
+
rrOnScroll?.(e);
|
|
16
|
+
outerOnScroll?.(e);
|
|
17
|
+
};
|
|
18
|
+
return /* @__PURE__ */ jsx("div", { ref, onScroll: handleScroll, ...props, ...outerProps });
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const VirtualizedListbox = forwardRef(
|
|
22
|
+
(props, ref) => {
|
|
23
|
+
const { children, ...other } = props;
|
|
24
|
+
const itemData = Children.toArray(children);
|
|
25
|
+
const itemCount = itemData.length;
|
|
26
|
+
const itemsToShow = Math.min(10, itemCount) + 0.5;
|
|
27
|
+
const height = itemsToShow * ITEM_SIZE;
|
|
28
|
+
return /* @__PURE__ */ jsx("div", { ref, children: /* @__PURE__ */ jsx(OuterElementContext.Provider, { value: other, children: /* @__PURE__ */ jsx(
|
|
29
|
+
FixedSizeList,
|
|
30
|
+
{
|
|
31
|
+
height,
|
|
32
|
+
itemData,
|
|
33
|
+
itemCount,
|
|
34
|
+
itemSize: ITEM_SIZE,
|
|
35
|
+
outerElementType: OuterElementType,
|
|
36
|
+
width: "100%",
|
|
37
|
+
children: renderRow
|
|
38
|
+
}
|
|
39
|
+
) }) });
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export { VirtualizedListbox };
|
|
44
|
+
//# sourceMappingURL=VirtualizedListbox.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualizedListbox.esm.js","sources":["../../../src/components/EntityOwnerPicker/VirtualizedListbox.tsx"],"sourcesContent":["/*\n * Copyright 2026 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n HTMLAttributes,\n UIEvent,\n cloneElement,\n createContext,\n forwardRef,\n useContext,\n Children,\n} from 'react';\nimport { FixedSizeList, ListChildComponentProps } from 'react-window';\n\n// MUI Autocomplete's ListboxComponent prop is typed as ComponentType<HTMLAttributes<HTMLElement>>,\n// so we use HTMLElement here to avoid a cast at the usage site.\ntype ListboxProps = HTMLAttributes<HTMLElement>;\n\nconst ITEM_SIZE = 36;\n\nconst renderRow = (props: ListChildComponentProps) => {\n const { data, index, style } = props;\n return cloneElement(data[index], { style });\n};\n\n// Passes Autocomplete listbox props (onScroll, data-testid, etc.) through to the\n// outer scroll container so MUI Autocomplete keeps working correctly.\n// See https://v4.mui.com/components/autocomplete/#Virtualize.tsx\nconst OuterElementContext = createContext<ListboxProps>({});\n\nconst OuterElementType = forwardRef<HTMLDivElement, ListboxProps>(\n ({ onScroll: rrOnScroll, ...props }, ref) => {\n const { onScroll: outerOnScroll, ...outerProps } =\n useContext(OuterElementContext);\n // Compose both handlers: spreading outerProps last would silently overwrite\n // react-window's onScroll, breaking virtualization.\n const handleScroll = (e: UIEvent<HTMLDivElement>) => {\n rrOnScroll?.(e);\n outerOnScroll?.(e);\n };\n return <div ref={ref} onScroll={handleScroll} {...props} {...outerProps} />;\n },\n);\n\nexport const VirtualizedListbox = forwardRef<HTMLDivElement, ListboxProps>(\n (props, ref) => {\n const { children, ...other } = props;\n const itemData = Children.toArray(children);\n const itemCount = itemData.length;\n\n const itemsToShow = Math.min(10, itemCount) + 0.5;\n const height = itemsToShow * ITEM_SIZE;\n\n return (\n <div ref={ref}>\n <OuterElementContext.Provider value={other}>\n <FixedSizeList\n height={height}\n itemData={itemData}\n itemCount={itemCount}\n itemSize={ITEM_SIZE}\n outerElementType={OuterElementType}\n width=\"100%\"\n >\n {renderRow}\n </FixedSizeList>\n </OuterElementContext.Provider>\n </div>\n );\n },\n);\n"],"names":[],"mappings":";;;;AA+BA,MAAM,SAAA,GAAY,EAAA;AAElB,MAAM,SAAA,GAAY,CAAC,KAAA,KAAmC;AACpD,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,EAA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QACA,SAAA;AAAA,QACA,QAAA,EAAU,SAAA;AAAA,QACV,gBAAA,EAAkB,gBAAA;AAAA,QAClB,KAAA,EAAM,MAAA;AAAA,QAEL,QAAA,EAAA;AAAA;AAAA,OAEL,CAAA,EACF,CAAA;AAAA,EAEJ;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-react",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20260724031548",
|
|
4
4
|
"description": "A frontend library that helps other Backstage plugins interact with the catalog",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "web-library",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@backstage/catalog-client": "1.16.1",
|
|
77
77
|
"@backstage/catalog-model": "1.9.0",
|
|
78
|
-
"@backstage/core-compat-api": "0.0.0-nightly-
|
|
79
|
-
"@backstage/core-components": "0.0.0-nightly-
|
|
78
|
+
"@backstage/core-compat-api": "0.0.0-nightly-20260724031548",
|
|
79
|
+
"@backstage/core-components": "0.0.0-nightly-20260724031548",
|
|
80
80
|
"@backstage/core-plugin-api": "1.12.8",
|
|
81
81
|
"@backstage/errors": "1.3.1",
|
|
82
82
|
"@backstage/filter-predicates": "0.1.4",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@backstage/plugin-permission-common": "0.9.9",
|
|
86
86
|
"@backstage/plugin-permission-react": "0.5.3",
|
|
87
87
|
"@backstage/types": "1.2.2",
|
|
88
|
-
"@backstage/ui": "0.0.0-nightly-
|
|
88
|
+
"@backstage/ui": "0.0.0-nightly-20260724031548",
|
|
89
89
|
"@backstage/version-bridge": "1.0.12",
|
|
90
90
|
"@material-ui/core": "^4.12.2",
|
|
91
91
|
"@material-ui/icons": "^4.9.1",
|
|
@@ -97,22 +97,24 @@
|
|
|
97
97
|
"material-ui-popup-state": "^5.3.6",
|
|
98
98
|
"qs": "^6.15.2",
|
|
99
99
|
"react-use": "^17.2.4",
|
|
100
|
+
"react-window": "^1.8.10",
|
|
100
101
|
"yaml": "^2.0.0",
|
|
101
102
|
"zen-observable": "^0.10.0",
|
|
102
103
|
"zod": "^4.0.0"
|
|
103
104
|
},
|
|
104
105
|
"devDependencies": {
|
|
105
106
|
"@backstage/cli": "0.36.4",
|
|
106
|
-
"@backstage/core-app-api": "0.0.0-nightly-
|
|
107
|
-
"@backstage/frontend-test-utils": "0.0.0-nightly-
|
|
107
|
+
"@backstage/core-app-api": "0.0.0-nightly-20260724031548",
|
|
108
|
+
"@backstage/frontend-test-utils": "0.0.0-nightly-20260724031548",
|
|
108
109
|
"@backstage/plugin-catalog-common": "1.1.10",
|
|
109
110
|
"@backstage/plugin-scaffolder-common": "2.2.1",
|
|
110
|
-
"@backstage/test-utils": "0.0.0-nightly-
|
|
111
|
+
"@backstage/test-utils": "0.0.0-nightly-20260724031548",
|
|
111
112
|
"@testing-library/dom": "^10.0.0",
|
|
112
113
|
"@testing-library/jest-dom": "^6.0.0",
|
|
113
114
|
"@testing-library/react": "^16.0.0",
|
|
114
115
|
"@testing-library/user-event": "^14.0.0",
|
|
115
116
|
"@types/react": "^18.0.0",
|
|
117
|
+
"@types/react-window": "^1.8.8",
|
|
116
118
|
"@types/zen-observable": "^0.8.0",
|
|
117
119
|
"react": "^18.0.2",
|
|
118
120
|
"react-dom": "^18.0.2",
|
|
@@ -120,7 +122,7 @@
|
|
|
120
122
|
"react-test-renderer": "^16.13.1"
|
|
121
123
|
},
|
|
122
124
|
"peerDependencies": {
|
|
123
|
-
"@backstage/frontend-test-utils": "0.0.0-nightly-
|
|
125
|
+
"@backstage/frontend-test-utils": "0.0.0-nightly-20260724031548",
|
|
124
126
|
"@types/react": "^17.0.0 || ^18.0.0",
|
|
125
127
|
"react": "^17.0.0 || ^18.0.0",
|
|
126
128
|
"react-dom": "^17.0.0 || ^18.0.0",
|