Skip to content

Commit

Permalink
feat(caluma): use new filter syntax of caluma
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ember-caluma` now requires Caluma version >=
8.0.0-beta.6
  • Loading branch information
anehx committed Jun 9, 2022
1 parent cc754d2 commit 7a00c03
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 1,786 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- dbdata:/var/lib/postgresql/data

caluma:
image: ghcr.io/projectcaluma/caluma:8.0.0-beta.3
image: ghcr.io/projectcaluma/caluma:8.0.0-beta.7
ports:
- "8000:8000"
depends_on:
Expand Down
10 changes: 5 additions & 5 deletions packages/distribution/addon/gql/fragments/inquiry.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fragment InquiryAnswerButtons on Case {
workItems(tasks: $buttonTasks, status: READY) {
workItems(filter: [{ tasks: $buttonTasks }, { status: READY }]) {
edges {
node {
id
Expand All @@ -15,7 +15,7 @@ fragment InquiryAnswerButtons on Case {

fragment InquiryDeadlineDocument on Document {
id
deadline: answers(question: $deadlineQuestion) {
deadline: answers(filter: [{ question: $deadlineQuestion }]) {
edges {
node {
id
Expand All @@ -29,7 +29,7 @@ fragment InquiryDeadlineDocument on Document {

fragment InquiryStatusDocument on Document {
id
status: answers(question: $statusQuestion) {
status: answers(filter: [{ question: $statusQuestion }]) {
edges {
node {
id
Expand All @@ -48,7 +48,7 @@ fragment InquiryStatusDocument on Document {
fragment InquiryRequest on Document {
id
...InquiryDeadlineDocument
info: answers(question: $infoQuestion) {
info: answers(filter: [{ question: $infoQuestion }]) {
edges {
node {
id
Expand Down Expand Up @@ -79,7 +79,7 @@ fragment InquiryDialog on WorkItem {
...InquiryAnswerButtons
document {
...InquiryStatusDocument
info: answers(questions: $answerInfoQuestions) {
info: answers(filter: [{ questions: $answerInfoQuestions }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mutation CompleteInquiryWorkItem(
id
...InquiryStatusDocument
}
workItems(tasks: $buttonTasks, status: READY) {
workItems(filter: [{ tasks: $buttonTasks }, { status: READY }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mutation AddFormQuestion($input: AddFormQuestionInput!, $search: String) {
form {
id
...FormInfo
questions(search: $search) {
questions(filter: [{ search: $search }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mutation RemoveFormQuestion($input: RemoveFormQuestionInput!, $search: String) {
form {
id
...FormInfo
questions(search: $search) {
questions(filter: [{ search: $search }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mutation ReorderFormQuestions(
form {
id
...FormInfo
questions(search: $search) {
questions(filter: [{ search: $search }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query CheckFormSlug($slug: String!) {
allForms(filter: [{ slug: $slug }]) {
allForms(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query CheckQuestionSlug($slug: String!) {
allQuestions(filter: [{ slug: $slug }]) {
allQuestions(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import FormInfo from '../fragments/form-info.graphql'

query FormEditorGeneral($slug: String!) {
allForms(filter: [{ slug: $slug }]) {
allForms(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import FieldQuestion, FieldTableQuestion, SimpleAnswer, SimpleQuestion from '../fragments/field.graphql'

query FormEditorQuestion($slug: String!) {
allQuestions(filter: [{ slug: $slug }]) {
allQuestions(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#import QuestionInfo from '../fragments/question-info.graphql'

query SearchFormQuestion($slug: String!, $search: String, $archived: Boolean) {
allForms(filter: [{ slug: $slug }]) {
query SearchFormQuestion($slug: String!, $search: String) {
allForms(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
slug
questions(search: $search, isArchived: $archived) {
questions(filter: [{ search: $search }]) {
edges {
node {
id
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/addon/routes/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class EditRoute extends Route {
{
query: gql`
query FormName($slug: String!) {
allForms(slug: $slug) {
allForms(filter: [{ slugs: [$slug] }]) {
edges {
node {
name
Expand Down
3 changes: 2 additions & 1 deletion packages/form-builder/addon/routes/edit/questions/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export default class EditQuestionsEditRoute extends Route {
{
query: gql`
query QuestionLabel($slug: String!) {
allQuestions(slug: $slug) {
allQuestions(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
label
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/form/addon/gql/queries/document-forms.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import FieldQuestion, FieldTableQuestion, SimpleQuestion from '../fragments/field.graphql'

query DocumentForms($slug: String!) {
allForms(filter: [{ slug: $slug }]) {
allForms(filter: [{ slugs: [$slug] }]) {
edges {
node {
id
Expand Down
2 changes: 1 addition & 1 deletion packages/form/addon/gql/queries/dynamic-options.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query DynamicOptions($question: String!) {
allQuestions(filter: [{ slug: $question }], first: 1) {
allQuestions(filter: [{ slugs: [$question] }], first: 1) {
edges {
node {
id
Expand Down
37 changes: 17 additions & 20 deletions packages/testing/addon/mirage-graphql/filters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ export default class BaseFilter {
}

_getFilterFns(rawFilters) {
const filters = Array.isArray(rawFilters)
? // new format
rawFilters
.filter((filter) => Object.keys(filter).length !== 0) // filter out empty filters
.map((filter) => {
const entries = Object.entries(filter);
const key = entries[0][0];
const value = entries[0][1];
const options = entries
.slice(1)
.reduce((opts, [k, v]) => ({ ...opts, [k]: v }), {});
const filters = rawFilters
.filter((filter) => Object.keys(filter).length !== 0) // filter out empty filters
.map((filter) => {
const entries = Object.entries(filter);
const key = entries[0][0];
const value = entries[0][1];
const options = entries
.slice(1)
.reduce((opts, [k, v]) => ({ ...opts, [k]: v }), {});

return { key, value, options };
})
: // old format
Object.entries(rawFilters).map(([key, value]) => ({
key,
value,
}));
return { key, value, options };
});

return filters.map(({ key, value, options = {} }) => {
const fn = this[key];
Expand Down Expand Up @@ -53,7 +46,7 @@ export default class BaseFilter {
}

filter(records, filters) {
return this._getFilterFns(filters?.filter ?? filters ?? []).reduce(
return this._getFilterFns(filters?.filter ?? []).reduce(
(recs, fn) => fn(recs),
this.sort(records, filters?.order)
);
Expand All @@ -64,7 +57,11 @@ export default class BaseFilter {
}

slug(records, value) {
return records.filter(({ slug }) => slug === value);
return this.slugs(records, [value]);
}

slugs(records, values) {
return records.filter(({ slug }) => values.includes(slug));
}

id(records, value) {
Expand Down
Loading

0 comments on commit 7a00c03

Please sign in to comment.