Skip to content

Commit

Permalink
sort by managed policy feature
Browse files Browse the repository at this point in the history
Signed-off-by: Mansi Shinde <[email protected]>
  • Loading branch information
MansiShinde committed Dec 11, 2023
1 parent 44da2ab commit d73fbad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function BackingIndices(props: SubDetailProps) {
{
field: "managed",
name: "Managed by policy",
sortable: false,
sortable: true,
truncateText: true,
textOnly: true,
render: renderNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,29 @@ exports[`<Indices /> spec renders the component 1`] = `
</button>
</th>
<th
aria-live="polite"
aria-sort="none"
class="euiTableHeaderCell"
data-test-subj="tableHeaderCell_managed_2"
role="columnheader"
scope="col"
>
<span
class="euiTableCellContent"
<button
class="euiTableHeaderButton"
data-test-subj="tableHeaderSortButton"
type="button"
>
<span
class="euiTableCellContent__text"
title="Managed by policy"
class="euiTableCellContent"
>
Managed by policy
<span
class="euiTableCellContent__text"
title="Managed by policy"
>
Managed by policy
</span>
</span>
</span>
</button>
</th>
<th
aria-live="polite"
Expand Down
2 changes: 1 addition & 1 deletion public/pages/Indices/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const getColumns = (props: IColumnOptions): EuiTableFieldDataColumnType<ManagedC
{
field: "managed",
name: "Managed by policy",
sortable: false,
sortable: true,
truncateText: true,
textOnly: true,
render: renderNumber,
Expand Down
32 changes: 25 additions & 7 deletions server/services/IndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ export default class IndexService {
const params: {
index: string;
format: string;
s: string;
s?: string;
expand_wildcards?: string;
} = {
index: getSearchString(terms, indices, dataStreams),
format: "json",
s: `${sortField}:${sortDirection}`,
// s: `${sortField}:${sortDirection}`,
};

if (sortField !== "managed" && sortField !== "data_stream") {
params.s = `${sortField}:${sortDirection}`;
}

if (expandWildcards) {
params.expand_wildcards = expandWildcards;
}
Expand Down Expand Up @@ -175,11 +179,25 @@ export default class IndexService {
body: {
ok: true,
response: {
indices: paginatedIndices.map((catIndex: CatIndex) => ({
...catIndex,
managed: managedStatus[catIndex.index] ? "Yes" : "No",
managedPolicy: managedStatus[catIndex.index],
})),
indices: paginatedIndices
.map((catIndex: CatIndex) => ({
...catIndex,
managed: managedStatus[catIndex.index] ? "Yes" : "No",
managedPolicy: managedStatus[catIndex.index],
}))
.sort((a, b) => {
let flag;
const aManaged = a.managed as string;
const bManaged = b.managed as string;

if (sortDirection === "asc") {
flag = aManaged < bManaged;
} else {
flag = aManaged > bManaged;
}

return flag ? -1 : 1;
}),
totalIndices: filteredIndices.length,
},
},
Expand Down

0 comments on commit d73fbad

Please sign in to comment.