Skip to content

Commit 5c5a406

Browse files
authored
[Snapshot & Restore] Add state filtering to snapshots list (#237254)
1 parent 710d5c5 commit 5c5a406

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

x-pack/platform/plugins/private/snapshot_restore/__jest__/client_integration/snapshot_list.test.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,52 @@ describe('<SnapshotList />', () => {
325325
});
326326
});
327327
});
328+
329+
describe('state', () => {
330+
test('partial state search is parsed', async () => {
331+
await setSearchText('state:SUCCESS');
332+
expect(useLoadSnapshots).lastCalledWith({
333+
...DEFAULT_SNAPSHOT_LIST_PARAMS,
334+
searchField: 'state',
335+
searchValue: 'SUCCESS',
336+
searchMatch: 'must',
337+
searchOperator: 'eq',
338+
});
339+
});
340+
341+
test('excluding partial state search is parsed', async () => {
342+
await setSearchText('-state:FAILED');
343+
expect(useLoadSnapshots).lastCalledWith({
344+
...DEFAULT_SNAPSHOT_LIST_PARAMS,
345+
searchField: 'state',
346+
searchValue: 'FAILED',
347+
searchMatch: 'must_not',
348+
searchOperator: 'eq',
349+
});
350+
});
351+
352+
test('exact state search is parsed', async () => {
353+
await setSearchText('state=IN_PROGRESS');
354+
expect(useLoadSnapshots).lastCalledWith({
355+
...DEFAULT_SNAPSHOT_LIST_PARAMS,
356+
searchField: 'state',
357+
searchValue: 'IN_PROGRESS',
358+
searchMatch: 'must',
359+
searchOperator: 'exact',
360+
});
361+
});
362+
363+
test('excluding exact state search is parsed', async () => {
364+
await setSearchText('-state=PARTIAL');
365+
expect(useLoadSnapshots).lastCalledWith({
366+
...DEFAULT_SNAPSHOT_LIST_PARAMS,
367+
searchField: 'state',
368+
searchValue: 'PARTIAL',
369+
searchMatch: 'must_not',
370+
searchOperator: 'exact',
371+
});
372+
});
373+
});
328374
});
329375

330376
describe('error handling', () => {

x-pack/platform/plugins/private/snapshot_restore/public/application/sections/home/snapshot_list/components/snapshot_search_bar.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const onlyOneClauseMessage = i18n.translate(
2828
defaultMessage: 'You can only use one clause in the search bar',
2929
}
3030
);
31-
// for now limit the search bar to snapshot, repository and policyName queries
31+
// for now limit the search bar to snapshot, repository, policyName and state queries
3232
const searchSchema: SchemaType = {
3333
strict: true,
3434
fields: {
@@ -41,6 +41,9 @@ const searchSchema: SchemaType = {
4141
policyName: {
4242
type: 'string',
4343
},
44+
state: {
45+
type: 'string',
46+
},
4447
},
4548
};
4649

@@ -118,6 +121,47 @@ export const SnapshotSearchBar: React.FunctionComponent<Props> = ({
118121
view: repository,
119122
})),
120123
},
124+
{
125+
type: 'field_value_selection' as const,
126+
field: 'state',
127+
name: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterLabel', {
128+
defaultMessage: 'State',
129+
}),
130+
operator: 'exact',
131+
multiSelect: false,
132+
options: [
133+
{
134+
value: 'SUCCESS',
135+
view: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterSuccess', {
136+
defaultMessage: 'Success',
137+
}),
138+
},
139+
{
140+
value: 'IN_PROGRESS',
141+
view: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterInProgress', {
142+
defaultMessage: 'In Progress',
143+
}),
144+
},
145+
{
146+
value: 'FAILED',
147+
view: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterFailed', {
148+
defaultMessage: 'Failed',
149+
}),
150+
},
151+
{
152+
value: 'PARTIAL',
153+
view: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterPartial', {
154+
defaultMessage: 'Partial',
155+
}),
156+
},
157+
{
158+
value: 'INCOMPATIBLE',
159+
view: i18n.translate('xpack.snapshotRestore.snapshotList.table.stateFilterIncompatible', {
160+
defaultMessage: 'Incompatible',
161+
}),
162+
},
163+
],
164+
},
121165
];
122166

123167
const reloadButton = (

x-pack/platform/plugins/private/snapshot_restore/server/routes/api/snapshots.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import type { TypeOf } from '@kbn/config-schema';
99
import { schema } from '@kbn/config-schema';
10+
import type { SnapshotSnapshotState } from '@elastic/elasticsearch/lib/api/types';
1011
import type { SnapshotDetailsEs } from '../../../common/types';
1112
import { deserializeSnapshotDetails } from '../../../common/lib';
1213
import type { RouteDependencies } from '../../types';
@@ -146,6 +147,9 @@ export function registerSnapshotsRoutes({
146147
operator: searchOperator,
147148
})
148149
: '*,_none',
150+
...(searchField === 'state' && searchValue
151+
? { state: searchValue as SnapshotSnapshotState }
152+
: {}),
149153
order: sortDirection,
150154
// @ts-expect-error sortField: string is not compatible with SnapshotSnapshotSort type
151155
sort: sortField,

x-pack/platform/plugins/private/snapshot_restore/server/routes/api/validate_schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const snapshotListSchema = schema.object({
4545
schema.literal('snapshot'),
4646
schema.literal('repository'),
4747
schema.literal('policyName'),
48+
schema.literal('state'),
4849
])
4950
),
5051
searchValue: schema.maybe(schema.string()),

0 commit comments

Comments
 (0)