Skip to content

Commit

Permalink
don't repeat labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Oct 26, 2023
1 parent 1b000f6 commit 2d43a9c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 39 deletions.
38 changes: 24 additions & 14 deletions src/models/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export interface DataSourceFiles {
sortCols: string[];
slice: string[];
labels: string[];
optional?: {
fill: boolean;
temporality: boolean;
slices: Slice[];
filters: Filter[];
labels: Label[];
sorts: Sort[];
aggs: Agg[];
groups: Group[];
};
};
qsql: {
query: string;
Expand Down Expand Up @@ -107,6 +117,20 @@ export const aggOperators = [
"var",
];

export type Slice = {
active: boolean;
start: string;
end: string;
};

export function createSlice(): Slice {
return {
active: false,
start: "",
end: "",
};
}

export type Filter = {
active: boolean;
column: string;
Expand Down Expand Up @@ -176,17 +200,3 @@ export function createGroup(): Group {
column: "",
};
}

export type Slice = {
active: boolean;
start: string;
end: string;
};

export function createSlice(): Slice {
return {
active: false,
start: "",
end: "",
};
}
107 changes: 82 additions & 25 deletions src/webview/components/kdbDataSourceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,28 @@ export class KdbDataSourceView extends LitElement {
event.target as HTMLInputElement
).checked)}"></vscode-checkbox>
<div class="dropdown-container">
<label>Filter By Column</label>
<label
>${this.filters.indexOf(filter) === 0
? "Filter By Column"
: ""}</label
>
<vscode-dropdown
class="dropdown"
value="${filter.column}"
@change="${(event: Event) =>
(filter.column = (event.target as HTMLInputElement).value)}"
>${this.renderColumnOptions(filter.column)}
</vscode-dropdown>
</div>
<div class="dropdown-container">
<label>Apply Function</label>
<label
>${this.filters.indexOf(filter) === 0
? "Apply Function"
: ""}</label
>
<vscode-dropdown
class="dropdown"
value="${filter.operator}"
@change="${(event: Event) =>
(filter.operator = (event.target as HTMLInputElement).value)}">
${filterOperators.map(
Expand All @@ -272,15 +282,14 @@ export class KdbDataSourceView extends LitElement {
value="${filter.values}"
@input="${(event: Event) =>
(filter.values = (event.target as HTMLInputElement).value)}"
>Set Parameter</vscode-text-field
>
>${this.filters.indexOf(filter) === 0 ? "Set Parameter" : ""}
</vscode-text-field>
<div class="row gap-1 align-end">
<vscode-button
aria-label="Add Filter"
appearance="secondary"
@click="${() => {
if (this.filters.length < MAX_ITEMS) {
// TODO
const index = this.filters.indexOf(filter);
const value = this.filters;
this.filters = [];
Expand All @@ -298,14 +307,16 @@ export class KdbDataSourceView extends LitElement {
aria-label="Remove Filter"
appearance="secondary"
@click="${() => {
if (this.filters.length > 1) {
// TODO
if (this.filters.length > 0) {
const index = this.filters.indexOf(filter);
const value = this.filters;
this.filters = [];
this.requestUpdate();
queueMicrotask(() => {
value.splice(index, 1);
if (value.length === 0) {
value.push(createFilter());
}
this.filters = value;
this.requestUpdate();
});
Expand All @@ -327,11 +338,21 @@ export class KdbDataSourceView extends LitElement {
(label.active = (
event.target as HTMLInputElement
).checked)}"></vscode-checkbox>
<vscode-text-field class="text-field" value="${label.key}"
>Filter By Label</vscode-text-field
<vscode-text-field
class="text-field"
value="${label.key}"
@input="${(event: Event) =>
(label.key = (event.target as HTMLInputElement).value)}"
>${this.labels.indexOf(label) === 0
? "Filter By Label"
: ""}</vscode-text-field
>
<vscode-text-field class="text-field" value="${label.value}"
>Value</vscode-text-field
<vscode-text-field
class="text-field"
value="${label.value}"
@input="${(event: Event) =>
(label.value = (event.target as HTMLInputElement).value)}"
>${this.labels.indexOf(label) === 0 ? "Value" : ""}</vscode-text-field
>
<div class="row gap-1 align-end">
<vscode-button
Expand All @@ -356,13 +377,16 @@ export class KdbDataSourceView extends LitElement {
aria-label="Remove Label"
appearance="secondary"
@click="${() => {
if (this.labels.length > 1) {
if (this.labels.length > 0) {
const index = this.labels.indexOf(label);
const value = this.labels;
this.labels = [];
this.requestUpdate();
queueMicrotask(() => {
value.splice(index, 1);
if (value.length === 0) {
value.push(createLabel());
}
this.labels = value;
this.requestUpdate();
});
Expand All @@ -385,8 +409,11 @@ export class KdbDataSourceView extends LitElement {
event.target as HTMLInputElement
).checked)}"></vscode-checkbox>
<div class="dropdown-container">
<label>Sort By</label>
<vscode-dropdown class="dropdown">
<label>${this.sorts.indexOf(sort) === 0 ? "Sort By" : ""}</label>
<vscode-dropdown
class="dropdown"
@change="${(event: Event) =>
(sort.column = (event.target as HTMLInputElement).value)}">
${this.renderColumnOptions(sort.column)}
</vscode-dropdown>
</div>
Expand All @@ -413,13 +440,16 @@ export class KdbDataSourceView extends LitElement {
aria-label="Remove Sort By"
appearance="secondary"
@click="${() => {
if (this.sorts.length > 1) {
if (this.sorts.length > 0) {
const index = this.sorts.indexOf(sort);
const value = this.sorts;
this.sorts = [];
this.requestUpdate();
queueMicrotask(() => {
value.splice(index, 1);
if (value.length === 0) {
value.push(createSort());
}
this.sorts = value;
this.requestUpdate();
});
Expand All @@ -441,12 +471,23 @@ export class KdbDataSourceView extends LitElement {
(agg.active = (
event.target as HTMLInputElement
).checked)}"></vscode-checkbox>
<vscode-text-field class="text-field" value="${agg.key}"
>Define Output Aggregate</vscode-text-field
<vscode-text-field
class="text-field"
value="${agg.key}"
@input="${(event: Event) =>
(agg.key = (event.target as HTMLInputElement).value)}"
>${this.aggs.indexOf(agg) === 0
? "Define Output Aggregate"
: ""}</vscode-text-field
>
<div class="dropdown-container">
<label>Choose Aggregation</label>
<vscode-dropdown class="dropdown">
<label
>${this.aggs.indexOf(agg) === 0 ? "Choose Aggregation" : ""}</label
>
<vscode-dropdown
class="dropdown"
@change="${(event: Event) =>
(agg.operator = (event.target as HTMLInputElement).value)}">
${aggOperators.map(
(operator) =>
html`<vscode-option
Expand All @@ -458,8 +499,11 @@ export class KdbDataSourceView extends LitElement {
</vscode-dropdown>
</div>
<div class="dropdown-container">
<label>By Column</label>
<vscode-dropdown class="dropdown">
<label>${this.aggs.indexOf(agg) === 0 ? "By Column" : ""}</label>
<vscode-dropdown
class="dropdown"
@change="${(event: Event) =>
(agg.column = (event.target as HTMLInputElement).value)}">
${this.renderColumnOptions(agg.column)}
</vscode-dropdown>
</div>
Expand All @@ -486,13 +530,16 @@ export class KdbDataSourceView extends LitElement {
aria-label="Remove Aggregation"
appearance="secondary"
@click="${() => {
if (this.aggs.length > 1) {
if (this.aggs.length > 0) {
const index = this.aggs.indexOf(agg);
const value = this.aggs;
this.aggs = [];
this.requestUpdate();
queueMicrotask(() => {
value.splice(index, 1);
if (value.length === 0) {
value.push(createAgg());
}
this.aggs = value;
this.requestUpdate();
});
Expand All @@ -515,8 +562,15 @@ export class KdbDataSourceView extends LitElement {
event.target as HTMLInputElement
).checked)}"></vscode-checkbox>
<div class="dropdown-container">
<label>Group Aggregation By</label>
<vscode-dropdown class="dropdown">
<label
>${this.groups.indexOf(group) === 0
? "Group Aggregation By"
: ""}</label
>
<vscode-dropdown
class="dropdown"
@change="${(event: Event) =>
(group.column = (event.target as HTMLInputElement).value)}">
${this.renderColumnOptions(group.column)}
</vscode-dropdown>
</div>
Expand All @@ -543,13 +597,16 @@ export class KdbDataSourceView extends LitElement {
aria-label="Remove Group By"
appearance="secondary"
@click="${() => {
if (this.groups.length > 1) {
if (this.groups.length > 0) {
const index = this.groups.indexOf(group);
const value = this.groups;
this.groups = [];
this.requestUpdate();
queueMicrotask(() => {
value.splice(index, 1);
if (value.length === 0) {
value.push(createGroup());
}
this.groups = value;
this.requestUpdate();
});
Expand Down

0 comments on commit 2d43a9c

Please sign in to comment.