Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ensure collections are initiated in store #2627

Merged
merged 5 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graph-explorer-v2",
"version": "9.0.0",
"version": "9.0.1",
"private": true,
"dependencies": {
"@augloop/types-core": "file:packages/types-core-2.16.189.tgz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const UnstyledResourceExplorer = (props: any) => {

const dispatch: AppDispatch = useDispatch();
const classes = classNames(props);
const selectedLinks = collections ? collections.find(k => k.isDefault)!.paths : [];
const selectedLinks = collections && collections.length > 0 ? collections.find(k => k.isDefault)!.paths : [];
const versions: any[] = [
{ key: 'v1.0', text: 'v1.0' },
{ key: 'beta', text: 'beta' }
Expand Down
28 changes: 26 additions & 2 deletions src/app/views/sidebar/resource-explorer/ResourceLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { CSSProperties, useEffect } from 'react';

import { useAppSelector } from '../../../../store';
import { componentNames, eventTypes, telemetry } from '../../../../telemetry';
import { IResourceLink, ResourceOptions } from '../../../../types/resources';
import { IResourceLink, IResources, ResourceOptions } from '../../../../types/resources';
import { GRAPH_URL } from '../../../services/graph-constants';
import { validateExternalLink } from '../../../utils/external-link-validation';
import { getStyleFor } from '../../../utils/http-methods.utils';
import { translateMessage } from '../../../utils/translate-messages';
import DocumentationService from '../../query-runner/query-input/auto-complete/suffix/documentation';
import { getUrlFromLink } from './resource-explorer.utils';
import { existsInCollection, setExisting } from './resourcelink.utils';

interface IResourceLinkProps {
Expand All @@ -21,7 +24,7 @@ interface IResourceLinkProps {

const ResourceLink = (props: IResourceLinkProps) => {
const { classes, version } = props;
const { collections } = useAppSelector(state => state);
const { collections, resources } = useAppSelector(state => state);
const link = props.link as IResourceLink;

const paths = collections?.find(k => k.isDefault)?.paths || [];
Expand Down Expand Up @@ -78,6 +81,9 @@ const ResourceLink = (props: IResourceLinkProps) => {
textTransform: 'uppercase'
}

resourceLink.docLink = resourceLink.docLink ? resourceLink.docLink
: getDocumentationLink(resourceLink, version, resources);

const openDocumentationLink = () => {
window.open(resourceLink.docLink, '_blank');
trackDocumentLinkClickedEvent();
Expand Down Expand Up @@ -186,3 +192,21 @@ const ResourceLink = (props: IResourceLinkProps) => {


export default ResourceLink;

function getDocumentationLink(resourceLink: IResourceLink, version: string, resources: IResources): string | null {
if (!resourceLink.method) {
return null;
}

return new DocumentationService({
sampleQuery: {
sampleUrl: `${GRAPH_URL}/${version}${getUrlFromLink(resourceLink.paths)}`,
selectedVerb: resourceLink.method,
selectedVersion: version,
sampleBody: '',
sampleHeaders: []
},
source: resources.data.children
}).getDocumentationLink();
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PathsReview: React.FC<PopupsComponent<IPathsReview>> = (props) => {
const { collections } = useAppSelector(
(state) => state
);
const items = collections ? collections.find(k => k.isDefault)!.paths : [];
const items = collections && collections.length > 0 ? collections.find(k => k.isDefault)!.paths : [];
const [selectedItems, setSelectedItems] = useState<IResourceLink[]>([]);

const columns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CommandOptions = (props: ICommandOptions) => {
const theme = getTheme();

const { collections } = useAppSelector((state) => state);
const paths = collections ? collections.find(k => k.isDefault)!.paths : [];
const paths = collections && collections.length > 0 ? collections.find(k => k.isDefault)!.paths : [];

const itemStyles = resourceExplorerStyles(theme).itemStyles;
const commandStyles = resourceExplorerStyles(theme).commandBarStyles;
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const initialState: any = {
sampleHeaders: [],
selectedVersion: 'v1.0'
},
termsOfUse: true
termsOfUse: true,
collections: []
};

export const store = createStore(
Expand Down