🔧 Functioning select with Metron API pre-fetching and autosuggest with pagination
This commit is contained in:
@@ -1,20 +1,28 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { isNil } from "lodash";
|
||||||
import { METRON_SERVICE_URI } from "../constants/endpoints";
|
import { METRON_SERVICE_URI } from "../constants/endpoints";
|
||||||
|
|
||||||
export const fetchMetronResource = async (options) => {
|
export const fetchMetronResource = async (options) => {
|
||||||
console.log(options);
|
|
||||||
|
|
||||||
const metronResourceResults = await axios.post(
|
const metronResourceResults = await axios.post(
|
||||||
`${METRON_SERVICE_URI}/fetchResource`,
|
`${METRON_SERVICE_URI}/fetchResource`,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
console.log(metronResourceResults);
|
console.log(metronResourceResults);
|
||||||
const foo = metronResourceResults.data.results.map((result) => {
|
console.log("has more? ", !isNil(metronResourceResults.data.results.next));
|
||||||
|
const results = metronResourceResults.data.results.map((result) => {
|
||||||
return {
|
return {
|
||||||
label: result.name,
|
label: result.name,
|
||||||
value: result.id,
|
value: result.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
console.log({ options: foo, hasMore: false });
|
|
||||||
return { options: foo, hasMore: false };
|
return {
|
||||||
|
options: results,
|
||||||
|
hasMore: !isNil(metronResourceResults.data.next),
|
||||||
|
additional: {
|
||||||
|
page: !isNil(metronResourceResults.data.next)
|
||||||
|
? options.query.page + 1
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,14 +16,15 @@ export const EditMetadataPanel = (props): ReactElement => {
|
|||||||
};
|
};
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [value, onChange] = useState(null);
|
const [value, onChange] = useState(null);
|
||||||
|
const [isAddingInProgress, setIsAddingInProgress] = useState(false);
|
||||||
|
|
||||||
const mudasir = useCallback((query) => {
|
const mudasir = useCallback((query, loadedOptions, { page }) => {
|
||||||
return fetchMetronResource({
|
return fetchMetronResource({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
resource: "publisher",
|
resource: "publisher",
|
||||||
query: {
|
query: {
|
||||||
name: query,
|
name: query,
|
||||||
page: 1,
|
page,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
@@ -119,13 +120,14 @@ export const EditMetadataPanel = (props): ReactElement => {
|
|||||||
<p className="control is-expanded has-icons-left">
|
<p className="control is-expanded has-icons-left">
|
||||||
<CreatableAsyncPaginate
|
<CreatableAsyncPaginate
|
||||||
SelectComponent={Creatable}
|
SelectComponent={Creatable}
|
||||||
debounceTimeout={3}
|
debounceTimeout={200}
|
||||||
// isDisabled={isAddingInProgress}
|
isDisabled={isAddingInProgress}
|
||||||
value={value}
|
value={value}
|
||||||
loadOptions={(e) => mudasir(e)}
|
loadOptions={mudasir}
|
||||||
// onCreateOption={onCreateOption}
|
// onCreateOption={onCreateOption}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
// cacheUniqs={[cacheUniq]}
|
// cacheUniqs={[cacheUniq]}
|
||||||
|
additional={{ page: 1 }}
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user