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

Selector recommendations in Owner, Tag and Domain Modal #5197

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce46dc1
Added suggestion to tags select input
Ankit-Keshari-Vituity Jun 10, 2022
e5922eb
Added colors in tag suggestions
Ankit-Keshari-Vituity Jun 13, 2022
b67c7c1
Variable Name Modification
Ankit-Keshari-Vituity Jun 13, 2022
dabfd53
Changed internal CSS to page specific
Ankit-Keshari-Vituity Jun 13, 2022
87d9e76
Created started file and use Owner Label
Ankit-Keshari-Vituity Jun 13, 2022
dda06b7
Added Owner suggestion
Ankit-Keshari-Vituity Jun 14, 2022
1608caf
Added the recommended tags in select input field
Ankit-Keshari-Vituity Jun 14, 2022
c406432
Remmoved Tag Browse and stash the owners code
Ankit-Keshari-Vituity Jun 14, 2022
913c40e
Recommended Owners in select input
Ankit-Keshari-Vituity Jun 15, 2022
ebe27e9
Fixed UI issue
Ankit-Keshari-Vituity Jun 15, 2022
ea8eb79
Fixed UI issue
Ankit-Keshari-Vituity Jun 15, 2022
e49e704
Added recommendation on Domain select
Ankit-Keshari-Vituity Jun 15, 2022
94b7cc2
Added ref to the selector to fix the autofocus issue
Ankit-Keshari-Vituity Jun 17, 2022
a6fdde0
Rename the recommendate Function
Ankit-Keshari-Vituity Jun 21, 2022
e3bd40c
Added a custom hook and checked the logic to fetcht the data
Ankit-Keshari-Vituity Jun 22, 2022
b62b368
Removed on blur changes
Ankit-Keshari-Vituity Jun 23, 2022
e1d6a54
Merge branch 'datahub-project:master' into input-suggestions
Ankit-Keshari-Vituity Jun 23, 2022
2c1b200
Customized Tag
Ankit-Keshari-Vituity Jun 23, 2022
607ff6b
Fixed the on blur issue
Ankit-Keshari-Vituity Jun 23, 2022
be683d2
Issue: Recommendation not showing on opening the modal second time
Ankit-Keshari-Vituity Jun 24, 2022
969095a
Optimize the code
Ankit-Keshari-Vituity Jun 24, 2022
027283f
Optimize the code
Ankit-Keshari-Vituity Jun 24, 2022
845e752
Optimize the code
Ankit-Keshari-Vituity Jun 24, 2022
612d023
removed the mode property from the select input field
Ankit-Keshari-Vituity Jun 24, 2022
0077e8c
Added inputEl ref to defousing the input field after select
Ankit-Keshari-Vituity Jun 24, 2022
f7ffb22
Worked on defocusing from select after select
Ankit-Keshari-Vituity Jun 24, 2022
74e223c
Added search issue
Ankit-Keshari-Vituity Jun 24, 2022
73d5275
Fixed logo issue
Ankit-Keshari-Vituity Jun 24, 2022
fda9da0
Create Tag test
Ankit-Keshari-Vituity Jun 28, 2022
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
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import React, { useEffect, useRef, useState } from 'react';
import { Button, Form, message, Modal, Select, Tag } from 'antd';
import React, { useRef, useState } from 'react';
import styled from 'styled-components';
import { Link } from 'react-router-dom';

import { useGetSearchResultsLazyQuery } from '../../../../../../../graphql/search.generated';
import { EntityType, SearchResult } from '../../../../../../../types.generated';
import { useSetDomainMutation } from '../../../../../../../graphql/mutations.generated';
import { useEntityRegistry } from '../../../../../../useEntityRegistry';
import { useEntityData } from '../../../../EntityContext';
import { useEnterKeyListener } from '../../../../../../shared/useEnterKeyListener';
import { GetDomainRecommendation } from '../../../../../../shared/recommendation';
import { DomainLabel } from '../../../../../../shared/DomainLabel';

type Props = {
visible: boolean;
onClose: () => void;
onCloseModal: () => void;
refetch?: () => Promise<any>;
};

const SearchResultContainer = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
`;

const SearchResultContent = styled.div`
display: flex;
justify-content: start;
align-items: center;
`;

const SearchResultDisplayName = styled.div`
margin-left: 12px;
`;

type SelectedDomain = {
displayName: string;
type: EntityType;
urn: string;
};

export const SetDomainModal = ({ visible, onClose, refetch }: Props) => {
const StyleTag = styled(Tag)`
padding: 0px 7px;
margin-right: 3px;
display: flex;
justify-content: start;
align-items: center;
`;

export const SetDomainModal = ({ visible, onCloseModal, refetch }: Props) => {
const entityRegistry = useEntityRegistry();
const [inputValue, setInputValue] = useState('');
const { urn } = useEntityData();
const [selectedDomain, setSelectedDomain] = useState<SelectedDomain | undefined>(undefined);
const [domainSearch, { data: domainSearchData }] = useGetSearchResultsLazyQuery();
Expand All @@ -48,35 +42,53 @@ export const SetDomainModal = ({ visible, onClose, refetch }: Props) => {

const inputEl = useRef(null);

const onOk = async () => {
if (!selectedDomain) {
return;
}
try {
await setDomainMutation({
useEffect(() => {
setTimeout(() => {
if (inputEl && inputEl.current) {
(inputEl.current as any).focus();
}
}, 1);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment about autoFocus on the input not working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and fixed it by unmounting the component.

            {showModal && (
                <SetDomainModal
                    visible={showModal}
                    refetch={refetch}
                    onCloseModal={() => {
                        setShowModal(false);
                    }}
                />
            )}


const recommendedDomainsData = GetDomainRecommendation();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename from GetDomainRecommendation to

useGetRecommendedDomains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checked and fixed.


const handleSearch = (text: string) => {
if (text.length > 2) {
domainSearch({
variables: {
entityUrn: urn,
domainUrn: selectedDomain.urn,
input: {
type: EntityType.Domain,
query: text,
start: 0,
count: 5,
},
},
});
message.success({ content: 'Updated Domain!', duration: 2 });
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to set Domain: \n ${e.message || ''}`, duration: 3 });
}
}
setSelectedDomain(undefined);
refetch?.();
onClose();
};

