Conversation
📝 WalkthroughWalkthroughThis PR introduces support for API token expiration configuration across the client library and UI layer. It adds a new configuration type with a corresponding parser function and a React hook to consume this configuration in the UI. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/javascript/bh-shared-ui/src/hooks/useConfiguration.ts`:
- Around line 57-65: The hook useAPITokenExpirationConfiguration is collapsing
the "still loading" state into the default {enabled: false, days: '90'}, which
makes loading indistinguishable from an actual server value; change it to
preserve loading explicitly (or return undefined for fields while loading) by
checking the query status from useGetConfiguration() before applying defaults
from parseAPITokenExpirationConfiguration(data) — for example, return a
structure that includes a loading flag (or leaves days undefined) when the query
is not settled, and only apply the fallback defaults ('90' and false) when the
configuration is loaded or known-missing; update callers to handle the explicit
loading/undefined state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 77f2cb29-4943-4d19-ba62-ce86fbd26c67
📒 Files selected for processing (2)
packages/javascript/bh-shared-ui/src/hooks/useConfiguration.tspackages/javascript/js-client-library/src/utils/config.ts
| export const useAPITokenExpirationConfiguration = () => { | ||
| const { data } = useGetConfiguration(); | ||
| const apiTokenExpirationConfig = parseAPITokenExpirationConfiguration(data)?.value; | ||
|
|
||
| return { | ||
| enabled: apiTokenExpirationConfig?.enabled ?? false, | ||
| days: apiTokenExpirationConfig?.days ?? '90', | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Don't collapse loading state into { enabled: false, days: '90' }.
This makes “query still loading” look identical to a real config value. Any form that snapshots this hook into local state on first render can save 90 over an existing server value before the fetch resolves. Keep the fallback for the “loaded but missing” case only, or surface loading explicitly.
💡 Suggested fix
export const useAPITokenExpirationConfiguration = () => {
- const { data } = useGetConfiguration();
+ const { data, isLoading } = useGetConfiguration();
const apiTokenExpirationConfig = parseAPITokenExpirationConfiguration(data)?.value;
+
+ if (isLoading) return undefined;
return {
enabled: apiTokenExpirationConfig?.enabled ?? false,
days: apiTokenExpirationConfig?.days ?? '90',
};
};🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/javascript/bh-shared-ui/src/hooks/useConfiguration.ts` around lines
57 - 65, The hook useAPITokenExpirationConfiguration is collapsing the "still
loading" state into the default {enabled: false, days: '90'}, which makes
loading indistinguishable from an actual server value; change it to preserve
loading explicitly (or return undefined for fields while loading) by checking
the query status from useGetConfiguration() before applying defaults from
parseAPITokenExpirationConfiguration(data) — for example, return a structure
that includes a loading flag (or leaves days undefined) when the query is not
settled, and only apply the fallback defaults ('90' and false) when the
configuration is loaded or known-missing; update callers to handle the explicit
loading/undefined state.
Description
This changeset adds an API key expiration feature where admin users can set a specific amount of days for an API token to expire. An admin can set a number of days from 1 - 365 for the token to expire.
Motivation and Context
Resolves BED-7450
How Has This Been Tested?
Unit tests were added as well as manual testing
Screenshots (optional):
Types of changes
Checklist:
Summary by CodeRabbit