ronantakizawa/codereview-bench huggingface dataset:
Repository: directus/directus
File: app/src/modules/settings/routes/data-model/collections/components/collection-item.vue (Vue)

Code before:
						isCollectionExpanded.value = expanded;
					} else {
						return;
					}
				} else {
					isCollectionExpanded.value = expanded;
				}

				break;
			case false:
				if (nestedCollections.value.length > 0) {
					if (props.collection.meta?.group) {
						isCollectionExpanded.value = expanded;
					} else {
						return;
					}
				} else {
					isCollectionExpanded.value = expanded;
				}

				break;
		}
	},
	{ immediate: true },
);

function onGroupSortChange(collections: Collection[]) {
	const updates = collections.map((collection) => ({
		collection: collection.collection,
		meta: {
			group: props.collection.collection,
		},
	}));

	emit('setNestedSort', updates);
}
</script>

<template>
	<div v-show="visibilityTree.visible" class="collection-item">
		<v-list-item
			block
			dense
			clickable
			:class="{ hidden: collection.meta?.hidden }"
			:to="collection.schema ? `/settings/data-model/${collection.collection}` : undefined"
			@click.self="!collection.schema ? $emit('editCollection', collection) : null"
		>
			<v-list-item-icon>
				<v-icon v-if="!disableDrag" class="drag-handle" name="drag_handle" />
			</v-list-item-icon>

Review comment (refactor):
This approach is not very clean 😅, but I wanted to first confirm if this meets your expectations before refactoring.


Code after:
		>
			<v-list-item-icon>
				<v-icon v-if="!disableDrag" class="drag-handle" name="drag_handle" />
			</v-list-item-icon>
			<div class="collection-item-detail">
				<v-icon
					:color="
						collection.meta?.hidden ? 'var(--theme--foreground-subdued)' : collection.color ?? 'var(--theme--primary)'
					"
					class="collection-icon"
					:name="collection.meta?.hidden ? 'visibility_off' : collection.icon"
				/>
				<v-highlight
					ref="collectionName"
					:query="visibilityTree.search"
					:text="collection.collection"
					class="collection-name"
				/>
				<span v-if="collection.meta?.note" class="collection-note">{{ collection.meta.note }}</span>
			</div>

			<v-icon
				v-if="nestedCollections?.length"
				v-tooltip="!isCollapsed ? t('collapse') : t('expand')"
				:name="!isCollapsed ? 'unfold_less' : 'unfold_more'"
				clickable
				class="collapse-toggle"
				@click.stop.prevent="toggleCollapse"
			/>
			<collection-options
				:has-nested-collections="nestedCollections.length > 0"
				:collection="collection"
				@collection-toggle="toggleCollapse"
			/>
		</v-list-item>

		<transition-expand class="collection-items">
			<draggable
				v-if="!isCollapsed"
				:model-value="nestedCollections"
				:group="{ name: 'collections' }"
				:swap-threshold="0.3"
				class="drag-container"
				item-key="collection"
				handle=".drag-handle"
				v-bind="{ 'force-fallback': true }"
				@update:model-value="onGroupSortChange"
			>
				<template #item="{ element }">
					<collection-item
						:collection="element"
Repository: directus/directus
File: sdk/src/rest/commands/create/policies.ts (TypeScript)

Code before:
import type { DirectusPolicy } from '../../../schema/policy.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import type { RestCommand } from '../../types.js';

export type CreatePolicyOutput<
	Schema,
	TQuery extends Query<Schema, Item>,
	Item extends object = DirectusPolicy<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;

/**
 * Create multiple new policies
 *
 * @param items The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy objects for the created policy.
 */
export const createPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		items: Partial<DirectusPolicy<Schema>>[],
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(items),
		method: 'POST',
	});

/**
 * Create a new policy
 *
 * @param item The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy for the created policy.
 */
export const createPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		item: Partial<DirectusPolicy<Schema>>,
		query?: TQuery,

Review comment (suggestion):
```suggestion
 * @param items The policies to create
 * @param query Optional return data query
 *
 * @returns Returns the policy objects for the created policies.
```

Code after:
import type { DirectusPolicy } from '../../../schema/policy.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import type { RestCommand } from '../../types.js';

export type CreatePolicyOutput<
	Schema,
	TQuery extends Query<Schema, Item>,
	Item extends object = DirectusPolicy<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;

/**
 * Create multiple new policies
 *
 * @param items The policies to create
 * @param query Optional return data query
 *
 * @returns Returns the policy objects for the created policies.
 */
