Repository navigation
Fix ClickUp view filter payload formatting #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,25 @@ import type { | |
| UpdateViewSettingsRequest, | ||
| ViewSharingRequest, | ||
| ViewFilter, | ||
| FilterOperator, | ||
| ViewGrouping, | ||
| ViewSorting | ||
| // ViewSettings | ||
| } from '../schemas/views-schemas.js'; | ||
|
|
||
| const CLICKUP_FILTER_OPERATOR_MAP: Partial<Record<FilterOperator, string>> = { | ||
| equals: 'EQ', | ||
| not_equals: 'NOT', | ||
| greater_than: 'GT', | ||
| less_than: 'LT', | ||
| greater_than_or_equal: 'GTE', | ||
| less_than_or_equal: 'LTE', | ||
| in: 'ANY', | ||
| not_in: 'NOT ANY', | ||
| is_set: 'IS SET', | ||
| is_not_set: 'IS NOT SET' | ||
| }; | ||
|
Comment on lines
+19
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make operator mapping exhaustive and remove silent fallback. Using Suggested diff-const CLICKUP_FILTER_OPERATOR_MAP: Partial<Record<FilterOperator, string>> = {
+const CLICKUP_FILTER_OPERATOR_MAP: Record<FilterOperator, string> = {
equals: 'EQ',
not_equals: 'NOT',
+ contains: 'CONTAINS',
+ not_contains: 'NOT CONTAINS',
+ starts_with: 'STARTS WITH',
+ ends_with: 'ENDS WITH',
+ is_empty: 'IS EMPTY',
+ is_not_empty: 'IS NOT EMPTY',
greater_than: 'GT',
less_than: 'LT',
greater_than_or_equal: 'GTE',
less_than_or_equal: 'LTE',
+ between: 'BETWEEN',
+ not_between: 'NOT BETWEEN',
in: 'ANY',
not_in: 'NOT ANY',
is_set: 'IS SET',
is_not_set: 'IS NOT SET'
};
...
- op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator] ?? filter.operator,
+ op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator],Also applies to: 334-335 🤖 Prompt for AI Agents |
||
|
|
||
| export interface ViewResponse { | ||
| id: string; | ||
| name: string; | ||
|
|
@@ -317,14 +331,30 @@ export class ViewsEnhancedClient extends ClickUpClient { | |
| op: 'AND', | ||
| fields: filters.map(filter => ({ | ||
| field: filter.field, | ||
| operator: filter.operator, | ||
| value: filter.value || filter.values | ||
| op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator] ?? filter.operator, | ||
| values: this.formatFilterValues(filter) | ||
| })), | ||
| search: '', | ||
| show_closed: false | ||
| }; | ||
| } | ||
|
|
||
| private formatFilterValues(filter: ViewFilter): Array<string | number | null> { | ||
| if (filter.values !== undefined) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Set/unset operators do not always force Prompt for AI agents |
||
| return filter.values; | ||
| } | ||
|
|
||
| if (Array.isArray(filter.value)) { | ||
| return filter.value; | ||
| } | ||
|
|
||
| if (filter.operator === 'is_set' || filter.operator === 'is_not_set') { | ||
| return [null]; | ||
| } | ||
|
|
||
| return filter.value !== undefined ? [filter.value] : []; | ||
|
Comment on lines
+342
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force
Suggested diff private formatFilterValues(filter: ViewFilter): Array<string | number | null> {
+ if (filter.operator === 'is_set' || filter.operator === 'is_not_set') {
+ return [null];
+ }
+
if (filter.values !== undefined) {
return filter.values;
}
if (Array.isArray(filter.value)) {
return filter.value;
}
- if (filter.operator === 'is_set' || filter.operator === 'is_not_set') {
- return [null];
- }
-
return filter.value !== undefined ? [filter.value] : [];
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /** | ||
| * Get available view fields for a parent | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { describe, it, expect, beforeEach } from '@jest/globals'; | ||
|
|
||
| import { ViewsEnhancedClient } from '../clickup-client/views-enhanced.js'; | ||
|
|
||
| class TestViewsClient extends ViewsEnhancedClient { | ||
| postCalls: Array<{ endpoint: string; data: any }> = []; | ||
| putCalls: Array<{ endpoint: string; data: any }> = []; | ||
|
|
||
| constructor() { | ||
| super('test-token'); | ||
| } | ||
|
|
||
| async post<T = unknown>(endpoint: string, data?: any): Promise<T> { | ||
| this.postCalls.push({ endpoint, data }); | ||
| return { view: { id: 'view-1' } } as T; | ||
| } | ||
|
|
||
| async put<T = unknown>(endpoint: string, data?: any): Promise<T> { | ||
| this.putCalls.push({ endpoint, data }); | ||
| return { view: { id: 'view-1' } } as T; | ||
| } | ||
| } | ||
|
|
||
| describe('ViewsEnhancedClient filter payloads', () => { | ||
| let client: TestViewsClient; | ||
|
|
||
| beforeEach(() => { | ||
| client = new TestViewsClient(); | ||
| }); | ||
|
|
||
| it('creates views with ClickUp filter field keys and values arrays', async () => { | ||
| await client.createView({ | ||
| parent_id: 'list-1', | ||
| parent_type: 'list', | ||
| name: 'Filtered tasks', | ||
| type: 'list', | ||
| access: 'private', | ||
| filters: [ | ||
| { field: 'status', operator: 'equals', value: 'in progress' }, | ||
| { field: 'tag', operator: 'in', values: ['bug', 'urgent'] }, | ||
| { field: 'priority', operator: 'greater_than_or_equal', value: 0 } | ||
| ] | ||
| }); | ||
|
|
||
| expect(client.postCalls).toHaveLength(1); | ||
| expect(client.postCalls[0].endpoint).toBe('/list/list-1/view'); | ||
| expect(client.postCalls[0].data.filters).toEqual({ | ||
| op: 'AND', | ||
| fields: [ | ||
| { field: 'status', op: 'EQ', values: ['in progress'] }, | ||
| { field: 'tag', op: 'ANY', values: ['bug', 'urgent'] }, | ||
| { field: 'priority', op: 'GTE', values: [0] } | ||
| ], | ||
| search: '', | ||
| show_closed: false | ||
| }); | ||
|
|
||
| for (const field of client.postCalls[0].data.filters.fields) { | ||
| expect(field).not.toHaveProperty('operator'); | ||
| expect(field).not.toHaveProperty('value'); | ||
| } | ||
| }); | ||
|
|
||
| it('sets view filters using API operator names and normalized values', async () => { | ||
| await client.setViewFilters({ | ||
| view_id: 'view-1', | ||
| filters: [ | ||
| { field: 'assignee', operator: 'not_in', value: [123, 456] }, | ||
| { field: 'dateClosed', operator: 'is_not_set' } | ||
| ] | ||
| }); | ||
|
|
||
| expect(client.putCalls).toHaveLength(1); | ||
| expect(client.putCalls[0].endpoint).toBe('/view/view-1'); | ||
| expect(client.putCalls[0].data.filters.fields).toEqual([ | ||
| { field: 'assignee', op: 'NOT ANY', values: [123, 456] }, | ||
| { field: 'dateClosed', op: 'IS NOT SET', values: [null] } | ||
| ]); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Operator map is non-exhaustive and silently falls back to raw schema names for unmapped operators, risking silent API failures.
Prompt for AI agents