-
Couldn't load subscription status.
- Fork 1
MILAB-3726: advanced filter component #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
erohinaelena
wants to merge
8
commits into
main
Choose a base branch
from
erohinaelena/MILAB-3726
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ceccbf6
pl advanced filter
erohinaelena fbf3c6d
use filtersUi
erohinaelena 1785beb
add 'position' for using dropdowns in 'stacks'
erohinaelena b1a3410
review fixes
erohinaelena 36d3f36
rename model -> filter
erohinaelena 80d5c34
review fixes
erohinaelena 39c398c
review fixes
erohinaelena a9209b0
fixes after rebase
erohinaelena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
238 changes: 238 additions & 0 deletions
238
etc/blocks/ui-examples/ui/src/pages/PlAdvancedFilterPage.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| <script setup lang="ts"> | ||
| import type { FilterSpec, ListOptionBase, SUniversalPColumnId } from '@platforma-sdk/model'; | ||
| import { PlAdvancedFilter, PlBlockPage, PlCheckbox, PlDropdown } from '@platforma-sdk/ui-vue'; | ||
| import { computed, ref, watch } from 'vue'; | ||
|
|
||
| const uniqueValuesByColumnOrAxisId: Record<string, ListOptionBase<string>[]> = { | ||
| 1: [{ value: '1', label: 'Value 1' }, { value: '2', label: 'Value 2' }], | ||
| 2: [{ value: '3', label: 'Value 3' }, { value: '4', label: 'Value 4' }], | ||
| 3: [{ value: '5', label: 'Value 5' }, { value: '6', label: 'Value 6' }], | ||
| }; | ||
| const uniqueValuesByAxisIdx: Record<string, Record<number, ListOptionBase<string>[]>> = { | ||
| 1: { 0: [{ value: 'axisValue1', label: 'Axis Value 1' }, { value: 'axisValue2', label: 'Axis Value 2' }] }, | ||
| }; | ||
|
|
||
| const options = [ | ||
| { | ||
| id: '1' as SUniversalPColumnId, | ||
| info: { | ||
| label: 'Column 1', | ||
| error: false, | ||
| axesToBeFixed: [{ | ||
| idx: 0, | ||
| label: 'Axis 1 label', | ||
| info: { | ||
| label: 'Axis 1 label', | ||
| spec: { type: 'String' as const, name: 'nameAxis1' }, | ||
| uniqueValues: [{ value: 'axisValue1', label: 'Axis Value 1' }, { value: 'axisValue2', label: 'Axis Value 2' }], | ||
| }, | ||
| }], | ||
| spec: { kind: 'PColumn' as const, valueType: 'Int' as const, name: 'c1', axesSpec: [{ type: 'String' as const, name: 'nameAxis1' }] }, | ||
| }, | ||
| }, | ||
| { | ||
| id: '2' as SUniversalPColumnId, | ||
| info: { | ||
| label: 'Column 2', | ||
| error: false, | ||
| spec: { kind: 'PColumn' as const, valueType: 'String' as const, name: 'c2', axesSpec: [] }, | ||
| }, | ||
| }, | ||
| { | ||
| id: '3' as SUniversalPColumnId, | ||
| info: { | ||
| label: 'Column 3', | ||
| error: false, | ||
| spec: { kind: 'PColumn' as const, valueType: 'Double' as const, name: 'c3', axesSpec: [] }, | ||
| }, | ||
| }, | ||
| ]; | ||
| const dndMode = ref(false); | ||
| const draggedId = ref<string | undefined>(); | ||
|
|
||
| async function searchOptions(id: string, str: string, axisIdx?: number) { | ||
| if (axisIdx !== undefined) { | ||
| return uniqueValuesByAxisIdx[id]?.[axisIdx] || []; | ||
| } | ||
| return uniqueValuesByColumnOrAxisId[id] || []; | ||
| } | ||
| async function searchModel(id: string, modelStr: string, axisIdx?: number) { | ||
| if (axisIdx !== undefined) { | ||
| const axisValues = uniqueValuesByAxisIdx[id]?.[axisIdx]; | ||
| return axisValues.find((v) => v.value === modelStr) || { value: modelStr, label: `Label of ${modelStr}` }; | ||
| } | ||
| const columnValues = uniqueValuesByColumnOrAxisId[id]; | ||
| return columnValues.find((v) => v.value === modelStr) || { value: modelStr, label: `Label of ${modelStr}` }; | ||
| } | ||
|
|
||
| const errorState = { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'patternEquals' as const, | ||
| column: 'someColumn' as SUniversalPColumnId, // error - column id is not from available columns | ||
| value: 'A', | ||
| }, | ||
| { | ||
| type: 'or' as const, | ||
| filters: [ | ||
| { | ||
| type: 'patternEquals' as const, | ||
| column: 'someColumn' as SUniversalPColumnId, // error - column id is not from available columns | ||
| value: 'A', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'isNA' as const, | ||
| column: 'someColumn' as SUniversalPColumnId, // error - column id is not from available columns | ||
| }, | ||
| { | ||
| type: 'isNotNA' as const, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's create objet with types for reusing it |
||
| column: 'someColumn' as SUniversalPColumnId, // error - column id is not from available columns | ||
| }, | ||
| ], | ||
| }, { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'patternContainSubsequence' as const, | ||
| column: 'someColumn' as SUniversalPColumnId, // error - column id is not from available columns | ||
| value: 'someString', | ||
| }, | ||
| ], | ||
| }], | ||
| }; | ||
|
|
||
| const normalState: FilterSpec = { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'or' as const, | ||
| filters: [{ | ||
| type: 'isNA' as const, | ||
| column: '1' as SUniversalPColumnId, | ||
| }, { | ||
| type: 'equal' as const, | ||
| column: '2' as SUniversalPColumnId, | ||
| x: 10, | ||
| }], | ||
| }, | ||
| { | ||
| type: 'and' as const, | ||
| filters: [ | ||
| { | ||
| type: 'isNotNA' as const, | ||
| column: '3' as SUniversalPColumnId, | ||
| }, { | ||
| type: 'patternFuzzyContainSubsequence' as const, | ||
| column: '3' as SUniversalPColumnId, | ||
| value: 'abc', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const filterStates: Record<string, FilterSpec> = { | ||
| normalState: normalState, | ||
| errorState: errorState, | ||
| emptyState: { | ||
| type: 'and', | ||
| filters: [], | ||
| }, | ||
| }; | ||
|
|
||
| const filtersModel = computed<FilterSpec>({ | ||
| get: () => { | ||
| return filterStates[selectedSavedFilters.value]; | ||
| }, | ||
| set: (v) => { | ||
| console.log('updated filters state: ', v); | ||
| }, | ||
| }); | ||
|
|
||
| const selectedSavedFilters = ref<keyof typeof filterStates>('normalState'); | ||
| const filterStatesOptions = [ | ||
| { value: 'normalState', label: 'Normal state' }, | ||
| { value: 'errorState', label: 'State with errors' }, | ||
| { value: 'emptyState', label: 'Empty state' }, | ||
| ]; | ||
|
|
||
| watch(() => filtersModel.value, (m) => { | ||
| console.log('Model changed: ', m); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <PlBlockPage> | ||
| <div :class="$style.controls"> | ||
| <PlCheckbox v-model="dndMode" >Drag-n-Drop mode</PlCheckbox> | ||
| <PlDropdown v-model="selectedSavedFilters" :options="filterStatesOptions" label="Examples" :style="{width: '300px'}" /> | ||
| </div> | ||
| <div :class="$style.block"> | ||
| <div v-if="dndMode" :class="$style.leftColumn"> | ||
| <div | ||
| v-for="option in options" | ||
| :key="option.id" | ||
| :draggable="dndMode ? 'true' : undefined" | ||
| :class="$style.columnChip" | ||
| @dragstart="() => draggedId = option.id" | ||
| @dragend="() => draggedId = undefined" | ||
| > | ||
| {{ option.info.label }} | ||
| </div> | ||
| </div> | ||
| <div :key="selectedSavedFilters" :class="$style.rightColumn" > | ||
| <PlAdvancedFilter | ||
| v-model="filtersModel" | ||
| :items="options" | ||
| :dnd-mode="dndMode" | ||
| :dragged-id="draggedId" | ||
| :search-options="searchOptions" | ||
| :search-model="searchModel" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </PlBlockPage> | ||
| </template> | ||
| <style module> | ||
| .controls { | ||
| display: flex; | ||
| gap: 16px; | ||
| } | ||
| .block { | ||
| display: flex; | ||
| height: 100%; | ||
| overflow: hidden; | ||
| } | ||
| .leftColumn { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| width: 280px; | ||
| padding: 10px; | ||
| margin: 10px; | ||
| border: 1px solid grey; | ||
| } | ||
| .rightColumn { | ||
| display: flex; | ||
| flex-direction: column; | ||
| width: 280px; | ||
| height: 100%; | ||
| overflow: auto; | ||
| } | ||
| .columnChip { | ||
| background: #fff; | ||
| border: 1px solid black; | ||
| border-radius: 6px; | ||
| padding: 6px; | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you highlight where exactly mistake in this state?