export const createPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		items: Partial<DirectusPolicy<Schema>>[],
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(items),
		method: 'POST',
	});

/**
 * Create a new policy
 *
 * @param item The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy object for the created policy.
 */
export const createPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		item: Partial<DirectusPolicy<Schema>>,
		query?: TQuery,
Repository: directus/directus
File: sdk/src/rest/commands/create/policies.ts (TypeScript)

Code before:
 * Create multiple new policies
 *
 * @param items The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy objects for the created policy.
 */
export const createPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		items: Partial<DirectusPolicy<Schema>>[],
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(items),
		method: 'POST',
	});

/**
 * Create a new policy
 *
 * @param item The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy for the created policy.
 */
export const createPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		item: Partial<DirectusPolicy<Schema>>,
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>, Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(item),
		method: 'POST',
	});


Review comment (suggestion):
```suggestion
 * @returns Returns the policy object for the created policy.
```

Code after:
 * Create multiple new policies
 *
 * @param items The policies to create
 * @param query Optional return data query
 *
 * @returns Returns the policy objects for the created policies.
 */
export const createPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		items: Partial<DirectusPolicy<Schema>>[],
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(items),
		method: 'POST',
	});

/**
 * Create a new policy
 *
 * @param item The policy to create
 * @param query Optional return data query
 *
 * @returns Returns the policy object for the created policy.
 */
export const createPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		item: Partial<DirectusPolicy<Schema>>,
		query?: TQuery,
	): RestCommand<CreatePolicyOutput<Schema, TQuery>, Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		body: JSON.stringify(item),
		method: 'POST',
	});
Repository: directus/directus
File: sdk/src/rest/commands/read/policies.ts (TypeScript)

Code before:
import type { DirectusPolicy } from '../../../schema/policy.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import type { RestCommand } from '../../types.js';
import { throwIfEmpty } from '../../utils/index.js';

export type ReadPolicyOutput<
	Schema,
	TQuery extends Query<Schema, Item>,
	Item extends object = DirectusPolicy<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;

export type ReadPolicyGlobalsOutput = {
	app_access: boolean;
	admin_access: boolean;
	enforce_tfa: boolean;
};

/**
 * List all policies that exist in Directus.
 * @param query The query parameters
 * @returns An array of up to limit Permission objects. If no items are available, data will be an empty array.
 */
export const readPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		method: 'GET',
	});

/**
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Permission object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>

Review comment (suggestion):
```suggestion
 * List all policies that exist in the project.
```

Code after:
import type { DirectusPolicy } from '../../../schema/policy.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import type { RestCommand } from '../../types.js';
import { throwIfEmpty } from '../../utils/index.js';

export type ReadPolicyOutput<
	Schema,
	TQuery extends Query<Schema, Item>,
	Item extends object = DirectusPolicy<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;

export type ReadPolicyGlobalsOutput = {
	app_access: boolean;
	admin_access: boolean;
	enforce_tfa: boolean;
};

/**
 * List all policies that exist in the project.
 * @param query The query parameters
 * @returns An array of up to limit Policy objects. If no items are available, data will be an empty array.
 */
export const readPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		method: 'GET',
	});

/**
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Policy object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>
Repository: directus/directus
File: sdk/src/rest/commands/read/policies.ts (TypeScript)

Code before:
export type ReadPolicyGlobalsOutput = {
	app_access: boolean;
	admin_access: boolean;
	enforce_tfa: boolean;
};

/**
 * List all policies that exist in Directus.
 * @param query The query parameters
 * @returns An array of up to limit Permission objects. If no items are available, data will be an empty array.
 */
export const readPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		method: 'GET',
	});

/**
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Permission object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/policies/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * Check the current user's global policy.
 * @param collection The collection of the item
 * @param key The primary key of the item
 * @returns Return
 */
export const readPolicyGlobals =
	<Schema>(): RestCommand<ReadPolicyGlobalsOutput, Schema> =>

Review comment (suggestion):
```suggestion
 * @returns Returns a Policy object if a valid primary key was provided.
```

Code after:
export type ReadPolicyGlobalsOutput = {
	app_access: boolean;
	admin_access: boolean;
	enforce_tfa: boolean;
};

/**
 * List all policies that exist in the project.
 * @param query The query parameters
 * @returns An array of up to limit Policy objects. If no items are available, data will be an empty array.
 */
