Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -297,11 +287,6 @@ export default function AIModelDetailsPage() {
)
);

const getPromptDomainEnumValues =
useQuery([`prompt_domain_enum_values_query`], () =>
GraphQL(promptDomainEnumValuesQueryDoc, {})
);

const AIModelData = useQuery(
[
`fetch_AIModelDetails`,
Expand Down Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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!) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams } from 'next/navigation';
import { graphql } from '@/gql';
import {
CreateFileResourceInput,
PromptFormat,
SchemaUpdateInput,
UpdateFileResourceInput,
UpdatePromptResourceInput,
Expand All @@ -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';
Expand Down Expand Up @@ -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!) {
Expand Down Expand Up @@ -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 }) =>
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions lib/enumValues.ts
Original file line number Diff line number Diff line change
@@ -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, string>): string[] =>
Object.values(schemaEnum);
Loading