@sanity/runtime-cli 12.2.0 → 12.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -31
- package/dist/actions/blueprints/assets.d.ts +3 -4
- package/dist/actions/blueprints/assets.js +124 -2
- package/dist/baseCommands.d.ts +43 -7
- package/dist/baseCommands.js +82 -10
- package/dist/commands/blueprints/add.d.ts +2 -2
- package/dist/commands/blueprints/add.js +2 -2
- package/dist/commands/blueprints/config.d.ts +2 -2
- package/dist/commands/blueprints/config.js +2 -2
- package/dist/commands/blueprints/deploy.d.ts +2 -2
- package/dist/commands/blueprints/deploy.js +2 -2
- package/dist/commands/blueprints/destroy.d.ts +2 -2
- package/dist/commands/blueprints/destroy.js +2 -2
- package/dist/commands/blueprints/doctor.d.ts +5 -4
- package/dist/commands/blueprints/doctor.js +10 -12
- package/dist/commands/blueprints/info.d.ts +2 -2
- package/dist/commands/blueprints/info.js +2 -2
- package/dist/commands/blueprints/init.d.ts +2 -2
- package/dist/commands/blueprints/init.js +6 -9
- package/dist/commands/blueprints/logs.d.ts +2 -2
- package/dist/commands/blueprints/logs.js +2 -2
- package/dist/commands/blueprints/plan.d.ts +2 -2
- package/dist/commands/blueprints/plan.js +2 -2
- package/dist/commands/blueprints/stacks.d.ts +2 -2
- package/dist/commands/blueprints/stacks.js +2 -2
- package/dist/commands/functions/add.d.ts +2 -2
- package/dist/commands/functions/add.js +2 -2
- package/dist/commands/functions/dev.d.ts +2 -2
- package/dist/commands/functions/dev.js +2 -2
- package/dist/commands/functions/env/add.d.ts +2 -2
- package/dist/commands/functions/env/add.js +2 -2
- package/dist/commands/functions/env/list.d.ts +2 -2
- package/dist/commands/functions/env/list.js +2 -2
- package/dist/commands/functions/env/remove.d.ts +2 -2
- package/dist/commands/functions/env/remove.js +2 -2
- package/dist/commands/functions/logs.d.ts +3 -3
- package/dist/commands/functions/logs.js +7 -4
- package/dist/commands/functions/test.d.ts +3 -3
- package/dist/commands/functions/test.js +7 -4
- package/dist/cores/blueprints/config.d.ts +2 -5
- package/dist/cores/blueprints/deploy.js +29 -13
- package/dist/cores/blueprints/destroy.d.ts +2 -5
- package/dist/cores/blueprints/doctor.js +12 -2
- package/dist/cores/blueprints/info.js +2 -2
- package/dist/cores/blueprints/stacks.d.ts +2 -5
- package/dist/cores/functions/logs.d.ts +3 -1
- package/dist/cores/functions/logs.js +11 -2
- package/dist/cores/functions/test.d.ts +3 -1
- package/dist/cores/functions/test.js +11 -2
- package/dist/server/static/components/app.css +0 -116
- package/dist/server/static/components/clear-button.js +1 -1
- package/dist/server/static/components/console-panel.js +27 -6
- package/dist/server/static/components/fetch-button.js +1 -1
- package/dist/server/static/components/filter-api-version.js +39 -3
- package/dist/server/static/components/filter-document-id.js +39 -3
- package/dist/server/static/components/filter-with-token.js +27 -4
- package/dist/server/static/components/filters.js +127 -62
- package/dist/server/static/components/function-list.js +33 -13
- package/dist/server/static/components/network-spinner.js +6 -4
- package/dist/server/static/components/payload-panel.js +46 -24
- package/dist/server/static/components/response-panel.js +33 -6
- package/dist/server/static/components/rule-panel.js +13 -4
- package/dist/server/static/components/run-panel.js +14 -7
- package/dist/server/static/components/select-dropdown.js +34 -5
- package/dist/server/static/components/shared-styles.js +31 -0
- package/dist/server/static/components/toggle-switch.js +11 -2
- package/dist/utils/display/blueprints-formatting.d.ts +2 -2
- package/dist/utils/display/blueprints-formatting.js +31 -26
- package/dist/utils/find-function.d.ts +4 -0
- package/dist/utils/find-function.js +6 -0
- package/dist/utils/types.d.ts +21 -3
- package/oclif.manifest.json +281 -38
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ import type { CoreConfig, CoreResult } from '../index.js';
|
|
|
3
3
|
export interface FunctionTestOptions extends CoreConfig {
|
|
4
4
|
blueprint: ReadBlueprintResult;
|
|
5
5
|
args: {
|
|
6
|
-
name: string;
|
|
6
|
+
name: string | undefined;
|
|
7
7
|
};
|
|
8
8
|
flags: {
|
|
9
9
|
data?: string;
|
|
@@ -24,5 +24,7 @@ export interface FunctionTestOptions extends CoreConfig {
|
|
|
24
24
|
'document-id-after'?: string;
|
|
25
25
|
'media-library-id'?: string;
|
|
26
26
|
};
|
|
27
|
+
error: (message: string, options: object) => void;
|
|
28
|
+
helpText: string;
|
|
27
29
|
}
|
|
28
30
|
export declare function functionTestCore(options: FunctionTestOptions): Promise<CoreResult>;
|
|
@@ -6,16 +6,25 @@ import { testAction } from '../../actions/functions/test.js';
|
|
|
6
6
|
import config from '../../config.js';
|
|
7
7
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET } from '../../constants.js';
|
|
8
8
|
import buildPayload from '../../utils/build-payload.js';
|
|
9
|
-
import { findFunctionInBlueprint } from '../../utils/find-function.js';
|
|
9
|
+
import { findFunctionInBlueprint, getFunctionNames } from '../../utils/find-function.js';
|
|
10
10
|
import { fetchAsset, fetchDocument } from '../../utils/functions/fetch-document.js';
|
|
11
11
|
import { parseJsonObject } from '../../utils/parse-json-object.js';
|
|
12
12
|
import { isEventType, isGroqContextOptions, } from '../../utils/types.js';
|
|
13
13
|
export async function functionTestCore(options) {
|
|
14
|
-
const { blueprint, log, args, flags } = options;
|
|
14
|
+
const { blueprint, log, error, args, flags, helpText } = options;
|
|
15
15
|
const { name: fnName } = args;
|
|
16
16
|
const { data, event, file, timeout, api, dataset, 'document-id': documentId, 'with-user-token': withUserToken, 'data-before': dataBefore, 'data-after': dataAfter, 'file-before': fileBefore, 'file-after': fileAfter, 'document-id-before': documentIdBefore, 'document-id-after': documentIdAfter, 'media-library-id': mediaLibraryId, } = flags;
|
|
17
17
|
const { parsedBlueprint } = blueprint;
|
|
18
18
|
const { 'project-id': projectId = blueprint?.projectId, 'organization-id': organizationId = blueprint?.organizationId, } = flags;
|
|
19
|
+
if (!fnName) {
|
|
20
|
+
const functionNames = getFunctionNames(blueprint.parsedBlueprint.resources);
|
|
21
|
+
const validNames = functionNames.length > 0
|
|
22
|
+
? `Valid names are: ${functionNames.join(', ')}`
|
|
23
|
+
: 'No functions are defined in the blueprint.';
|
|
24
|
+
error(`Missing required argument: name\n${validNames}\n`, { exit: false });
|
|
25
|
+
log(helpText);
|
|
26
|
+
return { success: true };
|
|
27
|
+
}
|
|
19
28
|
let eventType;
|
|
20
29
|
if (!event) {
|
|
21
30
|
eventType = 'create';
|
|
@@ -747,9 +747,6 @@ body {
|
|
|
747
747
|
header {
|
|
748
748
|
grid-area: header;
|
|
749
749
|
}
|
|
750
|
-
filters-component {
|
|
751
|
-
grid-area: filters;
|
|
752
|
-
}
|
|
753
750
|
nav {
|
|
754
751
|
grid-area: left-sidebar;
|
|
755
752
|
}
|
|
@@ -763,36 +760,6 @@ footer {
|
|
|
763
760
|
grid-area: footer;
|
|
764
761
|
}
|
|
765
762
|
|
|
766
|
-
/* Add styles for filters-component form */
|
|
767
|
-
/* Default (Mobile) Styles */
|
|
768
|
-
filters-component form {
|
|
769
|
-
display: block; /* Stack direct children */
|
|
770
|
-
padding: var(--m-space-3); /* Consistent padding */
|
|
771
|
-
border-bottom: 1px solid var(--card-border-color);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
filters-component form > * {
|
|
775
|
-
/* Target direct children: dropdowns, fieldset */
|
|
776
|
-
display: block; /* Ensure they are block level */
|
|
777
|
-
width: 100%; /* Make them take full width */
|
|
778
|
-
margin-bottom: var(--m-space-3); /* Add space below each item when stacked */
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
filters-component form > *:last-child {
|
|
782
|
-
margin-bottom: 0; /* Remove margin from the last stacked item */
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
filters-component form label {
|
|
786
|
-
display: block; /* Ensure label stacks above input if needed */
|
|
787
|
-
margin-bottom: var(--m-space-1); /* Small space between label and input */
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
filters-component form input {
|
|
791
|
-
width: 100%; /* Make input fill its container */
|
|
792
|
-
box-sizing: border-box; /* Include padding/border in width calculation */
|
|
793
|
-
}
|
|
794
|
-
/* End of Mobile Styles */
|
|
795
|
-
|
|
796
763
|
/* Apply grid styles to main#main-content */
|
|
797
764
|
#main-content {
|
|
798
765
|
display: grid;
|
|
@@ -808,26 +775,6 @@ filters-component form input {
|
|
|
808
775
|
min-height: 0; /* Important for nested overflow/height */
|
|
809
776
|
}
|
|
810
777
|
|
|
811
|
-
payload-panel {
|
|
812
|
-
grid-area: payload;
|
|
813
|
-
max-height: 100%; /* Fit within allocated grid row space */
|
|
814
|
-
overflow: hidden; /* Let internal elements scroll */
|
|
815
|
-
min-height: 0; /* Allow shrinking */
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
response-panel {
|
|
819
|
-
grid-area: response;
|
|
820
|
-
max-height: 100%;
|
|
821
|
-
overflow: hidden;
|
|
822
|
-
min-height: 0;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/* Target console-panel for grid area and height constraints */
|
|
826
|
-
console-panel {
|
|
827
|
-
grid-area: console;
|
|
828
|
-
overflow: hidden; /* The inner div handles scrolling */
|
|
829
|
-
}
|
|
830
|
-
|
|
831
778
|
@media (max-width: 40rem) {
|
|
832
779
|
/* Mobile layout: stack elements vertically */
|
|
833
780
|
#main-content {
|
|
@@ -843,20 +790,6 @@ console-panel {
|
|
|
843
790
|
overflow-y: auto; /* Allow scrolling for the whole main area */
|
|
844
791
|
}
|
|
845
792
|
|
|
846
|
-
/* Reset max-heights on mobile if they cause layout issues */
|
|
847
|
-
payload-panel,
|
|
848
|
-
response-panel,
|
|
849
|
-
console-panel {
|
|
850
|
-
max-height: none;
|
|
851
|
-
min-height: 200px; /* Give some minimum space on mobile */
|
|
852
|
-
overflow: auto; /* Allow individual scrolling if content is large */
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/* Ensure console has reasonable height on mobile */
|
|
856
|
-
console-panel {
|
|
857
|
-
max-height: 400px; /* Allow more console height on mobile maybe */
|
|
858
|
-
}
|
|
859
|
-
|
|
860
793
|
.block-lg {
|
|
861
794
|
display: block !important;
|
|
862
795
|
}
|
|
@@ -878,27 +811,6 @@ console-panel {
|
|
|
878
811
|
.border-top-none-l {
|
|
879
812
|
border-top: 0;
|
|
880
813
|
}
|
|
881
|
-
|
|
882
|
-
/* Revert filters-component form to horizontal layout on larger screens */
|
|
883
|
-
filters-component form {
|
|
884
|
-
display: flex;
|
|
885
|
-
flex-direction: row;
|
|
886
|
-
align-items: flex-end; /* Align form elements along their bottom edge */
|
|
887
|
-
gap: var(--m-space-3); /* Space between elements */
|
|
888
|
-
padding-left: var(--m-space-3);
|
|
889
|
-
padding-bottom: var(--m-space-3);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
filters-component form > * {
|
|
893
|
-
width: auto; /* Allow elements to size based on content/flex rules */
|
|
894
|
-
margin-bottom: 0; /* Remove stacking margin */
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
/* Optional: Give API version input a specific width or allow growth */
|
|
898
|
-
filters-component form fieldset {
|
|
899
|
-
min-width: 150px; /* Example minimum width */
|
|
900
|
-
/* flex-grow: 1; */ /* Uncomment to allow it to fill space */
|
|
901
|
-
}
|
|
902
814
|
}
|
|
903
815
|
|
|
904
816
|
header {
|
|
@@ -1088,34 +1000,6 @@ time {
|
|
|
1088
1000
|
font-family: var(--font-family-mono);
|
|
1089
1001
|
}
|
|
1090
1002
|
|
|
1091
|
-
response-panel,
|
|
1092
|
-
payload-panel {
|
|
1093
|
-
max-height: 100%;
|
|
1094
|
-
height: 100%;
|
|
1095
|
-
overflow: hidden;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
toggle-switch {
|
|
1099
|
-
display: inline-block;
|
|
1100
|
-
cursor: pointer;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
toggle-switch::part(track) {
|
|
1104
|
-
padding: 0.125em;
|
|
1105
|
-
border-radius: 1em;
|
|
1106
|
-
background-color: hsl(0, 0%, 67%);
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
toggle-switch::part(slider) {
|
|
1110
|
-
border-radius: 1em;
|
|
1111
|
-
background-color: hsl(0, 0%, 100%);
|
|
1112
|
-
box-shadow: 0.0625em 0.0625em 0.125em hsla(0, 0%, 0%, 0.25);
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
toggle-switch[checked]::part(track) {
|
|
1116
|
-
background-color: var(--color-interactive-primary-active-bg);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
1003
|
/* Default sidebar */
|
|
1120
1004
|
#sidebar {
|
|
1121
1005
|
transition:
|
|
@@ -36,10 +36,10 @@ export class ClearButton extends ApiBaseElement {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
clear = () => {
|
|
39
|
-
// this.api.store.result = {logs: '', timings: {bundle: 0, execute: 0}}
|
|
40
39
|
this.dispatchEvent(
|
|
41
40
|
new CustomEvent('clear-console', {
|
|
42
41
|
bubbles: true,
|
|
42
|
+
composed: true,
|
|
43
43
|
}),
|
|
44
44
|
)
|
|
45
45
|
}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
/* globals customElements document */
|
|
2
2
|
import {ApiBaseElement} from './api-base.js'
|
|
3
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
3
4
|
|
|
4
5
|
// Template for the console panel
|
|
5
|
-
const template =
|
|
6
|
+
const template = document.createElement('template')
|
|
7
|
+
template.innerHTML = `
|
|
8
|
+
<style>
|
|
9
|
+
:host {
|
|
10
|
+
grid-area: console;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@media (max-width: 40rem) {
|
|
15
|
+
:host {
|
|
16
|
+
max-height: 400px;
|
|
17
|
+
min-height: 200px;
|
|
18
|
+
overflow: auto;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
6
22
|
<div id="console-container" class="relative y-scroll h-100 max-h-100 bg-base pad-t-0 pad-r-3 pad-b-7 pad-l-5 border-top">
|
|
7
23
|
<div class="sticky top-0 left-0 right-0 mar-t-0 mar-b-0">
|
|
8
24
|
<h3 class="config-label mar-t-0 mar-b-0 pad-t-3 bg-base z-32">
|
|
@@ -17,10 +33,13 @@ const template = `
|
|
|
17
33
|
</div>
|
|
18
34
|
<pre id="console-output" class="pad-0 mar-t-0 mar-r-0 mar-b-5 mar-l-0 pre-wrap break-word"></pre>
|
|
19
35
|
</div>
|
|
20
|
-
|
|
21
36
|
`
|
|
22
37
|
|
|
23
38
|
class ConsolePanel extends ApiBaseElement {
|
|
39
|
+
constructor() {
|
|
40
|
+
super()
|
|
41
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
42
|
+
}
|
|
24
43
|
updateConsole = ({result}) => {
|
|
25
44
|
// Guard against element not being ready or API not injected yet
|
|
26
45
|
if (!this.consoleOutput || !result) return
|
|
@@ -45,13 +64,15 @@ class ConsolePanel extends ApiBaseElement {
|
|
|
45
64
|
clear = () => {
|
|
46
65
|
const backUp = this.api.store.preserveLog
|
|
47
66
|
this.api.store.result = {logs: undefined, error: undefined}
|
|
48
|
-
this.
|
|
67
|
+
this.consoleOutput.innerText = ''
|
|
49
68
|
this.api.store.preserveLog = backUp
|
|
50
69
|
}
|
|
51
70
|
|
|
52
|
-
connectedCallback() {
|
|
53
|
-
|
|
54
|
-
this.
|
|
71
|
+
async connectedCallback() {
|
|
72
|
+
const sheets = await getSharedStyleSheets()
|
|
73
|
+
this.shadowRoot.adoptedStyleSheets = sheets
|
|
74
|
+
|
|
75
|
+
this.consoleOutput = this.shadowRoot.querySelector('#console-output')
|
|
55
76
|
this.addEventListener('clear-console', this.clear)
|
|
56
77
|
|
|
57
78
|
// Subscribe to changes in the result state to update the console
|
|
@@ -56,7 +56,7 @@ export class FetchButton extends ApiBaseElement {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
fetchDoc = async () => {
|
|
59
|
-
const docId =
|
|
59
|
+
const docId = this.api.store.docId.trim()
|
|
60
60
|
|
|
61
61
|
if (docId) {
|
|
62
62
|
const originalContent = this.button.innerHTML
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {ApiBaseElement} from './api-base.js'
|
|
2
|
+
|
|
3
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
4
|
+
|
|
5
|
+
const template = document.createElement('template')
|
|
6
|
+
template.innerHTML = `
|
|
4
7
|
<fieldset class="mar-t-2">
|
|
5
8
|
<label class="slab-text">
|
|
6
9
|
<span class="block mar-b-1">API Version</span>
|
|
@@ -8,6 +11,39 @@ class ApiVersionComponent extends HTMLElement {
|
|
|
8
11
|
</label>
|
|
9
12
|
</fieldset>
|
|
10
13
|
`
|
|
14
|
+
|
|
15
|
+
class ApiVersionComponent extends ApiBaseElement {
|
|
16
|
+
constructor() {
|
|
17
|
+
super()
|
|
18
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async connectedCallback() {
|
|
22
|
+
const sheets = await getSharedStyleSheets()
|
|
23
|
+
|
|
24
|
+
// Create a component-specific stylesheet that will be applied after shared styles
|
|
25
|
+
const componentSheet = new CSSStyleSheet()
|
|
26
|
+
await componentSheet.replace(`
|
|
27
|
+
:host {
|
|
28
|
+
align-self: flex-end;
|
|
29
|
+
}
|
|
30
|
+
fieldset {
|
|
31
|
+
margin-top: 0 !important;
|
|
32
|
+
}
|
|
33
|
+
input {
|
|
34
|
+
background: transparent !important;
|
|
35
|
+
color: light-dark(var(--gray-950), var(--gray-300)) !important;
|
|
36
|
+
}
|
|
37
|
+
`)
|
|
38
|
+
|
|
39
|
+
this.shadowRoot.adoptedStyleSheets = [...sheets, componentSheet]
|
|
40
|
+
|
|
41
|
+
this.input = this.shadowRoot.querySelector('input')
|
|
42
|
+
this.input.addEventListener('input', this.updateApiVersion)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
updateApiVersion = (event) => {
|
|
46
|
+
this.api.store.apiVersion = event.target.value
|
|
11
47
|
}
|
|
12
48
|
}
|
|
13
49
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {ApiBaseElement} from './api-base.js'
|
|
2
|
+
|
|
3
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
4
|
+
|
|
5
|
+
const template = document.createElement('template')
|
|
6
|
+
template.innerHTML = `
|
|
4
7
|
<fieldset class="mar-t-2">
|
|
5
8
|
<label class="slab-text">
|
|
6
9
|
<span class="block mar-b-1">
|
|
@@ -20,6 +23,39 @@ class DocumentIdFilter extends HTMLElement {
|
|
|
20
23
|
</label>
|
|
21
24
|
</fieldset>
|
|
22
25
|
`
|
|
26
|
+
|
|
27
|
+
class DocumentIdFilter extends ApiBaseElement {
|
|
28
|
+
constructor() {
|
|
29
|
+
super()
|
|
30
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async connectedCallback() {
|
|
34
|
+
const sheets = await getSharedStyleSheets()
|
|
35
|
+
|
|
36
|
+
// Create a component-specific stylesheet that will be applied after shared styles
|
|
37
|
+
const componentSheet = new CSSStyleSheet()
|
|
38
|
+
await componentSheet.replace(`
|
|
39
|
+
:host {
|
|
40
|
+
align-self: flex-end;
|
|
41
|
+
}
|
|
42
|
+
fieldset {
|
|
43
|
+
margin-top: 0 !important;
|
|
44
|
+
}
|
|
45
|
+
input {
|
|
46
|
+
background: transparent !important;
|
|
47
|
+
color: light-dark(var(--gray-950), var(--gray-300)) !important;
|
|
48
|
+
}
|
|
49
|
+
`)
|
|
50
|
+
|
|
51
|
+
this.shadowRoot.adoptedStyleSheets = [...sheets, componentSheet]
|
|
52
|
+
|
|
53
|
+
this.input = this.shadowRoot.querySelector('input')
|
|
54
|
+
this.input.addEventListener('input', this.updateDocId)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updateDocId = (event) => {
|
|
58
|
+
this.api.store.docId = event.target.value
|
|
23
59
|
}
|
|
24
60
|
}
|
|
25
61
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
2
|
+
|
|
3
|
+
const template = document.createElement('template')
|
|
4
|
+
template.innerHTML = `
|
|
5
|
+
<fieldset class="mar-t-2 flex flex-col">
|
|
5
6
|
<span class="slab-text block mar-b-1">
|
|
6
7
|
<span class="flex items-center">
|
|
7
8
|
With Token
|
|
@@ -15,6 +16,28 @@ class WithTokenComponent extends HTMLElement {
|
|
|
15
16
|
<toggle-switch toggle-key="withToken" class="flex component-height"></toggle-switch>
|
|
16
17
|
</fieldset>
|
|
17
18
|
`
|
|
19
|
+
|
|
20
|
+
class WithTokenComponent extends HTMLElement {
|
|
21
|
+
constructor() {
|
|
22
|
+
super()
|
|
23
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async connectedCallback() {
|
|
27
|
+
const sheets = await getSharedStyleSheets()
|
|
28
|
+
|
|
29
|
+
// Create a component-specific stylesheet that will be applied after shared styles
|
|
30
|
+
const componentSheet = new CSSStyleSheet()
|
|
31
|
+
await componentSheet.replace(`
|
|
32
|
+
:host {
|
|
33
|
+
align-self: flex-end;
|
|
34
|
+
}
|
|
35
|
+
fieldset {
|
|
36
|
+
margin-top: 0 !important;
|
|
37
|
+
}
|
|
38
|
+
`)
|
|
39
|
+
|
|
40
|
+
this.shadowRoot.adoptedStyleSheets = [...sheets, componentSheet]
|
|
18
41
|
}
|
|
19
42
|
}
|
|
20
43
|
|
|
@@ -1,75 +1,140 @@
|
|
|
1
1
|
import {ApiBaseElement} from './api-base.js'
|
|
2
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
3
|
+
|
|
4
|
+
const template = document.createElement('template')
|
|
5
|
+
template.innerHTML = `
|
|
6
|
+
<style>
|
|
7
|
+
:host {
|
|
8
|
+
grid-area: filters;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
form {
|
|
12
|
+
display: block;
|
|
13
|
+
padding: var(--m-space-3);
|
|
14
|
+
border-bottom: 1px solid var(--card-border-color);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
form > * {
|
|
18
|
+
display: block;
|
|
19
|
+
width: 100%;
|
|
20
|
+
margin-bottom: var(--m-space-3);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
form > *:last-child {
|
|
24
|
+
margin-bottom: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
form label {
|
|
28
|
+
display: block;
|
|
29
|
+
margin-bottom: var(--m-space-1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
form input {
|
|
33
|
+
width: 100%;
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@media (min-width: 40em) {
|
|
38
|
+
form {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: row;
|
|
41
|
+
align-items: flex-end;
|
|
42
|
+
gap: var(--m-space-3);
|
|
43
|
+
padding-left: var(--m-space-3);
|
|
44
|
+
padding-bottom: var(--m-space-3);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
form > * {
|
|
48
|
+
width: auto;
|
|
49
|
+
margin-bottom: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
form fieldset {
|
|
53
|
+
min-width: 150px;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
57
|
+
<form class="gap-2 pad-l-3 pad-b-3 border-bottom">
|
|
58
|
+
<fieldset class="flex gap-2">
|
|
59
|
+
<legend class="config-label">Client Options</legend>
|
|
60
|
+
<div id="dynamic-dropdowns" class="flex gap-2"></div>
|
|
61
|
+
<select-dropdown
|
|
62
|
+
label="Event"
|
|
63
|
+
store-key="events"
|
|
64
|
+
selected-key="selectedEvent"
|
|
65
|
+
value-prop="name"
|
|
66
|
+
label-prop="name"
|
|
67
|
+
></select-dropdown>
|
|
68
|
+
<api-version></api-version>
|
|
69
|
+
<with-token></with-token>
|
|
70
|
+
<document-id></document-id>
|
|
71
|
+
</fieldset>
|
|
72
|
+
</form>
|
|
73
|
+
`
|
|
2
74
|
|
|
3
75
|
class FiltersComponent extends ApiBaseElement {
|
|
76
|
+
constructor() {
|
|
77
|
+
super()
|
|
78
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async connectedCallback() {
|
|
82
|
+
const sheets = await getSharedStyleSheets()
|
|
83
|
+
this.shadowRoot.adoptedStyleSheets = sheets
|
|
84
|
+
|
|
85
|
+
this.renderFilters()
|
|
86
|
+
this.api.subscribe(this.renderFilters, ['selectedFunctionType'])
|
|
87
|
+
}
|
|
88
|
+
|
|
4
89
|
renderFilters = () => {
|
|
5
90
|
const docFunction = this.api.store.selectedFunctionType === 'sanity.function.document'
|
|
6
91
|
const mediaFunction = this.api.store.selectedFunctionType?.startsWith(
|
|
7
92
|
'sanity.function.media-library',
|
|
8
93
|
)
|
|
9
94
|
|
|
10
|
-
|
|
11
|
-
<form class="gap-2 pad-l-3 pad-b-3 border-bottom">
|
|
12
|
-
<fieldset class="flex gap-2">
|
|
13
|
-
<legend class="config-label">Client Options</legend>
|
|
14
|
-
${
|
|
15
|
-
docFunction
|
|
16
|
-
? `<select-dropdown
|
|
17
|
-
label="Project"
|
|
18
|
-
store-key="projects"
|
|
19
|
-
selected-key="selectedProject"
|
|
20
|
-
value-prop="id"
|
|
21
|
-
label-prop="displayName"
|
|
22
|
-
trigger-fetch
|
|
23
|
-
></select-dropdown>
|
|
24
|
-
<select-dropdown
|
|
25
|
-
label="Dataset"
|
|
26
|
-
store-key="datasets"
|
|
27
|
-
selected-key="selectedDataset"
|
|
28
|
-
value-prop="name"
|
|
29
|
-
label-prop="name"
|
|
30
|
-
subscribe-to="selectedProject"
|
|
31
|
-
></select-dropdown>`
|
|
32
|
-
: ''
|
|
33
|
-
}
|
|
34
|
-
${
|
|
35
|
-
mediaFunction
|
|
36
|
-
? `<select-dropdown
|
|
37
|
-
label="Organization"
|
|
38
|
-
store-key="organizations"
|
|
39
|
-
selected-key="selectedOrganization"
|
|
40
|
-
value-prop="id"
|
|
41
|
-
label-prop="name"
|
|
42
|
-
trigger-fetch
|
|
43
|
-
></select-dropdown>
|
|
44
|
-
<select-dropdown
|
|
45
|
-
label="Media Library"
|
|
46
|
-
store-key="mediaLibraries"
|
|
47
|
-
selected-key="selectedMediaLibrary"
|
|
48
|
-
value-prop="id"
|
|
49
|
-
label-prop="id"
|
|
50
|
-
subscribe-to="selectedOrganization"
|
|
51
|
-
></select-dropdown>`
|
|
52
|
-
: ''
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
<select-dropdown
|
|
56
|
-
label="Event"
|
|
57
|
-
store-key="events"
|
|
58
|
-
selected-key="selectedEvent"
|
|
59
|
-
value-prop="name"
|
|
60
|
-
label-prop="name"
|
|
61
|
-
></select-dropdown>
|
|
62
|
-
|
|
63
|
-
<api-version></api-version>
|
|
64
|
-
<with-token></with-token>
|
|
65
|
-
<document-id></document-id>
|
|
66
|
-
</form>
|
|
67
|
-
`
|
|
68
|
-
}
|
|
95
|
+
const container = this.shadowRoot.querySelector('#dynamic-dropdowns')
|
|
69
96
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
97
|
+
if (docFunction) {
|
|
98
|
+
container.innerHTML = `
|
|
99
|
+
<select-dropdown
|
|
100
|
+
label="Project"
|
|
101
|
+
store-key="projects"
|
|
102
|
+
selected-key="selectedProject"
|
|
103
|
+
value-prop="id"
|
|
104
|
+
label-prop="displayName"
|
|
105
|
+
trigger-fetch
|
|
106
|
+
></select-dropdown>
|
|
107
|
+
<select-dropdown
|
|
108
|
+
label="Dataset"
|
|
109
|
+
store-key="datasets"
|
|
110
|
+
selected-key="selectedDataset"
|
|
111
|
+
value-prop="name"
|
|
112
|
+
label-prop="name"
|
|
113
|
+
subscribe-to="selectedProject"
|
|
114
|
+
></select-dropdown>
|
|
115
|
+
`
|
|
116
|
+
} else if (mediaFunction) {
|
|
117
|
+
container.innerHTML = `
|
|
118
|
+
<select-dropdown
|
|
119
|
+
label="Organization"
|
|
120
|
+
store-key="organizations"
|
|
121
|
+
selected-key="selectedOrganization"
|
|
122
|
+
value-prop="id"
|
|
123
|
+
label-prop="name"
|
|
124
|
+
trigger-fetch
|
|
125
|
+
></select-dropdown>
|
|
126
|
+
<select-dropdown
|
|
127
|
+
label="Media Library"
|
|
128
|
+
store-key="mediaLibraries"
|
|
129
|
+
selected-key="selectedMediaLibrary"
|
|
130
|
+
value-prop="id"
|
|
131
|
+
label-prop="id"
|
|
132
|
+
subscribe-to="selectedOrganization"
|
|
133
|
+
></select-dropdown>
|
|
134
|
+
`
|
|
135
|
+
} else {
|
|
136
|
+
container.innerHTML = ''
|
|
137
|
+
}
|
|
73
138
|
}
|
|
74
139
|
|
|
75
140
|
disconnectedCallback() {
|