Skip to content

Commit e0d628a

Browse files
author
Ahmon Dancy
committed
web: Get rid of remaining eslint warning
.. by defining the `Interaction` interface (translated from `scap/spiderpig/model.py`) and using it as the type of the `interaction` prop of the `SpInteraction` component. Thanks to Eric Gardner for assistance! Since this added the first TypeScript file to the project, I had to tweak `.eslintrc.json` to add TypeScript support and update the package list in `package.json` accordingly. Add `npm run test` to the Gitlab CI pipeline Change-Id: Ic9101286a917f13e7c1d66721bd9b41c1ebfabfe
1 parent 3dba496 commit e0d628a

File tree

7 files changed

+150
-23
lines changed

7 files changed

+150
-23
lines changed

.gitlab-ci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ verify-deps:
1919
variables:
2020
BUILD_VARIANT: verify-deps-$DISTRO
2121

22+
test-web:
23+
stage: test
24+
extends: .kokkuri:build-image
25+
variables:
26+
BUILD_VARIANT: test-web
27+
2228
test:
2329
stage: test
2430
extends: .kokkuri:build-image

.pipeline/blubber.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ variants:
116116
source: /srv/app/docs/_build/html/
117117
destination: docs/
118118

119+
test-web:
120+
base: docker-registry.wikimedia.org/nodejs20-slim
121+
builders:
122+
- node:
123+
requirements:
124+
- web
125+
- custom:
126+
command: [npm, run, test]
127+
119128
build-spiderpig-ui:
120129
base: docker-registry.wikimedia.org/nodejs20-slim
121130
builders:

web/.eslintrc.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020
"parser": "vue-eslint-parser",
2121
"extends": [
2222
"wikimedia/vue3-common",
23-
"wikimedia/client-common"
23+
"wikimedia/client-common",
24+
"plugin:@typescript-eslint/recommended"
2425
],
26+
"parserOptions": {
27+
"parser": "@typescript-eslint/parser",
28+
"extraFileExtensions": [ ".vue" ]
29+
},
30+
"plugins": [ "@typescript-eslint" ],
2531
"rules": {
2632
"vue/component-name-in-template-casing": [ "error", "kebab-case" ],
2733
"vue/custom-event-name-casing": [ "error", "kebab-case" ],

web/package-lock.json

+92-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
"vue-router": "^4.4.5"
2121
},
2222
"devDependencies": {
23+
"@typescript-eslint/eslint-plugin": "^8.13.0",
24+
"@typescript-eslint/parser": "^8.13.0",
2325
"@vitejs/plugin-vue": "^5.0.5",
2426
"eslint": "^8.57.1",
2527
"eslint-config-wikimedia": "^0.28.2",
2628
"eslint-plugin-vue": "^9.30.0",
2729
"less": "^4.2.0",
30+
"typescript": "^5.6.3",
2831
"vite": "^5.3.1"
2932
}
3033
}

web/src/components/Interaction.vue

+22-21
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,49 @@
1010
:value="code"
1111
action="progressive"
1212
:weight="code === interaction.default ? 'primary' : 'normal'"
13-
@click="choiceSelected"
13+
@click="choiceSelected( code )"
1414
>
1515
{{ choice }}
1616
</cdx-button>
1717
</div>
1818
</template>
1919

20-
<script>
20+
<script lang="ts">
21+
import { defineComponent, PropType } from 'vue';
2122
import useApi from '../api';
23+
import Interaction from '../types/Interaction';
2224
import { CdxButton } from '@wikimedia/codex';
2325
24-
export default {
26+
export default defineComponent( {
2527
name: 'SpInteraction',
2628
2729
components: {
2830
CdxButton
2931
},
3032
31-
props: [
32-
'interaction'
33-
],
34-
35-
data() {
36-
return {
37-
api: null
38-
};
33+
props: {
34+
interaction: {
35+
type: Object as PropType<Interaction>,
36+
required: true
37+
}
3938
},
4039
41-
methods: {
42-
choiceSelected( e ) {
43-
this.api.respondInteraction(
44-
this.interaction.job_id,
45-
this.interaction.id,
46-
e.currentTarget.value
40+
setup( props ) {
41+
const api = useApi();
42+
43+
function choiceSelected( code: string ) {
44+
api.respondInteraction(
45+
props.interaction.job_id,
46+
props.interaction.id,
47+
code
4748
);
4849
}
49-
},
5050
51-
mounted() {
52-
this.api = useApi();
51+
return {
52+
choiceSelected
53+
};
5354
}
54-
};
55+
} );
5556
</script>
5657

5758
<style scoped>

web/src/types/Interaction.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Keep in sync with scap/spiderpig/model.py
2+
export default interface Interaction {
3+
id: number,
4+
job_id: number
5+
type: string
6+
prompt: string
7+
choices?: string
8+
default?: string
9+
responded_by?: string
10+
response?: string
11+
}

0 commit comments

Comments
 (0)