Skip to content

Commit

Permalink
Display event keys created via integration (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
djfarrelly committed Mar 22, 2024
1 parent 61717ce commit 4591f2b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ type KeysListItemProps = {
}[];
};

const pageFilters: { [key: string]: string[] } = {
keys: ['key', 'integration'],
webhooks: ['webhook'],
};

export default function KeysListItem({ list }: KeysListItemProps) {
const env = useEnvironment();
const pathname = usePathname();
const page = getManageKey(pathname);

// Change once there's a way to get the route param in a server component
const filteredList = list.filter((item) => `${item.source}s` === page);
const filteredList = page ? list.filter((item) => pageFilters[page]?.includes(item.source)) : [];

if (filteredList.length === 0) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ type DeleteKeyModalProps = {
keyID: string;
isOpen: boolean;
onClose: () => void;
description?: string;
};

export default function DeleteKeyModal({ keyID, isOpen, onClose }: DeleteKeyModalProps) {
export default function DeleteKeyModal({
keyID,
isOpen,
onClose,
description,
}: DeleteKeyModalProps) {
const env = useEnvironment();
const [, deleteEventKey] = useMutation(DeleteEventKey);
const router = useRouter();
Expand Down Expand Up @@ -52,6 +58,7 @@ export default function DeleteKeyModal({ keyID, isOpen, onClose }: DeleteKeyModa
isOpen={isOpen}
onClose={onClose}
title={'Are you sure you want to delete this ' + currentContent?.name.toLowerCase() + '?'}
description={description}
onSubmit={handleDelete}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const GetKeyDocument = graphql(`
events
}
metadata
source
}
}
}
Expand All @@ -48,6 +49,8 @@ type KeyDetailsProps = {
};
};

const SOURCE_INTEGRATION = 'integration';

export default function Keys({ params: { ingestKeys, keyID } }: KeyDetailsProps) {
const [isDeleteKeyModalVisible, setIsDeleteKeyModalVisible] = useState(false);
const [isEditKeyNameModalVisible, setIsEditKeyNameModalVisible] = useState(false);
Expand Down Expand Up @@ -77,6 +80,9 @@ export default function Keys({ params: { ingestKeys, keyID } }: KeyDetailsProps)
throw new Error(`invalid filter type: ${filterType}`);
}

// Integration created keys cannot be deleted or renamed
const isIntegration = key.source === SOURCE_INTEGRATION;

let value = '',
maskedValue = '',
keyLabel = 'Key';
Expand Down Expand Up @@ -112,18 +118,25 @@ export default function Keys({ params: { ingestKeys, keyID } }: KeyDetailsProps)
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>

<DeleteKeyModal
keyID={keyID}
isOpen={isDeleteKeyModalVisible}
onClose={() => setIsDeleteKeyModalVisible(false)}
description={
isIntegration
? 'Warning: This key was created via integration. Please confirm that you are no longer using it before deleting.'
: ''
}
/>
<EditKeyNameModal
keyID={keyID}
keyName={key.name}
isOpen={isEditKeyNameModalVisible}
onClose={() => setIsEditKeyNameModalVisible(false)}
/>
{key.source === SOURCE_INTEGRATION && (
<span className="ml-8 text-sm text-slate-400">Created via integration</span>
)}
</div>
<div className="w-3/5">
<CodeKey fullKey={value} maskedKey={maskedValue} label={keyLabel} />
Expand Down
4 changes: 2 additions & 2 deletions ui/apps/dashboard/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const documents = {
"\n query GetIngestKeys($environmentID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKeys {\n id\n name\n createdAt\n source\n }\n }\n }\n": types.GetIngestKeysDocument,
"\n mutation UpdateIngestKey($id: ID!, $input: UpdateIngestKey!) {\n updateIngestKey(id: $id, input: $input) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n }\n }\n": types.UpdateIngestKeyDocument,
"\n mutation DeleteEventKey($input: DeleteIngestKey!) {\n deleteIngestKey(input: $input) {\n ids\n }\n }\n": types.DeleteEventKeyDocument,
"\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n }\n }\n }\n": types.GetIngestKeyDocument,
"\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n source\n }\n }\n }\n": types.GetIngestKeyDocument,
"\n query GetSigningKey($environmentID: ID!) {\n environment: workspace(id: $environmentID) {\n webhookSigningKey\n }\n }\n": types.GetSigningKeyDocument,
"\n query UnattachedSync($syncID: ID!) {\n sync: deploy(id: $syncID) {\n commitAuthor\n commitHash\n commitMessage\n commitRef\n error\n framework\n id\n lastSyncedAt\n platform\n repoURL\n sdkLanguage\n sdkVersion\n status\n removedFunctions: removedFunctions {\n id\n name\n slug\n }\n syncedFunctions: deployedFunctions {\n id\n name\n slug\n }\n url\n vercelDeploymentID\n vercelDeploymentURL\n vercelProjectID\n vercelProjectURL\n }\n }\n": types.UnattachedSyncDocument,
"\n query UnattachedSyncs($envID: ID!) {\n environment: workspace(id: $envID) {\n syncs: unattachedSyncs(first: 40) {\n commitAuthor\n commitHash\n commitMessage\n commitRef\n framework\n id\n lastSyncedAt\n platform\n repoURL\n sdkLanguage\n sdkVersion\n status\n url\n vercelDeploymentID\n vercelDeploymentURL\n vercelProjectID\n vercelProjectURL\n }\n }\n }\n": types.UnattachedSyncsDocument,
Expand Down Expand Up @@ -321,7 +321,7 @@ export function graphql(source: "\n mutation DeleteEventKey($input: DeleteInges
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n }\n }\n }\n"): (typeof documents)["\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n }\n }\n }\n"];
export function graphql(source: "\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n source\n }\n }\n }\n"): (typeof documents)["\n query GetIngestKey($environmentID: ID!, $keyID: ID!) {\n environment: workspace(id: $environmentID) {\n ingestKey(id: $keyID) {\n id\n name\n createdAt\n presharedKey\n url\n filter {\n type\n ips\n events\n }\n metadata\n source\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit 4591f2b

Please sign in to comment.