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

chore: handle modal close on runbook creation and minor style changes #12

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
20 changes: 14 additions & 6 deletions keep-ui/app/runbooks/runbook-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TextInput,
Title,
Card,
Callout,
} from "@tremor/react";
import {
createColumnHelper,
Expand All @@ -27,6 +28,7 @@ import { fetcher } from "@/utils/fetcher";
import { useSession } from "next-auth/react";
import RunbookActions from "./runbook-actions";
import { RunbookDto, RunbookResponse } from "./models";
import { ExclamationCircleIcon } from "@heroicons/react/20/solid";

const customStyles = {
content: {
Expand Down Expand Up @@ -123,7 +125,7 @@ function SettingsPage() {
handleSubmit: submitHandler,
provider,
fileData,
} = useRunBookTriggers(getValues(), refresh);
} = useRunBookTriggers(getValues(), refresh, setIsModalOpen);

const selectedProviderId = watch(
"providerId",
Expand Down Expand Up @@ -269,7 +271,7 @@ function RunbookIncidentTable() {

let shouldFetch = session?.accessToken ? true : false;

const { data: runbooksData, error } = useSWR<RunbookResponse>(
const { data: runbooksData, error, isLoading } = useSWR<RunbookResponse>(
shouldFetch
? `${getApiURL()}/runbooks?limit=${limit}&offset=${offset}`
: null,
Expand Down Expand Up @@ -301,13 +303,13 @@ function RunbookIncidentTable() {
};

return (
<div className="flex flex-col h-full gap-4">
<div className="flex justify-between items-center h-[10%]">
<div className="flex flex-col gap-4">
<div className="flex justify-between items-center">
<Title>Runbook</Title>
<SettingsPage />
</div>
<Card className="flex-1 overflow-auto">
{!!total_count && (
<Card className="flex-grow">
{!isLoading && !error && (
<GenericTable<RunbookDto>
data={runbooks}
columns={columnsv2}
Expand All @@ -322,6 +324,12 @@ function RunbookIncidentTable() {
isRowSelectable={true}
/>
)}
{error && (
<Callout title={""}>
<ExclamationCircleIcon className="h-6 w-6 text-red-600" />
Something went wrong. please try again or reach out support team.
</Callout>
)}
</Card>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions keep-ui/components/table/GenericTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function GenericTable<T>({

return (
<div className="flex flex-col w-full h-full max-h-full">
<div className="overflow-auto h-1/2">
<div className="overflow-auto h-[85%]">
{!!selectedRowIds.length && getActions && <div className="mb-2">{getActions(table, selectedRowIds)}</div>}
<TremorTable className="w-full rounded border border-tremor-border dark:border-dark-tremor-border">
<TableHead>
Expand Down Expand Up @@ -183,7 +183,7 @@ export function GenericTable<T>({
</TableBody>
</TremorTable>
</div>
<div className="mt-4">
<div className="mt-4 h-[15%]">
{pagination&&<Pagination
table={table}
isRefreshAllowed={false}
Expand Down
22 changes: 12 additions & 10 deletions keep-ui/utils/hooks/useRunbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import { debounce } from "lodash";
import { useSession } from "next-auth/react";
import { toast } from "react-toastify";

export const useRunBookTriggers = (values: any, refresh: number) => {
export const useRunBookTriggers = (values: any, refresh: number, setIsModalOpen: React.Dispatch<React.SetStateAction<boolean>>) => {
const providersData = useProviders();
const [error, setError] = useState("");
const [synced, setSynced] = useState(false);
const [fileData, setFileData] = useState<any>({});
const [reposData, setRepoData] = useState<any>([]);
const { pathToMdFile, repoName, userName, providerId, domain } = values || {};
const { providerId } = values || {};
const { data: session } = useSession();
const { installed_providers, providers } = (providersData?.data ||
const { installed_providers } = (providersData?.data ||
{}) as ProvidersResponse;
const runBookInstalledProviders =
installed_providers?.filter((provider) =>
Expand All @@ -41,6 +39,7 @@ export const useRunBookTriggers = (values: any, refresh: number) => {
setRepoData(data);
} catch (err) {
console.log("error occurred while fetching data");
toast.error("Failed to fetch repositories. Please check the provider settings.");
setRepoData([]);
}
};
Expand Down Expand Up @@ -83,20 +82,23 @@ export const useRunBookTriggers = (values: any, refresh: number) => {
});

if (!response) {
return setError("Something went wrong. try agian after some time");
toast.error("Failed to create runbook. Something went wrong, please try again later.");
return;
}

if(!response.ok) {
return setError("Something went wrong. try agian after some time");
toast.error("Failed to create runbook. Something went wrong, please try again later.");
return;

}
const result = await response.json();
setFileData(result);
setSynced(false);
setIsModalOpen(false);
toast.success("Runbook created successfully");
} catch (err) {
return setError("Something went wrong. try agian after some time");
return;
} finally {
setSynced(true);

}
};

Expand Down
Loading