From 68ee9743fec2c7f5a496ce2fa480652df220d5a6 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Sun, 9 Feb 2025 01:31:01 +0530 Subject: [PATCH] (feat:upload) advanced fields --- frontend/src/upload/Upload.tsx | 221 +++++++++++++++----------- frontend/src/upload/types/ingestor.ts | 3 +- 2 files changed, 126 insertions(+), 98 deletions(-) diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index e7635f3e..bff31b10 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -44,106 +44,121 @@ function Upload({ const [remoteName, setRemoteName] = useState(''); const [files, setfiles] = useState(receivedFile); const [activeTab, setActiveTab] = useState(renderTab); + const [showAdvancedOptions, setShowAdvancedOptions] = useState(false); const renderFormFields = () => { const schema = IngestorFormSchemas[ingestor.type]; - return schema.map((field: FormField) => { - const isRequired = field.required ?? false; - switch (field.type) { - case 'string': - return ( - , - ) => - handleIngestorChange( - field.name as keyof IngestorConfig['config'], - e.target.value, - ) - } - borderVariant="thin" - label={field.label} - required={field.required} - colorVariant="gray" - /> - ); - case 'number': - return ( - , - ) => - handleIngestorChange( - field.name as keyof IngestorConfig['config'], - Number(e.target.value), - ) - } - borderVariant="thin" - label={field.label} - required={field.required} - colorVariant="gray" - /> - ); - case 'enum': - return ( - { - const value = - typeof selected === 'string' ? selected : selected.value; - handleIngestorChange( - field.name as keyof IngestorConfig['config'], - value, - ); - }} - size="w-full" - rounded="3xl" - placeholder={field.label} - border="border" - borderColor="gray-5000" - /> - ); - case 'boolean': - return ( - { - handleIngestorChange( - field.name as keyof IngestorConfig['config'], - checked, - ); - }} - className="mt-2" - /> - ); - default: - return null; - } - }); + if (!schema) return null; + + const generalFields = schema.filter((field) => !field.advanced); + const advancedFields = schema.filter((field) => field.advanced); + + return ( + <> + {generalFields.map((field: FormField) => renderField(field))} + + {advancedFields.length > 0 && showAdvancedOptions && ( + <> +
+ {advancedFields.map((field: FormField) => renderField(field))} + + )} + + ); + }; + + const renderField = (field: FormField) => { + const isRequired = field.required ?? false; + switch (field.type) { + case 'string': + return ( + + handleIngestorChange( + field.name as keyof IngestorConfig['config'], + e.target.value, + ) + } + borderVariant="thin" + label={field.label} + required={isRequired} + colorVariant="gray" + /> + ); + case 'number': + return ( + + handleIngestorChange( + field.name as keyof IngestorConfig['config'], + Number(e.target.value), + ) + } + borderVariant="thin" + label={field.label} + required={isRequired} + colorVariant="gray" + /> + ); + case 'enum': + return ( + + opt.value === + ingestor.config[field.name as keyof typeof ingestor.config], + ) || null + } + onSelect={(selected: { label: string; value: string }) => { + handleIngestorChange( + field.name as keyof IngestorConfig['config'], + selected.value, + ); + }} + size="w-full" + rounded="3xl" + placeholder={field.label} + border="border" + borderColor="gray-5000" + /> + ); + case 'boolean': + return ( + { + handleIngestorChange( + field.name as keyof IngestorConfig['config'], + checked, + ); + }} + className="mt-2" + /> + ); + default: + return null; + } }; // New unified ingestor state @@ -645,6 +660,18 @@ function Upload({ label="Name" /> {renderFormFields()} + {IngestorFormSchemas[ingestor.type].some( + (field) => field.advanced, + ) && ( + + )} )}
diff --git a/frontend/src/upload/types/ingestor.ts b/frontend/src/upload/types/ingestor.ts index 155e1fb9..cd709847 100644 --- a/frontend/src/upload/types/ingestor.ts +++ b/frontend/src/upload/types/ingestor.ts @@ -1,5 +1,5 @@ export interface BaseIngestorConfig { - [key: string]: string | number | boolean; + [key: string]: string | number | boolean | undefined; } export interface RedditIngestorConfig extends BaseIngestorConfig { @@ -48,6 +48,7 @@ export interface FormField { label: string; type: FieldType; required?: boolean; + advanced?: boolean; options?: { label: string; value: string }[]; }