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(native-filters): add option to create value in select filter #14314

Merged
merged 2 commits into from
Apr 24, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
? firstItem
: initSelectValue,
);
const [currentSuggestionSearch, setCurrentSuggestionSearch] = useState('');

const clearSuggestionSearch = () => {
setCurrentSuggestionSearch('');
};

const [col] = groupby;
const datatype: GenericDataType = coltypeMap[col];
Expand Down Expand Up @@ -137,7 +142,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
]);

const placeholderText =
(data || []).length === 0
data.length === 0
? t('No data')
: tn('%s option', '%s options', data.length, data.length);
return (
Expand All @@ -150,11 +155,14 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
showSearch={showSearch}
mode={multiSelect ? 'multiple' : undefined}
placeholder={placeholderText}
onSearch={setCurrentSuggestionSearch}
onSelect={clearSuggestionSearch}
onBlur={clearSuggestionSearch}
// @ts-ignore
onChange={handleChange}
ref={inputRef}
>
{(data || []).map(row => {
{data.map(row => {
const [value] = groupby.map(col => row[col]);
return (
// @ts-ignore
Expand All @@ -163,6 +171,14 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
</Option>
);
})}
{currentSuggestionSearch &&
!ensureIsArray(values).some(
suggestion => suggestion === currentSuggestionSearch,
) && (
<Option value={currentSuggestionSearch}>
{currentSuggestionSearch}
</Option>
)}
</StyledSelect>
</Styles>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function transformProps(
const newFormData = { ...DEFAULT_FORM_DATA, ...formData };
const { setDataMask = () => {} } = hooks;
const [queryData] = queriesData;
const { colnames = [], coltypes = [], data } = queryData || [];
const { colnames = [], coltypes = [], data = [] } = queryData || {};
const coltypeMap: Record<string, GenericDataType> = colnames.reduce(
(accumulator, item, index) => ({ ...accumulator, [item]: coltypes[index] }),
{},
Expand Down