diff --git a/src/app/api/native/git/branches/route.ts b/src/app/api/native/git/branches/route.ts index d79fa18d..126fe931 100644 --- a/src/app/api/native/git/branches/route.ts +++ b/src/app/api/native/git/branches/route.ts @@ -6,6 +6,8 @@ import path from 'path'; // Get the repository path from the environment variable const LOCAL_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_LOCAL_TAXONOMY_ROOT_DIR || `${process.env.HOME}/.instructlab-ui`; +const REMOTE_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_TAXONOMY_REPO_DIR || ''; +const REMOTE_TAXONOMY_REPO_CONTAINER_MOUNT_DIR = process.env.NEXT_PUBLIC_TAXONOMY_REPO_CONTAINER_MOUNT_DIR || '/tmp/.instructlab-ui/taxonomy'; interface Diffs { file: string; @@ -47,8 +49,8 @@ export async function GET() { // Handle POST requests for merge or branch comparison export async function POST(req: NextRequest) { const LOCAL_TAXONOMY_DIR = path.join(LOCAL_TAXONOMY_ROOT_DIR, '/taxonomy'); - const { branchName, action, remoteTaxonomyRepoDir } = await req.json(); - console.log('Received POST request:', { branchName, action, remoteTaxonomyRepoDir }); + const { branchName, action } = await req.json(); + console.log('Received POST request:', { branchName, action }); if (action === 'delete') { return handleDelete(branchName, LOCAL_TAXONOMY_DIR); @@ -59,6 +61,19 @@ export async function POST(req: NextRequest) { } if (action === 'publish') { + let remoteTaxonomyRepoDir: string = ''; + // Check if directory pointed by remoteTaxonomyRepoDir exists and not empty + if (fs.existsSync(REMOTE_TAXONOMY_REPO_CONTAINER_MOUNT_DIR) && fs.readdirSync(remoteTaxonomyRepoDir).length !== 0) { + remoteTaxonomyRepoDir = REMOTE_TAXONOMY_REPO_CONTAINER_MOUNT_DIR; + } else { + if (fs.existsSync(REMOTE_TAXONOMY_ROOT_DIR) && fs.readdirSync(REMOTE_TAXONOMY_ROOT_DIR).length !== 0) { + remoteTaxonomyRepoDir = REMOTE_TAXONOMY_ROOT_DIR; + } + } + if (remoteTaxonomyRepoDir === '') { + return NextResponse.json({ error: 'Remote taxonomy repository path does not exist.' }, { status: 400 }); + } + return handlePublish(branchName, LOCAL_TAXONOMY_DIR, remoteTaxonomyRepoDir); } return NextResponse.json({ error: 'Invalid action specified' }, { status: 400 }); diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 740427f1..3ffc88a8 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -21,7 +21,7 @@ import { PageSidebar } from '@patternfly/react-core/dist/dynamic/components/Page import { PageSidebarBody } from '@patternfly/react-core/dist/dynamic/components/Page'; import { SkipToContent } from '@patternfly/react-core/dist/dynamic/components/SkipToContent'; import { Spinner } from '@patternfly/react-core/dist/dynamic/components/Spinner'; -import { Bullseye } from '@patternfly/react-core'; +import { Bullseye } from '@patternfly/react-core/dist/dynamic/layouts/Bullseye'; import UserMenu from './UserMenu/UserMenu'; import { useSession } from 'next-auth/react'; // import { useTheme } from '../context/ThemeContext'; diff --git a/src/components/Contribute/Knowledge/DownloadAttribution/DownloadAttribution.tsx b/src/components/Contribute/Knowledge/DownloadAttribution/DownloadAttribution.tsx index 53b4da89..d61394fe 100644 --- a/src/components/Contribute/Knowledge/DownloadAttribution/DownloadAttribution.tsx +++ b/src/components/Contribute/Knowledge/DownloadAttribution/DownloadAttribution.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem'; -import { Icon } from '@patternfly/react-core'; +import { Icon } from '@patternfly/react-core/dist/dynamic/components/Icon'; import FileIcon from '@patternfly/react-icons/dist/esm/icons/file-icon'; import { KnowledgeFormData } from '@/types'; diff --git a/src/components/Contribute/Knowledge/DownloadDropdown/DownloadDropdown.tsx b/src/components/Contribute/Knowledge/DownloadDropdown/DownloadDropdown.tsx index 76a03b59..2dc99c3f 100644 --- a/src/components/Contribute/Knowledge/DownloadDropdown/DownloadDropdown.tsx +++ b/src/components/Contribute/Knowledge/DownloadDropdown/DownloadDropdown.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Dropdown } from '@patternfly/react-core/dist/dynamic/components/Dropdown'; import { DropdownList } from '@patternfly/react-core/dist/dynamic/components/Dropdown'; -import { Icon } from '@patternfly/react-core'; +import { Icon } from '@patternfly/react-core/dist/dynamic/components/Icon'; import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/dynamic/components/MenuToggle'; import DownloadYaml from '../DownloadYaml/DownloadYaml'; import DownloadAttribution from '../DownloadAttribution/DownloadAttribution'; diff --git a/src/components/Contribute/Knowledge/DownloadYaml/DownloadYaml.tsx b/src/components/Contribute/Knowledge/DownloadYaml/DownloadYaml.tsx index 6edb94ad..f39b6c2a 100644 --- a/src/components/Contribute/Knowledge/DownloadYaml/DownloadYaml.tsx +++ b/src/components/Contribute/Knowledge/DownloadYaml/DownloadYaml.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { KnowledgeFormData, KnowledgeYamlData } from '@/types'; import { KnowledgeSchemaVersion } from '@/types/const'; import { dumpYaml } from '@/utils/yamlConfig'; -import { Icon } from '@patternfly/react-core'; +import { Icon } from '@patternfly/react-core/dist/dynamic/components/Icon'; import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem'; import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon'; diff --git a/src/components/Contribute/Knowledge/ViewDropdown/ViewDropdown.tsx b/src/components/Contribute/Knowledge/ViewDropdown/ViewDropdown.tsx index c30e85eb..2dad0480 100644 --- a/src/components/Contribute/Knowledge/ViewDropdown/ViewDropdown.tsx +++ b/src/components/Contribute/Knowledge/ViewDropdown/ViewDropdown.tsx @@ -8,7 +8,7 @@ import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon'; import { AttributionData, KnowledgeFormData, KnowledgeYamlData } from '@/types'; import { KnowledgeSchemaVersion } from '@/types/const'; import { dumpYaml } from '@/utils/yamlConfig'; -import { Icon } from '@patternfly/react-core'; +import { Icon } from '@patternfly/react-core/dist/dynamic/components/Icon'; import FileIcon from '@patternfly/react-icons/dist/dynamic/icons/file-icon'; import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon'; diff --git a/src/components/Dashboard/Native/dashboard.tsx b/src/components/Dashboard/Native/dashboard.tsx index f5ffdf07..d9af688c 100644 --- a/src/components/Dashboard/Native/dashboard.tsx +++ b/src/components/Dashboard/Native/dashboard.tsx @@ -22,19 +22,12 @@ import { Alert, AlertProps, AlertVariant } from '@patternfly/react-core/dist/esm import { AlertActionCloseButton } from '@patternfly/react-core/dist/esm/components/Alert/AlertActionCloseButton'; import { PencilAltIcon } from '@patternfly/react-icons/dist/esm/icons/pencil-alt-icon'; import { UploadIcon } from '@patternfly/react-icons/dist/esm/icons/upload-icon'; -import { ModalHeader } from '@patternfly/react-core/dist/esm/components/Modal/ModalHeader'; -import { ModalBody } from '@patternfly/react-core/dist/esm/components/Modal/ModalBody'; -import { FormGroup } from '@patternfly/react-core/dist/esm/components/Form/FormGroup'; -import { Form } from '@patternfly/react-core/dist/esm/components/Form/Form'; -import { TextInput } from '@patternfly/react-core/dist/esm/components/TextInput/TextInput'; -import { ModalFooter } from '@patternfly/react-core/dist/esm/components/Modal/ModalFooter'; const InstructLabLogo: React.FC = () => ; const DashboardNative: React.FunctionComponent = () => { const [branches, setBranches] = React.useState<{ name: string; creationDate: number }[]>([]); - const [selectedTaxonomyRepoDir, setSelectedTaxonomyRepoDir] = React.useState(''); - const [defaultTaxonomyRepoDir, setDefaultTaxonomyRepoDir] = React.useState(''); + const [taxonomyRepoDir, setTaxonomyRepoDir] = React.useState(''); const [isLoading, setIsLoading] = React.useState(true); const [mergeStatus] = React.useState<{ branch: string; message: string; success: boolean } | null>(null); const [diffData, setDiffData] = React.useState<{ branch: string; changes: { file: string; status: string }[] } | null>(null); @@ -53,8 +46,7 @@ const DashboardNative: React.FunctionComponent = () => { const getEnvVariables = async () => { const res = await fetch('/api/envConfig'); const envConfig = await res.json(); - setDefaultTaxonomyRepoDir(envConfig.TAXONOMY_REPO_DIR); - setSelectedTaxonomyRepoDir(envConfig.TAXONOMY_REPO_DIR); + setTaxonomyRepoDir(envConfig.TAXONOMY_REPO_DIR); }; getEnvVariables(); @@ -126,28 +118,6 @@ const DashboardNative: React.FunctionComponent = () => { return `${date.toLocaleDateString()} ${date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`; }; - // Disabling Merge for now, leaving the code for when we re-implement the feature. - // const handleMerge = async (branchName: string) => { - // setMergeStatus(null); // Clear previous status - // try { - // const response = await fetch('/api/native/git/branches', { - // method: 'POST', - // headers: { 'Content-Type': 'application/json' }, - // body: JSON.stringify({ branchName, action: 'merge' }) - // }); - // - // const result = await response.json(); - // if (response.ok) { - // setMergeStatus({ branch: branchName, message: result.message, success: true }); - // } else { - // setMergeStatus({ branch: branchName, message: result.error, success: false }); - // } - // } catch (error) { - // setMergeStatus({ branch: branchName, message: 'Merge failed due to an unexpected error.', success: false }); - // console.error('Error merging branch:', error); - // } - // }; - const handleShowChanges = async (branchName: string) => { try { const response = await fetch('/api/native/git/branches', { @@ -229,13 +199,12 @@ const DashboardNative: React.FunctionComponent = () => { const response = await fetch('/api/native/git/branches', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ branchName: selectedBranch, action: 'publish', remoteTaxonomyRepoDir: selectedTaxonomyRepoDir }) + body: JSON.stringify({ branchName: selectedBranch, action: 'publish' }) }); const result = await response.json(); if (response.ok) { addSuccessAlert(result.message); - setSelectedTaxonomyRepoDir(defaultTaxonomyRepoDir); setSelectedBranch(null); setIsPublishModalOpen(false); } else { @@ -250,7 +219,6 @@ const DashboardNative: React.FunctionComponent = () => { }; const handlePublishContributionCancel = () => { - setSelectedTaxonomyRepoDir(defaultTaxonomyRepoDir); setSelectedBranch(null); setIsPublishModalOpen(false); }; @@ -397,40 +365,20 @@ const DashboardNative: React.FunctionComponent = () => { setIsPublishModalOpen(false)} - aria-labelledby="form-modal-title" - aria-describedby="modal-box-description-form" - > - - - - - setSelectedTaxonomyRepoDir(value)} - /> - - - - - handlePublishContributionConfirm()}> + actions={[ + handlePublishContributionConfirm()}> Publish - - handlePublishContributionCancel()}> + , + handlePublishContributionCancel()}> Cancel - + ]} + > + are you sure you want to publish contribution to remote taxonomy repository present at : {taxonomyRepoDir}?
are you sure you want to publish contribution to remote taxonomy repository present at : {taxonomyRepoDir}?