Skip to content

Commit

Permalink
Add yadocs to file connections (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
imsitnikov authored Mar 1, 2024
1 parent e3a5c13 commit cbd5c8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/db/models/new/entry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export enum EntryScope {
export enum EntryType {
File = 'file',
GsheetsV2 = 'gsheets_v2',
YaDocs = 'yadocs',
// types can be added as needed
}
7 changes: 1 addition & 6 deletions src/services/entry/actions/copy-to-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {AppError} from '@gravity-ui/nodekit';

import {getId} from '../../../db';
import {Entry, EntryColumn} from '../../../db/models/new/entry';
import {EntryScope, EntryType} from '../../../db/models/new/entry/types';
import {JoinedEntryRevision} from '../../../db/presentations/joined-entry-revision';
import {WorkbookModel} from '../../../db/models/new/workbook';
import {CTX} from '../../../types/models';
Expand Down Expand Up @@ -58,8 +57,6 @@ export const validateParams = makeSchemaValidator({
},
});

const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2];

export const copyToWorkbook = async (ctx: CTX, params: Params) => {
const {
entryIds,
Expand Down Expand Up @@ -147,9 +144,7 @@ export const copyToWorkbook = async (ctx: CTX, params: Params) => {
}
}

const isFileConnection =
joinedEntryRevision.scope === EntryScope.Connection &&
fileConnectionTypes.includes(joinedEntryRevision.type);
const isFileConnection = Utils.isFileConnection(joinedEntryRevision);

if (isFileConnection) {
throw new AppError(
Expand Down
20 changes: 13 additions & 7 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {EntryScope, USAPIResponse} from '../types/models';

import {ID_VARIABLES, CODING_BASE, TRUE_FLAGS, COPY_START, COPY_END} from '../const';

import type {Entry} from '../db/models/new/entry';
import {EntryScope as EntryScopeEnum, EntryType} from '../db/models/new/entry/types';

const PROFILES: {
Expand Down Expand Up @@ -351,14 +350,21 @@ export class Utils {
.join('');
}

static checkFileConnectionsExistence(entries: Entry[]) {
const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2];
static isFileConnection(entry: {scope: Nullable<EntryScope>; type: string}) {
const fileConnectionTypes: string[] = [
EntryType.File,
EntryType.GsheetsV2,
EntryType.YaDocs,
];

return (
entry.scope === EntryScopeEnum.Connection && fileConnectionTypes.includes(entry.type)
);
}

static checkFileConnectionsExistence(entries: {scope: Nullable<EntryScope>; type: string}[]) {
return entries.some((entry) => {
return (
entry.scope === EntryScopeEnum.Connection &&
fileConnectionTypes.includes(entry.type)
);
return Utils.isFileConnection(entry);
});
}

Expand Down

0 comments on commit cbd5c8d

Please sign in to comment.