Skip to content

Commit 10dc5aa

Browse files
Merge pull request #7738 from TheThingsNetwork/fix/fetch-table
Block requests on Fetch Table when fetching
2 parents a240f09 + a0c7b1a commit 10dc5aa

7 files changed

Lines changed: 71 additions & 50 deletions

File tree

pkg/webui/components/tabs/index.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,53 @@ const Tabs = ({
3535
divider,
3636
narrow,
3737
toggleStyle,
38-
}) => (
39-
<ul
40-
className={classnames(className, style.tabs, {
41-
[style.divider]: divider,
42-
[style.tabsToggleStyle]: toggleStyle,
43-
})}
44-
data-test-id="tabs"
45-
>
46-
{tabs.map(
47-
({ name, disabled, narrow: nrw, link, exact, icon, title, hidden, description }, index) =>
48-
!Boolean(hidden) && (
49-
<Tab
50-
key={index}
51-
active={name === active}
52-
name={name}
53-
disabled={disabled}
54-
onClick={onTabChange}
55-
narrow={nrw || narrow}
56-
link={link}
57-
exact={exact}
58-
tabClassName={individualTabClassName}
59-
className={tabItemClassName}
60-
toggleStyle={toggleStyle}
61-
tooltip={description}
62-
>
63-
{icon && <Icon icon={icon} className={style.icon} />}
64-
<Message content={title} />
65-
</Tab>
66-
),
67-
)}
68-
</ul>
69-
)
38+
disabled,
39+
}) => {
40+
const handleClick = tabName => {
41+
if (!disabled && onTabChange) {
42+
onTabChange(tabName)
43+
}
44+
}
45+
46+
return (
47+
<ul
48+
className={classnames(className, style.tabs, {
49+
[style.divider]: divider,
50+
[style.tabsToggleStyle]: toggleStyle,
51+
})}
52+
data-test-id="tabs"
53+
>
54+
{tabs.map(
55+
({ name, disabled, narrow: nrw, link, exact, icon, title, hidden, description }, index) =>
56+
!Boolean(hidden) && (
57+
<Tab
58+
key={index}
59+
active={name === active}
60+
name={name}
61+
disabled={disabled}
62+
onClick={handleClick}
63+
narrow={nrw || narrow}
64+
link={link}
65+
exact={exact}
66+
tabClassName={individualTabClassName}
67+
className={tabItemClassName}
68+
toggleStyle={toggleStyle}
69+
tooltip={description}
70+
>
71+
{icon && <Icon icon={icon} className={style.icon} />}
72+
<Message content={title} />
73+
</Tab>
74+
),
75+
)}
76+
</ul>
77+
)
78+
}
7079

