Skip to content

Commit b8b01ef

Browse files
authored
Chore/custom content logs default query (supabase#38087)
* Init custom content hook * Implement useCustomContent hook similarly to useIsFeatureEnabled, and implement extension of organization documents * Attempt to type things nicely * Add support for custom content example projects * Add support for custom content logs explorer default query * nit * Fix types
1 parent 0beba89 commit b8b01ef

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

apps/studio/hooks/custom-content/CustomContent.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export type CustomContentTypes = {
1111
iconUrl: string
1212
url: string
1313
}[]
14+
15+
logsDefaultQuery: string
1416
}

apps/studio/hooks/custom-content/custom-content.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33

44
"organization:legal_documents": null,
55

6-
"project_homepage:example_projects": null
6+
"project_homepage:example_projects": null,
7+
8+
"logs:default_query": null
79
}

apps/studio/hooks/custom-content/custom-content.sample.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@
3535
"iconUrl": "https://supabase.com/dashboard/img/supabase-logo.svg",
3636
"url": "https://supabase.com"
3737
}
38-
]
38+
],
39+
40+
"logs:default_query": "This is a sample query"
3941
}

apps/studio/hooks/custom-content/custom-content.schema.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@
3737
"url": { "type": "string" }
3838
}
3939
}
40+
},
41+
42+
"logs:default_query": {
43+
"type": ["string", "null"],
44+
"description": "Renders a default query when landing on the logs explorer"
4045
}
4146
},
42-
"required": ["organization:legal_documents", "project_homepage:example_projects"],
47+
"required": [
48+
"organization:legal_documents",
49+
"project_homepage:example_projects",
50+
"logs:default_query"
51+
],
4352
"additionalProperties": false
4453
}

apps/studio/pages/project/[ref]/logs/explorer/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
} from 'data/content/content-upsert-mutation'
3737
import useLogsQuery from 'hooks/analytics/useLogsQuery'
3838
import { useLogsUrlState } from 'hooks/analytics/useLogsUrlState'
39+
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
3940
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
4041
import { useUpgradePrompt } from 'hooks/misc/useUpgradePrompt'
4142
import { uuidv4 } from 'lib/helpers'
@@ -57,8 +58,6 @@ const LOCAL_PLACEHOLDER_QUERY =
5758
const PLATFORM_PLACEHOLDER_QUERY =
5859
'select\n cast(timestamp as datetime) as timestamp,\n event_message, metadata \nfrom edge_logs \nlimit 5'
5960

60-
const PLACEHOLDER_QUERY = IS_PLATFORM ? PLATFORM_PLACEHOLDER_QUERY : LOCAL_PLACEHOLDER_QUERY
61-
6261
export const LogsExplorerPage: NextPageWithLayout = () => {
6362
useEditorHints()
6463
const monaco = useMonaco()
@@ -72,6 +71,11 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
7271
const [editorId] = useState<string>(uuidv4())
7372
const { timestampStart, timestampEnd, setTimeRange } = useLogsUrlState()
7473

74+
const { logsDefaultQuery } = useCustomContent(['logs:default_query'])
75+
const PLACEHOLDER_QUERY = IS_PLATFORM
76+
? logsDefaultQuery ?? PLATFORM_PLACEHOLDER_QUERY
77+
: LOCAL_PLACEHOLDER_QUERY
78+
7579
const [editorValue, setEditorValue] = useState<string>(PLACEHOLDER_QUERY)
7680
const [saveModalOpen, setSaveModalOpen] = useState<boolean>(false)
7781
const [warnings, setWarnings] = useState<LogsWarning[]>([])

0 commit comments

Comments
 (0)