Skip to content

Commit

Permalink
Merge pull request #838 from tailwarden/develop
Browse files Browse the repository at this point in the history
v3.0.18 release 🚀
  • Loading branch information
mlabouardy authored Jun 3, 2023
2 parents 811cf10 + d750465 commit 1ce65f8
Show file tree
Hide file tree
Showing 33 changed files with 1,523 additions and 766 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG SEGMENT_WRITE_KEY
ARG VERSION
MAINTAINER mlabouardy <[email protected]>
LABEL MAINTAINER="mlabouardy <[email protected]>"

RUN echo "Running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log

Expand All @@ -15,4 +15,4 @@ RUN chmod +x /usr/bin/komiser && \
mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2

EXPOSE $PORT
ENTRYPOINT ["komiser", "start"]
ENTRYPOINT ["komiser", "start"]
10 changes: 9 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ import (
"golang.org/x/text/language"
)

const logo = `
_ __ _
| |/ /___ _ __ ___ (_)___ ___ _ __
| ' // _ \| '_ \ _ \| / __|/ _ \ '__|
| . \ (_) | | | | | | \__ \ __/ |
|_|\_\___/|_| |_| |_|_|___/\___|_|
`

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show tool version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Komiser")
fmt.Println(logo)
showLine(cmd, "Version", internal.Version)
showLine(cmd, "Go version", internal.GoVersion)
showLine(cmd, "Commit", internal.Commit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ function useCostExplorerChart({
)}`;
},
label(chart) {
return `${chart.dataset.label}: $${formatNumber(
Number(chart.formattedValue)
)}`;
return `${chart.dataset.label}: ${chart.formattedValue}`;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,123 @@
import { ToastProps } from '../../../../toast/hooks/useToast';
import useSlackAlerts from './hooks/useSlackAlerts';
import InventoryViewAlertsDisplay from './InventoryViewAlertsDisplay';
import InventoryViewAlertsEditSlackAlert from './InventoryViewAlertsEditSlackAlert';
import useAlerts from './hooks/useAlerts';
import InventoryViewAlertsDeleteAlert from './InventoryViewAlertsDeleteAlert';
import InventoryViewAlertDisplayAlerts from './InventoryViewAlertsDisplay';
import InventoryViewAlertsCreateOrEditAlert from './InventoryViewAlertsEditAlert';
import InventoryViewAlertsError from './InventoryViewAlertsError';
import InventoryViewAlertHasNoSlackAlerts from './InventoryViewAlertsHasNoSlackAlerts';
import InventoryViewAlertHasNoSlackIntegration from './InventoryViewAlertsHasNoSlackIntegration';
import InventoryViewAlertHasNoExistingAlerts from './InventoryViewAlertsHasNoAlerts';
import InventoryViewAlertsSkeleton from './InventoryViewAlertsSkeleton';
import InventoryViewAlertsChooseAlertMethod from './InventoryViewAlertsChooseAlertMethod';

type InventoryViewAlertsProps = {
viewId: number;
setToast: (toast: ToastProps | undefined) => void;
};

const viewControllerOptions = {
NO_ALERTS_OR_EXSITING_ALERTS: 0,
CHOOSE_ALERT_METHOD: 1,
CREATE_OR_EDIT_ALERT: 2,
DELETE_ALERT: 3
};

function InventoryViewAlerts({ viewId, setToast }: InventoryViewAlertsProps) {
const {
loading,
error,
hasSlack,
slackAlerts,
hasNoSlackAlerts,
editSlackAlert,
currentSlackAlert,
createOrEditSlackAlert,
closeSlackAlert,
hasAlerts,
isSlackConfigured,
alerts,
alertsViewController,
editAlert,
alertMethod,
currentAlert,
setAlertMethodInAndIncrementViewController,
setViewControllerToAlertsBaseView,
setViewControllerToDeleteView,
createOrEditAlert,
incrementViewController,
decrementViewController,
closeAlert,
fetchViewAlerts
} = useSlackAlerts({ viewId });

if (loading) return <InventoryViewAlertsSkeleton />;
} = useAlerts({ viewId });

if (error)
if (loading) {
return <InventoryViewAlertsSkeleton />;
}
if (error) {
return <InventoryViewAlertsError fetchViewAlerts={fetchViewAlerts} />;
}

if (!hasSlack) return <InventoryViewAlertHasNoSlackIntegration />;

if (hasNoSlackAlerts)
return (
<InventoryViewAlertHasNoSlackAlerts
createOrEditSlackAlert={createOrEditSlackAlert}
/>
);

if (editSlackAlert)
return (
<InventoryViewAlertsEditSlackAlert
currentSlackAlert={currentSlackAlert}
closeSlackAlert={closeSlackAlert}
viewId={viewId}
setToast={setToast}
/>
);
switch (alertsViewController) {
case viewControllerOptions.NO_ALERTS_OR_EXSITING_ALERTS:
if (!hasAlerts) {
return (
<InventoryViewAlertHasNoExistingAlerts
incrementViewController={incrementViewController}
/>
);
}
if (editAlert) {
return (
<InventoryViewAlertsCreateOrEditAlert
alertMethod={alertMethod}
setViewControllerOnSubmit={setViewControllerToAlertsBaseView}
setViewControllerOnClickingBackButton={
setViewControllerToAlertsBaseView
}
setViewControllerOnDelete={setViewControllerToDeleteView}
currentAlert={currentAlert}
closeAlert={closeAlert}
viewId={viewId}
setToast={setToast}
/>
);
}
return (
<InventoryViewAlertDisplayAlerts
alerts={alerts}
createOrEditAlert={createOrEditAlert}
setViewControllerOnAddAlert={incrementViewController}
/>
);

return (
<InventoryViewAlertsDisplay
slackAlerts={slackAlerts}
createOrEditSlackAlert={createOrEditSlackAlert}
/>
);
case viewControllerOptions.CHOOSE_ALERT_METHOD:
return (
<InventoryViewAlertsChooseAlertMethod
setAlertMethodInViewController={
setAlertMethodInAndIncrementViewController
}
setViewControllerOnClickingBackButton={decrementViewController}
isSlackConfigured={isSlackConfigured}
/>
);
case viewControllerOptions.CREATE_OR_EDIT_ALERT:
return (
<InventoryViewAlertsCreateOrEditAlert
alertMethod={alertMethod}
setViewControllerOnSubmit={setViewControllerToAlertsBaseView}
setViewControllerOnClickingBackButton={decrementViewController}
setViewControllerOnDelete={incrementViewController}
currentAlert={currentAlert}
closeAlert={closeAlert}
viewId={viewId}
setToast={setToast}
/>
);
case viewControllerOptions.DELETE_ALERT:
return (
<InventoryViewAlertsDeleteAlert
alertMethod={alertMethod}
viewControllerOnCancelButton={decrementViewController}
currentAlert={currentAlert}
closeAlert={closeAlert}
viewId={viewId}
setToast={setToast}
/>
);
default:
return null;
}
}

export default InventoryViewAlerts;
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Image from 'next/image';
import ChevronRightIcon from '../../../../icons/ChevronRightIcon';
import ArrowLeftIcon from '../../../../icons/ArrowLeftIcon';
import { AlertMethod } from './hooks/useAlerts';

type InventoryViewAlertsChooseAlertMethodProps = {
setAlertMethodInViewController: (alertName: AlertMethod) => void;
setViewControllerOnClickingBackButton: () => void;
isSlackConfigured: boolean;
};

function InventoryViewAlertsChooseAlertMethod({
setAlertMethodInViewController,
setViewControllerOnClickingBackButton,
isSlackConfigured
}: InventoryViewAlertsChooseAlertMethodProps) {
const webhookOptions = [
{
id: AlertMethod.SLACK,
name: 'Slack',
message: 'Get directly notified to take action',
image: '/assets/img/others/slack.svg',
alt: 'Slack logo'
},
{
id: AlertMethod.WEBHOOK,
name: 'Webhook',
message: 'Integrate actions into your system',
image: '/assets/img/others/custom-webhook.svg',
alt: 'Webhook logo'
}
];

return (
<div className="flex flex-col gap-4">
<div
onClick={() => setViewControllerOnClickingBackButton()}
className="flex cursor-pointer items-center gap-2 self-start text-sm text-black-900"
>
<ArrowLeftIcon width={24} height={24} />
Pick a Handler
</div>

{webhookOptions?.map(alert => (
<div key={alert.id}>
<div
onClick={() => {
if (alert.id !== AlertMethod.SLACK || isSlackConfigured) {
setAlertMethodInViewController(alert.id);
}
}}
className={`flex cursor-pointer select-none items-center justify-between rounded-lg border border-black-170 p-6 hover:border-black-200
${
alert.id === AlertMethod.SLACK && !isSlackConfigured
? 'pointer-events-none bg-gray-200'
: ''
}`}
>
<div className="flex items-center gap-4">
<Image src={alert.image} height={42} width={42} alt={alert.alt} />
<div className="flex flex-col">
<p className="font-semibold text-black-900">{alert.name}</p>
<p className="text-xs text-black-400">{alert.message}</p>
</div>
</div>
<ChevronRightIcon width={24} height={24} />
</div>

{alert.id === AlertMethod.SLACK && !isSlackConfigured && (
<div className="mt-2">
<p className="text-xs text-black-400">
You have not set up your Slack integration. Learn how through
our{' '}
<a
href="https://docs.komiser.io/docs/introduction/getting-started/#slack-integration-alerts"
target="_blank"
rel="noreferrer"
className="text-primary"
>
<u>guide</u>
</a>
.
</p>
</div>
)}
</div>
))}
</div>
);
}

export default InventoryViewAlertsChooseAlertMethod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Image from 'next/image';
import Button from '../../../../button/Button';
import { AlertMethod, Alert } from './hooks/useAlerts';
import useEditAlerts from './hooks/useEditAlerts';
import { ToastProps } from '../../../../toast/hooks/useToast';

type InventoryViewAlertsDeleteAlertProps = {
alertMethod: AlertMethod;
closeAlert: (action?: 'hasChanges' | undefined) => void;
viewId: number;
setToast: (toast: ToastProps | undefined) => void;
viewControllerOnCancelButton: () => void;
currentAlert: Alert | undefined;
};

function InventoryViewAlertsDeleteAlert({
alertMethod,
viewId,
closeAlert,
setToast,
viewControllerOnCancelButton,
currentAlert
}: InventoryViewAlertsDeleteAlertProps) {
const { deleteAlert, loading } = useEditAlerts({
alertMethod,
currentAlert,
viewId,
closeAlert,
setToast
});
return (
<div className="rounded-lg bg-komiser-100 p-6">
<div className="flex flex-col items-center gap-6">
<Image
src="/assets/img/others/warning.svg"
alt="Purplin"
width={48}
height={48}
className="mx-auto flex-shrink-0"
/>
<div className="mb-8 flex flex-col items-center gap-2 px-4">
<p className="text-center font-semibold text-black-900">
Are you sure you want to delete this alert?
</p>
<p className="text-center text-sm text-black-400">
By deleting the “{currentAlert?.name}{' '}
{currentAlert?.isSlack ? 'slack' : 'webhook'} alert, you won’t
receive any more notifications regarding the cost limit you set up.
</p>
</div>
</div>
<div className="flex items-center justify-end">
<div className="flex gap-4">
<Button
style="ghost"
size="lg"
onClick={viewControllerOnCancelButton}
>
Cancel
</Button>
<Button
size="sm"
style="delete"
type="button"
onClick={() => {
viewControllerOnCancelButton();
if (currentAlert) {
deleteAlert(currentAlert.id);
}
}}
loading={loading}
>
Delete alert
</Button>
</div>
</div>
</div>
);
}

export default InventoryViewAlertsDeleteAlert;
Loading

0 comments on commit 1ce65f8

Please sign in to comment.