Skip to content

Commit

Permalink
fix: create DEFAULT_PROJECT_API_SERVICE_ID constant
Browse files Browse the repository at this point in the history
  • Loading branch information
phamhieu committed Apr 19, 2022
1 parent 7b4e1d2 commit b1916be
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Input } from '@supabase/ui'
import { JwtSecretUpdateStatus } from '@supabase/shared-types/out/events'
import { useJwtSecretUpdateStatus, useProjectSettings } from 'hooks'
import { SettingsLoadingState } from './SettingsLoadingState'
import { DEFAULT_API_SERVICE_ID } from './index.constants'
import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants'
import Panel from 'components/to-be-cleaned/Panel'

const DisplayApiSettings = () => {
Expand All @@ -24,7 +24,7 @@ const DisplayApiSettings = () => {
const isNotUpdatingJwtSecret =
jwtSecretUpdateStatus === undefined || jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updated
// Get the API service
const apiService = (services ?? []).find((x: any) => x.app.id == DEFAULT_API_SERVICE_ID)
const apiService = (services ?? []).find((x: any) => x.app.id == DEFAULT_PROJECT_API_SERVICE_ID)
const apiKeys = apiService?.service_api_keys ?? []
// api keys should not be empty. However it can be populated with a delay on project creation
const isApikeysEmpty = apiKeys.length === 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Input } from '@supabase/ui'
import { JwtSecretUpdateStatus } from '@supabase/shared-types/out/events'
import { useJwtSecretUpdateStatus, useProjectSettings } from 'hooks'
import { SettingsLoadingState } from './SettingsLoadingState'
import { DEFAULT_API_SERVICE_ID } from './index.constants'
import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants'
import Panel from 'components/to-be-cleaned/Panel'

const DisplayConfigSettings = () => {
Expand All @@ -26,7 +26,7 @@ const DisplayConfigSettings = () => {
jwtSecretUpdateStatus === undefined || jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updated
// Get the API service
const jwtSecret = project?.jwt_secret ?? ''
const apiService = (services ?? []).find((x: any) => x.app.id == DEFAULT_API_SERVICE_ID)
const apiService = (services ?? []).find((x: any) => x.app.id == DEFAULT_PROJECT_API_SERVICE_ID)
const apiConfig = apiService?.app_config ?? {}

return (
Expand Down
1 change: 0 additions & 1 deletion studio/components/ui/ProjectSettings/index.constants.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions studio/hooks/queries/useProjectSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { API_URL, DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants'
import useSWR from 'swr'

export function useProjectSettings(ref?: string) {
Expand All @@ -10,7 +10,9 @@ export function useProjectSettings(ref?: string) {
* check for data.services.service_api_keys, return a valid refresh interval if it's empty
*/
refreshInterval: function (data: any) {
const apiService = (data?.services ?? []).find((x: any) => x.app.id == DEFAULT_API_SERVICE_ID)
const apiService = (data?.services ?? []).find(
(x: any) => x.app.id == DEFAULT_PROJECT_API_SERVICE_ID
)
const apiKeys = apiService?.service_api_keys ?? []
const interval = apiKeys.length === 0 ? 2000 : 0
return interval
Expand All @@ -26,5 +28,3 @@ export function useProjectSettings(ref?: string) {
isError: !!anyError,
}
}

const DEFAULT_API_SERVICE_ID = 1
2 changes: 2 additions & 0 deletions studio/lib/constants/infrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ export const PASSWORD_STRENGTH_PERCENTAGE = {
export const DEFAULT_FREE_PROJECTS_LIMIT = 2

export const STORAGE_FILE_SIZE_LIMIT_MAX_BYTES = 5 * 1024 * 1024 * 1024 // 5 GB

export const DEFAULT_PROJECT_API_SERVICE_ID = 1

0 comments on commit b1916be

Please sign in to comment.