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

fix: Loading of native filter column #29647

Merged
Merged
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 @@ -56,6 +56,7 @@ export function ColumnSelect({
mode,
}: ColumnSelectProps) {
const [columns, setColumns] = useState<Column[]>();
const [loading, setLoading] = useState(false);
const { addDangerToast } = useToasts();
const resetColumnField = useCallback(() => {
form.setFields([
Expand Down Expand Up @@ -87,9 +88,11 @@ export function ColumnSelect({

useChangeEffect(datasetId, previous => {
if (previous != null) {
setColumns([]);
resetColumnField();
}
if (datasetId != null) {
setLoading(true);
cachedSupersetGet({
endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({
columns: [
Expand All @@ -98,26 +101,30 @@ export function ColumnSelect({
'columns.type_generic',
],
})}`,
}).then(
({ json: { result } }) => {
const lookupValue = Array.isArray(value) ? value : [value];
const valueExists = result.columns.some(
(column: Column) => lookupValue?.includes(column.column_name),
);
if (!valueExists) {
resetColumnField();
}
setColumns(result.columns);
},
async badResponse => {
const { error, message } = await getClientErrorObject(badResponse);
let errorText = message || error || t('An error has occurred');
if (message === 'Forbidden') {
errorText = t('You do not have permission to edit this dashboard');
}
addDangerToast(errorText);
},
);
})
.then(
({ json: { result } }) => {
const lookupValue = Array.isArray(value) ? value : [value];
const valueExists = result.columns.some(
(column: Column) => lookupValue?.includes(column.column_name),
);
if (!valueExists) {
resetColumnField();
}
setColumns(result.columns);
},
async badResponse => {
const { error, message } = await getClientErrorObject(badResponse);
let errorText = message || error || t('An error has occurred');
if (message === 'Forbidden') {
errorText = t(
'You do not have permission to edit this dashboard',
);
}
addDangerToast(errorText);
},
)
.finally(() => setLoading(false));
}
});

Expand All @@ -126,6 +133,7 @@ export function ColumnSelect({
mode={mode}
value={mode === 'multiple' ? value || [] : value}
ariaLabel={t('Column select')}
loading={loading}
onChange={onChange}
options={options}
placeholder={t('Select a column')}
Expand Down
Loading