Skip to content

Commit 75999c1

Browse files
preetriti1Priti Sambandam
andauthored
feat(knowledge): Adding create new hub and artifacts experience in knowledge wizard (#8937)
* Initial changes for adding files in hub * Fixing the tests * addressing pr comments --------- Co-authored-by: Priti Sambandam <psamband@microsoft.com>
1 parent 66b74b3 commit 75999c1

File tree

18 files changed

+2606
-304
lines changed

18 files changed

+2606
-304
lines changed

Localize/lang/strings.json

Lines changed: 66 additions & 2 deletions
Large diffs are not rendered by default.

apps/Standalone/src/knowledge/app/KnowledgeHub.tsx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type ConnectionsData,
1414
clone,
1515
resolveConnectionsReferences,
16+
type UploadFile,
1617
} from '@microsoft/logic-apps-shared';
1718
import { useKnowledgeStyles } from './styles';
1819
import { HttpClient } from '../../designer/app/AzureLogicAppsDesigner/Services/HttpClient';
@@ -25,6 +26,7 @@ import {
2526
import { addConnectionInJson, addOrUpdateAppSettings } from '../../designer/app/AzureLogicAppsDesigner/Utilities/Workflow';
2627
import { Spinner } from '@fluentui/react-components';
2728
import { CustomConnectionParameterEditorService } from '../Services/connectionParameterEditor';
29+
import { environment } from '../../environments/environment';
2830

2931
const apiVersion = '2020-06-01';
3032
const httpClient = new HttpClient();
@@ -86,7 +88,7 @@ export const KnowledgeHub = () => {
8688
<div className={styles.wizardContent}>
8789
<div className={styles.wizardWrapper}>
8890
<KnowledgeDataProvider resourceDetails={resourceDetails} services={services} isDarkMode={theme === 'dark'}>
89-
<KnowledgeHubWizard />
91+
<KnowledgeHubWizard onUploadArtifact={uploadFileToKnowledgeHub} />
9092
</KnowledgeDataProvider>
9193
</div>
9294
</div>
@@ -152,3 +154,73 @@ const getServices = (
152154
hostService: {} as any, // Placeholder for IHostService, not used in this context
153155
};
154156
};
157+
158+
const uploadFileToKnowledgeHub = async (
159+
siteResourceId: string,
160+
hubName: string,
161+
content: { file: UploadFile; name: string; description?: string },
162+
setIsLoading: (isLoading: boolean) => void
163+
): Promise<void> => {
164+
const { file, name, description } = content;
165+
const contentType = file.file.type || 'application/octet-stream';
166+
167+
const uri = `https://management.azure.com${siteResourceId}/hostruntime/runtime/webhooks/workflow/api/management/knowledgehubs/${hubName}/knowledgeArtifacts/${name}?api-version=2018-11-01`;
168+
169+
return new Promise((resolve, reject) => {
170+
const reader = new FileReader();
171+
172+
reader.onload = () => {
173+
const base64Content = (reader.result as string).split(',')[1]; // Remove data URL prefix
174+
175+
const payload = {
176+
description: description,
177+
payload: {
178+
'$content-type': contentType,
179+
$content: base64Content,
180+
},
181+
};
182+
183+
const xhr = new XMLHttpRequest();
184+
185+
xhr.onloadstart = () => {
186+
setIsLoading(true);
187+
};
188+
189+
xhr.onloadend = () => {
190+
setIsLoading(false);
191+
file.setProgress?.(1);
192+
193+
if (xhr.status >= 200 && xhr.status < 300) {
194+
resolve();
195+
} else {
196+
reject(new Error(`Upload failed with status ${xhr.status}: ${xhr.statusText}`));
197+
}
198+
};
199+
200+
xhr.onerror = () => {
201+
setIsLoading(false);
202+
reject(new Error('Upload failed due to network error'));
203+
};
204+
205+
xhr.upload.onprogress = (e) => {
206+
if (e.lengthComputable) {
207+
file.setProgress?.(e.loaded / e.total);
208+
}
209+
};
210+
211+
xhr.open('PUT', uri, true);
212+
xhr.setRequestHeader('Content-Type', 'application/json');
213+
xhr.setRequestHeader('Authorization', `Bearer ${environment.armToken}`);
214+
xhr.setRequestHeader('Cache-Control', 'no-cache');
215+
216+
xhr.send(JSON.stringify(payload));
217+
};
218+
219+
reader.onerror = () => {
220+
setIsLoading(false);
221+
reject(new Error('Failed to read file'));
222+
};
223+
224+
reader.readAsDataURL(file.file);
225+
});
226+
};

0 commit comments

Comments
 (0)