mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
Fix condition to show schema preview when in table/json view
This commit is contained in:
parent
843876e4b0
commit
bf35095e8d
|
@ -2,7 +2,7 @@ import { request } from '@/utils/apiUtils';
|
|||
import type { JSONSchema7 } from 'json-schema';
|
||||
|
||||
export type GetSchemaPreviewOptions = {
|
||||
nodeName: string;
|
||||
nodeType: string;
|
||||
version: number;
|
||||
resource?: string;
|
||||
operation?: string;
|
||||
|
@ -16,9 +16,9 @@ export const getSchemaPreview = async (
|
|||
baseUrl: string,
|
||||
options: GetSchemaPreviewOptions,
|
||||
): Promise<JSONSchema7> => {
|
||||
const { nodeName, version, resource, operation } = options;
|
||||
const { nodeType, version, resource, operation } = options;
|
||||
const versionString = padVersion(version);
|
||||
const path = ['schemas', nodeName, versionString, resource, operation].filter(Boolean).join('/');
|
||||
const path = ['schemas', nodeType, versionString, resource, operation].filter(Boolean).join('/');
|
||||
return await request({
|
||||
method: 'GET',
|
||||
baseURL: baseUrl,
|
||||
|
|
|
@ -62,7 +62,7 @@ import { useWorkflowsStore } from '@/stores/workflows.store';
|
|||
import { executionDataToJson } from '@/utils/nodeTypesUtils';
|
||||
import { getGenericHints } from '@/utils/nodeViewUtils';
|
||||
import { searchInObject } from '@/utils/objectUtils';
|
||||
import { clearJsonKey, isEmpty } from '@/utils/typesUtils';
|
||||
import { clearJsonKey, isEmpty, isPresent } from '@/utils/typesUtils';
|
||||
import { isEqual, isObject } from 'lodash-es';
|
||||
import {
|
||||
N8nBlockUi,
|
||||
|
@ -561,19 +561,24 @@ const isSchemaPreviewEnabled = computed(
|
|||
);
|
||||
|
||||
const hasPreviewSchema = asyncComputed(async () => {
|
||||
if (!node.value || !isSchemaPreviewEnabled.value) return false;
|
||||
const {
|
||||
type,
|
||||
typeVersion,
|
||||
parameters: { resource, operation },
|
||||
} = node.value;
|
||||
const preview = await schemaPreviewStore.getSchemaPreview({
|
||||
nodeName: type,
|
||||
version: typeVersion,
|
||||
resource: resource as string,
|
||||
operation: operation as string,
|
||||
});
|
||||
return preview.ok;
|
||||
if (!isSchemaPreviewEnabled.value || props.nodes.length === 0) return false;
|
||||
const nodes = props.nodes
|
||||
.filter((n) => n.depth === 1)
|
||||
.map((n) => workflowsStore.getNodeByName(n.name))
|
||||
.filter(isPresent);
|
||||
|
||||
for (const connectedNode of nodes) {
|
||||
const { type, typeVersion, parameters } = connectedNode;
|
||||
const hasPreview = await schemaPreviewStore.getSchemaPreview({
|
||||
nodeType: type,
|
||||
version: typeVersion,
|
||||
resource: parameters.resource as string,
|
||||
operation: parameters.operation as string,
|
||||
});
|
||||
|
||||
if (hasPreview.ok) return true;
|
||||
}
|
||||
return false;
|
||||
}, false);
|
||||
|
||||
watch(node, (newNode, prevNode) => {
|
||||
|
@ -1622,7 +1627,7 @@ defineExpose({ enterEditMode });
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="!hasNodeRun && !(displaysMultipleNodes && node?.disabled) && !hasPreviewSchema"
|
||||
v-else-if="!hasNodeRun && !(displaysMultipleNodes && (node?.disabled || hasPreviewSchema))"
|
||||
:class="$style.center"
|
||||
>
|
||||
<slot name="node-not-run"></slot>
|
||||
|
|
|
@ -152,7 +152,7 @@ async function getSchemaPreview(node: INodeUi | null) {
|
|||
} = node;
|
||||
|
||||
return await schemaPreviewStore.getSchemaPreview({
|
||||
nodeName: type,
|
||||
nodeType: type,
|
||||
version: typeVersion,
|
||||
resource: resource as string,
|
||||
operation: operation as string,
|
||||
|
|
|
@ -124,7 +124,7 @@ const emit = defineEmits<{
|
|||
}
|
||||
|
||||
.notice {
|
||||
margin-left: var(--spacing-xl);
|
||||
margin-left: var(--spacing-2xl);
|
||||
margin-top: var(--spacing-2xs);
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
|
|
@ -7,17 +7,20 @@ import type { JSONSchema7 } from 'json-schema';
|
|||
|
||||
export const useSchemaPreviewStore = defineStore('schemaPreview', () => {
|
||||
// Type cast to avoid 'Type instantiation is excessively deep and possibly infinite'
|
||||
const schemaPreviews = reactive<Map<string, JSONSchema7>>(new Map()) as Map<string, JSONSchema7>;
|
||||
const schemaPreviews = reactive<Map<string, Result<JSONSchema7, Error>>>(new Map()) as Map<
|
||||
string,
|
||||
Result<JSONSchema7, Error>
|
||||
>;
|
||||
|
||||
const rootStore = useRootStore();
|
||||
|
||||
function getSchemaPreviewKey({
|
||||
nodeName,
|
||||
nodeType,
|
||||
version,
|
||||
operation,
|
||||
resource,
|
||||
}: schemaPreviewApi.GetSchemaPreviewOptions) {
|
||||
return `${nodeName}_${version}_${resource ?? 'all'}_${operation ?? 'all'}`;
|
||||
return `${nodeType}_${version}_${resource ?? 'all'}_${operation ?? 'all'}`;
|
||||
}
|
||||
|
||||
async function getSchemaPreview(
|
||||
|
@ -25,14 +28,17 @@ export const useSchemaPreviewStore = defineStore('schemaPreview', () => {
|
|||
): Promise<Result<JSONSchema7, Error>> {
|
||||
const key = getSchemaPreviewKey(options);
|
||||
const cached = schemaPreviews.get(key);
|
||||
if (cached) return createResultOk(cached);
|
||||
if (cached) return cached;
|
||||
|
||||
try {
|
||||
const preview = await schemaPreviewApi.getSchemaPreview(rootStore.baseUrl, options);
|
||||
schemaPreviews.set(key, preview);
|
||||
return createResultOk(preview);
|
||||
const result = createResultOk(preview);
|
||||
schemaPreviews.set(key, result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
return createResultError(error);
|
||||
const result = createResultError(error);
|
||||
schemaPreviews.set(key, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue