Skip to content

Commit

Permalink
Contentstack package: Fix single entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Wesley-BSA committed Oct 19, 2022
1 parent cc461fb commit ba2f6ab
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions plasmicpkgs/plasmic-content-stack/src/contentstack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,25 @@ export function ContentStackFetcher({
);

const { data: entriesData } = usePlasmicQueryData<any | null>(
contentType && fetchType === 'all' ? `${cacheKey}/${contentType}/entries${
contentType ? `${cacheKey}/${contentType}/entries` + (fetchType === 'all' ? `${
limit ? "/limit/" + limit : ''
}${
order && orderBy ? "/order/" + orderBy + (ascending ? '/ascending' : '') : ''
}${
filter && filterField && filterType && filterValue ? `/filter/${filterField}/${filterType}/${filterValue}` : ''
}` : null,
}` : '') : null,
async () => {
let Query = Stack.ContentType(`${contentType!}`).Query();
if (filter && filterField && filterType && filterValue) {
Query = Query[filterType](filterField, filterValue);
}
if (order && orderBy){
Query = Query[ascending ? 'ascending' : 'descending'](orderBy);
}
if (limit){
Query = Query.limit(limit);
if(fetchType === 'all'){
if (filter && filterField && filterType && filterValue) {
Query = Query[filterType](filterField, filterValue);
}
if (order && orderBy){
Query = Query[ascending ? 'ascending' : 'descending'](orderBy);
}
if (limit){
Query = Query.limit(limit);
}
}
return await Query.toJSON().find();
}
Expand All @@ -314,15 +316,16 @@ export function ContentStackFetcher({
}

let renderedData;
if (contentType && entryUID) {
if (contentType && fetchType === 'single') {
if (!entryUID) return <div>Please select an entry</div>;
renderedData = (
<DataProvider name={"contentstackItem"} data={entryData} hidden={true}>
<DataProvider name={makeDataProviderName(contentType)} data={entryData}>
{children}
</DataProvider>
</DataProvider>
);
} else if (contentType && !entryUID) {
} else if (contentType && fetchType === 'all') {
const entries = entriesData?.flat();
renderedData = entries?.map((item: any, index: number) => (
<DataProvider
Expand Down

0 comments on commit ba2f6ab

Please sign in to comment.