-
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.
- Loading branch information
1 parent
42a277a
commit 64cc4a0
Showing
6 changed files
with
161 additions
and
2 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
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
Empty file.
73 changes: 73 additions & 0 deletions
73
packages/create-vue/src/components/widgets/FormulaWidget.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,73 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { computedAsync } from '@vueuse/core'; | ||
import { MapViewState } from '@deck.gl/core'; | ||
import { AggregationType, WidgetSource } from '@carto/api-client'; | ||
import { | ||
createSpatialFilter, | ||
WidgetStatus, | ||
numberFormatter, | ||
} from '../../utils'; | ||
const props = withDefaults( | ||
defineProps<{ | ||
data: Promise<{ widgetSource: WidgetSource }>; | ||
column?: string; | ||
operation?: AggregationType; | ||
viewState?: MapViewState; | ||
}>(), | ||
{ | ||
column: '', | ||
operation: 'count', | ||
}, | ||
); | ||
const status = ref<WidgetStatus>('loading'); | ||
const value = computedAsync(async (onCancel) => { | ||
const column = props.column; | ||
const operation = props.operation; | ||
const viewState = props.viewState; | ||
const abortController = new AbortController(); | ||
onCancel(() => abortController.abort()); | ||
status.value = 'loading'; | ||
return props.data | ||
.then(({ widgetSource }) => | ||
widgetSource.getFormula({ | ||
column, | ||
operation, | ||
spatialFilter: viewState && createSpatialFilter(viewState), | ||
abortController, | ||
}), | ||
) | ||
.then((response) => { | ||
status.value = 'complete'; | ||
return response.value; | ||
}) | ||
.catch(() => { | ||
if (!abortController.signal.aborted) { | ||
status.value = 'error'; | ||
} | ||
return -1; | ||
}); | ||
}, -1); | ||
</script> | ||
|
||
<template> | ||
<template v-if="status === 'loading'"> | ||
<span class="title">...</span> | ||
</template> | ||
|
||
<template v-else-if="status === 'error'"> | ||
<span class="title">⚠ Error</span> | ||
</template> | ||
|
||
<template v-else> | ||
<data class="title" :value="value" | ||
>{{ numberFormatter.format(value) }} | ||
</data> | ||
</template> | ||
</template> |
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