Skip to content

Commit 1cadad2

Browse files
committed
replace grapghql introspection with static list for prompt format options
1 parent a874715 commit 1cadad2

1 file changed

Lines changed: 24 additions & 68 deletions

File tree

  • app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/resources/components/EditResource.tsx

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { graphql } from '@/gql';
22
import {
3-
CreateFileResourceInput,
4-
SchemaUpdateInput,
5-
UpdateFileResourceInput,
3+
CreateFileResourceInput,
4+
SchemaUpdateInput,
5+
UpdateFileResourceInput,
66
} from '@/gql/generated/graphql';
77
import { useMutation, useQuery } from '@tanstack/react-query';
88
import { useParams } from 'next/navigation';
99
import { parseAsString, useQueryState } from 'nuqs';
1010
import {
11-
Button,
12-
Checkbox,
13-
Combobox,
14-
Divider,
15-
DropZone,
16-
Text,
17-
TextField,
18-
toast,
11+
Button,
12+
Checkbox,
13+
Combobox,
14+
Divider,
15+
DropZone,
16+
Text,
17+
TextField,
18+
toast,
1919
} from 'opub-ui';
2020
import React, { useEffect, useState } from 'react';
2121

@@ -26,9 +26,9 @@ import { useDatasetEditStatus } from '../../context';
2626
import { TListItem } from '../page-layout';
2727
import PreviewData from './PreviewData';
2828
import {
29-
createResourceFilesDoc,
30-
updateResourceDoc,
31-
updateSchema,
29+
createResourceFilesDoc,
30+
updateResourceDoc,
31+
updateSchema,
3232
} from './query';
3333
import ResourceHeader from './ResourceHeader';
3434
import { ResourceSchema } from './ResourceSchema';
@@ -39,18 +39,6 @@ interface EditProps {
3939
isPromptDataset?: boolean;
4040
}
4141

42-
// Type for GraphQL introspection query response
43-
interface IntrospectionEnumValue {
44-
name: string;
45-
description?: string;
46-
}
47-
48-
interface IntrospectionTypeResponse {
49-
__type: {
50-
enumValues: IntrospectionEnumValue[];
51-
} | null;
52-
}
53-
5442
const resourceDetails: any = graphql(`
5543
query resourceById($resourceId: UUID!) {
5644
resourceById(resourceId: $resourceId) {
@@ -104,18 +92,6 @@ const resourceDetails: any = graphql(`
10492
}
10593
`);
10694

107-
// Introspection query to get PromptFormat enum values from schema
108-
const promptFormatEnumQuery: any = graphql(`
109-
query PromptFormatEnumResource {
110-
__type(name: "PromptFormat") {
111-
enumValues {
112-
name
113-
description
114-
}
115-
}
116-
}
117-
`);
118-
11995
// Mutation to update prompt resource metadata
12096
const updatePromptResourceMutationDoc: any = graphql(`
12197
mutation UpdatePromptResource($updateInput: UpdatePromptResourceInput!) {
@@ -140,7 +116,6 @@ const updatePromptResourceMutationDoc: any = graphql(`
140116
}
141117
`);
142118

143-
// Prompt format templates for different prompt types (CSV format for multiple prompts)
144119
const PROMPT_FORMAT_TEMPLATES: Record<
145120
string,
146121
{ description: string; template: string }
@@ -197,6 +172,15 @@ const PROMPT_FORMAT_TEMPLATES: Record<
197172
},
198173
};
199174

175+
const PROMPT_FORMAT_OPTIONS = Object.keys(PROMPT_FORMAT_TEMPLATES).map(
176+
(key) => ({
177+
label: key
178+
.replace(/_/g, ' ')
179+
.replace(/\b\w/g, (c: string) => c.toUpperCase()),
180+
value: key,
181+
})
182+
);
183+
200184
export const EditResource = ({
201185
refetch,
202186
allResources,
@@ -350,22 +334,6 @@ export const EditResource = ({
350334
const [hasSystemPrompt, setHasSystemPrompt] = useState(false);
351335
const [hasExampleResponses, setHasExampleResponses] = useState(false);
352336

353-
// Fetch PromptFormat enum values from GraphQL schema
354-
const getPromptFormatEnum = useQuery<IntrospectionTypeResponse>(
355-
['prompt_format_enum_resource'],
356-
() => GraphQL(promptFormatEnumQuery, {}, []),
357-
{ staleTime: Infinity, enabled: isPromptDataset }
358-
);
359-
360-
// Debug: Log enum data when it changes
361-
React.useEffect(() => {
362-
if (getPromptFormatEnum.data) {
363-
console.log(
364-
'PromptFormat enum raw data:',
365-
JSON.stringify(getPromptFormatEnum.data, null, 2)
366-
);
367-
}
368-
}, [getPromptFormatEnum.data]);
369337

370338
// Mutation for updating prompt resource metadata
371339
const updatePromptResourceMutation = useMutation(
@@ -617,19 +585,7 @@ export const EditResource = ({
617585
name="promptFormat"
618586
label="Prompt Format"
619587
displaySelected
620-
list={
621-
getPromptFormatEnum.data?.__type?.enumValues?.map(
622-
(enumValue: {
623-
name: string;
624-
description?: string;
625-
}) => ({
626-
label: enumValue.name
627-
.replace(/_/g, ' ')
628-
.replace(/\b\w/g, (c: string) => c.toUpperCase()),
629-
value: enumValue.name,
630-
})
631-
) || []
632-
}
588+
list={PROMPT_FORMAT_OPTIONS}
633589
selectedValue={
634590
promptFormat
635591
? promptFormat

0 commit comments

Comments
 (0)