7180
Tabs.propTypes = {
7281
/** The name of the active tab. */
7382
active: PropTypes.string,
7483
className: PropTypes.string,
84+
disabled: PropTypes.bool,
7585
/** Flag specifying whether the tab should render a bottom divider. */
7686
divider: PropTypes.bool,
7787
individualTabClassName: PropTypes.string,
@@ -104,6 +114,7 @@ Tabs.defaultProps = {
104114
divider: false,
105115
narrow: false,
106116
toggleStyle: false,
117+
disabled: false,
107118
}
108119

109120
export default Tabs

pkg/webui/console/containers/applications-table/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ const ApplicationsTable = props => {
265265
const { tab, query } = filters
266266
const isDeletedTab = tab === DELETED_TAB
267267

268-
setTab(tab)
269-
270268
return getApplicationsList(
271269
{ ...filters, deleted: isDeletedTab },
272270
[
@@ -297,6 +295,7 @@ const ApplicationsTable = props => {
297295
tabs={isAdmin ? tabs : []}
298296
searchPlaceholderMessage={sharedMessages.searchApplications}
299297
{...rest}
298+
setTab={setTab}
300299
/>
301300
)
302301
}

pkg/webui/console/containers/gateways-table/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ const GatewaysTable = () => {
233233
const { tab, query } = filters
234234
const isDeletedTab = tab === DELETED_TAB
235235

236-
setTab(tab)
237-
238236
return getGatewaysList(
239237
{ ...filters, deleted: isDeletedTab },
240238
['name', 'description', 'frequency_plan_ids', 'gateway_server_address'],
@@ -258,6 +256,7 @@ const GatewaysTable = () => {
258256
searchPlaceholderMessage={sharedMessages.searchGateways}
259257
clickable={!isDeletedTab}
260258
tabs={isAdmin ? tabs : undefined}
259+
setTab={setTab}
261260
/>
262261
)
263262
}

pkg/webui/console/containers/oauth-clients-table/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ const ClientsTable = () => {
191191
const { tab, query } = filters
192192
const isDeletedTab = tab === DELETED_TAB
193193

194-
setTab(tab)
195194
return getClientsList({ ...filters, deleted: isDeletedTab }, ['name', 'description', 'state'], {
196195
isSearch: tab === ALL_TAB || isDeletedTab || query.length > 0,
197196
})
@@ -209,6 +208,7 @@ const ClientsTable = () => {
209208
searchable
210209
clickable={!isDeletedTab}
211210
tabs={isAdmin ? tabs : EMPTY_ARRAY}
211+
setTab={setTab}
212212
/>
213213
)
214214
}

pkg/webui/console/containers/organizations-table/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ const OrganizationsTable = () => {
202202
const { tab, query } = filters
203203
const isDeletedTab = tab === DELETED_TAB
204204

205-
setTab(tab)
206-
207205
return getOrganizationsList({ ...filters, deleted: isDeletedTab }, ['name', 'description'], {
208206
isSearch: tab === ALL_TAB || isDeletedTab || query.length > 0,
209207
withCollaboratorCount: true,
@@ -222,6 +220,7 @@ const OrganizationsTable = () => {
222220
searchable
223221
clickable={!isDeletedTab}
224222
tabs={isAdmin ? tabs : []}
223+
setTab={setTab}
225224
/>
226225
)
227226
}

pkg/webui/console/containers/users-table/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ const UsersTable = () => {
306306
const getItems = React.useCallback(params => {
307307
const { tab, query } = params
308308
const isDeletedTab = tab === DELETED_TAB
309-
setTab(tab)
310309

311310
if (tab === INVITATIONS_TAB) {
312311
return getUserInvitations(params, ['state'])
@@ -356,6 +355,7 @@ const UsersTable = () => {
356355
clickable={!isDeletedTab}
357356
tabs={mayInvite ? tabsWithInvitations : tabs}
358357
searchable={!isInvitationsTab}
358+
setTab={setTab}
359359
/>
360360
)
361361
}

pkg/webui/containers/fetch-table/index.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const FetchTable = props => {
8888
filtersClassName,
8989
smallCells,
9090
tableClassName,
91+
setTab,
9192
} = props
9293

9394
const globalPageSize = useSelector(selectPageSize)
@@ -96,7 +97,7 @@ const FetchTable = props => {
9697
const dispatch = useDispatch()
9798
const defaultTab = tabs.length > 0 ? tabs[0].name : undefined
9899
const [page, setPage] = useQueryState('page', 1, parseInt)
99-
const [tab, setTab] = useQueryState('tab', defaultTab)
100+
const [queryTab, setQueryTab] = useQueryState('tab', defaultTab)
100101
const [order, setOrder] = useQueryState('order', defaultOrder)
101102
const [query, setQuery] = useQueryState('query', '')
102103
const debouncedQuery = useDebounce(
@@ -113,7 +114,13 @@ const FetchTable = props => {
113114
const mayAdd = 'mayAdd' in base ? base.mayAdd : true
114115
const mayLink = 'mayLink' in base ? base.mayLink : true
115116

116-
const filters = { query: debouncedQuery, tab, order, page, limit: globalPageSize ?? pageSize }
117+
const filters = {
118+
query: debouncedQuery,
119+
queryTab,
120+
order,
121+
page,
122+
limit: globalPageSize ?? pageSize,
123+
}
117124
const [fetching, setFetching] = useState(true)
118125
const [error, setError] = useState(undefined)
119126
let orderDirection, orderBy
@@ -141,10 +148,10 @@ const FetchTable = props => {
141148
const fetchItems = async () => {
142149
setFetching(true)
143150
const f = { query: debouncedQuery || '', page, limit: globalPageSize ?? pageSize }
144-
if (tabs.find(t => t.name === tab)) {
145-
f.tab = tab
151+
if (tabs.find(t => t.name === queryTab)) {
152+
f.tab = queryTab
146153
} else {
147-
setTab(defaultTab)
154+
setQueryTab(defaultTab)
148155
f.tab = undefined
149156
}
150157

@@ -162,6 +169,7 @@ const FetchTable = props => {
162169
await dispatch(attachPromise(searchItemsAction(f)))
163170
} else {
164171
await dispatch(attachPromise(getItemsAction(f)))
172+
setTab(f.tab)
165173
}
166174
if (isMounted.current) {
167175
setFetching(false)
@@ -187,9 +195,10 @@ const FetchTable = props => {
187195
pageSize,
188196
searchItemsAction,
189197
setOrder,
190-
setTab,
191-
tab,
192198
tabs,
199+
queryTab,
200+
setQueryTab,
201+
setTab,
193202
])
194203

195204
const onPageChange = useCallback(
@@ -217,11 +226,11 @@ const FetchTable = props => {
217226

218227
const onTabChange = useCallback(
219228
tab => {
220-
setTab(tab)
229+
setQueryTab(tab)
221230
setPage(1)
222231
setQuery('')
223232
},
224-
[setPage, setQuery, setTab],
233+
[setPage, setQuery, setQueryTab],
225234
)
226235

227236
const rowHrefSelector = useCallback(
@@ -262,11 +271,12 @@ const FetchTable = props => {
262271
<div className={style.filtersLeft}>
263272
{tabs.length > 0 ? (
264273
<Tabs
265-
active={tab}
274+
active={queryTab}
266275
className={style.tabs}
267276
tabs={tabs}
268277
onTabChange={onTabChange}
269278
toggleStyle
279+
disabled={fetching}
270280
/>
271281
) : (
272282
tableTitle && (
@@ -286,6 +296,7 @@ const FetchTable = props => {
286296
className={style.searchBar}
287297
inputWidth="full"
288298
maxLength={searchQueryMaxLength}
299+
disabled={fetching}
289300
/>
290301
)}
291302
{(Boolean(actionItems) || mayAdd) && (
@@ -378,6 +389,7 @@ FetchTable.propTypes = {
378389
searchPlaceholderMessage: PropTypes.message,
379390
searchQueryMaxLength: PropTypes.number,
380391
searchable: PropTypes.bool,
392+
setTab: PropTypes.func,
381393
smallCells: PropTypes.bool,
382394
tableClassName: PropTypes.string,
383395
tableTitle: PropTypes.message,
@@ -416,6 +428,7 @@ FetchTable.defaultProps = {
416428
filtersClassName: undefined,
417429
smallCells: false,
418430
tableClassName: undefined,
431+
setTab: () => {},
419432
}
420433

421434
export default FetchTable

0 commit comments

Comments
 (0)