Skip to content

Commit 54d6492

Browse files
feat(adoption-insights): add frontend plugin for adoption insights unit tests and addressed review comments
1 parent e405481 commit 54d6492

File tree

8 files changed

+66
-30
lines changed

8 files changed

+66
-30
lines changed

workspaces/adoption-insights/plugins/adoption-insights/src/components/ActiveUsers/ActiveUsers.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const ActiveUsers = () => {
6565
}
6666

6767
return (
68-
<CardWrapper title="Active Users" filter={<ExportCSVButton />}>
68+
<CardWrapper title="Active users" filter={<ExportCSVButton />}>
6969
{loading ? (
7070
<Box
7171
display="flex"

workspaces/adoption-insights/plugins/adoption-insights/src/components/CatalogEntities/CatalogEntities.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ const CatalogEntities = () => {
165165
},
166166
}}
167167
>
168-
{entity.name}
168+
{entity.name ?? '--'}
169169
</Link>
170170
</TableCell>
171-
<TableCell>{entity.kind}</TableCell>
172-
<TableCell>{getLastUsedDay(entity.last_used)}</TableCell>
173-
<TableCell>{Number(entity.count).toLocaleString()}</TableCell>
171+
<TableCell>{entity.kind ?? '--'}</TableCell>
172+
<TableCell>
173+
{getLastUsedDay(entity.last_used) ?? '--'}
174+
</TableCell>
175+
<TableCell>
176+
{Number(entity.count).toLocaleString() ?? '--'}
177+
</TableCell>
174178
</TableRow>
175179
))
176180
)}

workspaces/adoption-insights/plugins/adoption-insights/src/components/Header/DateRangePicker.tsx

