Skip to content

Commit add779e

Browse files
committed
Some cleanup
1 parent df24506 commit add779e

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Placeholder} from 'sentry/components/placeholder';
2+
import {ProjectList} from 'sentry/components/projectList';
3+
import {EmptyCell} from 'sentry/components/workflowEngine/gridCell/emptyCell';
4+
import type {Automation} from 'sentry/types/workflowEngine/automations';
5+
import {useAutomationProjectSlugs} from 'sentry/views/automations/hooks/utils';
6+
7+
export function ProjectsCell({automation}: {automation: Automation}) {
8+
const {projectSlugs, isLoading: isProjectsLoading} =
9+
useAutomationProjectSlugs(automation);
10+
11+
if (isProjectsLoading) {
12+
return <Placeholder height="20px" />;
13+
}
14+
15+
if (projectSlugs.length === 0) {
16+
return <EmptyCell />;
17+
}
18+
19+
return <ProjectList projectSlugs={projectSlugs} />;
20+
}

static/app/views/automations/components/automationListTable/row.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ import {Flex} from '@sentry/scraps/layout';
55

66
import {hasEveryAccess} from 'sentry/components/acl/access';
77
import {Placeholder} from 'sentry/components/placeholder';
8-
import {ProjectList} from 'sentry/components/projectList';
98
import {SimpleTable} from 'sentry/components/tables/simpleTable';
109
import {ActionCell} from 'sentry/components/workflowEngine/gridCell/actionCell';
1110
import {AutomationTitleCell} from 'sentry/components/workflowEngine/gridCell/automationTitleCell';
12-
import {EmptyCell} from 'sentry/components/workflowEngine/gridCell/emptyCell';
1311
import {TimeAgoCell} from 'sentry/components/workflowEngine/gridCell/timeAgoCell';
14-
import {ProjectsStore} from 'sentry/stores/projectsStore';
1512
import type {Automation} from 'sentry/types/workflowEngine/automations';
1613
import {useOrganization} from 'sentry/utils/useOrganization';
1714
import {AutomationListConnectedDetectors} from 'sentry/views/automations/components/automationListTable/connectedDetectors';
18-
import {
19-
getAutomationActions,
20-
useAutomationProjectIds,
21-
} from 'sentry/views/automations/hooks/utils';
15+
import {ProjectsCell} from 'sentry/views/automations/components/automationListTable/projectsCell';
16+
import {getAutomationActions} from 'sentry/views/automations/hooks/utils';
2217

2318
type AutomationListRowProps = {
2419
automation: Automation;
@@ -36,10 +31,6 @@ export function AutomationListRow({
3631

3732
const actions = getAutomationActions(automation);
3833
const {enabled, lastTriggered, detectorIds = []} = automation;
39-
const {projectIds, isLoading: isProjectsLoading} = useAutomationProjectIds(automation);
40-
const projectSlugs = projectIds.map(
41-
projectId => ProjectsStore.getById(projectId)?.slug
42-
) as string[];
4334

4435
return (
4536
<AutomationSimpleTableRow
@@ -67,13 +58,7 @@ export function AutomationListRow({
6758
<ActionCell actions={actions} disabled={!enabled} />
6859
</SimpleTable.RowCell>
6960
<SimpleTable.RowCell data-column-name="projects">
70-
{isProjectsLoading ? (
71-
<Placeholder height="20px" />
72-
) : projectSlugs.length > 0 ? (
73-
<ProjectList projectSlugs={projectSlugs} />
74-
) : (
75-
<EmptyCell />
76-
)}
61+
<ProjectsCell automation={automation} />
7762
</SimpleTable.RowCell>
7863
<SimpleTable.RowCell data-column-name="connected-monitors">
7964
<AutomationListConnectedDetectors detectorIds={detectorIds} />

static/app/views/automations/hooks/utils.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {t} from 'sentry/locale';
2+
import {ProjectsStore} from 'sentry/stores/projectsStore';
23
import {ActionType} from 'sentry/types/workflowEngine/actions';
34
import type {Automation, StatusWarning} from 'sentry/types/workflowEngine/automations';
45
import type {DataConditionGroup} from 'sentry/types/workflowEngine/dataConditions';
@@ -52,18 +53,21 @@ export function getAutomationActionsWarning(
5253
return null;
5354
}
5455

55-
export function useAutomationProjectIds(automation: Automation): {
56-
isLoading: boolean;
57-
projectIds: string[];
58-
} {
56+
export function useAutomationProjectSlugs(automation: Automation) {
5957
const {data: detectors, isLoading} = useDetectorsQuery(
6058
{ids: automation.detectorIds},
6159
{enabled: automation.detectorIds.length > 0}
6260
);
61+
6362
const projectIds = [
6463
...new Set(detectors?.map(detector => detector.projectId).filter(x => x) ?? []),
6564
] as string[];
66-
return {projectIds, isLoading};
65+
66+
const projectSlugs = projectIds.map(
67+
projectId => ProjectsStore.getById(projectId)?.slug
68+
) as string[];
69+
70+
return {projectSlugs, isLoading};
6771
}
6872

6973
export function findConflictingConditions(

0 commit comments

Comments
 (0)