Skip to content

Commit 3d09ce9

Browse files
committed
feat: add exclude and include tags fields to entry popups
1 parent dcd034b commit 3d09ce9

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

ui/src/dashboard/Entry/AddPopup.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as gqlDashboard from '../../gql/dashboard';
1010
import {Fade} from '../../common/Fade';
1111
import {DashboardEntryForm, isValidDashboardEntry} from './DashboardEntryForm';
1212
import {AddDashboardEntry, AddDashboardEntryVariables} from '../../gql/__generated__/AddDashboardEntry';
13+
import {handleError} from '../../utils/errors';
14+
import {useSnackbar} from 'notistack';
1315

1416
interface EditPopupProps {
1517
dashboardId: number;
@@ -38,6 +40,9 @@ export const AddPopup: React.FC<EditPopupProps> = ({
3840
refetchQueries: [{query: gqlDashboard.Dashboards}],
3941
});
4042
const valid = isValidDashboardEntry(entry);
43+
44+
const {enqueueSnackbar} = useSnackbar();
45+
4146
return (
4247
<Popper
4348
key="popup"
@@ -89,6 +94,8 @@ export const AddPopup: React.FC<EditPopupProps> = ({
8994
}
9095
: null,
9196
rangeId: entry.statsSelection.rangeId,
97+
excludeTags: entry.statsSelection.excludeTags,
98+
includeTags: entry.statsSelection.includeTags,
9299
},
93100
pos: {
94101
desktop: {
@@ -99,7 +106,9 @@ export const AddPopup: React.FC<EditPopupProps> = ({
99106
},
100107
},
101108
},
102-
}).then(finish);
109+
})
110+
.then(finish)
111+
.catch(handleError('Add Dashboard Entry', enqueueSnackbar));
103112
}}>
104113
Add
105114
</Button>

ui/src/dashboard/Entry/DashboardEntryForm.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import InputLabel from '@material-ui/core/InputLabel';
55
import Select from '@material-ui/core/NativeSelect/NativeSelect';
66
import {EntryType, StatsInterval} from '../../gql/__generated__/globalTypes';
77
import {TagKeySelector} from '../../tag/TagKeySelector';
8+
import {TagFilterSelector} from '../../tag/TagFilterSelector';
89
import {Dashboards_dashboards_items, Dashboards_dashboards_items_statsSelection_range} from '../../gql/__generated__/Dashboards';
910
import {RelativeDateTimeSelector} from '../../common/RelativeDateTimeSelector';
1011
import {parseRelativeTime} from '../../utils/time';
@@ -31,6 +32,27 @@ export const isValidDashboardEntry = (item: Dashboards_dashboards_items): boolea
3132
export const DashboardEntryForm: React.FC<EditPopupProps> = ({entry, onChange: setEntry, disabled = false, ranges}) => {
3233
const [staticRange, setStaticRange] = React.useState(!entry.statsSelection.rangeId);
3334

35+
const [excludeTags, setExcludeTags] = React.useState(
36+
(entry.statsSelection.excludeTags || []).map((tag) => ({
37+
tag: {
38+
key: tag.key,
39+
color: '',
40+
__typename: 'TagDefinition' as 'TagDefinition',
41+
},
42+
value: tag.value,
43+
}))
44+
);
45+
const [includeTags, setIncludeTags] = React.useState(
46+
(entry.statsSelection.includeTags || []).map((tag) => ({
47+
tag: {
48+
key: tag.key,
49+
color: '',
50+
__typename: 'TagDefinition' as 'TagDefinition',
51+
},
52+
value: tag.value,
53+
}))
54+
);
55+
3456
const range: Dashboards_dashboards_items_statsSelection_range = entry.statsSelection.range
3557
? entry.statsSelection.range
3658
: {
@@ -189,6 +211,32 @@ export const DashboardEntryForm: React.FC<EditPopupProps> = ({entry, onChange: s
189211
setEntry(entry);
190212
}}
191213
/>
214+
<TagFilterSelector
215+
type="Exclude"
216+
value={excludeTags}
217+
onChange={(tags) => {
218+
setExcludeTags(tags);
219+
entry.statsSelection.excludeTags = tags.map((tag) => ({
220+
key: tag.tag.key,
221+
value: tag.value,
222+
__typename: 'TimeSpanTag',
223+
}));
224+
setEntry(entry);
225+
}}
226+
/>
227+
<TagFilterSelector
228+
type="Include"
229+
value={includeTags}
230+
onChange={(tags) => {
231+
setIncludeTags(tags);
232+
entry.statsSelection.includeTags = tags.map((tag) => ({
233+
key: tag.tag.key,
234+
value: tag.value,
235+
__typename: 'TimeSpanTag',
236+
}));
237+
setEntry(entry);
238+
}}
239+
/>
192240
</>
193241
);
194242
};

ui/src/dashboard/Entry/EditPopup.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as gqlDashboard from '../../gql/dashboard';
1010
import {UpdateDashboardEntry, UpdateDashboardEntryVariables} from '../../gql/__generated__/UpdateDashboardEntry';
1111
import {Fade} from '../../common/Fade';
1212
import {DashboardEntryForm, isValidDashboardEntry} from './DashboardEntryForm';
13+
import {handleError} from '../../utils/errors';
14+
import {useSnackbar} from 'notistack';
1315

1416
interface EditPopupProps {
1517
entry: Dashboards_dashboards_items;
@@ -24,6 +26,9 @@ export const EditPopup: React.FC<EditPopupProps> = ({entry, anchorEl, onChange:
2426
refetchQueries: [{query: gqlDashboard.Dashboards}],
2527
});
2628
const valid = isValidDashboardEntry(entry);
29+
30+
const {enqueueSnackbar} = useSnackbar();
31+
2732
return (
2833
<Popper
2934
key="popup"
@@ -75,9 +80,13 @@ export const EditPopup: React.FC<EditPopupProps> = ({entry, anchorEl, onChange:
7580
}
7681
: null,
7782
rangeId: entry.statsSelection.rangeId,
83+
excludeTags: entry.statsSelection.excludeTags,
84+
includeTags: entry.statsSelection.includeTags,
7885
},
7986
},
80-
}).then(() => setEdit(null));
87+
})
88+
.then(() => setEdit(null))
89+
.catch(handleError('Edit Dashboard Entry', enqueueSnackbar));
8190
}}>
8291
Save
8392
</Button>

0 commit comments

Comments
 (0)