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

feat(ingest): Support System Ingestion Sources, Show and hide system ingestion sources with Command-S #10938

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
15 changes: 15 additions & 0 deletions datahub-web-react/src/app/ingest/source/IngestionSourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
INGESTION_REFRESH_SOURCES_ID,
} from '../../onboarding/config/IngestionOnboardingConfig';
import { ONE_SECOND_IN_MS } from '../../entity/shared/tabs/Dataset/Queries/utils/constants';
import { useCommandS } from './hooks';

const PLACEHOLDER_URN = 'placeholder-urn';

Expand All @@ -51,6 +52,8 @@ const FilterWrapper = styled.div`
display: flex;
`;

const SYSTEM_INTERNAL_SOURCE_TYPE = 'SYSTEM';

export enum IngestionSourceType {
ALL,
UI,
Expand Down Expand Up @@ -102,6 +105,17 @@ export const IngestionSourceList = () => {
// Set of removed urns used to account for eventual consistency
const [removedUrns, setRemovedUrns] = useState<string[]>([]);
const [sourceFilter, setSourceFilter] = useState(IngestionSourceType.ALL);
const [hideSystemSources, setHideSystemSources] = useState(true);

/**
* Show or hide system ingestion sources using a hidden command S command.
*/
useCommandS(() => setHideSystemSources(!hideSystemSources));

// Ingestion Source Default Filters
const filters = hideSystemSources
? [{ field: 'sourceType', values: [SYSTEM_INTERNAL_SOURCE_TYPE], negated: true }]
: undefined;

// Ingestion Source Queries
const { loading, error, data, client, refetch } = useListIngestionSourcesQuery({
Expand All @@ -110,6 +124,7 @@ export const IngestionSourceList = () => {
start,
count: pageSize,
query: (query?.length && query) || undefined,
filters,
},
},
fetchPolicy: (query?.length || 0) > 0 ? 'no-cache' : 'cache-first',
Expand Down
16 changes: 16 additions & 0 deletions datahub-web-react/src/app/ingest/source/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useEffect } from 'react';

export const useCommandS = (onPress: () => void) => {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.metaKey && event.key === 's') {
event.preventDefault();
onPress();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [onPress]);
Comment on lines +3 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving readability and ensuring the event listener is added only once.

The hook implementation is correct, but you can improve readability and ensure the event listener is added only once by using a ref for the callback.

import { useEffect, useRef } from 'react';

export const useCommandS = (onPress: () => void) => {
    const onPressRef = useRef(onPress);

    useEffect(() => {
        onPressRef.current = onPress;
    }, [onPress]);

    useEffect(() => {
        const handleKeyDown = (event: KeyboardEvent) => {
            if (event.metaKey && event.key === 's') {
                event.preventDefault();
                onPressRef.current();
            }
        };
        window.addEventListener('keydown', handleKeyDown);
        return () => {
            window.removeEventListener('keydown', handleKeyDown);
        };
    }, []);
};
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const useCommandS = (onPress: () => void) => {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.metaKey && event.key === 's') {
event.preventDefault();
onPress();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [onPress]);
import { useEffect, useRef } from 'react';
export const useCommandS = (onPress: () => void) => {
const onPressRef = useRef(onPress);
useEffect(() => {
onPressRef.current = onPress;
}, [onPress]);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.metaKey && event.key === 's') {
event.preventDefault();
onPressRef.current();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, []);
};

};
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,24 @@ record DataHubIngestionSourceInfo {
*/
extraArgs: optional map[string, string]
}

/**
* The source or origin of the Ingestion Source
*
* Currently CLI and UI do not provide an explicit source.
*/
source: optional record DataHubIngestionSourceSource {
/**
* The source type of the ingestion source
*/
@Searchable = {
"fieldName": "sourceType"
}
type: enum DataHubIngestionSourceSourceType {
/**
* A system internal source, e.g. for running search indexing operations, feature computation, etc.
*/
SYSTEM
}
}
}
Loading