From 262140ab476974c2d90d0c219cbff228d01a5994 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 16 Sep 2026 10:19:36 +0530 Subject: [PATCH 1/3] fix: build prompt metadata dropdowns from codegen enums The four __type introspection queries fired together on form load; when the backend was slow the browser aborted them and staleTime: Infinity cached the failure, leaving Task Type / Domain / Target Languages / Target Model Types empty until a reload. Enum values are fixed at build time, so read them from the generated enums instead. --- .../[id]/edit/components/EditMetadata.tsx | 134 ++++-------------- lib/enumValues.ts | 8 ++ 2 files changed, 37 insertions(+), 105 deletions(-) create mode 100644 lib/enumValues.ts diff --git a/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditMetadata.tsx b/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditMetadata.tsx index e258be5a..097f05b6 100644 --- a/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditMetadata.tsx +++ b/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditMetadata.tsx @@ -5,6 +5,10 @@ import { useParams } from 'next/navigation'; import { graphql } from '@/gql'; import { MetadataModels, + PromptDomain, + PromptTaskType, + TargetLanguage, + TargetModelType, UpdateMetadataInput, UpdatePromptMetadataInput, } from '@/gql/generated/graphql'; @@ -21,6 +25,7 @@ import { } from 'opub-ui'; import { GraphQL } from '@/lib/api'; +import { enumValues } from '@/lib/enumValues'; import { RichTextEditor } from '@/components/RichTextEditor'; import DatasetLoading from '../../../components/loading-dataset'; import { useDatasetEditStatus } from '../context'; @@ -113,54 +118,6 @@ const metadataQueryDoc = graphql(` } `); -// Introspection query to get PromptTaskType enum values from schema -const promptTaskTypeEnumQuery = graphql(` - query PromptTaskTypeEnum { - __type(name: "PromptTaskType") { - enumValues { - name - description - } - } - } -`); - -// Introspection query to get PromptDomain enum values from schema -const promptDomainEnumQuery = graphql(` - query PromptDomainEnum { - __type(name: "PromptDomain") { - enumValues { - name - description - } - } - } -`); - -// Introspection query to get TargetLanguage enum values from schema -const targetLanguageEnumQuery = graphql(` - query TargetLanguageEnum { - __type(name: "TargetLanguage") { - enumValues { - name - description - } - } - } -`); - -// Introspection query to get TargetModelType enum values from schema -const targetModelTypeEnumQuery = graphql(` - query TargetModelTypeEnum { - __type(name: "TargetModelType") { - enumValues { - name - description - } - } - } -`); - // Mutation to update prompt-specific metadata const updatePromptMetadataMutationDoc = graphql(` mutation UpdatePromptMetadata($updateInput: UpdatePromptMetadataInput!) { @@ -362,31 +319,6 @@ export function EditMetadata({ id }: { id: string }) { ) ); - // Fetch PromptTaskType enum values from GraphQL schema - const getPromptTaskTypeEnum = useQuery( - ['prompt_task_type_enum'], - () => GraphQL(promptTaskTypeEnumQuery), - { staleTime: Infinity } - ); - - const getPromptDomainEnum = useQuery( - ['prompt_domain_enum'], - () => GraphQL(promptDomainEnumQuery), - { staleTime: Infinity } - ); - - const getTargetLanguageEnum = useQuery( - ['target_language_enum'], - () => GraphQL(targetLanguageEnumQuery), - { staleTime: Infinity } - ); - - const getTargetModelTypeEnum = useQuery( - ['target_model_type_enum'], - () => GraphQL(targetModelTypeEnumQuery), - { staleTime: Infinity } - ); - const [isTagsListUpdated, setIsTagsListUpdated] = useState(false); // State for prompt metadata fields @@ -975,14 +907,12 @@ export function EditMetadata({ id }: { id: string }) { label="Task Type" displaySelected list={ - getPromptTaskTypeEnum.data?.__type?.enumValues?.map( - (enumValue) => ({ - label: enumValue.name - .replace(/_/g, ' ') - .replace(/\b\w/g, (c: string) => c.toUpperCase()), - value: enumValue.name, - }) - ) || [] + enumValues(PromptTaskType).map((name) => ({ + label: name + .replace(/_/g, ' ') + .replace(/\b\w/g, (c: string) => c.toUpperCase()), + value: name, + })) } selectedValue={ promptMetadataState.taskType @@ -1010,14 +940,12 @@ export function EditMetadata({ id }: { id: string }) { label="Domain" displaySelected list={ - getPromptDomainEnum.data?.__type?.enumValues?.map( - (enumValue) => ({ - label: enumValue.name - .replace(/_/g, ' ') - .replace(/\b\w/g, (c: string) => c.toUpperCase()), - value: enumValue.name, - }) - ) || [] + enumValues(PromptDomain).map((name) => ({ + label: name + .replace(/_/g, ' ') + .replace(/\b\w/g, (c: string) => c.toUpperCase()), + value: name, + })) } selectedValue={ promptMetadataState.domain @@ -1046,14 +974,12 @@ export function EditMetadata({ id }: { id: string }) { displaySelected creatable list={ - getTargetLanguageEnum.data?.__type?.enumValues?.map( - (enumValue) => ({ - label: enumValue.name - .replace(/_/g, ' ') - .replace(/\b\w/g, (c: string) => c.toUpperCase()), - value: enumValue.name, - }) - ) || [] + enumValues(TargetLanguage).map((name) => ({ + label: name + .replace(/_/g, ' ') + .replace(/\b\w/g, (c: string) => c.toUpperCase()), + value: name, + })) } selectedValue={ promptMetadataState.targetLanguages?.map( @@ -1078,14 +1004,12 @@ export function EditMetadata({ id }: { id: string }) { displaySelected creatable list={ - getTargetModelTypeEnum.data?.__type?.enumValues?.map( - (enumValue) => ({ - label: enumValue.name - .replace(/_/g, ' ') - .replace(/\b\w/g, (c: string) => c.toUpperCase()), - value: enumValue.name, - }) - ) || [] + enumValues(TargetModelType).map((name) => ({ + label: name + .replace(/_/g, ' ') + .replace(/\b\w/g, (c: string) => c.toUpperCase()), + value: name, + })) } selectedValue={ promptMetadataState.targetModelTypes?.map( diff --git a/lib/enumValues.ts b/lib/enumValues.ts new file mode 100644 index 00000000..c12fd03c --- /dev/null +++ b/lib/enumValues.ts @@ -0,0 +1,8 @@ +/** + * Schema enums come from codegen, not from a runtime `__type` introspection + * query: the values are fixed at build time, and four introspection queries + * fired together on form load could be aborted by the browser, leaving the + * dropdowns permanently empty because the failure was cached. + */ +export const enumValues = (schemaEnum: Record): string[] => + Object.values(schemaEnum); From aae1156693a2047f9fb338fcdcf9f31c2ea5af0f Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 16 Sep 2026 10:19:42 +0530 Subject: [PATCH 2/3] fix: build the Prompt Format dropdown from the codegen enum Same abort-and-cache failure as the metadata form; also drops a debug effect that logged the whole enum payload to the console. --- .../resources/components/EditResource.tsx | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components/EditResource.tsx b/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components/EditResource.tsx index 28a15474..2ba88ffc 100644 --- a/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components/EditResource.tsx +++ b/app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components/EditResource.tsx @@ -3,6 +3,7 @@ import { useParams } from 'next/navigation'; import { graphql } from '@/gql'; import { CreateFileResourceInput, + PromptFormat, SchemaUpdateInput, UpdateFileResourceInput, UpdatePromptResourceInput, @@ -21,6 +22,7 @@ import { } from 'opub-ui'; import { GraphQL } from '@/lib/api'; +import { enumValues } from '@/lib/enumValues'; import { Loading } from '@/components/loading'; import PdfPreview from '../../../../../../../../(user)/components/PdfPreview'; import { useDatasetEditStatus } from '../../context'; @@ -93,18 +95,6 @@ const resourceDetails = graphql(` } `); -// Introspection query to get PromptFormat enum values from schema -const promptFormatEnumQuery = graphql(` - query PromptFormatEnumResource { - __type(name: "PromptFormat") { - enumValues { - name - description - } - } - } -`); - // Mutation to update prompt resource metadata const updatePromptResourceMutationDoc = graphql(` mutation UpdatePromptResource($updateInput: UpdatePromptResourceInput!) { @@ -407,23 +397,6 @@ export const EditResource = ({ } } - // Fetch PromptFormat enum values from GraphQL schema - const getPromptFormatEnum = useQuery( - ['prompt_format_enum_resource'], - () => GraphQL(promptFormatEnumQuery), - { staleTime: Infinity, enabled: isPromptDataset } - ); - - // Debug: Log enum data when it changes - React.useEffect(() => { - if (getPromptFormatEnum.data) { - console.log( - 'PromptFormat enum raw data:', - JSON.stringify(getPromptFormatEnum.data, null, 2) - ); - } - }, [getPromptFormatEnum.data]); - // Mutation for updating prompt resource metadata const updatePromptResourceMutation = useMutation( (data: { updateInput: UpdatePromptResourceInput }) => @@ -636,14 +609,12 @@ export const EditResource = ({ label="Prompt Format" displaySelected list={ - getPromptFormatEnum.data?.__type?.enumValues?.map( - (enumValue) => ({ - label: enumValue.name - .replace(/_/g, ' ') - .replace(/\b\w/g, (c: string) => c.toUpperCase()), - value: enumValue.name, - }) - ) || [] + enumValues(PromptFormat).map((name) => ({ + label: name + .replace(/_/g, ' ') + .replace(/\b\w/g, (c: string) => c.toUpperCase()), + value: name, + })) } selectedValue={promptFormat ? promptFormat : ''} onChange={(value) => { From fc0e40ea18db304b1ea7567d8542460f7826eb92 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 16 Sep 2026 10:19:42 +0530 Subject: [PATCH 3/3] fix: build the AI model domain dropdown from the codegen enum --- .../aimodels/edit/[id]/details/page.tsx | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/details/page.tsx b/app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/details/page.tsx index 579dc0fa..f4fa25f0 100644 --- a/app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/details/page.tsx +++ b/app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/details/page.tsx @@ -18,6 +18,7 @@ import { } from 'opub-ui'; import { GraphQL } from '@/lib/api'; +import { enumValues } from '@/lib/enumValues'; import RichTextEditor from '@/components/RichTextEditor/RichTextEditor'; import { useEditStatus } from '../../context'; @@ -170,17 +171,6 @@ const geographiesListQueryDoc = graphql(` } `); -const promptDomainEnumValuesQueryDoc = graphql(` - query PromptDomainEnum { - __type(name: "PromptDomain") { - enumValues { - name - description - } - } - } -`); - const FetchAIModelDetails = graphql(` query AIModelDetails($filters: AIModelFilter) { aiModels(filters: $filters) { @@ -297,11 +287,6 @@ export default function AIModelDetailsPage() { ) ); - const getPromptDomainEnumValues = - useQuery([`prompt_domain_enum_values_query`], () => - GraphQL(promptDomainEnumValuesQueryDoc, {}) - ); - const AIModelData = useQuery( [ `fetch_AIModelDetails`, @@ -477,16 +462,14 @@ export default function AIModelDetailsPage() { const domainOptions = [ { label: 'Click to select from dropdown', value: '' }, - ...( - getPromptDomainEnumValues.data?.__type?.enumValues?.map((item: { name: string }) => ({ - label: item.name - .toLowerCase() - .split('_') - .map((word: string) => word.charAt(0).toUpperCase() + word.slice(1)) - .join(' '), - value: item.name, - })) || [] - ), + ...enumValues(PromptDomain).map((name) => ({ + label: name + .toLowerCase() + .split('_') + .map((word: string) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '), + value: name, + })), ]; const modelTypeOptions = [