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(config-ui): some bugs #6295

Merged
merged 4 commits into from
Oct 20, 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
15 changes: 10 additions & 5 deletions config-ui/src/pages/blueprint/connection-detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Popover2 } from '@blueprintjs/popover2';
import API from '@/api';
import { PageLoading, PageHeader, ExternalLink, Message, Buttons, Table, Dialog } from '@/components';
import { useRefreshData, useTips } from '@/hooks';
import { DataScopeSelect, getPluginScopeId } from '@/plugins';
import { DataScopeSelect, getPluginScopeId, PluginConfig, PluginConfigType } from '@/plugins';
import { operator } from '@/utils';

import { encodeName } from '../../project/utils';
Expand All @@ -50,8 +50,11 @@ export const BlueprintConnectionDetailPage = () => {
return API.blueprint.get(bid as any);
};

const [plugin, connectionId] = unique.split('-');

const pluginConfig = PluginConfig.find((p) => p.plugin === plugin) as PluginConfigType;

const { ready, data } = useRefreshData(async () => {
const [plugin, connectionId] = unique.split('-');
const [blueprint, connection] = await Promise.all([
getBlueprint(pname, bid),
API.connection.get(plugin, connectionId),
Expand Down Expand Up @@ -205,9 +208,11 @@ export const BlueprintConnectionDetailPage = () => {
</S.Top>
<Buttons position="top">
<Button intent={Intent.PRIMARY} icon="annotation" text="Manage Data Scope" onClick={handleShowDataScope} />
<ExternalLink style={{ marginLeft: 8 }} link={`/connections/${connection.plugin}/${connection.id}`}>
<Button intent={Intent.PRIMARY} icon="annotation" text="Edit Scope Config" />
</ExternalLink>
{pluginConfig.scopeConfig && (
<ExternalLink style={{ marginLeft: 8 }} link={`/connections/${connection.plugin}/${connection.id}`}>
<Button intent={Intent.PRIMARY} icon="annotation" text="Edit Scope Config" />
</ExternalLink>
)}
</Buttons>
<Table
columns={[
Expand Down
13 changes: 3 additions & 10 deletions config-ui/src/pages/connection/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ import { operator } from '@/utils';
import * as S from './styled';

export const ConnectionDetailPage = () => {
const { plugin, id } = useParams() as { plugin: string; id: string };
return <ConnectionDetail plugin={plugin} connectionId={+id} />;
};

interface Props {
plugin: string;
connectionId: ID;
}

const ConnectionDetail = ({ plugin, connectionId }: Props) => {
const [type, setType] = useState<
| 'deleteConnection'
| 'updateConnection'
Expand All @@ -71,6 +61,9 @@ const ConnectionDetail = ({ plugin, connectionId }: Props) => {
const [conflict, setConflict] = useState<string[]>([]);
const [errorMsg, setErrorMsg] = useState('');

const { plugin, id } = useParams() as { plugin: string; id: string };
const connectionId = +id;

const connection = useAppSelector((state) => selectConnection(state, `${plugin}-${connectionId}`)) as IConnection;
const navigate = useNavigate();
const { setTips } = useTips();
Expand Down
2 changes: 1 addition & 1 deletion config-ui/src/plugins/register/webhook/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Wrapper = styled.div`
}

h5 {
margin: 8px 0;
margin: 16px 0 8px;
}

p {
Expand Down
40 changes: 10 additions & 30 deletions config-ui/src/routes/api-keys/api-keys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,9 @@

import { useState, useMemo } from 'react';
import { Button, Intent, InputGroup } from '@blueprintjs/core';
import { CopyToClipboard } from 'react-copy-to-clipboard';

import API from '@/api';
import {
PageHeader,
Table,
Dialog,
FormItem,
Selector,
ExternalLink,
TextTooltip,
IconButton,
toast,
Buttons,
Message,
} from '@/components';
import { PageHeader, Table, Dialog, FormItem, Selector, ExternalLink, CopyText, Message } from '@/components';
import { useRefreshData } from '@/hooks';
import { operator, formatTime } from '@/utils';

Expand All @@ -47,7 +34,7 @@ export const ApiKeys = () => {
const [operating, setOperating] = useState(false);
const [modal, setModal] = useState<'create' | 'show' | 'delete'>();
const [currentId, setCurrentId] = useState<string>();
const [currentKey, setCurrentKey] = useState<string>();
const [currentKey, setCurrentKey] = useState<string>('');
const [form, setForm] = useState<{
name: string;
expiredAt?: string;
Expand All @@ -61,6 +48,7 @@ export const ApiKeys = () => {
const { data, ready } = useRefreshData(() => API.apiKey.list({ page, pageSize }), [version, page, pageSize]);

const [dataSource, total] = useMemo(() => [data?.apikeys ?? [], data?.count ?? 0], [data]);
const hasError = useMemo(() => !form.name || !form.allowedPath, [form]);

const timeSelectedItem = useMemo(() => {
return C.timeOptions.find((it) => it.value === form.expiredAt || !it.value);
Expand All @@ -73,7 +61,6 @@ export const ApiKeys = () => {
const handleSubmit = async () => {
const [success, res] = await operator(() => API.apiKey.create(form), {
setOperating,
hideToast: true,
});

if (success) {
Expand Down Expand Up @@ -164,6 +151,7 @@ export const ApiKeys = () => {
title="Generate a New API Key"
okLoading={operating}
okText="Generate"
okDisabled={hasError}
onCancel={handleCancel}
onOk={handleSubmit}
>
Expand Down Expand Up @@ -191,8 +179,8 @@ export const ApiKeys = () => {
subLabel={
<p>
Enter a Regular Expression that matches the API URL(s) from the{' '}
<ExternalLink link="">DevLake API docs</ExternalLink>. The default Regular Expression is set to all
APIs.
<ExternalLink link="/api/swagger/index.html">DevLake API docs</ExternalLink>. The default Regular
Expression is set to all APIs.
</p>
}
required
Expand All @@ -216,18 +204,10 @@ export const ApiKeys = () => {
footer={null}
onCancel={handleCancel}
>
<div>Please make sure to copy your API key now. You will not be able to see it again.</div>
<S.KeyContainer>
<TextTooltip style={{ width: '96%' }} content="">
{currentKey}
</TextTooltip>
<CopyToClipboard text={currentKey as string} onCopy={() => toast.success('Copy successfully.')}>
<IconButton icon="clipboard" tooltip="Copy" />
</CopyToClipboard>
</S.KeyContainer>
<Buttons position="bottom" align="right">
<Button intent={Intent.PRIMARY} text="Confirm" onClick={handleCancel} />
</Buttons>
<div style={{ marginBottom: 16 }}>
Please make sure to copy your API key now. You will not be able to see it again.
</div>
<CopyText content={currentKey} />
</Dialog>
)}
{modal === 'delete' && (
Expand Down
10 changes: 0 additions & 10 deletions config-ui/src/routes/api-keys/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,3 @@ export const InputContainer = styled.div`
margin-right: 4px;
}
`;

export const KeyContainer = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 24px;
margin-bottom: 16px;
padding: 10px 16px;
background: #f0f4fe;
`;