Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
69a786a
change source of feeds from local feed to live npm/nuget feed
benbrown Jan 13, 2021
f035301
fixes to formatting
benbrown Jan 13, 2021
03d1adf
Merge branch 'main' into benbrown/packagefeeds
benbrown Jan 13, 2021
126ae0d
Merge branch 'main' into benbrown/packagefeeds
benbrown Jan 14, 2021
3e135ac
update feed urls
benbrown Jan 14, 2021
855c9a2
Merge branch 'main' into benbrown/packagefeeds
benbrown Jan 14, 2021
cf7baf6
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
benbrown Jan 14, 2021
29ab16e
Merge branch 'benbrown/packagefeeds' of https://github.com/microsoft/…
benbrown Jan 14, 2021
214773e
Apply linting and prettification rules
benbrown Jan 15, 2021
0361374
address feedback from peers
benbrown Jan 15, 2021
ad581d4
allow feeds to be searched either via api or by local filtering
benbrown Jan 15, 2021
79f4c03
support for private myget feeds
benbrown Jan 15, 2021
3df4c02
Merge branch 'main' into benbrown/packagefeeds
benbrown Jan 19, 2021
fa10bcd
remove unnecessary deps
benbrown Jan 19, 2021
1e15636
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
benbrown Jan 19, 2021
d88e2ae
Merge branch 'benbrown/packagefeeds' of https://github.com/microsoft/…
benbrown Jan 19, 2021
22c6b37
Merge branch 'benbrown/packagefeeds' into benbrown/searchfeeds
benbrown Jan 19, 2021
094373e
Merge branch 'main' of https://github.com/microsoft/BotFramework-Comp…
benbrown Jan 20, 2021
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
48 changes: 43 additions & 5 deletions extensions/packageManager/src/client/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ScrollablePane,
ScrollbarVisibility,
Stack,
SearchBox,
} from 'office-ui-fabric-react';
import { render, useHttpClient, useProjectApi, useApplicationApi } from '@bfc/extension-client';
import { Toolbar, IToolbarItem, LoadingSpinner } from '@bfc/ui-shared';
Expand Down Expand Up @@ -45,6 +46,7 @@ const Library: React.FC = () => {
const [runtimeLanguage, setRuntimeLanguage] = useState<string>('c#');
const [feeds, updateFeeds] = useState([]);
const [feed, setFeed] = useState<string | undefined>(undefined);
const [searchTerm, setSearchTerm] = useState<string>('');
const [loading, setLoading] = useState(false);
const [selectedItem, setSelectedItem] = useState<LibraryRef>();
const [currentProjectId, setCurrentProjectId] = useState<string>(projectId);
Expand Down Expand Up @@ -79,7 +81,7 @@ const Library: React.FC = () => {
),
ejectRuntime: formatMessage('Eject Runtime'),
noComponentsInstalled: formatMessage('No packages installed'),
noComponentsFound: formatMessage('No packages found. Check extension configuration.'),
noComponentsFound: formatMessage('No packages found'),
browseHeader: formatMessage('Browse'),
installHeader: formatMessage('Installed'),
libraryError: formatMessage('Package Manager Error'),
Expand All @@ -104,6 +106,14 @@ const Library: React.FC = () => {
return httpClient.get(feedUrl);
};

const getSearchResults = () => {
const feedUrl = feeds.find((f) => f.key == feed).searchUrl
? `${API_ROOT}/feed?url=` +
encodeURIComponent(feeds.find((f) => f.key == feed).searchUrl.replace(/\{\{keyword\}\}/g, searchTerm))
: `${API_ROOT}/feed?url=` + encodeURIComponent(feeds.find((f) => f.key == feed).url);
return httpClient.get(feedUrl);
};

const getFeeds = () => {
return httpClient.get(`${API_ROOT}/feeds`);
};
Expand Down Expand Up @@ -141,7 +151,7 @@ const Library: React.FC = () => {
if (feed && feeds.length) {
getLibraries();
}
}, [feed, feeds]);
}, [feed, feeds, searchTerm]);