export const readPolicies =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/policies`,
		params: query ?? {},
		method: 'GET',
	});

/**
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Policy object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/policies/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * Check the current user's policy globals.
 */
export const readPolicyGlobals =
	<Schema>(): RestCommand<ReadPolicyGlobalsOutput, Schema> =>
	() => ({
		path: `/policies/me/globals`,
		method: 'GET',
Repository: directus/directus
File: sdk/src/rest/commands/read/policies.ts (TypeScript)

Code before:
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Permission object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/policies/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * Check the current user's global policy.
 * @param collection The collection of the item
 * @param key The primary key of the item
 * @returns Return
 */
export const readPolicyGlobals =
	<Schema>(): RestCommand<ReadPolicyGlobalsOutput, Schema> =>
	() => ({
		path: `/policies/me/globals`,
		method: 'GET',
	});


Review comment (suggestion):
```suggestion
 * Check the current user's policy globals.
```

Code after:
 * Read a specific policy.
 * @param key The primary key of the permission
 * @param query The query parameters
 * @returns Returns a Policy object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readPolicy =
	<Schema, const TQuery extends Query<Schema, DirectusPolicy<Schema>>>(
		key: DirectusPolicy<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadPolicyOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/policies/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * Check the current user's policy globals.
 */
export const readPolicyGlobals =
	<Schema>(): RestCommand<ReadPolicyGlobalsOutput, Schema> =>
	() => ({
		path: `/policies/me/globals`,
		method: 'GET',
	});
Repository: directus/directus
File: sdk/src/rest/commands/read/roles.ts (TypeScript)

Code before:
/**
 * List an existing Role by primary key.
 * @param key The primary key of the role
 * @param query The query parameters
 * @returns Returns a Role object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readRole =
	<Schema, const TQuery extends Query<Schema, DirectusRole<Schema>>>(
		key: DirectusRole<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadRoleOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/roles/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * List the attached roles for the current user.
 * @param query The query parameters
 * @returns Returns a Role object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readRolesMe =
	<Schema, const TQuery extends Query<Schema, DirectusRole<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadRoleOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/roles/me`,
		params: query ?? {},
		method: 'GET',
	});


Review comment (suggestion):
```suggestion
 * @returns Returns Role objects
```

Code after:
/**
 * List an existing Role by primary key.
 * @param key The primary key of the role
 * @param query The query parameters
 * @returns Returns a Role object if a valid primary key was provided.
 * @throws Will throw if key is empty
 */
export const readRole =
	<Schema, const TQuery extends Query<Schema, DirectusRole<Schema>>>(
		key: DirectusRole<Schema>['id'],
		query?: TQuery,
	): RestCommand<ReadRoleOutput<Schema, TQuery>, Schema> =>
	() => {
		throwIfEmpty(String(key), 'Key cannot be empty');

		return {
			path: `/roles/${key}`,
			params: query ?? {},
			method: 'GET',
		};
	};

/**
 * List the attached roles for the current user.
 * @param query The query parameters
 * @returns Returns Role objects
 * @throws Will throw if key is empty
 */
export const readRolesMe =
	<Schema, const TQuery extends Query<Schema, DirectusRole<Schema>>>(
		query?: TQuery,
	): RestCommand<ReadRoleOutput<Schema, TQuery>[], Schema> =>
	() => ({
		path: `/roles/me`,
		params: query ?? {},
		method: 'GET',
	});
Repository: directus/directus
File: sdk/src/schema/policy.ts (TypeScript)

Code before:
import type { MergeCoreCollection } from '../index.js';
import type { DirectusPermission } from './permission.js';
import type { DirectusRole } from './role.js';
import type { DirectusUser } from './user.js';

/**
 * directus_policies type
 */
export type DirectusPolicy<Schema> = MergeCoreCollection<
	Schema,
	'directus_policies',
	{
		id: string; // uuid
		name: string;
		description: string | null;
		ip_access: string | null;
		enforce_tfa: boolean;
		admin_access: boolean;
		app_access: boolean;
		permissions: number[] | DirectusPermission<Schema>[];
		users: string[] | DirectusUser<Schema>[];
		roles: string[] | DirectusRole<Schema>[];
	}
>;


Review comment (suggestion):
Since the other types don't have such a comment either
```suggestion
```

Code after:
import type { MergeCoreCollection } from '../index.js';
import type { DirectusPermission } from './permission.js';
import type { DirectusRole } from './role.js';
import type { DirectusUser } from './user.js';

