Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing search feature #1286

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dashboards-observability/public/components/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const Home = ({
const resolutionSelectId = htmlIdGenerator('resolutionSelect')();
const [toasts, setToasts] = useState<Toast[]>([]);
const [toastRightSide, setToastRightSide] = useState<boolean>(true);
const [search, setSearch] = useState<boolean>(false);

// Side bar constants
const [isSidebarClosed, setIsSidebarClosed] = useState(false);
Expand Down Expand Up @@ -170,13 +171,16 @@ export const Home = ({
resolutionSelectId={resolutionSelectId}
savedObjects={savedObjects}
setToast={setToast}
setSearch={setSearch}
/>
<div className="dscAppContainer">
<div
className={`col-md-2 dscSidebar__container dscCollapsibleSidebar ${sidebarClassName}`}
>
<div className="">
{!isSidebarClosed && <Sidebar http={http} pplService={pplService} />}
{!isSidebarClosed && (
<Sidebar http={http} pplService={pplService} search={search} />
)}
<EuiButtonIcon
iconType={isSidebarClosed ? 'menuRight' : 'menuLeft'}
iconSize="m"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const initialState = {
pplService: PPLService,
metrics: [],
selected: [],
searched: [],
metricsLayout: [],
};

Expand Down Expand Up @@ -120,19 +121,34 @@ export const metricSlice = createSlice({
updateLayoutByDeSelection(state, payload);
state.selected = state.selected.filter((id) => id !== payload.id);
},
searchMetric: (state, { payload }) => {
state.searched = state.metrics.filter(
(metric: any) => metric.name.includes(payload.id) && !state.selected.includes(payload.id)
);
},
clearSearchedMetrics: (state, { payload }) => {
state.searched = [];
},
updateMetricsLayout: (state, { payload }) => {
state.metricsLayout = payload;
},
},
extraReducers: (builder) => {
builder.addCase(loadMetrics.fulfilled, (state, { payload }) => {
state.metrics = payload;
state.searched = [];
filterDeletedLayoutIds(state, payload);
});
},
});

export const { deSelectMetric, selectMetric, updateMetricsLayout } = metricSlice.actions;
export const {
deSelectMetric,
selectMetric,
updateMetricsLayout,
searchMetric,
clearSearchedMetrics,
} = metricSlice.actions;

export const metricsStateSelector = (state) => state.metrics;

Expand All @@ -149,6 +165,9 @@ export const recentlyCreatedMetricsSelector = (state) =>
(metric) => !state.metrics.selected.includes(metric.id) && metric.recentlyCreated
);

export const searchedMetricsSelector = (state) =>
state.metrics.searched.filter((metric) => !state.metrics.selected.includes(metric.id));

export const allAvailableMetricsSelector = (state) =>
state.metrics.metrics.filter((metric) => !state.metrics.selected.includes(metric.id));

Expand Down
Loading