Skip to content

Commit

Permalink
feat: 🎸 API resource url
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Pryka committed Oct 16, 2020
1 parent 8d5a55e commit c554fb7
Show file tree
Hide file tree
Showing 24 changed files with 230 additions and 165 deletions.
12 changes: 0 additions & 12 deletions lib/js/app/components/APIResource/APIResource.styles.ts

This file was deleted.

113 changes: 0 additions & 113 deletions lib/js/app/components/APIResource/APIResource.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions lib/js/app/components/APIResource/constants.ts

This file was deleted.

3 changes: 0 additions & 3 deletions lib/js/app/components/APIResource/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions lib/js/app/components/APIResource/text.json

This file was deleted.

31 changes: 28 additions & 3 deletions lib/js/app/components/ActionsMenu/ActionsMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Provider } from 'react-redux';
import { render as rtlRender, fireEvent } from '@testing-library/react';
import configureStore from 'redux-mock-store';

import { AppContext } from '../../contexts';

import ActionsMenu from './ActionsMenu';
import text from './text.json';

Expand All @@ -18,9 +20,11 @@ const render = (overProps: any = {}) => {
const store = mockStore({ queries: {} });

const wrapper = rtlRender(
<Provider store={store}>
<ActionsMenu {...props} />
</Provider>
<AppContext.Provider value={{ keenAnalysis: { config: {} } } as any}>
<Provider store={store}>
<ActionsMenu {...props} />
</Provider>
</AppContext.Provider>
);

return {
Expand Down Expand Up @@ -161,3 +165,24 @@ test('allows user to embed HTML code', () => {
]
`);
});

test('allows user to copy API Resource', () => {
const {
wrapper: { getByText },
store,
} = render();

const copyApiResource = getByText(text.apiResource);
fireEvent.click(copyApiResource);

expect(store.getActions()).toMatchInlineSnapshot(`
Array [
Object {
"payload": Object {
"config": Object {},
},
"type": "@app/COPY_API_RESOURCE_URL",
},
]
`);
});
23 changes: 18 additions & 5 deletions lib/js/app/components/ActionsMenu/ActionsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { FC, useState } from 'react';
import React, { FC, useState, useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { DropdownMenu, Tooltip } from '@keen.io/ui-core';
import { AnimatePresence } from 'framer-motion';

import { AppContext } from '../../contexts';
import { getQueryResults } from '../../modules/queries';

import {
Expand All @@ -22,6 +23,7 @@ import {
exportChartToJson,
exportDataToCsv,
showEmbedModal,
copyApiResourceUrl,
} from '../../modules/app';

type Props = {
Expand All @@ -43,6 +45,9 @@ const ActionsMenu: FC<Props> = ({ isNewQuery, onRemoveQuery, onHideMenu }) => {
const dispatch = useDispatch();
const queryResults = useSelector(getQueryResults);
const [tooltip, showTooltip] = useState(false);
const {
keenAnalysis: { config },
} = useContext(AppContext);
return (
<Container>
<DropdownMenu.Container>
Expand All @@ -51,15 +56,15 @@ const ActionsMenu: FC<Props> = ({ isNewQuery, onRemoveQuery, onHideMenu }) => {
onMouseEnter={() => !queryResults && showTooltip(true)}
onMouseLeave={() => tooltip && showTooltip(false)}
>
<AnimatePresence>
{tooltip && (
{tooltip && (
<AnimatePresence>
<TooltipMotion {...tooltipMotion}>
<Tooltip hasArrow={false} mode="dark">
<TooltipContent>{text.tooltip}</TooltipContent>
</Tooltip>
</TooltipMotion>
)}
</AnimatePresence>
</AnimatePresence>
)}
<ExportDataLinks isActive={queryResults}>
<DropdownMenu.Item
onClick={() => {
Expand Down Expand Up @@ -107,6 +112,14 @@ const ActionsMenu: FC<Props> = ({ isNewQuery, onRemoveQuery, onHideMenu }) => {
>
{text.shareQuery}
</DropdownMenu.Item>
<DropdownMenu.Item
onClick={() => {
dispatch(copyApiResourceUrl(config));
onHideMenu();
}}
>
{text.apiResource}
</DropdownMenu.Item>
<DropdownMenu.Item
onClick={() => {
dispatch(showEmbedModal());
Expand Down
3 changes: 2 additions & 1 deletion lib/js/app/components/ActionsMenu/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"json": "JSON",
"csv": "CSV",
"tooltip": "Run query to download result",
"embedHtml": "Embed HTML"
"embedHtml": "Embed HTML",
"apiResource": "API Resource"
}
2 changes: 2 additions & 0 deletions lib/js/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const ERRORS = {
TOO_MANY_QUERIES: 'TooManyCachedQueriesInTheCurrentBillingPeriod',
};

export const API_VERSION = '3.0';

export const EXTRACTION_PREVIEW_EVENTS_DEFAULT = 100;
export const EXTRACTION_PREVIEW_EVENTS_LIMIT = 100000;
export const EXTRACTION_BULK_EVENTS_DEFAULT = 1000;
Expand Down
10 changes: 10 additions & 0 deletions lib/js/app/modules/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DOWNLOAD_CODE_SNIPPET,
SHOW_EMAIL_EXTRACTION_MODAL,
HIDE_EMAIL_EXTRACTION_MODAL,
COPY_API_RESOURCE_URL,
} from './constants';

import {
Expand Down Expand Up @@ -212,3 +213,12 @@ export const downloadCodeSnippet = (
readKey,
},
});

export const copyApiResourceUrl = (
config: Record<string, any>
): AppActions => ({
type: COPY_API_RESOURCE_URL,
payload: {
config,
},
});
1 change: 1 addition & 0 deletions lib/js/app/modules/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const DOWNLOAD_CODE_SNIPPET = '@app/DOWNLOAD_CODE_SNIPPET';
export const APP_START = '@app/APP_START';
export const SHOW_EMAIL_EXTRACTION_MODAL = '@app/SHOW_EMAIL_EXTRACTION_MODAL';
export const HIDE_EMAIL_EXTRACTION_MODAL = '@app/HIDE_EMAIL_EXTRACTION_MODAL';
export const COPY_API_RESOURCE_URL = '@app/COPY_API_RESOURCE_URL';

export const URL_STATE = 'keen_explorer_state';
2 changes: 2 additions & 0 deletions lib/js/app/modules/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
downloadCodeSnippet,
showEmailExtractionModal,
hideEmailExtractionModal,
copyApiResourceUrl,
} from './actions';
import {
getConfirmation,
Expand Down Expand Up @@ -87,6 +88,7 @@ export {
copyEmbeddedCode,
downloadCodeSnippet,
exportDataToCsv,
copyApiResourceUrl,
ReducerState,
SettingsModalSource,
};
Expand Down
27 changes: 27 additions & 0 deletions lib/js/app/modules/app/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
exportToCsv,
createCodeSnippet,
exportToHtml,
createResourceUrl,
} from '../../utils';

import { SET_QUERY_EVENT, NEW_QUERY_EVENT } from '../../queryCreator';
Expand All @@ -67,6 +68,7 @@ import {
AppStartAction,
CopyEmbeddedCodeAction,
DownloadCodeSnippetAction,
CopyApiResourceUrlAction,
} from './types';

import {
Expand All @@ -88,6 +90,7 @@ import {
EXPORT_DATA_TO_CSV,
COPY_EMBEDDED_CODE,
DOWNLOAD_CODE_SNIPPET,
COPY_API_RESOURCE_URL,
} from './constants';

const createScreenResizeChannel = () =>
Expand Down Expand Up @@ -417,6 +420,29 @@ export function* downloadCodeSnippet({ payload }: DownloadCodeSnippetAction) {
}
}

export function* copyApiResourceUrl({ payload }: CopyApiResourceUrlAction) {
const { config } = payload;
const query = yield select(getQuerySettings);
const notificationManager = yield getContext(NOTIFICATION_MANAGER_CONTEXT);
try {
const url = createResourceUrl({ query, config });
console.log(url);
yield copyToClipboard(url);
yield notificationManager.showNotification({
type: 'success',
message: text.copyApiResourceUrl,
autoDismiss: true,
});
} catch (err) {
yield notificationManager.showNotification({
type: 'error',
message: text.copyApiResourceUrlError,
showDismissButton: true,
autoDismiss: false,
});
}
}

export function* appSaga() {
yield takeLatest(APP_START, appStart);
yield takeLatest(SHARE_QUERY_URL, shareQueryUrl);
Expand All @@ -432,5 +458,6 @@ export function* appSaga() {
yield takeLatest(EXPORT_DATA_TO_CSV, exportDataToCsv);
yield takeLatest(COPY_EMBEDDED_CODE, copyEmbeddedCode);
yield takeLatest(DOWNLOAD_CODE_SNIPPET, downloadCodeSnippet);
yield takeLatest(COPY_API_RESOURCE_URL, copyApiResourceUrl);
yield debounce(200, SCREEN_RESIZE, resizeBrowserScreen);
}
4 changes: 3 additions & 1 deletion lib/js/app/modules/app/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"downloadChartError": "download failed. Please try again later.",
"downloadInProgress": "download in progress",
"copyEmbeddedCode": "HTML code copied to clipboard",
"copyEmbeddedCodeError": "We were not able to copy HTML code. Try again later."
"copyEmbeddedCodeError": "We were not able to copy HTML code. Try again later.",
"copyApiResourceUrl": "API Resource copied to clipboard",
"copyApiResourceUrlError": "We were not able to copy API Resource. Try again later."
}
Loading

0 comments on commit c554fb7

Please sign in to comment.