-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/beta' into docs/component-doc-up…
…dates
- Loading branch information
1 parent
05a9a66
commit c7bbeaf
Showing
21 changed files
with
132 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,68 @@ | ||
<template> | ||
<slot v-if="!error$" /> | ||
<component | ||
:is="component" | ||
v-if="error" | ||
v-else | ||
class="pdap-flex-container-center h-[full]" | ||
:v-bind="params" | ||
> | ||
<h1>Oops, something went wrong!</h1> | ||
<p class="max-w-full" data-test="error-boundary-message"> | ||
If you keep seeing this message, please email | ||
<a href="mailto:[email protected]">[email protected]</a> for assistance. | ||
</p> | ||
</component> | ||
<slot v-else /> | ||
</template> | ||
<script> | ||
|
||
<script setup lang="ts"> | ||
import { ComponentPublicInstance, onErrorCaptured, ref } from 'vue'; | ||
import { PdapErrorBoundaryProps, PdapErrorEmitted } from './types'; | ||
const props = withDefaults(defineProps<PdapErrorBoundaryProps>(), { | ||
component: 'div', | ||
onError: undefined, | ||
params: undefined, | ||
}); | ||
const emits = defineEmits<{ | ||
(event: 'onError', { error, vm, info }: PdapErrorEmitted): void; | ||
}>(); | ||
const error$ = ref<Error>(); | ||
const info$ = ref<string | undefined>(''); | ||
function interceptError( | ||
error: Error, | ||
vm: ComponentPublicInstance | null, | ||
info?: string | ||
) { | ||
error$.value = error; | ||
info$.value = info; | ||
props.onError?.(error, vm, info); | ||
emits('onError', { error, vm, info }); | ||
} | ||
/* Impossible and unwise to try testing this, so we remove from the coverage report */ | ||
/* c8 ignore next 3 */ | ||
onErrorCaptured((err, vm, info) => { | ||
interceptError(err, vm, info); | ||
}); | ||
</script> | ||
|
||
<script lang="ts"> | ||
/** | ||
* # `ErrorBoundary` | ||
* Intercepts uncaught errors from its children and renders an error UI in place of its children. | ||
* | ||
* ## Props | ||
* @prop {string} component Optional: the component to render as a fallback, defaults to 'div' | ||
* @prop {PdapErrorBoundaryProps['onError']} onError Optional: callback to run on error, accepts two arguments, the error and the element (optional) | ||
* @prop {Record<string, string>} params Optional: parameters to be forwarded to fallback | ||
* | ||
* ## Emits | ||
* @emits onError includes object with `error`, and optionally `info` and `vm | ||
* | ||
* @example | ||
* @example Top level | ||
* | ||
* <template> | ||
* <AuthWrapper> | ||
|
@@ -30,27 +73,24 @@ | |
* <Footer :logo-image-src="acronym" /> | ||
* </AuthWrapper> | ||
* </template> | ||
* | ||
* @example Within a component | ||
<ErrorBoundary | ||
class="col-span-full items-start" | ||
component="div" | ||
@on-error="({ error, vm, info }) => console.debug({ error, vm, info })" | ||
> | ||
<div class="col-span-full"> | ||
<p> | ||
This is the content that will render inside the error boundary if | ||
there is no error | ||
</p> | ||
<Button @click="triggerError">Click here to trigger error</Button> | ||
</div> | ||
</ErrorBoundary> | ||
* | ||
*/ | ||
export default { | ||
props: { | ||
component: { | ||
type: String, | ||
default: 'div', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
error: false, | ||
}; | ||
}, | ||
/* TODO: figure out how to cover this lifecycle method in tests */ | ||
errorCaptured(error) { | ||
this.interceptError(error); | ||
}, | ||
methods: { | ||
interceptError(error) { | ||
this.error = error; | ||
}, | ||
}, | ||
name: 'ErrorBoundary', | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ErrorBoundary } from './PdapErrorBoundary.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ComponentPublicInstance } from 'vue'; | ||
|
||
export interface PdapErrorEmitted { | ||
error: Error; | ||
vm: ComponentPublicInstance | null; | ||
info?: string; | ||
} | ||
|
||
export interface PdapErrorBoundaryProps { | ||
component: string; | ||
onError?: ( | ||
error: Error, | ||
target?: ComponentPublicInstance | null | undefined, | ||
info?: string | ||
) => void; | ||
params?: Record<string, string>; | ||
} |
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
src/components/FlexContainer/__snapshots__/flex-container.spec.ts.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.