// Renders a search result in the select dropdown.
const renderSearchResult = (result: SearchResult) => {
const displayName = entityRegistry.getDisplayName(result.entity.type, result.entity);
return (
<Select.Option value={result.entity.urn} key={result.entity.urn}>
<DomainLabel name={displayName} />
</Select.Option>
);
};

const domainResult = !inputValue || inputValue.length === 0 ? recommendedDomainsData : domainSearchResults;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!


const domainSearchOptions = domainResult?.map((result) => {
return renderSearchResult(result);
});

const onSelectDomain = (newUrn: string) => {
if (inputEl && inputEl.current) {
(inputEl.current as any).blur();
}
const filteredDomains =
domainSearchResults?.filter((result) => result.entity.urn === newUrn).map((result) => result.entity) || [];
domainResult?.filter((result) => result.entity.urn === newUrn).map((result) => result.entity) || [];
if (filteredDomains.length) {
const domain = filteredDomains[0];
setSelectedDomain({
Expand All @@ -87,56 +99,66 @@ export const SetDomainModal = ({ visible, onClose, refetch }: Props) => {
}
};

const handleSearch = (text: string) => {
if (text.length > 2) {
domainSearch({
const onOk = async () => {
if (!selectedDomain) {
return;
}
try {
await setDomainMutation({
variables: {
input: {
type: EntityType.Domain,
query: text,
start: 0,
count: 5,
},
entityUrn: urn,
domainUrn: selectedDomain.urn,
},
});
message.success({ content: 'Updated Domain!', duration: 2 });
} catch (e: unknown) {
message.destroy();
if (e instanceof Error) {
message.error({ content: `Failed to set Domain: \n ${e.message || ''}`, duration: 3 });
}
}
setSelectedDomain(undefined);
refetch?.();
onCloseModal();
};

const tagRender = (props) => {
// eslint-disable-next-line react/prop-types
const { label, closable, onClose } = props;
const onPreventMouseDown = (event) => {
event.preventDefault();
event.stopPropagation();
};
return (
<StyleTag onMouseDown={onPreventMouseDown} closable={closable} onClose={onClose}>
{label}
</StyleTag>
);
};

const selectValue = (selectedDomain && [selectedDomain?.displayName]) || [];

// Handle the Enter press
useEnterKeyListener({
querySelectorToExecuteClick: '#setDomainButton',
});

const renderSearchResult = (result: SearchResult) => {
const displayName = entityRegistry.getDisplayName(result.entity.type, result.entity);
return (
<SearchResultContainer>
<SearchResultContent>
<SearchResultDisplayName>
<div>{displayName}</div>
</SearchResultDisplayName>
</SearchResultContent>
<Link
target="_blank"
rel="noopener noreferrer"
to={() => `/${entityRegistry.getPathName(result.entity.type)}/${result.entity.urn}`}
>
View
</Link>{' '}
</SearchResultContainer>
);
};
function clearInput() {
setInputValue('');
}

const selectValue = (selectedDomain && [selectedDomain?.displayName]) || [];
function handleBlur() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean that when we unfocus the text box is cleared? We probably don't want this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checked and fixed.

setInputValue('');
}

return (
<Modal
title="Set Domain"
visible={visible}
onCancel={onClose}
onCancel={onCloseModal}
footer={
<>
<Button onClick={onClose} type="text">
<Button onClick={onCloseModal} type="text">
Cancel
</Button>
<Button id="setDomainButton" disabled={selectedDomain === undefined} onClick={onOk}>
Expand All @@ -149,21 +171,27 @@ export const SetDomainModal = ({ visible, onClose, refetch }: Props) => {
<Form.Item>
<Select
autoFocus
value={selectValue}
defaultOpen
mode="multiple"
ref={inputEl}
placeholder="Search for Domains..."
showSearch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

filterOption={false}
defaultActiveFirstOption={false}
onSelect={(domainUrn: any) => onSelectDomain(domainUrn)}
onDeselect={() => setSelectedDomain(undefined)}
onSearch={handleSearch}
filterOption={false}
tagRender={(tagProps) => <Tag>{tagProps.value}</Tag>}
onSearch={(value: string) => {
// eslint-disable-next-line react/prop-types
handleSearch(value.trim());
// eslint-disable-next-line react/prop-types
setInputValue(value.trim());
}}
tagRender={tagRender}
value={selectValue}
onClear={clearInput}
onBlur={handleBlur}
>
{domainSearchResults.map((result) => {
return (
<Select.Option value={result.entity.urn}>{renderSearchResult(result)}</Select.Option>
);
})}
{domainSearchOptions}
</Select>
</Form.Item>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SidebarDomainSection = () => {
<SetDomainModal
visible={showModal}
refetch={refetch}
onClose={() => {
onCloseModal={() => {
setShowModal(false);
}}
/>
Expand Down
Loading