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

hide alerts on distributed mode #326

Merged
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
13 changes: 11 additions & 2 deletions src/components/Misc/RestrictedView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Stack, Text } from '@mantine/core';

const RestrictedView = () => {
const defaultMsg = 'Access restricted, Please contact your administrator.';

type RestrictedViewOpts = {
msg?: string;
};

const RestrictedView = (opts: RestrictedViewOpts) => {
const msg = opts.msg || defaultMsg;
return (
<Stack
style={{
Expand All @@ -11,7 +18,9 @@ const RestrictedView = () => {
justifyContent: 'center',
}}>
<Stack>
<Text ta="center" c='gray.6'>Access restricted, Please contact your administrator.</Text>
<Text ta="center" c="gray.6">
{msg}
</Text>
</Stack>
</Stack>
);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useAlertsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { AxiosError, isAxiosError } from 'axios';
import { useStreamStore, streamStoreReducers } from '@/pages/Stream/providers/StreamProvider';
const { setAlertsConfig } = streamStoreReducers;

const useAlertsQuery = (streamName: string, hasAlertsAccess: boolean) => {
const useAlertsQuery = (streamName: string, hasAlertsAccess: boolean, isStandAloneMode: boolean | null) => {
const [, setStreamStore] = useStreamStore((_store) => null);
const { data, isError, isSuccess, isLoading, refetch } = useQuery(
['fetch-log-stream-alert', streamName, hasAlertsAccess],
() => getLogStreamAlerts(streamName),
{
retry: false,
enabled: streamName !== '' && hasAlertsAccess,
enabled: streamName !== '' && hasAlertsAccess && !!isStandAloneMode,
refetchOnWindowFocus: false,
onSuccess: (data) => {
setStreamStore((store) => setAlertsConfig(store, data));
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Stream/Views/Manage/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ const Alerts = (props: {
isError: boolean;
hasAlertsAccess: boolean;
updateAlerts: ({ config, onSuccess }: { config: any; onSuccess?: () => void }) => void;
isStandAloneMode: boolean | null;
}) => {
const [alertName, setAlertName] = useState<string>('');
const [alertModalOpen, setAlertModalOpen] = useState<boolean>(false);
Expand All @@ -674,14 +675,16 @@ const Alerts = (props: {
setAlertModalOpen(false);
}, []);

const hideAlerts = !props.hasAlertsAccess || props.isStandAloneMode === false;

return (
<Stack className={classes.sectionContainer} gap={0} style={{ flex: 1 }}>
<AlertsModal open={alertModalOpen} alertName={alertName} onClose={closeModal} updateAlerts={props.updateAlerts} />
<Header selectAlert={selectAlert} isLoading={props.isLoading} showCreateBtn={props.hasAlertsAccess}/>
<Header selectAlert={selectAlert} isLoading={props.isLoading} showCreateBtn={!hideAlerts} />
{props.isError ? (
<ErrorView />
) : !props.hasAlertsAccess ? (
<RestrictedView />
) : hideAlerts ? (
<RestrictedView msg={!props.isStandAloneMode ? 'Alerts is unavailable on distributed mode.' : ''} />
) : (
<AlertList
selectAlert={selectAlert}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/Stream/Views/Manage/Management.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ const Management = (props: { schemaLoading: boolean }) => {
const [currentStream] = useAppStore((store) => store.currentStream);
const [instanceConfig] = useAppStore((store) => store.instanceConfig);
const [userAccessMap] = useAppStore((store) => store.userAccessMap);
const [isStandAloneMode] = useAppStore((store) => store.isStandAloneMode);
const { hasAlertsAccess, hasSettingsAccess } = userAccessMap;
const getStreamAlertsConfig = useAlertsQuery(currentStream || '', hasAlertsAccess);
const getStreamAlertsConfig = useAlertsQuery(currentStream || '', hasAlertsAccess, isStandAloneMode);
const getStreamStats = useLogStreamStats(currentStream || '');
const getRetentionConfig = useRetentionQuery(currentStream || '', hasSettingsAccess);
const getStreamInfo = useGetStreamInfo(currentStream || '', currentStream !== null);
const hotTierFetch = useHotTier(currentStream || '', hasSettingsAccess);

// todo - handle loading and error states separately
const isAlertsLoading = getStreamAlertsConfig.isError || getStreamAlertsConfig.isLoading;
const isAlertsLoading = getStreamAlertsConfig.isError || getStreamAlertsConfig.isLoading || isStandAloneMode === null;
const isRetentionLoading = getRetentionConfig.getLogRetentionIsLoading || instanceConfig === null;
const isHotTierLoading = hotTierFetch.getHotTierInfoLoading;

Expand Down Expand Up @@ -56,6 +57,7 @@ const Management = (props: { schemaLoading: boolean }) => {
updateAlerts={getStreamAlertsConfig.updateLogStreamAlerts}
isError={getStreamAlertsConfig.isError}
hasAlertsAccess={hasAlertsAccess}
isStandAloneMode={isStandAloneMode}
/>
</Stack>
</Stack>
Expand Down
Loading