export type DirectusPolicy<Schema> = MergeCoreCollection<
	Schema,
	'directus_policies',
	{
		id: string; // uuid
		icon: string | null;
		description: string | null;
		ip_access: string | null;
		enforce_tfa: boolean;
		admin_access: boolean;
		app_access: boolean;
		permissions: number[] | DirectusPermission<Schema>[];
		users: string[] | DirectusUser<Schema>[];
		roles: string[] | DirectusRole<Schema>[];
	}
>;
Repository: directus/directus
File: sdk/src/schema/policy.ts (TypeScript)

Code before:
import type { MergeCoreCollection } from '../index.js';
import type { DirectusPermission } from './permission.js';
import type { DirectusRole } from './role.js';
import type { DirectusUser } from './user.js';

/**
 * directus_policies type
 */
export type DirectusPolicy<Schema> = MergeCoreCollection<
	Schema,
	'directus_policies',
	{
		id: string; // uuid
		name: string;
		description: string | null;
		ip_access: string | null;
		enforce_tfa: boolean;
		admin_access: boolean;
		app_access: boolean;
		permissions: number[] | DirectusPermission<Schema>[];
		users: string[] | DirectusUser<Schema>[];
		roles: string[] | DirectusRole<Schema>[];
	}
>;


Review comment (suggestion):
Has now also an icon 🎨 
```suggestion
		name: string;
		icon: string | null;
```

Code after:
import type { MergeCoreCollection } from '../index.js';
import type { DirectusPermission } from './permission.js';
import type { DirectusRole } from './role.js';
import type { DirectusUser } from './user.js';

export type DirectusPolicy<Schema> = MergeCoreCollection<
	Schema,
	'directus_policies',
	{
		id: string; // uuid
		icon: string | null;
		description: string | null;
		ip_access: string | null;
		enforce_tfa: boolean;
		admin_access: boolean;
		app_access: boolean;
		permissions: number[] | DirectusPermission<Schema>[];
		users: string[] | DirectusUser<Schema>[];
		roles: string[] | DirectusRole<Schema>[];
	}
>;
Repository: directus/directus
File: app/src/interfaces/list-o2m/list-o2m.vue (Vue)

Code before:
		);
	}

	return addRelatedPrimaryKeyToFields(relationInfo.value.relatedCollection.collection, displayFields);
});

const limit = ref(props.limit);
const page = ref(1);
const search = ref('');
const searchFilter = ref<Filter>();
const sort = ref<Sort>();

const query = computed<RelationQueryMultiple>(() => {
	const q: RelationQueryMultiple = {
		limit: limit.value,
		page: page.value,
		fields: fields.value || ['id'],
	};

	if (!relationInfo.value) {
		return q;
	}

	if (props.sort && !relationInfo.value?.sortField) {
		const direction = props.sort_direction ? props.sort_direction : '';
		q.sort = [direction + props.sort];
	}

	if (searchFilter.value) {
		q.filter = searchFilter.value;
	}

	if (search.value) {
		q.search = search.value;
	}

	if (sort.value) {
		q.sort = [`${sort.value.desc ? '-' : ''}${sort.value.by}`];
	}

	return q;
});

watch([search, searchFilter, limit], () => {
	page.value = 1;
});

const {
	create,
	update,
	remove,

Review comment (suggestion):
Let's align that with the manual sort string creation
```suggestion
		q.sort = [`${props.sort_direction ?? ''}${props.sort}`];
```

Code after:
		);
	}

	return addRelatedPrimaryKeyToFields(relationInfo.value.relatedCollection.collection, displayFields);
});

const limit = ref(props.limit);
const page = ref(1);
const search = ref('');
const searchFilter = ref<Filter>();

const manualSort = ref<Sort | null>(
	props.sort && !relationInfo.value?.sortField ? { by: props.sort, desc: props.sortDirection === '-' } : null,
);

const query = computed<RelationQueryMultiple>(() => {
	const q: RelationQueryMultiple = {
		limit: limit.value,
		page: page.value,
		fields: fields.value || ['id'],
	};

	if (!relationInfo.value) {
		return q;
	}

	if (searchFilter.value) {
		q.filter = searchFilter.value;
	}

	if (search.value) {
		q.search = search.value;
	}

	if (manualSort.value) {
		q.sort = [`${manualSort.value.desc ? '-' : ''}${manualSort.value.by}`];
	}

	return q;
});

watch([search, searchFilter, limit], () => {
	page.value = 1;
});

const {
	create,
	update,
	remove,
	select,
	displayItems,