+23-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ const DateRangePicker: React.FC<DateRangePickerProps> = ({
4040
endDate,
4141
setEndDate,
4242
}) => {
43+
const startDateRef = React.useRef<HTMLInputElement | null>(null);
44+
const endDateRef = React.useRef<HTMLInputElement | null>(null);
45+
46+
React.useEffect(() => {
47+
if (!startDate && startDateRef.current) {
48+
startDateRef.current.focus();
49+
}
50+
if (startDate && !endDate && endDateRef.current) {
51+
endDateRef.current.focus();
52+
}
53+
}, [startDate, endDate]);
54+
4355
const handleDateChange = (date: Date | null) => {
4456
if (!date) return;
4557

@@ -117,7 +129,7 @@ const DateRangePicker: React.FC<DateRangePickerProps> = ({
117129
return (
118130
<LocalizationProvider dateAdapter={AdapterDateFns}>
119131
<Box>
120-
<Typography variant="h5" p={2} pb={0}>
132+
<Typography variant="h5" p={2} pb={0} fontWeight="400">
121133
Date range
122134
</Typography>
123135
<Divider sx={{ mt: 2 }} />
@@ -132,7 +144,11 @@ const DateRangePicker: React.FC<DateRangePickerProps> = ({
132144
value={startDate}
133145
onChange={handleStartDateChange}
134146
renderInput={params => (
135-
<TextField {...params} sx={{ width: 172 }} />
147+
<TextField
148+
{...params}
149+
sx={{ width: 172 }}
150+
inputRef={startDateRef}
151+
/>
136152
)}
137153
maxDate={new Date()}
138154
views={['day']}
@@ -145,7 +161,11 @@ const DateRangePicker: React.FC<DateRangePickerProps> = ({
145161
value={endDate}
146162
onChange={handleEndDateChange}
147163
renderInput={params => (
148-
<TextField {...params} sx={{ width: 172 }} />
164+
<TextField
165+
{...params}
166+
sx={{ width: 172 }}
167+
inputRef={endDateRef}
168+
/>
149169
)}
150170
maxDate={new Date()}
151171
views={['day']}

workspaces/adoption-insights/plugins/adoption-insights/src/components/Header/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const InsightsHeader: React.FC<InsightsHeaderProps> = ({ title }) => {
152152
handleDateRangeClick(event);
153153
}}
154154
>
155-
Date Range...
155+
Date range...
156156
</MenuItem>
157157
</Select>
158158

workspaces/adoption-insights/plugins/adoption-insights/src/components/Header/__tests__/Header.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ describe('InsightsHeader', () => {
112112
expect(screen.getByText('Last year')).toBeInTheDocument();
113113
});
114114

115-
it('should open date range picker when "Date Range..." is clicked', async () => {
115+
it('should open date range picker when "Date range..." is clicked', async () => {
116116
renderComponent();
117117
const select = screen.getByRole('combobox');
118118
await user.click(select);
119119

120-
const dateRangeOption = screen.getByText('Date Range...');
120+
const dateRangeOption = screen.getByText('Date range...');
121121
await user.click(dateRangeOption);
122122

123123
expect(screen.getByTestId('date-range-picker')).toBeInTheDocument();
@@ -140,7 +140,7 @@ describe('InsightsHeader', () => {
140140

141141
const select = screen.getByRole('combobox');
142142
await user.click(select);
143-
await user.click(screen.getByText('Date Range...'));
143+
await user.click(screen.getByText('Date range...'));
144144

145145
expect(screen.getByTestId('date-range-picker')).toBeInTheDocument();
146146

@@ -156,7 +156,7 @@ describe('InsightsHeader', () => {
156156

157157
const select = screen.getByRole('combobox');
158158
await user.click(select);
159-
await user.click(screen.getByText('Date Range...'));
159+
await user.click(screen.getByText('Date range...'));
160160

161161
expect(screen.getByTestId('date-range-picker')).toBeInTheDocument();
162162
});

workspaces/adoption-insights/plugins/adoption-insights/src/components/Plugins/Plugins.tsx

+17-13
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,25 @@ const Plugins = () => {
125125
},
126126
}}
127127
>
128-
{plugin.plugin_id}
128+
{plugin.plugin_id ?? '--'}
129129
</Link>
130130
</TableCell>
131131
<TableCell>
132-
<ResponsiveContainer width={250} height={50}>
133-
<LineChart data={plugin.trend}>
134-
<Line
135-
type="monotone"
136-
dataKey="count"
137-
stroke="#9370DB"
138-
strokeWidth={2}
139-
dot={false}
140-
/>
141-
</LineChart>
142-
</ResponsiveContainer>
132+
{plugin.trend?.length > 0 ? (
133+
<ResponsiveContainer width={250} height={50}>
134+
<LineChart data={plugin.trend}>
135+
<Line
136+
type="monotone"
137+
dataKey="count"
138+
stroke="#9370DB"
139+
strokeWidth={2}
140+
dot={false}
141+
/>
142+
</LineChart>
143+
</ResponsiveContainer>
144+
) : (
145+
'--'
146+
)}
143147
</TableCell>
144148
<TableCell>
145149
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
@@ -154,7 +158,7 @@ const Plugins = () => {
154158
</Box>
155159
</TableCell>
156160
<TableCell>
157-
{Number(plugin.visit_count).toLocaleString()}
161+
{Number(plugin.visit_count).toLocaleString() ?? '--'}
158162
</TableCell>
159163
</TableRow>
160164
))

workspaces/adoption-insights/plugins/adoption-insights/src/components/Techdocs/Techdocs.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ const Techdocs = () => {
134134
{parseEntityRef(techdoc.entityRef)?.name}
135135
</Link>
136136
</TableCell>
137-
<TableCell>{parseEntityRef(techdoc.entityRef)?.kind}</TableCell>
138-
<TableCell>{getLastUsedDay(techdoc.last_used)}</TableCell>
139-
<TableCell>{Number(techdoc.count).toLocaleString()}</TableCell>
137+
<TableCell>
138+
{parseEntityRef(techdoc.entityRef)?.kind ?? '--'}
139+
</TableCell>
140+
<TableCell>
141+
{getLastUsedDay(techdoc.last_used) ?? '--'}
142+
</TableCell>
143+
<TableCell>
144+
{Number(techdoc.count).toLocaleString() ?? '--'}
145+
</TableCell>
140146
</TableRow>
141147
))
142148
)}

workspaces/adoption-insights/plugins/adoption-insights/src/components/Templates/Templates.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ const Templates = () => {
133133
{parseEntityRef(template.entityRef).name}
134134
</Link>
135135
</TableCell>
136-
<TableCell>{Number(template.count).toLocaleString()}</TableCell>
136+
<TableCell>
137+
{Number(template.count).toLocaleString() ?? '--'}
138+
</TableCell>
137139
</TableRow>
138140
))
139141
)}

0 commit comments

Comments
 (0)