@backstage/ui 0.14.3 → 0.15.0-next.1
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 +55 -9
- package/dist/components/Alert/Alert.esm.js +8 -3
- package/dist/components/Alert/Alert.esm.js.map +1 -1
- package/dist/components/Alert/definition.esm.js +1 -0
- package/dist/components/Alert/definition.esm.js.map +1 -1
- package/dist/components/Box/Box.esm.js +1 -1
- package/dist/components/Box/Box.esm.js.map +1 -1
- package/dist/components/Box/definition.esm.js +3 -0
- package/dist/components/Box/definition.esm.js.map +1 -1
- package/dist/components/Button/Button.esm.js +10 -5
- package/dist/components/Button/Button.esm.js.map +1 -1
- package/dist/components/Button/Button.module.css.esm.js +2 -2
- package/dist/components/Button/definition.esm.js +1 -0
- package/dist/components/Button/definition.esm.js.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.esm.js +10 -5
- package/dist/components/ButtonIcon/ButtonIcon.esm.js.map +1 -1
- package/dist/components/ButtonIcon/ButtonIcon.module.css.esm.js +2 -2
- package/dist/components/ButtonIcon/definition.esm.js +1 -0
- package/dist/components/ButtonIcon/definition.esm.js.map +1 -1
- package/dist/components/Card/Card.esm.js +2 -1
- package/dist/components/Card/Card.esm.js.map +1 -1
- package/dist/components/Card/Card.module.css.esm.js +2 -2
- package/dist/components/Card/definition.esm.js +4 -2
- package/dist/components/Card/definition.esm.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.module.css.esm.js +2 -2
- package/dist/components/Container/Container.module.css.esm.js +2 -2
- package/dist/components/DateRangePicker/DateRangePicker.esm.js +60 -0
- package/dist/components/DateRangePicker/DateRangePicker.esm.js.map +1 -0
- package/dist/components/DateRangePicker/DateRangePicker.module.css.esm.js +8 -0
- package/dist/components/DateRangePicker/DateRangePicker.module.css.esm.js.map +1 -0
- package/dist/components/DateRangePicker/DateRangePickerCalendar.esm.js +24 -0
- package/dist/components/DateRangePicker/DateRangePickerCalendar.esm.js.map +1 -0
- package/dist/components/DateRangePicker/DateRangePickerGroup.esm.js +32 -0
- package/dist/components/DateRangePicker/DateRangePickerGroup.esm.js.map +1 -0
- package/dist/components/DateRangePicker/definition.esm.js +54 -0
- package/dist/components/DateRangePicker/definition.esm.js.map +1 -0
- package/dist/components/Dialog/Dialog.module.css.esm.js +2 -2
- package/dist/components/Flex/definition.esm.js +4 -1
- package/dist/components/Flex/definition.esm.js.map +1 -1
- package/dist/components/Grid/definition.esm.js +4 -1
- package/dist/components/Grid/definition.esm.js.map +1 -1
- package/dist/components/Header/Header.esm.js +187 -28
- package/dist/components/Header/Header.esm.js.map +1 -1
- package/dist/components/Header/Header.module.css.esm.js +2 -2
- package/dist/components/Header/HeaderMetadataStatus.esm.js +32 -0
- package/dist/components/Header/HeaderMetadataStatus.esm.js.map +1 -0
- package/dist/components/Header/HeaderMetadataStatus.module.css.esm.js +8 -0
- package/dist/components/Header/HeaderMetadataStatus.module.css.esm.js.map +1 -0
- package/dist/components/Header/HeaderMetadataUsers.esm.js +92 -0
- package/dist/components/Header/HeaderMetadataUsers.esm.js.map +1 -0
- package/dist/components/Header/HeaderMetadataUsers.module.css.esm.js +8 -0
- package/dist/components/Header/HeaderMetadataUsers.module.css.esm.js.map +1 -0
- package/dist/components/Header/definition.esm.js +22 -3
- package/dist/components/Header/definition.esm.js.map +1 -1
- package/dist/components/Select/Select.module.css.esm.js +2 -2
- package/dist/components/Select/SelectContent.esm.js.map +1 -1
- package/dist/components/Select/SelectListBox.esm.js +26 -12
- package/dist/components/Select/SelectListBox.esm.js.map +1 -1
- package/dist/components/Select/definition.esm.js +20 -4
- package/dist/components/Select/definition.esm.js.map +1 -1
- package/dist/components/Table/Table.module.css.esm.js +2 -2
- package/dist/components/Table/components/Table.esm.js +4 -2
- package/dist/components/Table/components/Table.esm.js.map +1 -1
- package/dist/components/Table/components/TableRoot.esm.js +7 -2
- package/dist/components/Table/components/TableRoot.esm.js.map +1 -1
- package/dist/components/Table/definition.esm.js +1 -0
- package/dist/components/Table/definition.esm.js.map +1 -1
- package/dist/components/Table/hooks/useCompletePagination.esm.js +6 -6
- package/dist/components/Table/hooks/useCompletePagination.esm.js.map +1 -1
- package/dist/components/Table/hooks/useCursorPagination.esm.js +1 -1
- package/dist/components/Table/hooks/useCursorPagination.esm.js.map +1 -1
- package/dist/components/Table/hooks/useOffsetPagination.esm.js +1 -1
- package/dist/components/Table/hooks/useOffsetPagination.esm.js.map +1 -1
- package/dist/components/Table/hooks/usePageCache.esm.js +9 -9
- package/dist/components/Table/hooks/usePageCache.esm.js.map +1 -1
- package/dist/components/Table/hooks/useTable.esm.js +4 -3
- package/dist/components/Table/hooks/useTable.esm.js.map +1 -1
- package/dist/components/Tabs/TabsIndicators.esm.js +1 -0
- package/dist/components/Tabs/TabsIndicators.esm.js.map +1 -1
- package/dist/css/styles.css +72 -0
- package/dist/hooks/useDefinition/helpers.esm.js +2 -1
- package/dist/hooks/useDefinition/helpers.esm.js.map +1 -1
- package/dist/hooks/useDefinition/useDefinition.esm.js +5 -10
- package/dist/hooks/useDefinition/useDefinition.esm.js.map +1 -1
- package/dist/index.d.ts +261 -57
- package/dist/index.esm.js +4 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/utilityClassMap.esm.js +18 -0
- package/dist/utils/utilityClassMap.esm.js.map +1 -1
- package/package.json +10 -4
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { ListBox, ListBoxItem, Text } from 'react-aria-components';
|
|
2
|
+
import { ListBox, ListBoxSection, Header, ListBoxItem, Text } from 'react-aria-components';
|
|
3
3
|
import { RiCheckLine } from '@remixicon/react';
|
|
4
4
|
import { useDefinition } from '../../hooks/useDefinition/useDefinition.esm.js';
|
|
5
|
-
import { SelectListBoxDefinition } from './definition.esm.js';
|
|
5
|
+
import { SelectListBoxDefinition, SelectSectionDefinition, SelectListBoxItemDefinition } from './definition.esm.js';
|
|
6
6
|
|
|
7
7
|
const NoResults = () => {
|
|
8
8
|
const { ownProps } = useDefinition(SelectListBoxDefinition, {});
|
|
9
9
|
const { classes } = ownProps;
|
|
10
10
|
return /* @__PURE__ */ jsx("div", { className: classes.noResults, children: "No results found." });
|
|
11
11
|
};
|
|
12
|
-
function
|
|
13
|
-
const { ownProps } = useDefinition(
|
|
14
|
-
const { classes
|
|
15
|
-
return /* @__PURE__ */
|
|
12
|
+
function SelectItem({ option }) {
|
|
13
|
+
const { ownProps } = useDefinition(SelectListBoxItemDefinition, {});
|
|
14
|
+
const { classes } = ownProps;
|
|
15
|
+
return /* @__PURE__ */ jsxs(
|
|
16
16
|
ListBoxItem,
|
|
17
17
|
{
|
|
18
18
|
id: option.value,
|
|
19
19
|
textValue: option.label,
|
|
20
|
-
className: classes.
|
|
20
|
+
className: classes.root,
|
|
21
21
|
isDisabled: option.disabled,
|
|
22
22
|
children: [
|
|
23
|
-
/* @__PURE__ */ jsx("div", { className: classes.
|
|
24
|
-
/* @__PURE__ */ jsx(Text, { slot: "label", className: classes.
|
|
23
|
+
/* @__PURE__ */ jsx("div", { className: classes.indicator, children: /* @__PURE__ */ jsx(RiCheckLine, {}) }),
|
|
24
|
+
/* @__PURE__ */ jsx(Text, { slot: "label", className: classes.label, children: option.label })
|
|
25
25
|
]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function SelectSectionItems({ section }) {
|
|
30
|
+
const { ownProps } = useDefinition(SelectSectionDefinition, {});
|
|
31
|
+
const { classes } = ownProps;
|
|
32
|
+
return /* @__PURE__ */ jsxs(ListBoxSection, { className: classes.root, children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Header, { className: classes.header, children: section.title }),
|
|
34
|
+
section.options.map((option) => /* @__PURE__ */ jsx(SelectItem, { option }, option.value))
|
|
35
|
+
] });
|
|
36
|
+
}
|
|
37
|
+
function SelectListBox(props) {
|
|
38
|
+
const { ownProps } = useDefinition(SelectListBoxDefinition, props);
|
|
39
|
+
const { classes, options } = ownProps;
|
|
40
|
+
return /* @__PURE__ */ jsx(ListBox, { className: classes.root, renderEmptyState: () => /* @__PURE__ */ jsx(NoResults, {}), children: options?.map(
|
|
41
|
+
(item) => "options" in item ? /* @__PURE__ */ jsx(SelectSectionItems, { section: item }, item.title) : /* @__PURE__ */ jsx(SelectItem, { option: item }, item.value)
|
|
42
|
+
) });
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
export { SelectListBox };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectListBox.esm.js","sources":["../../../src/components/Select/SelectListBox.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 {
|
|
1
|
+
{"version":3,"file":"SelectListBox.esm.js","sources":["../../../src/components/Select/SelectListBox.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 ListBox,\n ListBoxItem,\n ListBoxSection,\n Header,\n Text,\n} from 'react-aria-components';\nimport { RiCheckLine } from '@remixicon/react';\nimport { useDefinition } from '../../hooks/useDefinition';\nimport {\n SelectListBoxDefinition,\n SelectListBoxItemDefinition,\n SelectSectionDefinition,\n} from './definition';\nimport type { Option, OptionSection, SelectOwnProps } from './types';\n\ninterface SelectListBoxProps {\n options?: SelectOwnProps['options'];\n}\n\nconst NoResults = () => {\n const { ownProps } = useDefinition(SelectListBoxDefinition, {});\n const { classes } = ownProps;\n\n return <div className={classes.noResults}>No results found.</div>;\n};\n\nfunction SelectItem({ option }: { option: Option }) {\n const { ownProps } = useDefinition(SelectListBoxItemDefinition, {});\n const { classes } = ownProps;\n\n return (\n <ListBoxItem\n id={option.value}\n textValue={option.label}\n className={classes.root}\n isDisabled={option.disabled}\n >\n <div className={classes.indicator}>\n <RiCheckLine />\n </div>\n <Text slot=\"label\" className={classes.label}>\n {option.label}\n </Text>\n </ListBoxItem>\n );\n}\n\nfunction SelectSectionItems({ section }: { section: OptionSection }) {\n const { ownProps } = useDefinition(SelectSectionDefinition, {});\n const { classes } = ownProps;\n\n return (\n <ListBoxSection className={classes.root}>\n <Header className={classes.header}>{section.title}</Header>\n {section.options.map(option => (\n <SelectItem key={option.value} option={option} />\n ))}\n </ListBoxSection>\n );\n}\n\nexport function SelectListBox(props: SelectListBoxProps) {\n const { ownProps } = useDefinition(SelectListBoxDefinition, props);\n const { classes, options } = ownProps;\n\n return (\n <ListBox className={classes.root} renderEmptyState={() => <NoResults />}>\n {options?.map(item =>\n 'options' in item ? (\n <SelectSectionItems key={item.title} section={item} />\n ) : (\n <SelectItem key={item.value} option={item} />\n ),\n )}\n </ListBox>\n );\n}\n"],"names":[],"mappings":";;;;;;AAoCA,MAAM,YAAY,MAAM;AACtB,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,aAAA,CAAc,uBAAA,EAAyB,EAAE,CAAA;AAC9D,EAAA,MAAM,EAAE,SAAQ,GAAI,QAAA;AAEpB,EAAA,uBAAO,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAW,OAAA,CAAQ,WAAW,QAAA,EAAA,mBAAA,EAAiB,CAAA;AAC7D,CAAA;AAEA,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EAAE,QAAA,EAAS,GAAI,aAAA,CAAc,yBAAyB,KAAK,CAAA;AACjE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAQ,GAAI,QAAA;AAE7B,EAAA,uBACE,GAAA,CAAC,OAAA,EAAA,EAAQ,SAAA,EAAW,OAAA,CAAQ,IAAA,EAAM,kBAAkB,sBAAM,GAAA,CAAC,SAAA,EAAA,EAAU,CAAA,EAClE,QAAA,EAAA,OAAA,EAAS,GAAA;AAAA,IAAI,CAAA,IAAA,KACZ,SAAA,IAAa,IAAA,mBACX,GAAA,CAAC,sBAAoC,OAAA,EAAS,IAAA,EAAA,EAArB,IAAA,CAAK,KAAsB,oBAEpD,GAAA,CAAC,UAAA,EAAA,EAA4B,MAAA,EAAQ,IAAA,EAAA,EAApB,KAAK,KAAqB;AAAA,GAE/C,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -61,9 +61,6 @@ const SelectListBoxDefinition = defineComponent()(
|
|
|
61
61
|
styles,
|
|
62
62
|
classNames: {
|
|
63
63
|
root: "bui-SelectList",
|
|
64
|
-
item: "bui-SelectItem",
|
|
65
|
-
itemIndicator: "bui-SelectItemIndicator",
|
|
66
|
-
itemLabel: "bui-SelectItemLabel",
|
|
67
64
|
noResults: "bui-SelectNoResults"
|
|
68
65
|
},
|
|
69
66
|
propDefs: {
|
|
@@ -71,6 +68,25 @@ const SelectListBoxDefinition = defineComponent()(
|
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
);
|
|
71
|
+
const SelectListBoxItemDefinition = defineComponent()({
|
|
72
|
+
styles,
|
|
73
|
+
classNames: {
|
|
74
|
+
root: "bui-SelectItem",
|
|
75
|
+
indicator: "bui-SelectItemIndicator",
|
|
76
|
+
label: "bui-SelectItemLabel"
|
|
77
|
+
},
|
|
78
|
+
propDefs: {}
|
|
79
|
+
});
|
|
80
|
+
const SelectSectionDefinition = defineComponent()(
|
|
81
|
+
{
|
|
82
|
+
styles,
|
|
83
|
+
classNames: {
|
|
84
|
+
root: "bui-SelectSection",
|
|
85
|
+
header: "bui-SelectSectionHeader"
|
|
86
|
+
},
|
|
87
|
+
propDefs: {}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
74
90
|
|
|
75
|
-
export { SelectContentDefinition, SelectDefinition, SelectListBoxDefinition, SelectTriggerDefinition };
|
|
91
|
+
export { SelectContentDefinition, SelectDefinition, SelectListBoxDefinition, SelectListBoxItemDefinition, SelectSectionDefinition, SelectTriggerDefinition };
|
|
76
92
|
//# sourceMappingURL=definition.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Select/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { defineComponent } from '../../hooks/useDefinition';\nimport type {\n SelectOwnProps,\n SelectTriggerOwnProps,\n SelectContentOwnProps,\n SelectListBoxOwnProps,\n} from './types';\nimport styles from './Select.module.css';\n\n/**\n * Component definition for Select\n * @public\n */\nexport const SelectDefinition = defineComponent<SelectOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Select',\n popover: 'bui-SelectPopover',\n },\n propDefs: {\n icon: {},\n size: { dataAttribute: true, default: 'small' },\n options: {},\n searchable: {},\n searchPlaceholder: {},\n label: {},\n secondaryLabel: {},\n description: {},\n isRequired: {},\n className: {},\n },\n});\n\n/**\n * Component definition for SelectTrigger\n * @internal\n */\nexport const SelectTriggerDefinition = defineComponent<SelectTriggerOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectTrigger',\n chevron: 'bui-SelectTriggerChevron',\n value: 'bui-SelectValue',\n },\n bg: 'consumer',\n propDefs: {\n icon: {},\n },\n },\n);\n\n/**\n * Component definition for SelectContent\n * @internal\n */\nexport const SelectContentDefinition = defineComponent<SelectContentOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectSearchWrapper',\n search: 'bui-SelectSearch',\n searchClear: 'bui-SelectSearchClear',\n },\n propDefs: {\n searchable: {},\n searchPlaceholder: { default: 'Search...' },\n options: {},\n },\n },\n);\n\n/**\n * Component definition for SelectListBox\n * @internal\n */\nexport const SelectListBoxDefinition = defineComponent<SelectListBoxOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectList',\n
|
|
1
|
+
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Select/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { defineComponent } from '../../hooks/useDefinition';\nimport type {\n SelectOwnProps,\n SelectTriggerOwnProps,\n SelectContentOwnProps,\n SelectListBoxOwnProps,\n SelectListBoxItemOwnProps,\n SelectSectionOwnProps,\n} from './types';\nimport styles from './Select.module.css';\n\n/**\n * Component definition for Select\n * @public\n */\nexport const SelectDefinition = defineComponent<SelectOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Select',\n popover: 'bui-SelectPopover',\n },\n propDefs: {\n icon: {},\n size: { dataAttribute: true, default: 'small' },\n options: {},\n searchable: {},\n searchPlaceholder: {},\n label: {},\n secondaryLabel: {},\n description: {},\n isRequired: {},\n className: {},\n },\n});\n\n/**\n * Component definition for SelectTrigger\n * @internal\n */\nexport const SelectTriggerDefinition = defineComponent<SelectTriggerOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectTrigger',\n chevron: 'bui-SelectTriggerChevron',\n value: 'bui-SelectValue',\n },\n bg: 'consumer',\n propDefs: {\n icon: {},\n },\n },\n);\n\n/**\n * Component definition for SelectContent\n * @internal\n */\nexport const SelectContentDefinition = defineComponent<SelectContentOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectSearchWrapper',\n search: 'bui-SelectSearch',\n searchClear: 'bui-SelectSearchClear',\n },\n propDefs: {\n searchable: {},\n searchPlaceholder: { default: 'Search...' },\n options: {},\n },\n },\n);\n\n/**\n * Component definition for SelectListBox\n * @internal\n */\nexport const SelectListBoxDefinition = defineComponent<SelectListBoxOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectList',\n noResults: 'bui-SelectNoResults',\n },\n propDefs: {\n options: {},\n },\n },\n);\n\n/**\n * Component definition for SelectListBoxItem\n * @internal\n */\nexport const SelectListBoxItemDefinition =\n defineComponent<SelectListBoxItemOwnProps>()({\n styles,\n classNames: {\n root: 'bui-SelectItem',\n indicator: 'bui-SelectItemIndicator',\n label: 'bui-SelectItemLabel',\n },\n propDefs: {},\n });\n\n/**\n * Component definition for SelectSection\n * @internal\n */\nexport const SelectSectionDefinition = defineComponent<SelectSectionOwnProps>()(\n {\n styles,\n classNames: {\n root: 'bui-SelectSection',\n header: 'bui-SelectSectionHeader',\n },\n propDefs: {},\n },\n);\n"],"names":[],"mappings":";;;;;;;;;;AA+BO,MAAM,gBAAA,GAAmB,iBAAgC,CAAE;AAAA,EAChE,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,YAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACX;AAAA,EACA,QAAA,EAAU;AAAA,IACR,MAAM,EAAC;AAAA,IACP,IAAA,EAAM,EAAE,aAAA,EAAe,IAAA,EAAM,SAAS,OAAA,EAAQ;AAAA,IAC9C,SAAS,EAAC;AAAA,IACV,Y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A;AAAA,IACA,UAAA,EAAY;AAAA,MACV,IAAA,EAAM,mBAAA;AAAA,MACN,MAAA,EAAQ;AAAA,KACV;AAAA,IACA,UAAU;AAAC;AAEf;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from '../../node_modules_dist/style-inject/dist/style-inject.es.esm.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = "/*\n * Copyright 2025 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\n@layer tokens, base, components, utilities;\n\n@layer components {\n .Table_bui-
|
|
4
|
-
var styles = {"bui-TableWrapper":"Table_bui-
|
|
3
|
+
var css_248z = "/*\n * Copyright 2025 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\n@layer tokens, base, components, utilities;\n\n@layer components {\n .Table_bui-TableWrapper__1e8e8291a0 {\n display: flex;\n flex-direction: column;\n }\n\n .Table_bui-TableResizableContainer__1e8e8291a0 {\n display: flex;\n flex-direction: column;\n flex: 1;\n min-height: 0;\n overflow: hidden;\n }\n\n .Table_bui-Table__1e8e8291a0 {\n width: 100%;\n caption-side: bottom;\n border-collapse: collapse;\n table-layout: fixed;\n transition: opacity 0.2s ease-in-out;\n overflow: auto;\n flex: 1;\n min-height: 0;\n\n &[data-stale='true'],\n &[data-ispending='true'] {\n opacity: 0.6;\n }\n }\n\n .Table_bui-TableHeader__1e8e8291a0 {\n border-bottom: 1px solid var(--bui-border-2);\n transition: color 0.2s ease-in-out;\n }\n\n .Table_bui-TableHead__1e8e8291a0 {\n text-align: left;\n padding: var(--bui-space-3);\n font-size: var(--bui-font-size-3);\n color: var(--bui-fg-primary);\n }\n\n .Table_bui-TableHeadSelection__1e8e8291a0 {\n width: 40px;\n }\n\n .Table_bui-TableHeadContent__1e8e8291a0 {\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: var(--bui-space-1);\n }\n\n .Table_bui-TableHeadLabel__1e8e8291a0 {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n }\n\n .Table_bui-TableHeadSortButton__1e8e8291a0 {\n cursor: pointer;\n user-select: none;\n display: inline-flex;\n align-items: center;\n gap: var(--bui-space-1);\n opacity: 0;\n transition: opacity 0.1s ease-in-out;\n color: var(--bui-fg-secondary);\n\n .Table_bui-TableHead__1e8e8291a0:hover &,\n [data-sort-direction='ascending'] &,\n [data-sort-direction='descending'] & {\n opacity: 1;\n }\n\n & svg {\n transition: transform 0.1s ease-in-out;\n }\n [data-sort-direction='descending'] & svg {\n transform: rotate(180deg);\n }\n }\n\n .Table_bui-TableBody__1e8e8291a0 {\n color: var(--bui-fg-primary);\n }\n\n .Table_bui-TableRow__1e8e8291a0 {\n border-bottom: 1px solid var(--bui-border-2);\n transition: color 0.2s ease-in-out;\n cursor: default;\n\n &:hover {\n background-color: var(--bui-bg-neutral-1-hover);\n }\n\n &[data-selected] {\n background-color: var(--bui-bg-neutral-1-pressed);\n }\n\n &[data-pressed] {\n background-color: var(--bui-bg-neutral-1-pressed);\n }\n\n &[data-on-bg='neutral-1'] {\n &:hover {\n background-color: var(--bui-bg-neutral-2-hover);\n }\n\n &[data-selected] {\n background-color: var(--bui-bg-neutral-2-pressed);\n }\n\n &[data-pressed] {\n background-color: var(--bui-bg-neutral-2-pressed);\n }\n\n &[data-disabled] {\n background-color: var(--bui-bg-neutral-2-disabled);\n }\n }\n\n &[data-on-bg='neutral-2'] {\n &:hover {\n background-color: var(--bui-bg-neutral-3-hover);\n }\n\n &[data-selected] {\n background-color: var(--bui-bg-neutral-3-pressed);\n }\n\n &[data-pressed] {\n background-color: var(--bui-bg-neutral-3-pressed);\n }\n\n &[data-disabled] {\n background-color: var(--bui-bg-neutral-3-disabled);\n }\n }\n\n &[data-on-bg='neutral-3'] {\n &:hover {\n background-color: var(--bui-bg-neutral-4-hover);\n }\n\n &[data-selected] {\n background-color: var(--bui-bg-neutral-4-pressed);\n }\n\n &[data-pressed] {\n background-color: var(--bui-bg-neutral-4-pressed);\n }\n\n &[data-disabled] {\n background-color: var(--bui-bg-neutral-4-disabled);\n }\n }\n\n &[data-href],\n &[data-selection-mode],\n &[data-react-aria-pressable='true'] {\n cursor: pointer;\n }\n\n &[data-disabled] {\n background-color: var(--bui-bg-neutral-1-disabled);\n cursor: not-allowed;\n }\n }\n\n .Table_bui-TableCell__1e8e8291a0 {\n padding: var(--bui-space-3);\n font-size: var(--bui-font-size-3);\n font-family: var(--bui-font-regular);\n font-weight: var(--bui-font-weight-regular);\n min-width: 0;\n overflow: hidden;\n }\n\n .Table_bui-TableCellSelection__1e8e8291a0 {\n width: 40px;\n }\n\n .Table_bui-TableCellContentWrapper__1e8e8291a0 {\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: var(--bui-space-2);\n min-width: 0;\n width: 100%;\n max-width: 100%;\n }\n\n .Table_bui-TableCellIcon__1e8e8291a0,\n .Table_bui-TableCellIcon__1e8e8291a0 svg {\n display: inline-flex;\n align-items: center;\n color: var(--bui-fg-primary);\n }\n\n .Table_bui-TableCellContent__1e8e8291a0 {\n display: flex;\n flex-direction: column;\n gap: var(--bui-space-0_5);\n min-width: 0;\n flex: 1;\n overflow: hidden;\n max-width: 100%;\n }\n\n .Table_bui-TableCellContent__1e8e8291a0 > * {\n min-width: 0;\n max-width: 100%;\n }\n\n .Table_bui-TableCellProfile__1e8e8291a0 {\n display: flex;\n flex-direction: row;\n gap: var(--bui-space-2);\n align-items: center;\n }\n}\n";
|
|
4
|
+
var styles = {"bui-TableWrapper":"Table_bui-TableWrapper__1e8e8291a0","bui-TableResizableContainer":"Table_bui-TableResizableContainer__1e8e8291a0","bui-Table":"Table_bui-Table__1e8e8291a0","bui-TableHeader":"Table_bui-TableHeader__1e8e8291a0","bui-TableHead":"Table_bui-TableHead__1e8e8291a0","bui-TableHeadSelection":"Table_bui-TableHeadSelection__1e8e8291a0","bui-TableHeadContent":"Table_bui-TableHeadContent__1e8e8291a0","bui-TableHeadLabel":"Table_bui-TableHeadLabel__1e8e8291a0","bui-TableHeadSortButton":"Table_bui-TableHeadSortButton__1e8e8291a0","bui-TableBody":"Table_bui-TableBody__1e8e8291a0","bui-TableRow":"Table_bui-TableRow__1e8e8291a0","bui-TableCell":"Table_bui-TableCell__1e8e8291a0","bui-TableCellSelection":"Table_bui-TableCellSelection__1e8e8291a0","bui-TableCellContentWrapper":"Table_bui-TableCellContentWrapper__1e8e8291a0","bui-TableCellIcon":"Table_bui-TableCellIcon__1e8e8291a0","bui-TableCellContent":"Table_bui-TableCellContent__1e8e8291a0","bui-TableCellProfile":"Table_bui-TableCellProfile__1e8e8291a0"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { styles as default };
|
|
@@ -62,6 +62,7 @@ function useLiveRegionLabel(pagination, isStale, isLoading, hasData) {
|
|
|
62
62
|
function Table({
|
|
63
63
|
columnConfig,
|
|
64
64
|
data,
|
|
65
|
+
isPending = false,
|
|
65
66
|
loading = false,
|
|
66
67
|
isStale = false,
|
|
67
68
|
error,
|
|
@@ -74,6 +75,7 @@ function Table({
|
|
|
74
75
|
style,
|
|
75
76
|
virtualized
|
|
76
77
|
}) {
|
|
78
|
+
const pending = isPending || loading;
|
|
77
79
|
const {
|
|
78
80
|
ownProps: { classes }
|
|
79
81
|
} = useDefinition(TableWrapperDefinition, { className });
|
|
@@ -89,7 +91,7 @@ function Table({
|
|
|
89
91
|
behavior: selectionBehavior,
|
|
90
92
|
onSelectionChange
|
|
91
93
|
} = selection || {};
|
|
92
|
-
const isInitialLoading =
|
|
94
|
+
const isInitialLoading = pending && !data;
|
|
93
95
|
if (error) {
|
|
94
96
|
return /* @__PURE__ */ jsxs("div", { className: classes.root, style, children: [
|
|
95
97
|
"Error: ",
|
|
@@ -125,7 +127,7 @@ function Table({
|
|
|
125
127
|
onSortChange: sort?.onSortChange,
|
|
126
128
|
disabledKeys: disabledRows,
|
|
127
129
|
stale: isStale,
|
|
128
|
-
|
|
130
|
+
isPending: isInitialLoading,
|
|
129
131
|
"aria-describedby": liveRegionId,
|
|
130
132
|
children: [
|
|
131
133
|
/* @__PURE__ */ jsx(TableHeader, { columns: visibleColumns, children: (column) => column.header ? column.header() : /* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.esm.js","sources":["../../../../src/components/Table/components/Table.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { useId } from 'react-aria';\nimport {\n type Key,\n ResizableTableContainer,\n Virtualizer,\n} from 'react-aria-components';\nimport { TableLayout } from 'react-stately';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableWrapperDefinition } from '../definition';\nimport { TableRoot } from './TableRoot';\nimport { TableHeader } from './TableHeader';\nimport { TableBody } from './TableBody';\nimport { Row } from './Row';\nimport { Column } from './Column';\nimport { TablePagination } from '../../TablePagination';\nimport type {\n TableProps,\n TableItem,\n RowConfig,\n RowRenderFn,\n TablePaginationType,\n} from '../types';\nimport { useMemo } from 'react';\nimport { VisuallyHidden } from '../../VisuallyHidden';\nimport { Flex } from '../../Flex';\nimport { TableBodySkeleton } from './TableBodySkeleton';\n\nfunction isRowRenderFn<T extends TableItem>(\n rowConfig: RowConfig<T> | RowRenderFn<T> | undefined,\n): rowConfig is RowRenderFn<T> {\n return typeof rowConfig === 'function';\n}\n\nfunction useDisabledRows<T extends TableItem>({\n data,\n rowConfig,\n}: Pick<TableProps<T>, 'data' | 'rowConfig'>): Set<Key> | undefined {\n return useMemo(() => {\n if (!data || typeof rowConfig === 'function' || !rowConfig?.getIsDisabled) {\n return;\n }\n\n return data.reduce<Set<Key>>((set, item) => {\n const isDisabled = rowConfig.getIsDisabled?.(item);\n if (isDisabled) {\n set.add(String(item.id));\n }\n return set;\n }, new Set<Key>());\n }, [data, rowConfig]);\n}\n\nfunction useLiveRegionLabel(\n pagination: TablePaginationType,\n isStale: boolean,\n isLoading: boolean,\n hasData: boolean,\n): string {\n if (isLoading) {\n return 'Loading table data.';\n }\n\n if (!hasData || pagination.type === 'none') {\n return '';\n }\n\n const { pageSize, offset, totalCount, getLabel } = pagination;\n\n if (isStale) {\n return 'Loading table data.';\n }\n\n let liveRegionLabel = 'Table page loaded. ';\n\n if (getLabel) {\n liveRegionLabel += getLabel({ pageSize, offset, totalCount });\n } else if (offset !== undefined) {\n const fromCount = offset + 1;\n const toCount = Math.min(offset + pageSize, totalCount ?? 0);\n liveRegionLabel += `Showing ${fromCount} to ${toCount} of ${totalCount}`;\n }\n return liveRegionLabel;\n}\n\n/**\n * A full-featured data table with built-in pagination, sorting, row selection, loading and error states, and optional virtualization.\n * Pair with `useTable` to manage data fetching and state, or pass `data`, `columnConfig`, and `pagination` directly for manual control.\n *\n * @public\n */\nexport function Table<T extends TableItem>({\n columnConfig,\n data,\n loading = false,\n isStale = false,\n error,\n pagination,\n sort,\n rowConfig,\n selection,\n emptyState,\n className,\n style,\n virtualized,\n}: TableProps<T>) {\n const {\n ownProps: { classes },\n } = useDefinition(TableWrapperDefinition, { className });\n const liveRegionId = useId();\n\n const visibleColumns = useMemo(\n () => columnConfig.filter(col => !col.isHidden),\n [columnConfig],\n );\n const disabledRows = useDisabledRows({ data, rowConfig });\n\n const {\n mode: selectionMode,\n selected: selectedKeys,\n behavior: selectionBehavior,\n onSelectionChange,\n } = selection || {};\n\n const isInitialLoading = loading && !data;\n\n if (error) {\n return (\n <div className={classes.root} style={style}>\n Error: {error.message}\n </div>\n );\n }\n\n const liveRegionLabel = useLiveRegionLabel(\n pagination,\n isStale,\n isInitialLoading,\n data !== undefined,\n );\n\n const manualColumnSizing = columnConfig.some(\n col =>\n col.width != null ||\n col.minWidth != null ||\n col.maxWidth != null ||\n col.defaultWidth != null,\n );\n\n const wrapResizable = manualColumnSizing\n ? (elem: React.ReactNode) => (\n <ResizableTableContainer className={classes.resizableContainer}>\n {elem}\n </ResizableTableContainer>\n )\n : (elem: React.ReactNode) => <>{elem}</>;\n\n const layoutOptions =\n typeof virtualized === 'object' ? virtualized : undefined;\n\n const wrapVirtualized = (elem: React.ReactNode) =>\n virtualized ? (\n <Virtualizer layout={TableLayout} layoutOptions={layoutOptions}>\n {elem}\n </Virtualizer>\n ) : (\n elem\n );\n\n return (\n <div className={classes.root} style={style}>\n <VisuallyHidden aria-live=\"polite\" id={liveRegionId}>\n {liveRegionLabel}\n </VisuallyHidden>\n {wrapResizable(\n wrapVirtualized(\n <TableRoot\n {...(isInitialLoading\n ? {}\n : {\n selectionMode,\n selectionBehavior,\n selectedKeys,\n onSelectionChange,\n })}\n sortDescriptor={sort?.descriptor ?? undefined}\n onSortChange={sort?.onSortChange}\n disabledKeys={disabledRows}\n stale={isStale}\n loading={isInitialLoading}\n aria-describedby={liveRegionId}\n >\n <TableHeader columns={visibleColumns}>\n {column =>\n column.header ? (\n column.header()\n ) : (\n <Column\n id={column.id}\n isRowHeader={column.isRowHeader}\n allowsSorting={column.isSortable}\n width={column.width}\n defaultWidth={column.defaultWidth}\n minWidth={column.minWidth}\n maxWidth={column.maxWidth}\n >\n {column.label}\n </Column>\n )\n }\n </TableHeader>\n {isInitialLoading ? (\n <TableBodySkeleton columns={visibleColumns} />\n ) : (\n <TableBody\n items={data}\n dependencies={[visibleColumns]}\n renderEmptyState={\n emptyState ? () => <Flex p=\"3\">{emptyState}</Flex> : undefined\n }\n >\n {item => {\n const itemIndex = data?.indexOf(item) ?? -1;\n\n if (isRowRenderFn(rowConfig)) {\n return rowConfig({\n item,\n index: itemIndex,\n });\n }\n\n return (\n <Row\n id={String(item.id)}\n columns={visibleColumns}\n href={rowConfig?.getHref?.(item)}\n onAction={\n rowConfig?.onClick\n ? () => rowConfig?.onClick?.(item)\n : undefined\n }\n >\n {column => column.cell(item)}\n </Row>\n );\n }}\n </TableBody>\n )}\n </TableRoot>,\n ),\n )}\n {pagination.type === 'page' && (\n <TablePagination\n pageSize={pagination.pageSize}\n pageSizeOptions={pagination.pageSizeOptions}\n offset={pagination.offset}\n totalCount={pagination.totalCount}\n hasNextPage={pagination.hasNextPage}\n hasPreviousPage={pagination.hasPreviousPage}\n onNextPage={pagination.onNextPage}\n onPreviousPage={pagination.onPreviousPage}\n onPageSizeChange={pagination.onPageSizeChange}\n showPageSizeOptions={pagination.showPageSizeOptions}\n getLabel={pagination.getLabel}\n showPaginationLabel={pagination.showPaginationLabel}\n />\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,cACP,SAAA,EAC6B;AAC7B,EAAA,OAAO,OAAO,SAAA,KAAc,UAAA;AAC9B;AAEA,SAAS,eAAA,CAAqC;AAAA,EAC5C,IAAA;AAAA,EACA;AACF,CAAA,EAAoE;AAClE,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,cAAc,UAAA,IAAc,CAAC,WAAW,aAAA,EAAe;AACzE,MAAA;AAAA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C,EAAA,EAAI,MAAA,CAAO,IAAA,CAAK,EAAE,CAAA;AAAA,wBAClB,OAAA,EAAS,cAAA;AAAA,wBACT,IAAA,EAAM,SAAA,EAAW,OAAA,GAAU,IAAI,CAAA;AAAA,wBAC/B,UACE,SAAA,EAAW,OAAA,GACP,MAAM,SAAA,EAAW,OAAA,GAAU,IAAI,CAAA,GAC/B,MAAA;AAAA,wBAGL,QAAA,EAAA,CAAA,MAAA,KAAU,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA;AAAA,qBAC7B;AAAA,kBAEJ;AAAA;AAAA;AACF;AAAA;AAAA;AAEJ;AACF,KACF;AAAA,IACC,UAAA,CAAW,SAAS,MAAA,oBACnB,GAAA;AAAA,MAAC,eAAA;AAAA,MAAA;AAAA,QACC,UAAU,UAAA,CAAW,QAAA;AAAA,QACrB,iBAAiB,UAAA,CAAW,eAAA;AAAA,QAC5B,QAAQ,UAAA,CAAW,MAAA;AAAA,QACnB,YAAY,UAAA,CAAW,UAAA;AAAA,QACvB,aAAa,UAAA,CAAW,WAAA;AAAA,QACxB,iBAAiB,UAAA,CAAW,eAAA;AAAA,QAC5B,YAAY,UAAA,CAAW,UAAA;AAAA,QACvB,gBAAgB,UAAA,CAAW,cAAA;AAAA,QAC3B,kBAAkB,UAAA,CAAW,gBAAA;AAAA,QAC7B,qBAAqB,UAAA,CAAW,mBAAA;AAAA,QAChC,UAAU,UAAA,CAAW,QAAA;AAAA,QACrB,qBAAqB,UAAA,CAAW;AAAA;AAAA;AAClC,GAAA,EAEJ,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Table.esm.js","sources":["../../../../src/components/Table/components/Table.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { useId } from 'react-aria';\nimport {\n type Key,\n ResizableTableContainer,\n Virtualizer,\n} from 'react-aria-components';\nimport { TableLayout } from 'react-stately';\nimport { useDefinition } from '../../../hooks/useDefinition';\nimport { TableWrapperDefinition } from '../definition';\nimport { TableRoot } from './TableRoot';\nimport { TableHeader } from './TableHeader';\nimport { TableBody } from './TableBody';\nimport { Row } from './Row';\nimport { Column } from './Column';\nimport { TablePagination } from '../../TablePagination';\nimport type {\n TableProps,\n TableItem,\n RowConfig,\n RowRenderFn,\n TablePaginationType,\n} from '../types';\nimport { useMemo } from 'react';\nimport { VisuallyHidden } from '../../VisuallyHidden';\nimport { Flex } from '../../Flex';\nimport { TableBodySkeleton } from './TableBodySkeleton';\n\nfunction isRowRenderFn<T extends TableItem>(\n rowConfig: RowConfig<T> | RowRenderFn<T> | undefined,\n): rowConfig is RowRenderFn<T> {\n return typeof rowConfig === 'function';\n}\n\nfunction useDisabledRows<T extends TableItem>({\n data,\n rowConfig,\n}: Pick<TableProps<T>, 'data' | 'rowConfig'>): Set<Key> | undefined {\n return useMemo(() => {\n if (!data || typeof rowConfig === 'function' || !rowConfig?.getIsDisabled) {\n return;\n }\n\n return data.reduce<Set<Key>>((set, item) => {\n const isDisabled = rowConfig.getIsDisabled?.(item);\n if (isDisabled) {\n set.add(String(item.id));\n }\n return set;\n }, new Set<Key>());\n }, [data, rowConfig]);\n}\n\nfunction useLiveRegionLabel(\n pagination: TablePaginationType,\n isStale: boolean,\n isLoading: boolean,\n hasData: boolean,\n): string {\n if (isLoading) {\n return 'Loading table data.';\n }\n\n if (!hasData || pagination.type === 'none') {\n return '';\n }\n\n const { pageSize, offset, totalCount, getLabel } = pagination;\n\n if (isStale) {\n return 'Loading table data.';\n }\n\n let liveRegionLabel = 'Table page loaded. ';\n\n if (getLabel) {\n liveRegionLabel += getLabel({ pageSize, offset, totalCount });\n } else if (offset !== undefined) {\n const fromCount = offset + 1;\n const toCount = Math.min(offset + pageSize, totalCount ?? 0);\n liveRegionLabel += `Showing ${fromCount} to ${toCount} of ${totalCount}`;\n }\n return liveRegionLabel;\n}\n\n/**\n * A full-featured data table with built-in pagination, sorting, row selection, loading and error states, and optional virtualization.\n * Pair with `useTable` to manage data fetching and state, or pass `data`, `columnConfig`, and `pagination` directly for manual control.\n *\n * @public\n */\nexport function Table<T extends TableItem>({\n columnConfig,\n data,\n isPending = false,\n loading = false,\n isStale = false,\n error,\n pagination,\n sort,\n rowConfig,\n selection,\n emptyState,\n className,\n style,\n virtualized,\n}: TableProps<T>) {\n const pending = isPending || loading;\n const {\n ownProps: { classes },\n } = useDefinition(TableWrapperDefinition, { className });\n const liveRegionId = useId();\n\n const visibleColumns = useMemo(\n () => columnConfig.filter(col => !col.isHidden),\n [columnConfig],\n );\n const disabledRows = useDisabledRows({ data, rowConfig });\n\n const {\n mode: selectionMode,\n selected: selectedKeys,\n behavior: selectionBehavior,\n onSelectionChange,\n } = selection || {};\n\n const isInitialLoading = pending && !data;\n\n if (error) {\n return (\n <div className={classes.root} style={style}>\n Error: {error.message}\n </div>\n );\n }\n\n const liveRegionLabel = useLiveRegionLabel(\n pagination,\n isStale,\n isInitialLoading,\n data !== undefined,\n );\n\n const manualColumnSizing = columnConfig.some(\n col =>\n col.width != null ||\n col.minWidth != null ||\n col.maxWidth != null ||\n col.defaultWidth != null,\n );\n\n const wrapResizable = manualColumnSizing\n ? (elem: React.ReactNode) => (\n <ResizableTableContainer className={classes.resizableContainer}>\n {elem}\n </ResizableTableContainer>\n )\n : (elem: React.ReactNode) => <>{elem}</>;\n\n const layoutOptions =\n typeof virtualized === 'object' ? virtualized : undefined;\n\n const wrapVirtualized = (elem: React.ReactNode) =>\n virtualized ? (\n <Virtualizer layout={TableLayout} layoutOptions={layoutOptions}>\n {elem}\n </Virtualizer>\n ) : (\n elem\n );\n\n return (\n <div className={classes.root} style={style}>\n <VisuallyHidden aria-live=\"polite\" id={liveRegionId}>\n {liveRegionLabel}\n </VisuallyHidden>\n {wrapResizable(\n wrapVirtualized(\n <TableRoot\n {...(isInitialLoading\n ? {}\n : {\n selectionMode,\n selectionBehavior,\n selectedKeys,\n onSelectionChange,\n })}\n sortDescriptor={sort?.descriptor ?? undefined}\n onSortChange={sort?.onSortChange}\n disabledKeys={disabledRows}\n stale={isStale}\n isPending={isInitialLoading}\n aria-describedby={liveRegionId}\n >\n <TableHeader columns={visibleColumns}>\n {column =>\n column.header ? (\n column.header()\n ) : (\n <Column\n id={column.id}\n isRowHeader={column.isRowHeader}\n allowsSorting={column.isSortable}\n width={column.width}\n defaultWidth={column.defaultWidth}\n minWidth={column.minWidth}\n maxWidth={column.maxWidth}\n >\n {column.label}\n </Column>\n )\n }\n </TableHeader>\n {isInitialLoading ? (\n <TableBodySkeleton columns={visibleColumns} />\n ) : (\n <TableBody\n items={data}\n dependencies={[visibleColumns]}\n renderEmptyState={\n emptyState ? () => <Flex p=\"3\">{emptyState}</Flex> : undefined\n }\n >\n {item => {\n const itemIndex = data?.indexOf(item) ?? -1;\n\n if (isRowRenderFn(rowConfig)) {\n return rowConfig({\n item,\n index: itemIndex,\n });\n }\n\n return (\n <Row\n id={String(item.id)}\n columns={visibleColumns}\n href={rowConfig?.getHref?.(item)}\n onAction={\n rowConfig?.onClick\n ? () => rowConfig?.onClick?.(item)\n : undefined\n }\n >\n {column => column.cell(item)}\n </Row>\n );\n }}\n </TableBody>\n )}\n </TableRoot>,\n ),\n )}\n {pagination.type === 'page' && (\n <TablePagination\n pageSize={pagination.pageSize}\n pageSizeOptions={pagination.pageSizeOptions}\n offset={pagination.offset}\n totalCount={pagination.totalCount}\n hasNextPage={pagination.hasNextPage}\n hasPreviousPage={pagination.hasPreviousPage}\n onNextPage={pagination.onNextPage}\n onPreviousPage={pagination.onPreviousPage}\n onPageSizeChange={pagination.onPageSizeChange}\n showPageSizeOptions={pagination.showPageS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UAAA,CAAW,cAAA;AAAA,QAC3B,kBAAkB,UAAA,CAAW,gBAAA;AAAA,QAC7B,qBAAqB,UAAA,CAAW,mBAAA;AAAA,QAChC,UAAU,UAAA,CAAW,QAAA;AAAA,QACrB,qBAAqB,UAAA,CAAW;AAAA;AAAA;AAClC,GAAA,EAEJ,CAAA;AAEJ;;;;"}
|
|
@@ -6,14 +6,19 @@ import { Table } from 'react-aria-components';
|
|
|
6
6
|
const TableRoot = (props) => {
|
|
7
7
|
const { ownProps, restProps, dataAttributes } = useDefinition(
|
|
8
8
|
TableDefinition,
|
|
9
|
-
|
|
9
|
+
// Merge deprecated `loading` into `isPending` so data attributes and
|
|
10
|
+
// internal logic only need to check a single prop.
|
|
11
|
+
{
|
|
12
|
+
...props,
|
|
13
|
+
isPending: props.isPending || props.loading ? true : props.isPending ?? props.loading
|
|
14
|
+
}
|
|
10
15
|
);
|
|
11
16
|
return /* @__PURE__ */ jsx(
|
|
12
17
|
Table,
|
|
13
18
|
{
|
|
14
19
|
className: ownProps.classes.root,
|
|
15
20
|
"aria-label": "Data table",
|
|
16
|
-
"aria-busy": ownProps.stale || ownProps.
|
|
21
|
+
"aria-busy": ownProps.stale || ownProps.isPending,
|
|
17
22
|
...dataAttributes,
|
|
18
23
|
...restProps
|
|
19
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRoot.esm.js","sources":["../../../../src/components/Table/components/TableRoot.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { useDefinition } from '../../../hooks/useDefinition';\nimport { TableDefinition } from '../definition';\nimport { Table as ReactAriaTable } from 'react-aria-components';\nimport { TableRootProps } from '../types';\n\n/**\n * The low-level table root element for building custom table layouts from atomic components.\n * For most use cases, prefer the `Table` convenience wrapper.\n *\n * @public\n */\nexport const TableRoot = (props: TableRootProps) => {\n const { ownProps, restProps, dataAttributes } = useDefinition(\n TableDefinition,\n props,\n );\n\n return (\n <ReactAriaTable\n className={ownProps.classes.root}\n aria-label=\"Data table\"\n aria-busy={ownProps.stale || ownProps.
|
|
1
|
+
{"version":3,"file":"TableRoot.esm.js","sources":["../../../../src/components/Table/components/TableRoot.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { useDefinition } from '../../../hooks/useDefinition';\nimport { TableDefinition } from '../definition';\nimport { Table as ReactAriaTable } from 'react-aria-components';\nimport { TableRootProps } from '../types';\n\n/**\n * The low-level table root element for building custom table layouts from atomic components.\n * For most use cases, prefer the `Table` convenience wrapper.\n *\n * @public\n */\nexport const TableRoot = (props: TableRootProps) => {\n const { ownProps, restProps, dataAttributes } = useDefinition(\n TableDefinition,\n // Merge deprecated `loading` into `isPending` so data attributes and\n // internal logic only need to check a single prop.\n {\n ...props,\n isPending:\n props.isPending || props.loading\n ? true\n : props.isPending ?? props.loading,\n },\n );\n\n return (\n <ReactAriaTable\n className={ownProps.classes.root}\n aria-label=\"Data table\"\n aria-busy={ownProps.stale || ownProps.isPending}\n {...dataAttributes}\n {...restProps}\n />\n );\n};\n"],"names":["ReactAriaTable"],"mappings":";;;;;AA2BO,MAAM,SAAA,GAAY,CAAC,KAAA,KAA0B;AAClD,EAAA,MAAM,EAAE,QAAA,EAAU,SAAA,EAAW,cAAA,EAAe,GAAI,aAAA;AAAA,IAC9C,eAAA;AAAA;AAAA;AAAA,IAGA;AAAA,MACE,GAAG,KAAA;AAAA,MACH,SAAA,EACE,MAAM,SAAA,IAAa,KAAA,CAAM,UACrB,IAAA,GACA,KAAA,CAAM,aAAa,KAAA,CAAM;AAAA;AACjC,GACF;AAEA,EAAA,uBACE,GAAA;AAAA,IAACA,KAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,SAAS,OAAA,CAAQ,IAAA;AAAA,MAC5B,YAAA,EAAW,YAAA;AAAA,MACX,WAAA,EAAW,QAAA,CAAS,KAAA,IAAS,QAAA,CAAS,SAAA;AAAA,MACrC,GAAG,cAAA;AAAA,MACH,GAAG;AAAA;AAAA,GACN;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Table/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { defineComponent } from '../../hooks/useDefinition';\nimport type {\n TableRootOwnProps,\n TableHeaderOwnProps,\n TableBodyOwnProps,\n RowOwnProps,\n ColumnOwnProps,\n CellOwnProps,\n CellTextOwnProps,\n CellProfileOwnProps,\n} from './types';\nimport styles from './Table.module.css';\n\n/** @internal */\nexport const TableWrapperDefinition = defineComponent<{\n className?: string;\n}>()({\n styles,\n classNames: {\n root: 'bui-TableWrapper',\n resizableContainer: 'bui-TableResizableContainer',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for Table\n * @public\n */\nexport const TableDefinition = defineComponent<TableRootOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Table',\n },\n propDefs: {\n stale: { dataAttribute: true },\n loading: { dataAttribute: true },\n },\n});\n\n/**\n * Component definition for TableHeader\n * @internal\n */\nexport const TableHeaderDefinition = defineComponent<TableHeaderOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHeader',\n headSelection: 'bui-TableHeadSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n },\n});\n\n/**\n * Component definition for TableBody\n * @internal\n */\nexport const TableBodyDefinition = defineComponent<TableBodyOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableBody',\n },\n propDefs: {},\n});\n\n/**\n * Component definition for Row\n * @internal\n */\nexport const RowDefinition = defineComponent<RowOwnProps>()({\n styles,\n analytics: true,\n bg: 'consumer',\n classNames: {\n root: 'bui-TableRow',\n cell: 'bui-TableCell',\n cellSelection: 'bui-TableCellSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n href: {},\n noTrack: {},\n },\n});\n\n/**\n * Component definition for Column\n * @internal\n */\nexport const ColumnDefinition = defineComponent<ColumnOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHead',\n headContent: 'bui-TableHeadContent',\n headLabel: 'bui-TableHeadLabel',\n headSortButton: 'bui-TableHeadSortButton',\n },\n propDefs: {\n children: {},\n className: {},\n },\n});\n\n/**\n * Component definition for Cell\n * @internal\n */\nexport const CellDefinition = defineComponent<CellOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for CellText\n * @internal\n */\nexport const CellTextDefinition = defineComponent<CellTextOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n cellIcon: 'bui-TableCellIcon',\n },\n propDefs: {\n title: {},\n description: {},\n color: { default: 'primary' },\n leadingIcon: {},\n href: {},\n className: {},\n },\n});\n\n/**\n * Component definition for CellProfile\n * @internal\n */\nexport const CellProfileDefinition = defineComponent<CellProfileOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n },\n propDefs: {\n src: {},\n name: {},\n href: {},\n description: {},\n color: { default: 'primary' },\n className: {},\n },\n});\n"],"names":[],"mappings":";;;;;;;;;;AA8BO,MAAM,sBAAA,GAAyB,iBAEnC,CAAE;AAAA,EACH,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,kBAAA;AAAA,IACN,kBAAA,EAAoB;AAAA,GACtB;AAAA,EACA,QAAA,EAAU;AAAA,IACR,WAAW;AAAC;AAEhB,CAAC;AAMM,MAAM,eAAA,GAAkB,iBAAmC,CAAE;AAAA,EAClE,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM;AAAA,GACR;AAAA,EACA,QAAA,EAAU;AAAA,IACR,KAAA,EAAO,EAAE,aAAA,EAAe,IAAA,EAAK;AAAA,IAC7B,OAAA,EAAS,EAAE,aAAA,EAAe,IAAA;AAAK;AAEnC,CAAC;AAMM,MAAM,qBAAA,GAAwB,iBAAqC,CAAE;AAAA,EAC1E,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,iBAAA;AAAA,IACN,aAAA,EAAe;AAAA,GACjB;AAAA,EACA,QAAA,EAAU;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAU;AAAC;AAEf,CAAC;AAMM,MAAM,mBAAA,GAAsB,iBAAmC,CAAE;AAAA,EACtE,MAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM;AAAA,GACR;AAAA,EACA,UAAU;AACZ,CAAC;AAMM,MAAM,aAAA,GAAgB,iBAA6B,CAAE;AAAA,EAC1D,MAAA;AAAA,EACA,SAAA,EAAW,IAAA;AAAA,EACX,EAA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AA,EAAM,eAAA;AAAA,IACN,kBAAA,EAAoB,6BAAA;AAAA,IACpB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,QAAA,EAAU;AAAA,IACR,KAAK,EAAC;AAAA,IACN,MAAM,EAAC;AAAA,IACP,MAAM,EAAC;AAAA,IACP,aAAa,EAAC;AAAA,IACd,KAAA,EAAO,EAAE,OAAA,EAAS,SAAA,EAAU;AAAA,IAC5B,WAAW;AAAC;AAEhB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"definition.esm.js","sources":["../../../src/components/Table/definition.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { defineComponent } from '../../hooks/useDefinition';\nimport type {\n TableRootOwnProps,\n TableHeaderOwnProps,\n TableBodyOwnProps,\n RowOwnProps,\n ColumnOwnProps,\n CellOwnProps,\n CellTextOwnProps,\n CellProfileOwnProps,\n} from './types';\nimport styles from './Table.module.css';\n\n/** @internal */\nexport const TableWrapperDefinition = defineComponent<{\n className?: string;\n}>()({\n styles,\n classNames: {\n root: 'bui-TableWrapper',\n resizableContainer: 'bui-TableResizableContainer',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for Table\n * @public\n */\nexport const TableDefinition = defineComponent<TableRootOwnProps>()({\n styles,\n classNames: {\n root: 'bui-Table',\n },\n propDefs: {\n stale: { dataAttribute: true },\n isPending: { dataAttribute: true },\n loading: { dataAttribute: true },\n },\n});\n\n/**\n * Component definition for TableHeader\n * @internal\n */\nexport const TableHeaderDefinition = defineComponent<TableHeaderOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHeader',\n headSelection: 'bui-TableHeadSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n },\n});\n\n/**\n * Component definition for TableBody\n * @internal\n */\nexport const TableBodyDefinition = defineComponent<TableBodyOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableBody',\n },\n propDefs: {},\n});\n\n/**\n * Component definition for Row\n * @internal\n */\nexport const RowDefinition = defineComponent<RowOwnProps>()({\n styles,\n analytics: true,\n bg: 'consumer',\n classNames: {\n root: 'bui-TableRow',\n cell: 'bui-TableCell',\n cellSelection: 'bui-TableCellSelection',\n },\n propDefs: {\n columns: {},\n children: {},\n href: {},\n noTrack: {},\n },\n});\n\n/**\n * Component definition for Column\n * @internal\n */\nexport const ColumnDefinition = defineComponent<ColumnOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableHead',\n headContent: 'bui-TableHeadContent',\n headLabel: 'bui-TableHeadLabel',\n headSortButton: 'bui-TableHeadSortButton',\n },\n propDefs: {\n children: {},\n className: {},\n },\n});\n\n/**\n * Component definition for Cell\n * @internal\n */\nexport const CellDefinition = defineComponent<CellOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n },\n propDefs: {\n className: {},\n },\n});\n\n/**\n * Component definition for CellText\n * @internal\n */\nexport const CellTextDefinition = defineComponent<CellTextOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n cellIcon: 'bui-TableCellIcon',\n },\n propDefs: {\n title: {},\n description: {},\n color: { default: 'primary' },\n leadingIcon: {},\n href: {},\n className: {},\n },\n});\n\n/**\n * Component definition for CellProfile\n * @internal\n */\nexport const CellProfileDefinition = defineComponent<CellProfileOwnProps>()({\n styles,\n classNames: {\n root: 'bui-TableCell',\n cellContentWrapper: 'bui-TableCellContentWrapper',\n cellContent: 'bui-TableCellContent',\n },\n propDefs: {\n src: {},\n name: {},\n href: {},\n description: {},\n color: { default: 'prim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a,EAAC;AAAA,IACd,KAAA,EAAO,EAAE,OAAA,EAAS,SAAA,EAAU;AAAA,IAC5B,WAAW;AAAC;AAEhB,CAAC;;;;"}
|
|
@@ -18,7 +18,7 @@ function useCompletePagination(options, query) {
|
|
|
18
18
|
const getData = useStableCallback(getDataProp);
|
|
19
19
|
const { sort, filter, search } = query;
|
|
20
20
|
const [items, setItems] = useState(void 0);
|
|
21
|
-
const [
|
|
21
|
+
const [isPending, setIsPending] = useState(!data);
|
|
22
22
|
const [error, setError] = useState(void 0);
|
|
23
23
|
const [loadCount, setLoadCount] = useState(0);
|
|
24
24
|
const [offset, setOffset] = useState(initialOffset);
|
|
@@ -29,14 +29,14 @@ function useCompletePagination(options, query) {
|
|
|
29
29
|
}, [defaultPageSize]);
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
if (data) {
|
|
32
|
-
|
|
32
|
+
setIsPending(false);
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
if (!hasGetData) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
let cancelled = false;
|
|
39
|
-
|
|
39
|
+
setIsPending(true);
|
|
40
40
|
setError(void 0);
|
|
41
41
|
(async () => {
|
|
42
42
|
try {
|
|
@@ -44,12 +44,12 @@ function useCompletePagination(options, query) {
|
|
|
44
44
|
const resolvedData = result instanceof Promise ? await result : result;
|
|
45
45
|
if (!cancelled) {
|
|
46
46
|
setItems(resolvedData);
|
|
47
|
-
|
|
47
|
+
setIsPending(false);
|
|
48
48
|
}
|
|
49
49
|
} catch (err) {
|
|
50
50
|
if (!cancelled) {
|
|
51
51
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
52
|
-
|
|
52
|
+
setIsPending(false);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
})();
|
|
@@ -108,7 +108,7 @@ function useCompletePagination(options, query) {
|
|
|
108
108
|
}, []);
|
|
109
109
|
return {
|
|
110
110
|
data: paginatedData,
|
|
111
|
-
|
|
111
|
+
isPending,
|
|
112
112
|
error,
|
|
113
113
|
totalCount,
|
|
114
114
|
offset,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompletePagination.esm.js","sources":["../../../../src/components/Table/hooks/useCompletePagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { useState, useCallback, useMemo, useEffect, useRef } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n PaginationResult,\n QueryState,\n UseTableCompleteOptions,\n} from './types';\nimport { useStableCallback } from './useStableCallback';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\n/** @internal */\nexport function useCompletePagination<T extends TableItem, TFilter>(\n options: UseTableCompleteOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const {\n data,\n getData: getDataProp = () => [],\n paginationOptions = {},\n sortFn,\n filterFn,\n searchFn,\n } = options;\n const hasGetData = 'getData' in options;\n const noPagination = paginationOptions.type === 'none';\n const { initialOffset = 0 } = paginationOptions;\n const defaultPageSize = noPagination\n ? Infinity\n : getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [items, setItems] = useState<T[] | undefined>(undefined);\n const [
|
|
1
|
+
{"version":3,"file":"useCompletePagination.esm.js","sources":["../../../../src/components/Table/hooks/useCompletePagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { useState, useCallback, useMemo, useEffect, useRef } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n PaginationResult,\n QueryState,\n UseTableCompleteOptions,\n} from './types';\nimport { useStableCallback } from './useStableCallback';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\n/** @internal */\nexport function useCompletePagination<T extends TableItem, TFilter>(\n options: UseTableCompleteOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const {\n data,\n getData: getDataProp = () => [],\n paginationOptions = {},\n sortFn,\n filterFn,\n searchFn,\n } = options;\n const hasGetData = 'getData' in options;\n const noPagination = paginationOptions.type === 'none';\n const { initialOffset = 0 } = paginationOptions;\n const defaultPageSize = noPagination\n ? Infinity\n : getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [items, setItems] = useState<T[] | undefined>(undefined);\n const [isPending, setIsPending] = useState(!data);\n const [error, setError] = useState<Error | undefined>(undefined);\n const [loadCount, setLoadCount] = useState(0);\n\n const [offset, setOffset] = useState(initialOffset);\n const [pageSize, setPageSize] = useState(defaultPageSize);\n\n // Sync pageSize when the caller changes paginationOptions.pageSize\n useEffect(() => {\n setPageSize(defaultPageSize);\n setOffset(0);\n }, [defaultPageSize]);\n\n // Load data on mount and when loadCount changes (reload trigger)\n useEffect(() => {\n if (data) {\n setIsPending(false);\n return;\n }\n\n if (!hasGetData) {\n return;\n }\n\n let cancelled = false;\n setIsPending(true);\n setError(undefined);\n\n (async () => {\n try {\n const result = getData();\n const resolvedData = result instanceof Promise ? await result : result;\n if (!cancelled) {\n setItems(resolvedData);\n setIsPending(false);\n }\n } catch (err) {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsPending(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n };\n }, [data, getData, hasGetData, loadCount]);\n\n // Reset offset when query changes (query object is memoized)\n const prevQueryRef = useRef(query);\n useEffect(() => {\n if (prevQueryRef.current !== query) {\n prevQueryRef.current = query;\n setOffset(0);\n }\n }, [query]);\n\n const resolvedItems = useMemo(() => data ?? items, [data, items]);\n\n // Process data client-side (filter, search, sort)\n const processedData = useMemo(() => {\n if (!resolvedItems) {\n return undefined;\n }\n let result = [...resolvedItems];\n if (filter !== undefined && filterFn) {\n result = filterFn(result, filter);\n }\n if (search && searchFn) {\n result = searchFn(result, search);\n }\n if (sort && sortFn) {\n result = sortFn(result, sort);\n }\n return result;\n }, [resolvedItems, sort, filter, search, filterFn, searchFn, sortFn]);\n\n const totalCount = processedData?.length ?? 0;\n\n // Paginate the processed data\n const paginatedData = useMemo(\n () =>\n noPagination\n ? processedData\n : processedData?.slice(offset, offset + pageSize),\n [processedData, offset, pageSize, noPagination],\n );\n\n const hasNextPage = !noPagination && offset + pageSize < totalCount;\n const hasPreviousPage = !noPagination && offset > 0;\n\n const onNextPage = useCallback(() => {\n if (offset + pageSize < totalCount) {\n setOffset(offset + pageSize);\n }\n }, [offset, pageSize, totalCount]);\n\n const onPreviousPage = useCallback(() => {\n if (offset > 0) {\n setOffset(Math.max(0, offset - pageSize));\n }\n }, [offset, pageSize]);\n\n const onPageSizeChange = useCallback((newSize: number) => {\n setPageSize(newSize);\n setOffset(0);\n }, []);\n\n const reload = useCallback(() => {\n setOffset(0);\n setLoadCount(c => c + 1);\n }, []);\n\n return {\n data: paginatedData,\n isPending: isPending,\n error,\n totalCount,\n offset,\n pageSize,\n hasNextPage,\n hasPreviousPage,\n onNextPage,\n onPreviousPage,\n onPageSizeChange,\n reload,\n };\n}\n"],"names":[],"mappings":";;;;AA2BO,SAAS,qBAAA,CACd,SACA,KAAA,EAC8C;AAC9C,EAAA,MAAM;AAAA,IACJ,IAAA;AAAA,IACA,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A,MAAM,cAAA,GAAiB,YAAY,MAAM;AACvC,IAAA,IAAI,SAAS,CAAA,EAAG;AACd,MAAA,SAAA,CAAU,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,MAAA,GAAS,QAAQ,CAAC,CAAA;AAAA,IAC1C;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,QAAQ,CAAC,CAAA;AAErB,EAAA,MAAM,gBAAA,GAAmB,WAAA,CAAY,CAAC,OAAA,KAAoB;AACxD,IAAA,WAAA,CAAY,OAAO,CAAA;AACnB,IAAA,SAAA,CAAU,CAAC,CAAA;AAAA,EACb,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM;AAC/B,IAAA,SAAA,CAAU,CAAC,CAAA;AACX,IAAA,YAAA,CAAa,CAAA,CAAA,KAAK,IAAI,CAAC,CAAA;AAAA,EACzB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,SAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA;AAAA,IACA,UAAA;AAAA,IACA,cAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCursorPagination.esm.js","sources":["../../../../src/components/Table/hooks/useCursorPagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport { useState, useCallback } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n UseTableCursorOptions,\n CursorParams,\n QueryState,\n PaginationResult,\n} from './types';\nimport { usePageCache } from './usePageCache';\nimport { useStableCallback } from './useStableCallback';\nimport { useDebouncedReload } from './useDebouncedReload';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\nexport function useCursorPagination<T extends TableItem, TFilter>(\n options: UseTableCursorOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const { getData: getDataProp, paginationOptions = {} } = options;\n const defaultPageSize = getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [pageSize, setPageSize] = useState(defaultPageSize);\n\n const wrappedGetData = useCallback(\n async ({\n cursor,\n signal,\n }: {\n cursor: string | undefined;\n signal: AbortSignal;\n }) => {\n const params: CursorParams<TFilter> = {\n cursor,\n pageSize,\n sort,\n filter,\n search,\n signal,\n };\n\n const response = await getData(params);\n\n return {\n data: response.data,\n prevCursor: response.prevCursor,\n nextCursor: response.nextCursor,\n totalCount: response.totalCount,\n };\n },\n [getData, pageSize, sort, filter, search],\n );\n\n const cache = usePageCache<T, string>({ getData: wrappedGetData });\n\n useDebouncedReload(query, pageSize, cache.reload);\n\n const onPageSizeChange = useCallback(\n (newSize: number) => setPageSize(newSize),\n [],\n );\n\n return {\n data: cache.data,\n
|
|
1
|
+
{"version":3,"file":"useCursorPagination.esm.js","sources":["../../../../src/components/Table/hooks/useCursorPagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport { useState, useCallback } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n UseTableCursorOptions,\n CursorParams,\n QueryState,\n PaginationResult,\n} from './types';\nimport { usePageCache } from './usePageCache';\nimport { useStableCallback } from './useStableCallback';\nimport { useDebouncedReload } from './useDebouncedReload';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\nexport function useCursorPagination<T extends TableItem, TFilter>(\n options: UseTableCursorOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const { getData: getDataProp, paginationOptions = {} } = options;\n const defaultPageSize = getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [pageSize, setPageSize] = useState(defaultPageSize);\n\n const wrappedGetData = useCallback(\n async ({\n cursor,\n signal,\n }: {\n cursor: string | undefined;\n signal: AbortSignal;\n }) => {\n const params: CursorParams<TFilter> = {\n cursor,\n pageSize,\n sort,\n filter,\n search,\n signal,\n };\n\n const response = await getData(params);\n\n return {\n data: response.data,\n prevCursor: response.prevCursor,\n nextCursor: response.nextCursor,\n totalCount: response.totalCount,\n };\n },\n [getData, pageSize, sort, filter, search],\n );\n\n const cache = usePageCache<T, string>({ getData: wrappedGetData });\n\n useDebouncedReload(query, pageSize, cache.reload);\n\n const onPageSizeChange = useCallback(\n (newSize: number) => setPageSize(newSize),\n [],\n );\n\n return {\n data: cache.data,\n isPending: cache.isPending,\n error: cache.error,\n totalCount: cache.totalCount,\n offset: undefined,\n pageSize,\n hasNextPage: cache.hasNextPage,\n hasPreviousPage: cache.hasPreviousPage,\n onNextPage: cache.onNextPage,\n onPreviousPage: cache.onPreviousPage,\n onPageSizeChange,\n reload: cache.reload,\n };\n}\n"],"names":[],"mappings":";;;;;;AA4BO,SAAS,mBAAA,CACd,SACA,KAAA,EAC8C;AAC9C,EAAA,MAAM,EAAE,OAAA,EAAS,WAAA,EAAa,iBAAA,GAAoB,IAAG,GAAI,OAAA;AACzD,EAA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AAA;AAAA,IAClB,MAAA,EAAQ,MAAA;AAAA,IACR,QAAA;AAAA,IACA,aAAa,KAAA,CAAM,WAAA;AAAA,IACnB,iBAAiB,KAAA,CAAM,eAAA;AAAA,IACvB,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,gBAAgB,KAAA,CAAM,cAAA;AAAA,IACtB,gBAAA;AAAA,IACA,QAAQ,KAAA,CAAM;AAAA,GAChB;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOffsetPagination.esm.js","sources":["../../../../src/components/Table/hooks/useOffsetPagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport { useState, useCallback } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n UseTableOffsetOptions,\n OffsetParams,\n QueryState,\n PaginationResult,\n} from './types';\nimport { usePageCache } from './usePageCache';\nimport { useStableCallback } from './useStableCallback';\nimport { useDebouncedReload } from './useDebouncedReload';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\nexport function useOffsetPagination<T extends TableItem, TFilter>(\n options: UseTableOffsetOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const { getData: getDataProp, paginationOptions = {} } = options;\n const { initialOffset = 0 } = paginationOptions;\n const defaultPageSize = getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [pageSize, setPageSize] = useState(defaultPageSize);\n\n const wrappedGetData = useCallback(\n async ({\n cursor,\n signal,\n }: {\n cursor: number | undefined;\n signal: AbortSignal;\n }) => {\n const currentOffset = cursor ?? 0;\n\n const params: OffsetParams<TFilter> = {\n offset: currentOffset,\n pageSize,\n sort,\n filter,\n search,\n signal,\n };\n\n const response = await getData(params);\n\n const prevCursor =\n currentOffset > 0 ? Math.max(0, currentOffset - pageSize) : undefined;\n const nextCursor =\n currentOffset + pageSize < response.totalCount\n ? currentOffset + pageSize\n : undefined;\n\n return {\n data: response.data,\n prevCursor,\n nextCursor,\n totalCount: response.totalCount,\n };\n },\n [getData, pageSize, sort, filter, search],\n );\n\n const cache = usePageCache<T, number>({\n getData: wrappedGetData,\n initialCurrentCursor: initialOffset > 0 ? initialOffset : undefined,\n });\n\n useDebouncedReload(query, pageSize, cache.reload);\n\n const onPageSizeChange = useCallback(\n (newSize: number) => setPageSize(newSize),\n [],\n );\n\n return {\n data: cache.data,\n
|
|
1
|
+
{"version":3,"file":"useOffsetPagination.esm.js","sources":["../../../../src/components/Table/hooks/useOffsetPagination.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\nimport { useState, useCallback } from 'react';\nimport type { TableItem } from '../types';\nimport type {\n UseTableOffsetOptions,\n OffsetParams,\n QueryState,\n PaginationResult,\n} from './types';\nimport { usePageCache } from './usePageCache';\nimport { useStableCallback } from './useStableCallback';\nimport { useDebouncedReload } from './useDebouncedReload';\nimport { getEffectivePageSize } from './getEffectivePageSize';\n\nexport function useOffsetPagination<T extends TableItem, TFilter>(\n options: UseTableOffsetOptions<T, TFilter>,\n query: QueryState<TFilter>,\n): PaginationResult<T> & { reload: () => void } {\n const { getData: getDataProp, paginationOptions = {} } = options;\n const { initialOffset = 0 } = paginationOptions;\n const defaultPageSize = getEffectivePageSize(paginationOptions);\n\n const getData = useStableCallback(getDataProp);\n const { sort, filter, search } = query;\n\n const [pageSize, setPageSize] = useState(defaultPageSize);\n\n const wrappedGetData = useCallback(\n async ({\n cursor,\n signal,\n }: {\n cursor: number | undefined;\n signal: AbortSignal;\n }) => {\n const currentOffset = cursor ?? 0;\n\n const params: OffsetParams<TFilter> = {\n offset: currentOffset,\n pageSize,\n sort,\n filter,\n search,\n signal,\n };\n\n const response = await getData(params);\n\n const prevCursor =\n currentOffset > 0 ? Math.max(0, currentOffset - pageSize) : undefined;\n const nextCursor =\n currentOffset + pageSize < response.totalCount\n ? currentOffset + pageSize\n : undefined;\n\n return {\n data: response.data,\n prevCursor,\n nextCursor,\n totalCount: response.totalCount,\n };\n },\n [getData, pageSize, sort, filter, search],\n );\n\n const cache = usePageCache<T, number>({\n getData: wrappedGetData,\n initialCurrentCursor: initialOffset > 0 ? initialOffset : undefined,\n });\n\n useDebouncedReload(query, pageSize, cache.reload);\n\n const onPageSizeChange = useCallback(\n (newSize: number) => setPageSize(newSize),\n [],\n );\n\n return {\n data: cache.data,\n isPending: cache.isPending,\n error: cache.error,\n totalCount: cache.totalCount,\n offset: cache.currentCursor ?? 0,\n pageSize,\n hasNextPage: cache.hasNextPage,\n hasPreviousPage: cache.hasPreviousPage,\n onNextPage: cache.onNextPage,\n onPreviousPage: cache.onPreviousPage,\n onPageSizeChange,\n reload: cache.reload,\n };\n}\n"],"names":[],"mappings":";;;;;;AA4BO,SAAS,mBAAA,CACd,SACA,KAAA,EAC8C;AAC9C,EAAA,MAAM,EAAE,OAAA,EAAS,WAAA,EAAa,iBAAA,GAAoB,IAAG,GAAI,OAAA;AACzD,EAAA,MAAM,EAAE,aAAA,GAAgB,CAAA,EAAE,GAAI,iBAAA;AAC9B,EAAA,MAAM,eAAA,GAAkB,qBAAqB,iBAAiB,CAAA;AAE9D,EAAA,MAAM,OAAA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AmB,WAAA;AAAA,IACvB,CAAC,OAAA,KAAoB,WAAA,CAAY,OAAO,CAAA;AAAA,IACxC;AAAC,GACH;AAEA,EAAA,OAAO;AAAA,IACL,MAAM,KAAA,CAAM,IAAA;AAAA,IACZ,WAAW,KAAA,CAAM,SAAA;AAAA,IACjB,OAAO,KAAA,CAAM,KAAA;AAAA,IACb,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,MAAA,EAAQ,MAAM,aAAA,IAAiB,CAAA;AAAA,IAC/B,QAAA;AAAA,IACA,aAAa,KAAA,CAAM,WAAA;AAAA,IACnB,iBAAiB,KAAA,CAAM,eAAA;AAAA,IACvB,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,gBAAgB,KAAA,CAAM,cAAA;AAAA,IACtB,gBAAA;AAAA,IACA,QAAQ,KAAA,CAAM;AAAA,GAChB;AACF;;;;"}
|
|
@@ -58,7 +58,7 @@ function usePageCache(options) {
|
|
|
58
58
|
() => toInternalCursor(initialCurrentCursor)
|
|
59
59
|
);
|
|
60
60
|
const cacheStore = useRef(new PageCacheStore()).current;
|
|
61
|
-
const [
|
|
61
|
+
const [isPending, setIsPending] = useState(true);
|
|
62
62
|
const [error, setError] = useState(void 0);
|
|
63
63
|
const [totalCount, setTotalCount] = useState(void 0);
|
|
64
64
|
const abortControllerRef = useRef(null);
|
|
@@ -89,7 +89,7 @@ function usePageCache(options) {
|
|
|
89
89
|
}
|
|
90
90
|
const abortController = new AbortController();
|
|
91
91
|
abortControllerRef.current = abortController;
|
|
92
|
-
|
|
92
|
+
setIsPending(true);
|
|
93
93
|
setError(void 0);
|
|
94
94
|
try {
|
|
95
95
|
const result = await getData({
|
|
@@ -109,13 +109,13 @@ function usePageCache(options) {
|
|
|
109
109
|
if (result.totalCount !== void 0) {
|
|
110
110
|
setTotalCount(result.totalCount);
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
setIsPending(false);
|
|
113
113
|
} catch (err) {
|
|
114
114
|
if (abortController.signal.aborted) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
118
|
-
|
|
118
|
+
setIsPending(false);
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
121
|
[getData, initialCurrentCursor, currentCursor, cacheStore]
|
|
@@ -129,17 +129,17 @@ function usePageCache(options) {
|
|
|
129
129
|
};
|
|
130
130
|
}, []);
|
|
131
131
|
const onNextPage = useCallback(() => {
|
|
132
|
-
if (
|
|
132
|
+
if (isPending) return;
|
|
133
133
|
const page = cacheStore.get(currentCursor);
|
|
134
134
|
if (!page?.nextCursor) return;
|
|
135
135
|
goToPage("next");
|
|
136
|
-
}, [
|
|
136
|
+
}, [isPending, currentCursor, goToPage, cacheStore]);
|
|
137
137
|
const onPreviousPage = useCallback(() => {
|
|
138
|
-
if (
|
|
138
|
+
if (isPending) return;
|
|
139
139
|
const page = cacheStore.get(currentCursor);
|
|
140
140
|
if (!page?.prevCursor) return;
|
|
141
141
|
goToPage("prev");
|
|
142
|
-
}, [
|
|
142
|
+
}, [isPending, currentCursor, goToPage, cacheStore]);
|
|
143
143
|
const reload = useCallback(
|
|
144
144
|
(reloadOptions) => {
|
|
145
145
|
if (abortControllerRef.current) {
|
|
@@ -151,7 +151,7 @@ function usePageCache(options) {
|
|
|
151
151
|
[goToPage, cacheStore]
|
|
152
152
|
);
|
|
153
153
|
return {
|
|
154
|
-
|
|
154
|
+
isPending,
|
|
155
155
|
error,
|
|
156
156
|
data,
|
|
157
157
|
totalCount,
|