Skip to content

Commit 86aa2b7

Browse files
authored
Merge pull request #4 from lopentu/feature/adjust-frontend-display
feat:Gesture 標籤可點Chip自動加進搜尋條件
2 parents f627069 + 8e3b680 commit 86aa2b7

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

components/corpus-result.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export default function CorpusResult(props: CorpusResultProps) {
122122
annotationSpans={annotationSpans}
123123
searchType={searchType}
124124
onSelectedSpanChanged={onSelectedSpanChanged}
125+
cosp={cosp}
126+
setCosp={setCosp}
125127
/>
126128
</>
127129

components/corpus-table.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ interface ICorpusTable {
139139
annotationSpans: AnnotationSpans
140140
searchType: string
141141
onSelectedSpanChanged(arg0: string, arg1: number): void
142+
cosp: string[]
143+
setCosp: React.Dispatch<React.SetStateAction<string[]>>
142144
}
143145

144-
export default function CorpusTable({ annotationSpans, searchType, onSelectedSpanChanged }: ICorpusTable) {
146+
export default function CorpusTable({ annotationSpans, searchType, onSelectedSpanChanged, cosp, setCosp }: ICorpusTable) {
145147
const [page, setPage] = React.useState(0);
146148
const [rowsPerPage, setRowsPerPage] = React.useState(10);
147149
let groupedAnnotationSpans = Array.from(annotationSpans.reduce(
@@ -211,13 +213,20 @@ export default function CorpusTable({ annotationSpans, searchType, onSelectedSpa
211213
{row.cosp && row.cosp.length > 0 &&
212214
<Box sx={{ mt: 0.5, display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
213215
{(row.cosp as string[]).slice(0, 8).map((g) => (
214-
<Chip
215-
key={g}
216-
label={g}
217-
size="small"
218-
variant="outlined"
219-
color={g.startsWith('SP1') ? 'primary' : 'secondary'}
220-
/>
216+
<Chip
217+
key={g}
218+
label={g}
219+
size="small"
220+
variant={cosp.includes(g.replace(/^SP[12]_/, '')) ? 'filled' : 'outlined'}
221+
color={g.startsWith('SP1') ? 'primary' : 'secondary'}
222+
onClick={() => {
223+
const label = g.replace(/^SP[12]_/, '');
224+
if (!cosp.includes(label)) {
225+
setCosp([...cosp, label]);
226+
}
227+
}}
228+
sx={{ cursor: 'pointer' }}
229+
/>
221230
))}
222231
{row.cosp.length > 8 &&
223232
<Chip

0 commit comments

Comments
 (0)