From 257bb3e75573f737f138e6977c59fab3555b4186 Mon Sep 17 00:00:00 2001 From: Valentin Dassonville Date: Wed, 2 Oct 2024 17:22:35 +0200 Subject: [PATCH] change all occurence of hydra in templates --- src/generators/ReactGenerator.js | 6 ++--- templates/nuxt/components/foo/FooList.vue | 8 +++--- templates/nuxt/composables/api.ts | 10 +++---- templates/react-common/actions/foo/list.js | 4 +-- templates/react-common/reducers/foo/list.js | 4 +-- templates/react-common/utils/dataAccess.js | 8 +++--- templates/react-native/components/foo/List.js | 4 +-- templates/react-native/utils/helpers.js | 26 +++++++++---------- templates/react/components/Pagination.tsx | 10 +++---- templates/react/components/foo/List.tsx | 2 +- templates/react/hooks/fetch.ts | 8 +++--- templates/react/hooks/mercure.ts | 4 +-- templates/react/hooks/show.ts | 4 +-- templates/react/interfaces/Collection.ts | 24 ++++++++--------- templates/vuetify/store/foo/list.ts | 4 +-- 15 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/generators/ReactGenerator.js b/src/generators/ReactGenerator.js index 21f36cf7..80a137e4 100644 --- a/src/generators/ReactGenerator.js +++ b/src/generators/ReactGenerator.js @@ -20,8 +20,8 @@ export default class ReactGenerator extends BaseGenerator { "hooks/list.ts", "hooks/mercure.ts", "hooks/retrieve.ts", - "hooks/update.ts", "hooks/show.ts", + "hooks/update.ts", // interfaces "interfaces/Collection.ts", @@ -32,9 +32,9 @@ export default class ReactGenerator extends BaseGenerator { "components/foo/Form.tsx", "components/foo/index.ts", "components/foo/List.tsx", - "components/foo/Update.tsx", - "components/foo/type.ts", "components/foo/Show.tsx", + "components/foo/type.ts", + "components/foo/Update.tsx", "components/Field.tsx", "components/Links.tsx", "components/Pagination.tsx", diff --git a/templates/nuxt/components/foo/FooList.vue b/templates/nuxt/components/foo/FooList.vue index f3137907..9fe7a9e2 100644 --- a/templates/nuxt/components/foo/FooList.vue +++ b/templates/nuxt/components/foo/FooList.vue @@ -266,10 +266,10 @@ const { items, view, error, isLoading, hubUrl } = await useFetchList<{{titleUcFi {{lc}}ListStore.setData({ items, view, error, isLoading, hubUrl }); const pagination = { - first: view.value?.["hydra:first"]?.slice(-1), - previous: view.value?.["hydra:previous"]?.slice(-1), - next: view.value?.["hydra:next"]?.slice(-1), - last: view.value?.["hydra:last"]?.slice(-1), + first: view.value?.["{{hydraPrefix}}first"]?.slice(-1), + previous: view.value?.["{{hydraPrefix}}previous"]?.slice(-1), + next: view.value?.["{{hydraPrefix}}next"]?.slice(-1), + last: view.value?.["{{hydraPrefix}}last"]?.slice(-1), }; useMercureList({ store: {{lc}}ListStore, deleteStore: {{lc}}DeleteStore }); diff --git a/templates/nuxt/composables/api.ts b/templates/nuxt/composables/api.ts index 84bac452..a10b9eca 100644 --- a/templates/nuxt/composables/api.ts +++ b/templates/nuxt/composables/api.ts @@ -20,7 +20,7 @@ async function useApi(path: string, options: UseFetchOptions) { onResponseError({ response }) { const data = response._data; - const error = data["hydra:description"] || response.statusText; + const error = data["{{hydraPrefix}}description"] || response.statusText; throw new Error(error); }, @@ -51,8 +51,8 @@ export async function useFetchList( }); const value = data.value as PagedCollection; - items.value = value["hydra:member"]; - view.value = value["hydra:view"]; + items.value = value["{{hydraPrefix}}member"]; + view.value = value["{{hydraPrefix}}view"]; return { items, @@ -94,7 +94,7 @@ export async function useCreateItem(resource: string, payload: Item) { onResponseError({ response }) { const data = response._data; - const error = data["hydra:description"] || response.statusText; + const error = data["{{hydraPrefix}}description"] || response.statusText; if (!data.violations) throw new Error(error); @@ -135,7 +135,7 @@ export async function useUpdateItem(item: Item, payload: Item) { onResponseError({ response }) { const data = response._data; - const error = data["hydra:description"] || response.statusText; + const error = data["{{hydraPrefix}}description"] || response.statusText; if (!data.violations) throw new Error(error); diff --git a/templates/react-common/actions/foo/list.js b/templates/react-common/actions/foo/list.js index 86cb78c2..7bb655eb 100644 --- a/templates/react-common/actions/foo/list.js +++ b/templates/react-common/actions/foo/list.js @@ -31,11 +31,11 @@ export function list(page = '{{{name}}}') { dispatch(loading(false)); dispatch(success(retrieved)); - if (hubURL && retrieved['hydra:member'].length) + if (hubURL && retrieved['{{hydraPrefix}}member'].length) dispatch( mercureSubscribe( hubURL, - retrieved['hydra:member'].map(i => i['@id']) + retrieved['{{hydraPrefix}}member'].map(i => i['@id']) ) ); }) diff --git a/templates/react-common/reducers/foo/list.js b/templates/react-common/reducers/foo/list.js index 11514a49..7e10c372 100644 --- a/templates/react-common/reducers/foo/list.js +++ b/templates/react-common/reducers/foo/list.js @@ -40,7 +40,7 @@ export function retrieved(state = null, action) { case '{{{uc}}}_LIST_MERCURE_MESSAGE': return { ...state, - 'hydra:member': state['hydra:member'].map(item => + '{{hydraPrefix}}member': state['{{hydraPrefix}}member'].map(item => item['@id'] === action.retrieved['@id'] ? action.retrieved : item ) }; @@ -48,7 +48,7 @@ export function retrieved(state = null, action) { case '{{{uc}}}_LIST_MERCURE_DELETED': return { ...state, - 'hydra:member': state['hydra:member'].filter( + '{{hydraPrefix}}member': state['{{hydraPrefix}}member'].filter( item => item['@id'] !== action.retrieved['@id'] ) }; diff --git a/templates/react-common/utils/dataAccess.js b/templates/react-common/utils/dataAccess.js index e03b6fb2..852d87d3 100644 --- a/templates/react-common/utils/dataAccess.js +++ b/templates/react-common/utils/dataAccess.js @@ -24,8 +24,8 @@ export function fetch(id, options = {}) { return response.json().then( json => { const error = - json['hydra:description'] || - json['hydra:title'] || + json['{{hydraPrefix}}description'] || + json['{{hydraPrefix}}title'] || 'An error occurred.'; if (!json.violations) throw Error(error); @@ -47,9 +47,9 @@ export function fetch(id, options = {}) { } export function normalize(data) { - if (has(data, 'hydra:member')) { + if (has(data, '{{hydraPrefix}}member')) { // Normalize items in collections - data['hydra:member'] = data['hydra:member'].map(item => normalize(item)); + data['{{hydraPrefix}}member'] = data['{{hydraPrefix}}member'].map(item => normalize(item)); return data; } diff --git a/templates/react-native/components/foo/List.js b/templates/react-native/components/foo/List.js index c929697b..88b90b8c 100644 --- a/templates/react-native/components/foo/List.js +++ b/templates/react-native/components/foo/List.js @@ -73,11 +73,11 @@ class ListComponent extends Component { - {this.props.retrieved['hydra:member'].map( + {this.props.retrieved['{{hydraPrefix}}member'].map( item => ListComponent.renderRow(item))} - {pagination(this.props.retrieved['hydra:view'], this.props.list)} + {pagination(this.props.retrieved['{{hydraPrefix}}view'], this.props.list)} ); } diff --git a/templates/react-native/utils/helpers.js b/templates/react-native/utils/helpers.js index 9fcd2ad3..66a3c17d 100644 --- a/templates/react-native/utils/helpers.js +++ b/templates/react-native/utils/helpers.js @@ -13,28 +13,28 @@ export function pagination(view, list) { list(paginationRoute(view['hydra:first']))} - disabled={!view['hydra:previous']} + iconColor={view['{{hydraPrefix}}previous'] ? '#3faab4' : 'grey'} + onPress={() => list(paginationRoute(view['{{hydraPrefix}}first']))} + disabled={!view['{{hydraPrefix}}previous']} /> list(paginationRoute(view['hydra:previous']))} - disabled={!view['hydra:previous']} + iconColor={view['{{hydraPrefix}}previous'] ? '#3faab4' : 'grey'} + onPress={() => list(paginationRoute(view['{{hydraPrefix}}previous']))} + disabled={!view['{{hydraPrefix}}previous']} /> list(paginationRoute(view['hydra:next']))} - disabled={!view['hydra:next']} + iconColor={view['{{hydraPrefix}}next'] ? '#3faab4' : 'grey'} + onPress={() => list(paginationRoute(view['{{hydraPrefix}}next']))} + disabled={!view['{{hydraPrefix}}next']} /> list(paginationRoute(view['hydra:last']))} + iconColor={view['{{hydraPrefix}}next'] ? '#3faab4' : 'grey'} + disabled={!view['{{hydraPrefix}}next']} + onPress={() => list(paginationRoute(view['{{hydraPrefix}}last']))} activityIndicatorStyle={ {backgroundColor:'red'} } /> @@ -45,4 +45,4 @@ export function delayRefresh() { setTimeout(() => { Actions.refresh({refresh: Math.random()}); }, 500); -} \ No newline at end of file +} diff --git a/templates/react/components/Pagination.tsx b/templates/react/components/Pagination.tsx index e38b5b9b..baa125a1 100644 --- a/templates/react/components/Pagination.tsx +++ b/templates/react/components/Pagination.tsx @@ -6,16 +6,16 @@ interface PaginationProps { } const Pagination = ({retrieved}: PaginationProps) => { - const view = retrieved && retrieved["hydra:view"]; + const view = retrieved && retrieved["{{hydraPrefix}}view"]; if (!view) { return null; } const { - "hydra:first": first, - "hydra:previous": previous, - "hydra:next": next, - "hydra:last": last, + "{{hydraPrefix}}first": first, + "{{hydraPrefix}}previous": previous, + "{{hydraPrefix}}next": next, + "{{hydraPrefix}}last": last, } = view; return ( diff --git a/templates/react/components/foo/List.tsx b/templates/react/components/foo/List.tsx index e846fcb0..f4eb4c29 100644 --- a/templates/react/components/foo/List.tsx +++ b/templates/react/components/foo/List.tsx @@ -13,7 +13,7 @@ interface ListProps { } const ListView = ({error, loading, retrieved}: ListProps) => { - const items = (retrieved && retrieved["hydra:member"]) || []; + const items = (retrieved && retrieved["{{hydraPrefix}}member"]) || []; return (
diff --git a/templates/react/hooks/fetch.ts b/templates/react/hooks/fetch.ts index edb2f79a..f3995e75 100644 --- a/templates/react/hooks/fetch.ts +++ b/templates/react/hooks/fetch.ts @@ -64,8 +64,8 @@ const normalizeAuth = (auth: string) => { // Error handling const regularHandler = (response: Response, json: any) => { const error = - json["hydra:description"] || - json["hydra:title"] || + json["{{hydraPrefix}}description"] || + json["{{hydraPrefix}}title"] || json["message"] || "An error occurred."; @@ -78,8 +78,8 @@ const submissionHandler = (response: Response, json: any) => { } const error = - json["hydra:description"] || - json["hydra:title"] || + json["{{hydraPrefix}}description"] || + json["{{hydraPrefix}}title"] || json["message"] || "An error occurred."; diff --git a/templates/react/hooks/mercure.ts b/templates/react/hooks/mercure.ts index 768c973a..8b2725b3 100644 --- a/templates/react/hooks/mercure.ts +++ b/templates/react/hooks/mercure.ts @@ -71,8 +71,8 @@ const useMercure = (retrieved: Resource | null): I const collection = retrieved as PagedCollection; if (hubURL && retrieved) { - if (collection["hydra:member"]) { - setEventSource(subscribe(hubURL, collection["hydra:member"].map(item => item["@id"]))); + if (collection["{{hydraPrefix}}member"]) { + setEventSource(subscribe(hubURL, collection["{{hydraPrefix}}member"].map(item => item["@id"]))); } else { setEventSource(subscribe(hubURL, retrieved["@id"])); } diff --git a/templates/react/hooks/show.ts b/templates/react/hooks/show.ts index 78d63f2d..9e56b37c 100644 --- a/templates/react/hooks/show.ts +++ b/templates/react/hooks/show.ts @@ -34,8 +34,8 @@ const useShow = (): IShowStore => { useEffect(() => { if (message) { const collection = (retrieved as PagedCollection); - if (collection && collection['hydra:member']) { - const item = collection['hydra:member'].find((i) => i["@id"] === message["@id"]); + if (collection && collection['{{hydraPrefix}}member']) { + const item = collection['{{hydraPrefix}}member'].find((i) => i["@id"] === message["@id"]); if (item && retrieved) { Object.assign(item, message); setRetrieved({ ...retrieved }); diff --git a/templates/react/interfaces/Collection.ts b/templates/react/interfaces/Collection.ts index be7932e1..3fdd018b 100644 --- a/templates/react/interfaces/Collection.ts +++ b/templates/react/interfaces/Collection.ts @@ -1,21 +1,21 @@ import { ApiResource } from "../utils/types"; export interface Pagination { - "hydra:first"?: string; - "hydra:previous"?: string; - "hydra:next"?: string; - "hydra:last"?: string; + "{{hydraPrefix}}first"?: string; + "{{hydraPrefix}}previous"?: string; + "{{hydraPrefix}}next"?: string; + "{{hydraPrefix}}last"?: string; } export interface PagedCollection extends ApiResource { "@context"?: string; "@type"?: string; - "hydra:firstPage"?: string; - "hydra:itemsPerPage"?: number; - "hydra:lastPage"?: string; - "hydra:member"?: T[]; - "hydra:nextPage"?: string; - "hydra:search"?: object; - "hydra:totalItems"?: number; - "hydra:view"?: Pagination; + "{{hydraPrefix}}firstPage"?: string; + "{{hydraPrefix}}itemsPerPage"?: number; + "{{hydraPrefix}}lastPage"?: string; + "{{hydraPrefix}}member"?: T[]; + "{{hydraPrefix}}nextPage"?: string; + "{{hydraPrefix}}search"?: object; + "{{hydraPrefix}}totalItems"?: number; + "{{hydraPrefix}}view"?: Pagination; } diff --git a/templates/vuetify/store/foo/list.ts b/templates/vuetify/store/foo/list.ts index eb5d6461..5e687a7a 100644 --- a/templates/vuetify/store/foo/list.ts +++ b/templates/vuetify/store/foo/list.ts @@ -34,8 +34,8 @@ export const use{{titleUcFirst}}ListStore = defineStore("{{lc}}List", { this.toggleLoading(); - this.setItems(data["hydra:member"]); - this.setTotalItems(data["hydra:totalItems"] ?? 0); + this.setItems(data["{{hydraPrefix}}member"]); + this.setTotalItems(data["{{hydraPrefix}}totalItems"] ?? 0); if (hubUrl) { this.setHubUrl(hubUrl);