Skip to content

Commit

Permalink
refactor: move const vaiables to const-vars.ts (#2728)
Browse files Browse the repository at this point in the history
**Changes:**

This PR refactors the handling of constant variables related to unlimited max containers per session and unlimited max concurrent sessions. The main changes include:

1. Created a new file `const-vars.ts` to centralize these constants.
2. Moved `UNLIMITED_MAX_CONTAINERS_PER_SESSIONS` and `UNLIMITED_MAX_CONCURRENT_SESSIONS` from `KeypairResourcePolicySettingModal.tsx` to `const-vars.ts`.
3. Updated import statements in affected files to use the new centralized constants.

**Rationale:**

Centralizing these constants improves code maintainability and reduces duplication. It allows for easier updates if these values need to change in the future and ensures consistency across the application.

**Impact:**

This change does not affect functionality but improves code organization and maintainability. Developers working on the project will now have a single source of truth for these constants.
  • Loading branch information
yomybaby committed Sep 30, 2024
1 parent 3e1a1f6 commit 6002fea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions react/src/components/KeypairResourcePolicyList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { localeCompare, numberSorterWithInfinityValue } from '../helper';
import {
UNLIMITED_MAX_CONCURRENT_SESSIONS,
UNLIMITED_MAX_CONTAINERS_PER_SESSIONS,
} from '../helper/const-vars';
import { exportCSVWithFormattingRules } from '../helper/csv-util';
import { useSuspendedBackendaiClient, useUpdatableState } from '../hooks';
import Flex from './Flex';
import KeypairResourcePolicySettingModal, {
UNLIMITED_MAX_CONCURRENT_SESSIONS,
UNLIMITED_MAX_CONTAINERS_PER_SESSIONS,
} from './KeypairResourcePolicySettingModal';
import KeypairResourcePolicySettingModal from './KeypairResourcePolicySettingModal';
import ResourceNumber from './ResourceNumber';
import TableColumnsSettingModal from './TableColumnsSettingModal';
import { KeypairResourcePolicyListMutation } from './__generated__/KeypairResourcePolicyListMutation.graphql';
Expand Down
7 changes: 4 additions & 3 deletions react/src/components/KeypairResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { iSizeToSize } from '../helper';
import {
UNLIMITED_MAX_CONCURRENT_SESSIONS,
UNLIMITED_MAX_CONTAINERS_PER_SESSIONS,
} from '../helper/const-vars';
import { useSuspendedBackendaiClient } from '../hooks';
import { useResourceSlotsDetails } from '../hooks/backendai';
import AllowedHostNamesSelect from './AllowedHostNamesSelect';
Expand Down Expand Up @@ -34,9 +38,6 @@ import {
useMutation,
} from 'react-relay';

export const UNLIMITED_MAX_CONTAINERS_PER_SESSIONS = 1000000;
export const UNLIMITED_MAX_CONCURRENT_SESSIONS = 1000000;

interface KeypairResourcePolicySettingModalProps extends BAIModalProps {
existingPolicyNames?: string[];
keypairResourcePolicyFrgmt?: KeypairResourcePolicySettingModalFragment$key | null;
Expand Down
2 changes: 2 additions & 0 deletions react/src/helper/const-vars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const UNLIMITED_MAX_CONTAINERS_PER_SESSIONS = 1000000;
export const UNLIMITED_MAX_CONCURRENT_SESSIONS = 1000000;
2 changes: 1 addition & 1 deletion react/src/hooks/hooksUsingRelay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSuspendedBackendaiClient, useUpdatableState } from '.';
import { UNLIMITED_MAX_CONCURRENT_SESSIONS } from '../helper/const-vars';
import { hooksUsingRelay_KeyPairQuery } from './__generated__/hooksUsingRelay_KeyPairQuery.graphql';
import { hooksUsingRelay_KeyPairResourcePolicyQuery } from './__generated__/hooksUsingRelay_KeyPairResourcePolicyQuery.graphql';
import graphql from 'babel-plugin-relay/macro';
Expand Down Expand Up @@ -51,7 +52,6 @@ export const useCurrentKeyPairResourcePolicyLazyLoadQuery = (
const [fetchKey, updateFetchKey] = useUpdatableState('first');
const baiClient = useSuspendedBackendaiClient();
const [keypair] = useKeyPairLazyLoadQuery(baiClient?._config.accessKey);
const UNLIMITED_MAX_CONCURRENT_SESSIONS = 1000000;

const { keypair_resource_policy } =
useLazyLoadQuery<hooksUsingRelay_KeyPairResourcePolicyQuery>(
Expand Down

0 comments on commit 6002fea

Please sign in to comment.