useEffect(() => {
const settings = projectCollection.find((b) => b.projectId === currentProjectId).setting;
Expand Down Expand Up @@ -276,13 +286,33 @@ const Library: React.FC = () => {
}
};

// return true if the name, description or any of the keywords match the search term
const applySearchTerm = (i): boolean => {
const term = searchTerm.trim().toLocaleLowerCase();
return (
i.name.toLowerCase().match(term) ||
i.description.toLowerCase().match(term) ||
i.keywords.filter((tag) => tag.toLowerCase().match(term)).length
);
};

const getLibraries = async () => {
try {
updateAvailableLibraries(undefined);
setLoading(true);
const response = await getLibraryAPI();
updateAvailableLibraries(response.data.available);
setRecentlyUsed(response.data.recentlyUsed);
if (searchTerm) {
const response = await getSearchResults();
// if we are searching, but there is not a searchUrl, apply a local filter
if (!feeds.find((f) => f.key === feed).searchUrl) {
response.data.available = response.data.available.filter(applySearchTerm);
}
updateAvailableLibraries(response.data.available);
setRecentlyUsed(response.data.recentlyUsed);
} else {
const response = await getLibraryAPI();
updateAvailableLibraries(response.data.available);
setRecentlyUsed(response.data.recentlyUsed);
}
setLoading(false);
} catch (err) {
setApplicationLevelError({
Expand Down Expand Up @@ -422,6 +452,14 @@ const Library: React.FC = () => {
}}
></Dropdown>
</section>
<section>
<SearchBox
placeholder="Search"
onClear={() => setSearchTerm('')}
onSearch={setSearchTerm}
disabled={!feeds || !feed}
/>
</section>
{loading && <LoadingSpinner />}
{items?.length ? (
<LibraryList
Expand Down
22 changes: 19 additions & 3 deletions extensions/packageManager/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SchemaMerger } from '@microsoft/bf-dialog/lib/library/schemaMerger';

const API_ROOT = '/api';

const normalizeFeed = (feed) => {
const normalizeFeed = async (feed) => {
if (feed.objects) {
// this is an NPM feed
return feed.objects.map((i) => {
Expand Down Expand Up @@ -38,6 +38,15 @@ const normalizeFeed = (feed) => {
source: 'nuget',
};
});
} else if (feed.resources) {
// this is actually a myget feed that points to the feed we want...
const queryEndpoint = feed.resources.find((resource) => resource['@type'] === 'SearchQueryService');
if (queryEndpoint) {
const raw = await axios.get(queryEndpoint['@id']);
return normalizeFeed(raw.data);
} else {
return [];
}
} else {
return null;
}
Expand All @@ -57,7 +66,12 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
const LibraryController = {
getFeeds: async function (req, res) {
// read the list of sources from the config file.
let packageSources = composer.store.read('feeds') as { key: string; text: string; url: string }[];
let packageSources = composer.store.read('feeds') as {
key: string;
text: string;
url: string;
searchUrl?: string;
}[];

// if no sources are in the config file, set the default list to our 1st party feed.
if (!packageSources) {
Expand All @@ -66,11 +80,13 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
key: 'npm',
text: 'npm',
url: 'https://registry.npmjs.org/-/v1/search?text=keywords:bf-component&size=100&from=0',
searchUrl: 'https://registry.npmjs.org/-/v1/search?text={{keyword}}+keywords:bf-component&size=100&from=0',
},
{
key: 'nuget',
text: 'nuget',
url: 'https://azuresearch-usnc.nuget.org/query?q=Tags:%22bf-component%22&prerelease=true',
searchUrl: 'https://azuresearch-usnc.nuget.org/query?q={{keyword}}+Tags:%22bf-component%22&prerelease=true',
// only ours
// https://azuresearch-usnc.nuget.org/query?q={search keyword}+preview.bot.component+Tags:%22bf-component%22&prerelease=true
},
Expand Down Expand Up @@ -125,7 +141,7 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
for (const url of packageSources) {
try {
const raw = await axios.get(url);
const feed = normalizeFeed(raw.data);
const feed = await normalizeFeed(raw.data);
if (Array.isArray(feed)) {
combined = combined.concat(feed);
} else {
Expand Down