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: Add option to delete Insight from IEX but keep GH repository #824

Merged
merged 3 commits into from
May 11, 2022
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 packages/backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ type Mutation {
cloneInsight(insightId: ID!): Draft!
deleteComment(commentId: ID!): Comment!
deleteDraft(draftKey: String!): Draft!
deleteInsight(insightId: ID!): ID!
deleteInsight(archiveRepo: Boolean!, insightId: ID!): ID!
deleteNews(newsId: ID!): News!
getAccessToken(code: String!): String!
likeActivity(activityId: ID!, liked: Boolean!): Activity!
Expand Down
8 changes: 6 additions & 2 deletions packages/backend/src/resolvers/insight.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,18 @@ export class InsightResolver {

@Authorized<Permission>({ user: true, github: true })
@Mutation(() => ID)
async deleteInsight(@Arg('insightId', () => ID) insightId: string, @Ctx() ctx: Context): Promise<string> {
async deleteInsight(
@Arg('insightId', () => ID) insightId: string,
@Arg('archiveRepo') archiveRepo: boolean,
@Ctx() ctx: Context
): Promise<string> {
logger.debug('Deleting Insight', insightId);

try {
const [, dbInsightId] = fromGlobalId(insightId);

// Delete Insight
await this.insightService.deleteInsight(dbInsightId, ctx.user!);
await this.insightService.deleteInsight(dbInsightId, archiveRepo, ctx.user!);

return insightId;
} catch (error: any) {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/services/insight.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export class InsightService {
* @param user User making the change
* @param hard True for a hard delete, false for a soft delete (default)
*/
async deleteInsight(insightId: number, user: User, hard = false): Promise<DbInsight> {
async deleteInsight(insightId: number, archiveRepo: boolean, user: User, hard = false): Promise<DbInsight> {
if (hard === true) {
throw new Error('Hard deletes of Insights are not yet supported.');
}
Expand All @@ -644,7 +644,7 @@ export class InsightService {
const insight = await getInsight(insightId);
const isMissing = await this.isRepositoryMissing(insight!.repository);

if (!isMissing) {
if (!isMissing && archiveRepo) {
// Archive GitHub repository
await archiveRepository(user.githubPersonalAccessToken!, existingInsight.externalId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface Props {
nextInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
previousInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
onClone: () => Promise<boolean>;
onDelete: () => Promise<boolean>;
onDelete: (archiveRepo: boolean) => Promise<boolean>;
onFetchLikedBy: (insightId?: string) => Promise<User[]>;
onLike: (liked: boolean) => Promise<boolean>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { iconFactory } from '../../../../../../shared/icon-factory';
interface Props {
insight: Insight;
isOpen: boolean;
onDelete: () => Promise<boolean>;
onDelete: (archiveRepo: boolean) => Promise<boolean>;
onClose: () => void;
}

Expand All @@ -47,9 +47,9 @@ export const DeleteDialog = ({ insight, isOpen, onDelete, onClose }: Props) => {
const [isDeleting, setDeleting] = useState(false);
const navigate = useNavigate();

const onDeleteInternal = async () => {
const onDeleteInternal = async (archiveRepo) => {
setDeleting(true);
const deleted = await onDelete();
const deleted = await onDelete(archiveRepo);
if (deleted) {
navigate('/');
} else {
Expand All @@ -73,18 +73,25 @@ export const DeleteDialog = ({ insight, isOpen, onDelete, onClose }: Props) => {
accessible.
</Text>
<Text>
The GitHub repository for the {titleize(insight.itemType)} will be archived rather than deleted. This
will make it read-only on GitHub, and it can be manually recovered later if necessary.
Based on your choice, the Github repository for this {titleize(insight.itemType)} can be either archived
or left untouched after the Insight is deleted.
</Text>
<Text>
If you click 'Delete' the Github repository will be left untouched, else if you click 'Delete & Archive'
the Github repository will be archived.
</Text>
</VStack>
</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>
Cancel
</Button>
<Button colorScheme="red" onClick={onDeleteInternal} ml={3} isLoading={isDeleting}>
<Button colorScheme="red" onClick={() => onDeleteInternal(false)} ml={3} isLoading={isDeleting}>
Delete
</Button>
<Button colorScheme="red" onClick={() => onDeleteInternal(true)} ml={3} isLoading={isDeleting}>
Delete & Archive
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Props {
nextInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
previousInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
onClone: () => Promise<boolean>;
onDelete: () => Promise<boolean>;
onDelete: (archiveRepo: boolean) => Promise<boolean>;
onFetchLikedBy: (insightId?: string) => Promise<User[]>;
onLike: (liked: boolean) => Promise<boolean>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Props {
nextInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
previousInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
onClone: () => Promise<boolean>;
onDelete: () => Promise<boolean>;
onDelete: (archiveRepo: boolean) => Promise<boolean>;
onFetchLikedBy: (insightId?: string) => Promise<User[]>;
onLike: (liked: boolean) => Promise<boolean>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ItemTypeViewerProps {
nextInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
previousInsight?: Pick<Insight, 'id' | 'name' | 'fullName' | 'itemType'>;
onClone: () => Promise<boolean>;
onDelete: () => Promise<boolean>;
onDelete: (archiveRepo: boolean) => Promise<boolean>;
onFetchLikedBy: (insightId?: string) => Promise<User[]>;
onLike: (liked: boolean) => Promise<boolean>;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/frontend/src/pages/insight-page/insight-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ export const InsightPage = ({ isExport = false }) => {
return true;
};

const onDelete = async (): Promise<boolean> => {
const onDelete = async (archiveRepo): Promise<boolean> => {
const { error } = await deleteInsight({
insightId: insight.id
insightId: insight.id,
archiveRepo: archiveRepo
});

if (error) {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/shared/useInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ const INSIGHT_QUERY = gql`
`;

const INSIGHT_DELETE_MUTATION = gql`
mutation InsightDelete($insightId: ID!) {
deleteInsight(insightId: $insightId)
mutation InsightDelete($insightId: ID!, $archiveRepo: Boolean!) {
deleteInsight(insightId: $insightId, archiveRepo: $archiveRepo)
}
`;

Expand Down