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

Added empty and error states for local UI #261

Merged
merged 1 commit into from
Mar 11, 2024
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
107 changes: 58 additions & 49 deletions pebblo/app/pebblo-ui/src/components/applicationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { GET_REPORT } from "../constants/routesConstant.js";
import { DownloadIcon, SearchIcon } from "../icons/index.js";
import { GET_FILE } from "../services/get.js";
import { waitForElement } from "../util.js";
import { EmptyState } from "./emptyState.js";
import { Button, Table, Td } from "./index.js";

// PROPS { title: string,
// PROPS { title: string,
// tableCol: Array<{
// label:string;
// field:string;
// align?:string;
// render?:(e)=>void
// }>,
// tableData: Array<unknown>,
// isDownloadReport?: boolean,
// searchField: Array < string >,
// isSorting?: boolean,
// link?: string,
// render?:(e)=>void
// }>,
// tableData: Array<unknown>,
// isDownloadReport?: boolean,
// searchField: Array < string >,
// isSorting?: boolean,
// link?: string,
// inputPlaceholder?: string }

export function ApplicationsList(props) {
Expand All @@ -28,7 +29,8 @@ export function ApplicationsList(props) {
searchField,
isSorting,
link,
inputPlaceholder = "Search"
inputPlaceholder = "Search",
error,
} = props;

window.addEventListener(LOAD, function () {
Expand Down Expand Up @@ -67,57 +69,64 @@ export function ApplicationsList(props) {
document.getElementsByTagName("tbody")[0].innerHTML = filteredData?.length
? `
${filteredData?.myMap(
(item) => /*html*/ `
(item) => /*html*/ `
<tr class="table-row">
${tableCol?.myMap((col) =>
Td({
children: col?.actions
? col?.actions(item)
: col?.render
? col?.render(item)
: item[col?.field],
align: col?.align,
link:
col?.field !== ACTIONS && link
? `${link}?app_name=${item?.name}`
: "",
maxWidth: col?.type === "label" ? "text-ellipsis" : "fit",
})
)}
Td({
children: col?.actions
? col?.actions(item)
: col?.render
? col?.render(item)
: item[col?.field],
align: col?.align,
link:
col?.field !== ACTIONS && link
? `${link}?app_name=${item?.name}`
: "",
maxWidth: col?.type === "label" ? "text-ellipsis" : "fit",
})
)}
</tr>`
)}
)}
`
: /*html*/ ` <tr class="table-row">
<td class="pt-3 pb-3 pl-3 pr-3 text-center" colspan="${tableCol?.length}">No Data Found</td>
</tr>`;
}

return /*html*/ `
<div class="application-container flex flex-col gap-4">
<div class="flex justify-between">
<div class="inter surface-10 font-16 medium">${title}</div>
<div class="flex">
<div class="search" title="Search">
<input type="text" id="search_field" name="search" placeholder="${inputPlaceholder}" autocomplete="off" />
${SearchIcon({ color: 'grey' })}
<div>
<div class="application-container flex flex-col gap-4">
<div class="flex justify-between">
<div class="inter surface-10 font-16 medium">${title}</div>
<div class="flex">
<div class="search" title="Search">
<input type="text" id="search_field" name="search" placeholder="${inputPlaceholder}" autocomplete="off" />
${SearchIcon({ color: "grey" })}
</div>
${
isDownloadReport
? /*html*/ `<div class="divider mt-2 mb-2 ml-4 mr-1"></div>
${Button({
btnText: "Download Reports",
startIcon: DownloadIcon({ color: "primary" }),
color: "primary",
})}`
: ""
}
</div>
</div>
${isDownloadReport
? /*html*/ `<div class="divider mt-2 mb-2 ml-4 mr-1"></div>
${Button({
btnText: "Download Reports",
startIcon: DownloadIcon({ color: "primary" }),
color: "primary"
})}`
: ""
}
${
!error
? Table({
tableCol,
tableData,
link,
isSorting,
})
: `<div>${EmptyState({ variant: error })}</div>`
}
</div>
</div>
${Table({
tableCol,
tableData,
link,
isSorting,
})}
</div>
</div>
`;
}
25 changes: 25 additions & 0 deletions pebblo/app/pebblo-ui/src/components/emptyState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { EMPTY_STATES } from "../constants/constant.js";
import { Button } from "./index.js";

export const EmptyState = (props) => {
const { image, heading, subHeading, buttonNodes } =
EMPTY_STATES[props?.variant];

return /*html*/ `
<div class="inter flex flex-col gap-4 justify-center items-center">
<img src=${image} alt="pebblo" height=${180} />
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-3">
<div class="font-24 medium">${heading}</div>
<div class="font-16 surface-80">${subHeading}</div>
</div>
${
buttonNodes?.length
? `<div class="flex justify-center gap-2">
${buttonNodes?.myMap((btnDetails) => Button({ ...btnDetails }))}
</div>`
: ""
}
</div>
</div>`;
};
92 changes: 51 additions & 41 deletions pebblo/app/pebblo-ui/src/components/snippetDetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { KEYUP } from "../constants/enums.js";
import { SearchIcon } from "../icons/index.js";
import { waitForElement } from "../util.js";
import { EmptyState } from "./emptyState.js";
import { KeyValue } from "./index.js";

// PROPS {
Expand All @@ -10,7 +11,7 @@ import { KeyValue } from "./index.js";
// }

export function SnippetDetails(props) {
const { title, data, searchField, inputPlaceholder } = props;
const { title, data, searchField, inputPlaceholder, error } = props;

waitForElement("#snippet_search", 1000).then(function () {
const inputEl = document.getElementById("snippet_search");
Expand Down Expand Up @@ -38,29 +39,31 @@ export function SnippetDetails(props) {
snippet_body.innerHTML = "";
snippet_body.innerHTML = filteredData?.length
? filteredData?.myMap(
(item) => /*html*/ `
(item) => /*html*/ `
<div class="flex flex-col gap-1">
<div class="snippet-header bg-main flex gap-2 pt-3 pb-3 pl-3 pr-3 inter items-center">
<div class="surface-10-opacity-65 font-14 medium">${item?.labelName
}</div>
<div class="surface-10-opacity-50 font-12">Showing ${item?.snippetCount
} out of ${item?.findings}</div>
<div class="surface-10-opacity-65 font-14 medium">${
item?.labelName
}</div>
<div class="surface-10-opacity-50 font-12">Showing ${
item?.snippetCount
} out of ${item?.findings}</div>
</div>
${item?.snippets?.myMap(
(snipp) => `
(snipp) => `
<div class="snippet-body flex flex-col gap-3 pr-3 pl-3 pt-3 pb-3">
${KeyValue({ key: "Snippets", value: snipp?.snippet })}
${KeyValue({
key: "Retrieved From",
value: snipp?.sourcePath,
})}
key: "Retrieved From",
value: snipp?.sourcePath,
})}
<div class="divider-horizontal"></div>
</div>
`
)}
)}
</div>
`
)
)
: /*html*/ `<div class="text-center pt-3 pb-3 pl-3 pr-3 inter surface-10 font-13 medium">No Data Found!!</div>`;
}

Expand All @@ -71,39 +74,46 @@ export function SnippetDetails(props) {
<div class="flex">
<div class="search">
<input type="text" id="snippet_search" placeholder="${inputPlaceholder}" autocomplete="off" />
${SearchIcon({ color: 'grey' })}
${SearchIcon({ color: "grey" })}
</div>
</div>
</div>
<div id="snippet_body" class="flex flex-col gap-10 h-full">
${data?.length
? data?.myMap(
(item) => /*html*/ `
<div class="flex flex-col gap-1">
<div class="snippet-header bg-main flex gap-2 pt-3 pb-3 pl-3 pr-3 inter items-center">
<div class="surface-10-opacity-65 font-14 medium">${item?.labelName
}</div>
<div class="surface-10-opacity-50 font-12">Showing ${item?.snippets?.length
} out of ${item?.snippetCount}</div>
</div>
${item?.snippets?.myMap(
(snipp) => `
<div class="snippet-body flex flex-col gap-3 pr-3 pl-3 pt-3 pb-3">
${KeyValue({ key: "Snippets", value: snipp?.snippet })}
${KeyValue({
key: "Retrieved From",
value: snipp?.sourcePath,
})}
<div class="divider-horizontal"></div>
</div>
`
)}
</div>
${
!error
? `<div id="snippet_body" class="flex flex-col gap-10 h-full">
${
data?.length
? data?.myMap(
(item) => /*html*/ `
<div class="flex flex-col gap-1">
<div class="snippet-header bg-main flex gap-2 pt-3 pb-3 pl-3 pr-3 inter items-center">
<div class="surface-10-opacity-65 font-14 medium">${
item?.labelName
}</div>
<div class="surface-10-opacity-50 font-12">Showing ${
item?.snippets?.length
} out of ${item?.snippetCount}</div>
</div>
${item?.snippets?.myMap(
(snipp) => `
<div class="snippet-body flex flex-col gap-3 pr-3 pl-3 pt-3 pb-3">
${KeyValue({ key: "Snippets", value: snipp?.snippet })}
${KeyValue({
key: "Retrieved From",
value: snipp?.sourcePath,
})}
<div class="divider-horizontal"></div>
</div>
`
)}
</div>
`
)
: /*html*/ `<div class="text-center pt-3 pb-3 pl-3 pr-3 inter surface-10 font-13 medium">No Data Found!!</div>`
}
</div>
)
: /*html*/ `<div class="text-center pt-3 pb-3 pl-3 pr-3 inter surface-10 font-13 medium">No Data Found!!</div>`
}
</div>`
: `<div>${EmptyState({ variant: error })}</div>`
}
</div>
`;
}
Loading