Skip to content

Commit

Permalink
feat(native-filters): add option to create value in select filter (#1…
Browse files Browse the repository at this point in the history
…4314)

* feat(native-filters): add option to create value in select filter

* address comments

(cherry picked from commit e392e2e)
  • Loading branch information
villebro authored and amitmiran137 committed Apr 27, 2021
1 parent 7fbe2bf commit 4c05628
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 4c05628

Please sign in to comment.